Skip to content

Commit

Permalink
[TrafficControl] Scale spam sample weight by request size
Browse files Browse the repository at this point in the history
  • Loading branch information
williampsmith committed Feb 27, 2025
1 parent e919e84 commit fa4df00
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/sui-json-rpc/src/traffic_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -79,6 +80,7 @@ fn handle_traffic_resp(
traffic_controller: &TrafficController,
client: Option<IpAddr>,
response: &MethodResponse,
request_size: Option<usize>,
) {
let error = response.as_error_code().map(ErrorCode::from);
traffic_controller.tally(TrafficTally {
Expand All @@ -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(),
});
}
Expand Down

0 comments on commit fa4df00

Please sign in to comment.