Skip to content

Commit

Permalink
Merge branch 'exc-1420' into 'master'
Browse files Browse the repository at this point in the history
chore: [EXC-1420] Update http outcalls price cost

This MR updates the price formula for HTTP outcalls which has the effect to reduce the cost overall. See IC post: https://forum.dfinity.org/t/a-new-price-function-for-https-outcalls/20838/5

New proposed formula: 

`(3M + 60K * n + 400 * request_size + 800 * max_response_bytes) * n` where n is the number of nodes in the subnet. 

See merge request dfinity-lab/public/ic!13150
  • Loading branch information
AlexandraZapuc committed Jun 26, 2023
2 parents 5a5ea03 + 860ecc0 commit 65cdba9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ http_archive(
package(default_visibility = ["//visibility:public"])
filegroup(name = "artifacts", srcs = glob(["build/*", "test-data/*"]), visibility = ["//visibility:public"])
""",
sha256 = "f8e43ed579ee4300150518a394d45a2d0ccaa0e04dc0835b245656de75282561",
urls = ["https://download.dfinity.systems/ic-ref/ic-ref-test-0.0.1-f3acf563-x86_64-linux.tar.gz"],
sha256 = "2b8cf324a10e1da98f5bd6469d9932653aaddf11d6f789b3a2fae82608684764",
urls = ["https://download.dfinity.systems/ic-ref/ic-ref-test-0.0.1-f698974a-x86_64-linux.tar.gz"],
)

# Deployed NNS canisters
Expand Down
24 changes: 18 additions & 6 deletions rs/config/src/subnet_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,19 @@ pub struct CyclesAccountManagerConfig {
/// Amount to charge for an ECDSA signature.
pub ecdsa_signature_fee: Cycles,

/// Baseline cost to charge for HTTP request.
pub http_request_baseline_fee: Cycles,
/// A linear factor of the baseline cost to be charged for HTTP requests per node.
/// The cost of an HTTP request is represented by a quadratic function due to the communication complexity of the subnet.
pub http_request_linear_baseline_fee: Cycles,

/// Fee per byte for networking and consensus work done for a http request or response.
/// A quadratic factor of the baseline cost to be charged for HTTP requests per node.
/// The cost of an HTTP request is represented by a quadratic function due to the communication complexity of the subnet.
pub http_request_quadratic_baseline_fee: Cycles,

/// Fee per byte for networking and consensus work done for an HTTP request per node.
pub http_request_per_byte_fee: Cycles,

/// Fee per byte for networking and consensus work done for an HTTP response per node.
pub http_response_per_byte_fee: Cycles,
}

impl CyclesAccountManagerConfig {
Expand All @@ -405,8 +413,10 @@ impl CyclesAccountManagerConfig {
gib_storage_per_second_fee: Cycles::new(127_000),
duration_between_allocation_charges: Duration::from_secs(10),
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
http_request_baseline_fee: Cycles::new(400_000_000),
http_request_per_byte_fee: Cycles::new(100_000),
http_request_linear_baseline_fee: Cycles::new(3_000_000),
http_request_quadratic_baseline_fee: Cycles::new(60_000),
http_request_per_byte_fee: Cycles::new(400),
http_response_per_byte_fee: Cycles::new(800),
}
}

Expand All @@ -433,8 +443,10 @@ impl CyclesAccountManagerConfig {
/// - zero cost if called from NNS subnet
/// - non-zero cost if called from any other subnet which is not NNS subnet
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
http_request_baseline_fee: Cycles::new(0),
http_request_linear_baseline_fee: Cycles::new(0),
http_request_quadratic_baseline_fee: Cycles::new(0),
http_request_per_byte_fee: Cycles::new(0),
http_response_per_byte_fee: Cycles::new(0),
}
}
}
Expand Down
36 changes: 30 additions & 6 deletions rs/cycles_account_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,12 +870,12 @@ impl CyclesAccountManager {
// Defaults to maximum response size.
None => MAX_CANISTER_HTTP_RESPONSE_BYTES,
};
let total_bytes = response_size + request_size.get();
self.scale_cost(
self.config.http_request_baseline_fee
+ self.config.http_request_per_byte_fee * total_bytes,
subnet_size,
)

(self.config.http_request_linear_baseline_fee
+ self.config.http_request_quadratic_baseline_fee * (subnet_size as u64)
+ self.config.http_request_per_byte_fee * request_size.get()
+ self.config.http_response_per_byte_fee * response_size)
* (subnet_size as u64)
}
}

Expand Down Expand Up @@ -964,4 +964,28 @@ mod tests {
0
);
}

#[test]
fn http_requets_fee_scale() {
let subnet_size: u64 = 34;
let reference_subnet_size: u64 = 13;
let request_size = NumBytes::from(17);
let cycles_account_manager = create_cycles_account_manager(reference_subnet_size as usize);

// Check the fee for a 13-node subnet.
assert_eq!(
cycles_account_manager.http_request_fee(
request_size,
None,
reference_subnet_size as usize,
),
Cycles::from(1_603_786_800u64) * reference_subnet_size
);

// Check the fee for a 34-node subnet.
assert_eq!(
cycles_account_manager.http_request_fee(request_size, None, subnet_size as usize),
Cycles::from(1_605_046_800u64) * subnet_size
);
}
}
21 changes: 12 additions & 9 deletions rs/execution_environment/tests/subnet_size_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,11 @@ fn calculate_http_request_cost(
// Defaults to maximum response size.
None => MAX_CANISTER_HTTP_RESPONSE_BYTES,
};
let total_bytes = response_size + request_size.get();
scale_cost(
config,
config.http_request_baseline_fee + config.http_request_per_byte_fee * total_bytes,
subnet_size,
)
(config.http_request_linear_baseline_fee
+ config.http_request_quadratic_baseline_fee * (subnet_size as u64)
+ config.http_request_per_byte_fee * request_size.get()
+ config.http_response_per_byte_fee * response_size)
* (subnet_size as u64)
}

fn calculate_sign_with_ecdsa_cost(
Expand Down Expand Up @@ -660,8 +659,10 @@ fn get_cycles_account_manager_config(subnet_type: SubnetType) -> CyclesAccountMa
/// explicit exception for requests originating from the NNS when the
/// charging occurs.
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
http_request_baseline_fee: Cycles::new(0),
http_request_linear_baseline_fee: Cycles::new(0),
http_request_quadratic_baseline_fee: Cycles::new(0),
http_request_per_byte_fee: Cycles::new(0),
http_response_per_byte_fee: Cycles::new(0),
},
SubnetType::Application | SubnetType::VerifiedApplication => CyclesAccountManagerConfig {
reference_subnet_size: DEFAULT_REFERENCE_SUBNET_SIZE,
Expand All @@ -681,8 +682,10 @@ fn get_cycles_account_manager_config(subnet_type: SubnetType) -> CyclesAccountMa
gib_storage_per_second_fee: Cycles::new(127_000),
duration_between_allocation_charges: Duration::from_secs(10),
ecdsa_signature_fee: ECDSA_SIGNATURE_FEE,
http_request_baseline_fee: Cycles::new(400_000_000),
http_request_per_byte_fee: Cycles::new(100_000),
http_request_linear_baseline_fee: Cycles::new(3_000_000),
http_request_quadratic_baseline_fee: Cycles::new(60_000),
http_request_per_byte_fee: Cycles::new(400),
http_response_per_byte_fee: Cycles::new(800),
},
}
}
Expand Down

0 comments on commit 65cdba9

Please sign in to comment.