diff --git a/crates/sui-json-rpc/src/traffic_control.rs b/crates/sui-json-rpc/src/traffic_control.rs index adaa8b064b464..1ca16077034b8 100644 --- a/crates/sui-json-rpc/src/traffic_control.rs +++ b/crates/sui-json-rpc/src/traffic_control.rs @@ -49,8 +49,9 @@ where if let Err(response) = handle_traffic_req(&traffic_controller, &client).await { response } else { + let req_size = req.params.as_ref().map(|p| p.get().len()); let response = service.call(req).await; - handle_traffic_resp(&traffic_controller, client, &response); + handle_traffic_resp(&traffic_controller, client, &response, req_size); response } } else { @@ -79,6 +80,7 @@ fn handle_traffic_resp( traffic_controller: &TrafficController, client: Option, response: &MethodResponse, + request_size: Option, ) { let error = response.as_error_code().map(ErrorCode::from); traffic_controller.tally(TrafficTally { @@ -89,14 +91,10 @@ fn handle_traffic_resp( let error_weight = normalize(e); (error_weight, error_type) }), - // For now, count everything as spam with equal weight - // on the rpc node side, including gas-charging endpoints - // such as `sui_executeTransactionBlock`, as this can enable - // node operators who wish to rate limit their transcation - // traffic and incentivize high volume clients to choose a - // suitable rpc provider (or run their own). Later we may want - // to provide a weight distribution based on the method being called. - spam_weight: Weight::one(), + // Scale the weight based on the request size + spam_weight: request_size.map_or(Weight::new(0.1).unwrap(), |size| { + Weight::new((size as f32 * 0.1).min(1.0)).unwrap() + }), timestamp: SystemTime::now(), }); }