Skip to content
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

Open
wants to merge 6 commits into
base: staging
Choose a base branch
from

Conversation

PatStiles
Copy link
Contributor

This pr adds three functions to aligned_sdk:

  • estimate_max_fee: Returns to the user there estimated max_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 the fee_per_proof of a batch size of size num_proofs_per_batch
  • compute_max_feee: returns the computing max_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.

Copy link
Contributor

@MauroToscano MauroToscano left a 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

@PatStiles
Copy link
Contributor Author

@MauroToscano tests added

Copy link
Contributor

@MauroToscano MauroToscano left a 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";
Copy link
Contributor

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

Comment on lines +41 to +48
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;
Copy link
Contributor

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.
Copy link
Collaborator

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,
Copy link
Collaborator

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?

Comment on lines +831 to +836
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();
Copy link
Collaborator

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:

  1. 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 than small_fee;
  2. We may end up hitting rate limits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants