-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API] Add X-Aptos-Gas-Used header #13237
Conversation
api/src/response.rs
Outdated
@@ -143,6 +143,8 @@ macro_rules! generate_error_response { | |||
#[oai(header = "X-Aptos-Block-Height")] Option<u64>, | |||
/// Oldest non-pruned block height of the chain | |||
#[oai(header = "X-Aptos-Oldest-Block-Height")] Option<u64>, | |||
/// The cost of the call in terms of gas | |||
#[oai(header = "x-aptos-gas-cost")] Option<u64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- nit: Any reason not to follow the existing case conventions? (
X-Aptos-Gas-Cost
) - Should we just be consistent with "gas used" as in the code? Especially with txn simulation I think it might confuse people in thinking this cost is "APT/octas" paid instead of just "gas units" used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Headers are actually meant to be lower case it turns out. Most libraries handle them case insensitively anyway. But I can make this follow the existing convention.
- Good call.
6a27200
to
b13552c
Compare
api/src/tests/simulation_test.rs
Outdated
@@ -70,6 +70,8 @@ const LARGE_TRANSFER_AMOUNT: u64 = 1_000_000_000; | |||
async fn test_simulate_transaction_with_valid_signature() { | |||
let mut context = new_test_context(current_function_name!()); | |||
let resp = simulate_aptos_transfer(&mut context, true, SMALL_TRANSFER_AMOUNT, 400).await; | |||
// Assert the gas used header is present. | |||
//assert!(resp.headers().contains_key("X-Aptos-Gas-Used")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oop let me address that.
ca7ce2d
to
528ad6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
api/src/tests/simulation_test.rs
Outdated
assert_eq!( | ||
resp.headers().get("X-Aptos-Gas-Used").unwrap(), | ||
expected_gas_used.to_string().as_str() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this looks a bit fragile to me, since the gas cost of a transaction could change if we modify or re-calibrate the gas schedule.
Would it make sense if you just assert that resp.headers().get("X-Aptos-Gas-Used").is_some()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that at first actually because I also thought it was fragile, but I wanted a better test. How about we assert gas is at least > 0?
/// The cost of the call in terms of gas | ||
#[oai(header = "X-Aptos-Gas-Used")] Option<u64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this belongs here, would it be on every response? I guess it shows up only on simulations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View function and simulation yeah.
api/src/tests/view_function.rs
Outdated
// Confirm the gas used header is present and has the expected value. | ||
assert_eq!(resp.headers().get("X-Aptos-Gas-Used").unwrap(), "2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably best to just check it exists, rather than that it's 2
528ad6c
to
aa3785c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
This PR makes the simulate and view function endpoints return how much gas they used. We will use this for compute unit based ratelimiting in API Gateway.
Type of Change
Which Components or Systems Does This Change Impact?
How Has This Been Tested?
New API test. I can add one for simulation too if we want.
Key Areas to Review
Consider if there is a better, easier way to do this than with a header.
Checklist