Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions canister/src/rpc_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl GetAccountInfoRequest {
let providers = Providers::new(rpc_sources, consensus_strategy.clone())?;
let max_response_bytes = config
.response_size_estimate
.unwrap_or(1024 + HEADER_SIZE_LIMIT);
.unwrap_or(512 + HEADER_SIZE_LIMIT);

Ok(MultiRpcRequest::new(
providers,
Expand Down Expand Up @@ -162,15 +162,17 @@ impl GetBlockRequest {
}

fn response_size_estimate(params: &json::GetBlockParams) -> u64 {
let cycles = match params.get_transaction_details() {
let mut cycles = HEADER_SIZE_LIMIT;
cycles += match params.get_transaction_details() {
Some(TransactionDetails::Accounts) => CyclesCostEstimator::DEFAULT_MAX_RESPONSE_BYTES,
Some(TransactionDetails::Signatures) => 262_144,
Some(TransactionDetails::None) | None => 2_048,
Some(TransactionDetails::Signatures) => 256 * 1024,
Some(TransactionDetails::None) | None => 512,
};
match params.include_rewards() {
Some(true) | None => CyclesCostEstimator::DEFAULT_MAX_RESPONSE_BYTES.min(cycles + 256),
Some(false) => cycles,
}
cycles += match params.include_rewards() {
Some(true) | None => 256,
Some(false) => 0,
};
CyclesCostEstimator::DEFAULT_MAX_RESPONSE_BYTES.min(cycles)
}
}

Expand Down Expand Up @@ -246,7 +248,7 @@ impl GetSlotRequest {
let providers = Providers::new(rpc_sources, consensus_strategy.clone())?;
let max_response_bytes = config
.response_size_estimate
.unwrap_or(1024 + HEADER_SIZE_LIMIT);
.unwrap_or(64 + HEADER_SIZE_LIMIT);
let rounding_error = config.rounding_error.unwrap_or_default();

Ok(MultiRpcRequest::new(
Expand Down Expand Up @@ -303,7 +305,7 @@ impl GetTokenAccountBalanceRequest {
let providers = Providers::new(rpc_sources, consensus_strategy.clone())?;
let max_response_bytes = config
.response_size_estimate
.unwrap_or(1024 + HEADER_SIZE_LIMIT);
.unwrap_or(256 + HEADER_SIZE_LIMIT);

Ok(MultiRpcRequest::new(
providers,
Expand All @@ -330,8 +332,7 @@ impl GetTransactionRequest {
let providers = Providers::new(rpc_sources, consensus_strategy.clone())?;
let max_response_bytes = config
.response_size_estimate
// TODO XC-343: Revisit this when we add support for more values of `encoding`
.unwrap_or(10 * 1024 + HEADER_SIZE_LIMIT);
.unwrap_or(8 * 1024 + HEADER_SIZE_LIMIT);

Ok(MultiRpcRequest::new(
providers,
Expand Down
10 changes: 5 additions & 5 deletions integration_tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ mod cycles_cost_tests {
check(
&setup,
client.get_account_info(USDC_PUBLIC_KEY),
1_793_744_800,
1_752_822_400,
)
.await;
}
Expand All @@ -1666,8 +1666,8 @@ mod cycles_cost_tests {
for transaction_details in TransactionDetails::iter() {
let expected_cycles_cost = match transaction_details {
TransactionDetails::Accounts => 164_743_232_800,
TransactionDetails::None => 1_731_076_000,
TransactionDetails::Signatures => 22_955_154_400,
TransactionDetails::None => 1_772_855_200,
TransactionDetails::Signatures => 23_122_271_200,
};
check(
&setup,
Expand Down Expand Up @@ -1707,7 +1707,7 @@ mod cycles_cost_tests {
check(
&setup,
client.get_slot().with_params(GetSlotParams::default()),
1_792_548_000,
1_714_103_200,
)
.await;
}
Expand All @@ -1723,7 +1723,7 @@ mod cycles_cost_tests {
check(
&setup,
client.get_transaction(some_signature()),
2_548_381_600,
2_381_264_800,
)
.await;
}
Expand Down