-
Notifications
You must be signed in to change notification settings - Fork 335
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
feat(utils): Utility functions for computing and estimating the max_fee
of a proof
#1045
base: staging
Are you sure you want to change the base?
Conversation
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.
Decouple calculation from the fetching of the GasCost, and add tests assuming you have the GasCost. It can be just checking that one is bigger than another one
@MauroToscano tests added |
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.
Mention this function in the one that is used to send a task, with ///, so the user knows this one should be used to get the right estimation
@@ -35,6 +35,18 @@ use futures_util::{ | |||
StreamExt, TryStreamExt, | |||
}; | |||
|
|||
//Public constants for convenience | |||
pub const HOLESKY_PUBLIC_RPC_URL: &str = "https://ethereum-holesky-rpc.publicnode.com"; |
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.
this is used only for testing, it should be in the testing section at the end of the file
const AGGREGATOR_GAS_COST: u128 = 400_000; | ||
const ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF: u128 = 13_000; | ||
const CONSTANT_GAS_COST: u128 = ((AGGREGATOR_GAS_COST * DEFAULT_AGGREGATOR_FEE_MULTIPLIER) | ||
/ DEFAULT_AGGREGATOR_FEE_DIVIDER) | ||
+ BATCHER_SUBMISSION_BASE_GAS_COST; | ||
const DEFAULT_AGGREGATOR_FEE_MULTIPLIER: u128 = 3; // to set the feeForAggregator variable higher than what was calculated | ||
const DEFAULT_AGGREGATOR_FEE_DIVIDER: u128 = 2; | ||
const BATCHER_SUBMISSION_BASE_GAS_COST: u128 = 125_000; |
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.
duplication of these constants make the code difficult to maintain. If here is a good place for them to be held until we centralize all constants into some file, then remove them from other places and make them be imported from here
Returns the estimated `max_fee` depending on the batch inclusion preference of the user, based on the max priority gas price. | ||
NOTE: The `max_fee` is computed from an rpc nodes max priority gas price. | ||
For batch cost estimates we estimate a batch will have ~32 proofs present. |
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.
Batch size sounds like the kind of parameter you might want to tune eventually. It should probably be a global constant instead of a magic number, so we can change it in one place.
let proof_price = match estimate { | ||
PriceEstimate::Min => fee_per_proof, | ||
PriceEstimate::Default => U256::from(10) * fee_per_proof, | ||
PriceEstimate::Instant => U256::from(32) * fee_per_proof, |
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 will guess: this is the batch size, because "instant" means "close the batch now, even if this is the only proof, I'll pay for the whole batch if necessary", right?
let small_fee = compute_max_fee(HOLESKY_PUBLIC_RPC_URL, 5, 20) | ||
.await | ||
.unwrap(); | ||
let large_fee = compute_max_fee(HOLESKY_PUBLIC_RPC_URL, 5, 10) | ||
.await | ||
.unwrap(); |
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 worried these tests may be flaky, for the following reasons:
- Querying the API means it can change with time, due to congestion, so at some points in time where prices lower
large_fee
may become cheaper thansmall_fee
; - We may end up hitting rate limits.
This pr adds three functions to
aligned_sdk
:estimate_max_fee
: Returns to the user there estimatedmax_fee
: Min, Default, Instant based on a theoretical batch of 32 proofs. 32 was decided upon as a suggested arbitrary large batch size.fee_per_proof
: Returns thefee_per_proof
of a batch size of sizenum_proofs_per_batch
compute_max_feee
: returns the computingmax_fee
for a proof based on (num_proofs
/num_proofs_per_batch
).It deduplicates constants originally found in
aligned-batcher
that can be imported once #964 is completed.