forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add instructions on how to use the dynamic fee pallet (parityte…
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Dynamic fee pallet | ||
|
||
The dynamic fee pallet allows a Substrate blockchain with Frontier to simulate | ||
the functionality of Ethereum dynamic fee adjustment. | ||
|
||
## Overview | ||
|
||
The pallet works by keeping track of the current minimum gas price in a | ||
Substrate storage `MinGasPrice`. Each Substrate block, the proposer can submit | ||
an inherent extrinsic `note_min_gas_price_target`. When a block is built, the | ||
minimum gas price is adjusted similar to Ethereum's algorithm. | ||
|
||
## Usage | ||
|
||
To use the dynamic fee pallet, first include the pallet in runtime by | ||
implementing `pallet_dynamic_fee::Config`. The `MinGasPriceBoundDivisor` is a | ||
divisor used to set how much the minimum gas price is adjusted each block. You | ||
can set it to `1024` to get the same algorithm as Ethereum. After implementing | ||
`pallet_dynamic_fee::Config`, include the pallet in the runtime definition. | ||
|
||
With the pallet in place, you can now extend the node to allow it to vote on the | ||
minimum gas price target, via the inherent data providers. Locate in the node | ||
service code where the `InherentDataProviders` struct is built, and add | ||
`pallet_dynamic_fee`'s inherent data provider. The inherent data provider | ||
requires a target gas price parameter to be provided. For that, you simply need | ||
to add a new custom command line argument. | ||
|
||
An example code snippet is shown below: | ||
|
||
```rust | ||
fn inherent_data_providers( | ||
target_min_gas_price: U256 | ||
) -> Result<sp_inherents::InherentDataProviders, ServiceError> { | ||
let inherent_data_providers = sp_inherents::InherentDataProviders::new(); | ||
|
||
if !inherent_data_providers.has_provider(&pallet_dynamic_fee::INHERENT_IDENTIFIER) { | ||
inherent_data_providers | ||
.register_provider(pallet_dynamic_fee::InherentDataProvider(target_min_gas_price)) | ||
.map_err(Into::into) | ||
.map_err(sp_consensus::Error::InherentData)?; | ||
} | ||
|
||
Ok(inherent_data_providers) | ||
} | ||
``` |