-
Notifications
You must be signed in to change notification settings - Fork 346
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
Use transaction-payment
's congestion modifier for Ethereum base-fee
#1765
Changes from all commits
a0fc51b
52bf3f8
a182d56
2bdfb9e
b3e84c4
3af5c6c
94e6e0e
a83778d
cac3a2e
167d566
4b58131
66a1d9b
86e6d41
e55c392
ccce143
751bede
55058d5
25fdd29
928a03e
4675940
6382888
c29b28e
da46a52
5d403fb
3240bcd
dd71c93
efa30ac
e97ed70
4648b30
90a7029
8fdc4b1
6a8f12c
840f0f3
78b3dfb
3867c06
9b45a6a
0b3b938
6291c7d
50c275d
ab6a537
43d9c97
029f83e
a5eb9d3
62c355a
a6b186e
15271c1
0e6a7f4
05313b3
174aad7
4cfd346
240efa8
a80e059
4d4f14d
9456ed9
bafec82
284ece4
6d3cd9f
c95da99
683feff
ea1c5b3
a847654
98d7374
9da3ce9
3d0ecb6
0a9f1be
370c19f
1c2c5ec
5bb3b49
5f2511d
fc0ab3d
86978cf
84b9f5d
0c3866e
d56ea3f
14f9b7a
5988fb2
0890e92
160f82f
23c9942
d84a467
16fa4e8
dd5b4cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,7 +196,7 @@ pub fn native_version() -> NativeVersion { | |
} | ||
|
||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); | ||
const NORMAL_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_mul(3).saturating_div(4); | ||
pub const NORMAL_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_mul(3).saturating_div(4); | ||
// Here we assume Ethereum's base fee of 21000 gas and convert to weight, but we | ||
// subtract roughly the cost of a balance transfer from it (about 1/3 the cost) | ||
// and some cost to account for per-byte-fee. | ||
|
@@ -388,27 +388,37 @@ parameter_types! { | |
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25); | ||
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to | ||
/// change the fees more rapidly. This low value causes changes to occur slowly over time. | ||
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); | ||
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(4, 1_000); | ||
/// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure | ||
/// that combined with `AdjustmentVariable`, we can recover from the minimum. | ||
/// See `multiplier_can_grow_from_zero` in integration_tests.rs. | ||
/// This value is currently only used by pallet-transaction-payment as an assertion that the | ||
/// next multiplier is always > min value. | ||
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128); | ||
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000); | ||
/// Maximum multiplier. We pick a value that is expensive but not impossibly so; it should act | ||
/// as a safety net. | ||
pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128); | ||
pub PrecompilesValue: MoonbasePrecompiles<Runtime> = MoonbasePrecompiles::<_>::new(); | ||
pub WeightPerGas: Weight = Weight::from_ref_time(WEIGHT_PER_GAS); | ||
} | ||
|
||
pub struct FixedGasPrice; | ||
impl FeeCalculator for FixedGasPrice { | ||
pub struct TransactionPaymentAsGasPrice; | ||
impl FeeCalculator for TransactionPaymentAsGasPrice { | ||
fn min_gas_price() -> (U256, Weight) { | ||
( | ||
(1 * currency::GIGAWEI * currency::SUPPLY_FACTOR).into(), | ||
Weight::zero(), | ||
) | ||
// TODO: transaction-payment differs from EIP-1559 in that its tip and length fees are not | ||
// scaled by the multiplier, which means its multiplier will be overstated when | ||
// applied to an ethereum transaction | ||
// note: transaction-payment uses both a congestion modifier (next_fee_multiplier, which is | ||
// updated once per block in on_finalize) and a 'WeightToFee' implementation. Our | ||
// runtime implements this as a 'ConstantModifier', so we can get away with a simple | ||
// multiplication here. | ||
// It is imperative that `saturating_mul_int` be performed as late as possible in the | ||
// expression since it involves fixed point multiplication with a division by a fixed | ||
// divisor. This leads to truncation and subsequent precision loss if performed too early. | ||
// This can lead to min_gas_price being same across blocks even if the multiplier changes. | ||
// There's still some precision loss when the final `gas_price` (used_gas * min_gas_price) | ||
// is computed in frontier, but that's currently unavoidable. | ||
let min_gas_price = TransactionPayment::next_fee_multiplier() | ||
.saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128)); | ||
(min_gas_price.into(), Weight::zero()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that we read There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this should be more than 0, will PR a fix soon :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @notlesh Think I vaguely recall us discussing this and you mentioned that since this is read way too often, we could offer this for free (since it's cached more or less). Not sure if that condition still applied. |
||
} | ||
} | ||
|
||
|
@@ -451,7 +461,7 @@ where | |
moonbeam_runtime_common::impl_on_charge_evm_transaction!(); | ||
|
||
impl pallet_evm::Config for Runtime { | ||
type FeeCalculator = FixedGasPrice; | ||
type FeeCalculator = TransactionPaymentAsGasPrice; | ||
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>; | ||
type WeightPerGas = WeightPerGas; | ||
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>; | ||
|
@@ -1131,7 +1141,7 @@ construct_runtime! { | |
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 4, | ||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 5, | ||
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>} = 6, | ||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 7, | ||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Config, Event<T>} = 7, | ||
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 8, | ||
EthereumChainId: pallet_ethereum_chain_id::{Pallet, Storage, Config} = 9, | ||
EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 10, | ||
|
@@ -1389,7 +1399,6 @@ mod tests { | |
5_u8 | ||
); | ||
assert_eq!(STORAGE_BYTE_FEE, Balance::from(100 * MICROUNIT)); | ||
assert_eq!(FixedGasPrice::min_gas_price().0, (1 * GIGAWEI).into()); | ||
|
||
// democracy minimums | ||
assert_eq!( | ||
|
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.
Shouldn't we add a migration to initialize the
FeeMultiplier
amount? Today it seems to be worth 1000000000000 on moonbase, moonriver in moonbeam, which is not in the expected range.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.
Good question. I've explored this pretty thoroughly, here's my summary:
transaction-payment
will kick in immediately at the end of the runtime upgrade blockA migration could force the multiplier bounds to be enforced earlier (before extrinsics are charged fees for the runtime upgrade block), but this doesn't seem like a big deal to me.
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.
To elaborate:
In
transaction-payment
'son_finalize()
, theTargetedFeeAdjustment::convert()
will check the new min and max bounds and enforce them. This value will then be updated in pallet storage and will cause the next block to have fees within bounds.