-
Notifications
You must be signed in to change notification settings - Fork 283
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: add priority fees to gas settings #10763
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b84c30
Add priority fees.
LeilaWang f30bba9
Add missing field.
LeilaWang 4f74c79
Update fee computation in trace.
LeilaWang f3c1b9b
Add optional max fees to cancel-tx.
LeilaWang 2304ed9
Merge remote-tracking branch 'origin/master' into lw/priority_fees
LeilaWang f7d99ae
Fix after merge.
LeilaWang 3c1ed35
Merge remote-tracking branch 'origin/master' into lw/priority_fees
LeilaWang 76daa78
Merge remote-tracking branch 'origin/master' into lw/priority_fees
LeilaWang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...up-lib/src/base/components/private_base_rollup_output_composer/compute_transaction_fee.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use types::abis::{gas::Gas, gas_fees::GasFees, gas_settings::GasSettings}; | ||
|
||
pub fn compute_transaction_fee( | ||
gas_fees: GasFees, | ||
gas_settings: GasSettings, | ||
gas_used: Gas, | ||
) -> Field { | ||
let max_priority_fees = gas_settings.max_priority_fees_per_gas; | ||
let max_fees = gas_settings.max_fees_per_gas; | ||
// max_fees are guaranteed to be greater than or equal to gas_fees, which is checked in tube_data_validator. | ||
let priority_fees = GasFees::new( | ||
dep::types::utils::field::min( | ||
max_priority_fees.fee_per_da_gas, | ||
max_fees.fee_per_da_gas - gas_fees.fee_per_da_gas, | ||
), | ||
dep::types::utils::field::min( | ||
max_priority_fees.fee_per_l2_gas, | ||
max_fees.fee_per_l2_gas - gas_fees.fee_per_l2_gas, | ||
), | ||
); | ||
|
||
let total_fees = GasFees::new( | ||
gas_fees.fee_per_da_gas + priority_fees.fee_per_da_gas, | ||
gas_fees.fee_per_l2_gas + priority_fees.fee_per_l2_gas, | ||
); | ||
|
||
gas_used.compute_fee(total_fees) | ||
} | ||
|
||
mod tests { | ||
use super::compute_transaction_fee; | ||
use types::abis::{gas::Gas, gas_fees::GasFees, gas_settings::GasSettings}; | ||
|
||
struct TestBuilder { | ||
gas_fees: GasFees, | ||
gas_settings: GasSettings, | ||
gas_used: Gas, | ||
} | ||
|
||
impl TestBuilder { | ||
pub fn new() -> Self { | ||
let gas_fees = GasFees::new(12, 34); | ||
|
||
let mut gas_settings = GasSettings::empty(); | ||
gas_settings.max_fees_per_gas = GasFees::new(56, 78); | ||
gas_settings.max_priority_fees_per_gas = GasFees::new(5, 7); | ||
|
||
let gas_used = Gas::new(2, 3); | ||
|
||
TestBuilder { gas_fees, gas_settings, gas_used } | ||
} | ||
|
||
pub fn compute(self) -> Field { | ||
compute_transaction_fee(self.gas_fees, self.gas_settings, self.gas_used) | ||
} | ||
} | ||
|
||
#[test] | ||
fn compute_transaction_fee_default() { | ||
let builder = TestBuilder::new(); | ||
let fee = builder.compute(); | ||
|
||
// Make sure the following value matches the one in `transaction_fee.test.ts` in `circuits.js`. | ||
// Paying gas_fees + max_priority_fees. | ||
let expected_fee = 2 * (12 + 5) + 3 * (34 + 7); | ||
assert_eq(fee, expected_fee); | ||
} | ||
|
||
#[test] | ||
fn compute_transaction_fee_zero_priority_fees() { | ||
let mut builder = TestBuilder::new(); | ||
|
||
builder.gas_settings.max_priority_fees_per_gas = GasFees::empty(); | ||
|
||
let fee = builder.compute(); | ||
|
||
// Make sure the following value matches the one in `transaction_fee.test.ts` in `circuits.js`. | ||
// Paying gas_fees only. | ||
let expected_fee_empty_priority = 2 * 12 + 3 * 34; | ||
assert_eq(fee, expected_fee_empty_priority); | ||
} | ||
|
||
#[test] | ||
fn compute_transaction_fee_capped_max_fees() { | ||
let mut builder = TestBuilder::new(); | ||
|
||
// Increase gas_fees so that gas_fees + max_priority_fees > max_fees. | ||
builder.gas_fees = GasFees::new(53, 74); | ||
|
||
let fee = builder.compute(); | ||
|
||
// Make sure the following value matches the one in `transaction_fee.test.ts` in `circuits.js`. | ||
// max_fees were applied. | ||
let expected_max_fee = 2 * 56 + 3 * 78; | ||
assert_eq(fee, expected_max_fee); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...circuits/crates/rollup-lib/src/base/components/private_base_rollup_output_composer/mod.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod compute_transaction_fee; | ||
|
||
pub use compute_transaction_fee::compute_transaction_fee; | ||
|
||
// TODO: Move everything that composes the output of private base rollup to this component. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think we also need to update fee calculation in
AvmTraceBuilder::pay_fee
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.
Oh right! Didn't realise fee computation is already implemented there.