diff --git a/src/accounting.rs b/src/accounting.rs index 45a3517f..6655834e 100644 --- a/src/accounting.rs +++ b/src/accounting.rs @@ -5,7 +5,7 @@ use crate::*; /// Returns the cycles cost of a JSON-RPC request. pub fn get_json_rpc_cost( source: &ResolvedJsonRpcSource, - payload_size_bytes: usize, + payload_size_bytes: u64, max_response_bytes: u64, ) -> u128 { match source { @@ -22,7 +22,7 @@ pub fn get_json_rpc_cost( /// Returns the cycles cost of a Candid-RPC request. pub fn get_candid_rpc_cost( provider: &Provider, - payload_size_bytes: usize, + payload_size_bytes: u64, effective_response_size_estimate: u64, ) -> u128 { let base_cost = 400_000_000u128 + 100_000u128 * (2 * effective_response_size_estimate as u128); @@ -35,11 +35,11 @@ pub fn get_candid_rpc_cost( /// Calculates the baseline cost of sending a JSON-RPC request using HTTP outcalls. pub fn get_http_request_cost( api: &RpcApi, - payload_size_bytes: usize, + payload_size_bytes: u64, max_response_bytes: u64, ) -> u128 { let nodes_in_subnet = UNSTABLE_SUBNET_SIZE.with(|n| *n.borrow()); - let ingress_bytes = (payload_size_bytes + api.url.len()) as u128 + INGRESS_OVERHEAD_BYTES; + let ingress_bytes = payload_size_bytes as u128 + api.url.len() as u128 + INGRESS_OVERHEAD_BYTES; let base_cost = INGRESS_MESSAGE_RECEIVED_COST + INGRESS_MESSAGE_BYTE_RECEIVED_COST * ingress_bytes + HTTP_OUTCALL_REQUEST_COST @@ -48,7 +48,7 @@ pub fn get_http_request_cost( } /// Calculate the additional cost for calling a registered JSON-RPC provider. -pub fn get_provider_cost(provider: &Provider, payload_size_bytes: usize) -> u128 { +pub fn get_provider_cost(provider: &Provider, payload_size_bytes: u64) -> u128 { let nodes_in_subnet = UNSTABLE_SUBNET_SIZE.with(|m| *m.borrow()); let cost_per_node = provider.cycles_per_call as u128 + provider.cycles_per_message_byte as u128 * payload_size_bytes as u128; @@ -69,7 +69,7 @@ fn test_request_cost() { url: url.to_string(), headers: vec![], }), - payload.len(), + payload.len() as u64, 1000, ); let base_cost_10_extra_bytes = get_json_rpc_cost( @@ -77,7 +77,7 @@ fn test_request_cost() { url: url.to_string(), headers: vec![], }), - payload.len() + 10, + payload.len() as u64 + 10, 1000, ); let estimated_cost_10_extra_bytes = base_cost @@ -113,7 +113,7 @@ fn test_provider_cost() { }; let base_cost = get_provider_cost( &provider, - "{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}".len(), + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}".len() as u64, ); let provider_10_extra_bytes = Provider { @@ -130,7 +130,8 @@ fn test_provider_cost() { }; let base_cost_10_extra_bytes = get_provider_cost( &provider_10_extra_bytes, - "{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}".len() + 10, + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}".len() as u64 + + 10, ); assert_eq!( base_cost + (10 * 2 + 1000) * nodes_in_subnet as u128, diff --git a/src/candid_rpc.rs b/src/candid_rpc.rs index d9fb82b4..476e84b3 100644 --- a/src/candid_rpc.rs +++ b/src/candid_rpc.rs @@ -39,7 +39,7 @@ impl RpcTransport for CanisterTransport { request .body .as_ref() - .map(|bytes| bytes.len()) + .map(|bytes| bytes.len() as u64) .unwrap_or_default(), effective_response_size_estimate, ); diff --git a/src/http.rs b/src/http.rs index 10486155..de93cc1f 100644 --- a/src/http.rs +++ b/src/http.rs @@ -19,7 +19,7 @@ pub async fn do_json_rpc_request( add_metric!(err_no_permission, 1); return Err(ProviderError::NoPermission.into()); } - let cycles_cost = get_json_rpc_cost(&source, json_rpc_payload.len(), max_response_bytes); + let cycles_cost = get_json_rpc_cost(&source, json_rpc_payload.len() as u64, max_response_bytes); let (api, provider) = match source { ResolvedJsonRpcSource::Api(api) => (api, None), ResolvedJsonRpcSource::Provider(provider) => (provider.api(), Some(provider)), @@ -81,7 +81,7 @@ pub async fn do_http_request_with_metrics( request .body .as_ref() - .map(|bytes| bytes.len()) + .map(|bytes| bytes.len() as u64) .unwrap_or_default(), ); PROVIDERS.with(|p| { diff --git a/src/main.rs b/src/main.rs index 75638514..829fabb1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,7 +116,7 @@ fn request_cost( ) -> Result { Ok(get_json_rpc_cost( &source.resolve().unwrap(), - json_rpc_payload.len(), + json_rpc_payload.len() as u64, max_response_bytes, )) }