feemarket

package
v0.0.1-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

Additive Increase Multiplicative Decrease (AIMD) EIP-1559

Overview

Definitions:

  • Target Block Size: This is the target block gas consumption.
  • Max Block Size: This is the maximum block gas consumption.

This plugin implements the AIMD (Additive Increase Multiplicative Decrease) EIP-1559 fee market as described in this AIMD EIP-1559 research publication.

The AIMD EIP-1559 fee market is a slight modification to Ethereum's EIP-1559 fee market. Specifically it introduces the notion of a adaptive learning rate which scales the base fee (reserve price to be included in a block) more aggressively when the network is congested and less aggressively when the network is not congested. This is primarily done to address the often cited criticism of EIP-1559 that it's base fee often lags behind the current demand for block space. The learning rate on Ethereum is effectively hard-coded to be 12.5%, which means that between any two blocks the base fee can maximally increase by 12.5% or decrease by 12.5%. Additionally, AIMD EIP-1559 differs from Ethereum's EIP-1559 by considering a configured time window (number of blocks) to consider when calculating and comparing target block utilization and current block utilization.

Parameters

Ethereum EIP-1559

Base EIP-1559 currently utilizes the following parameters to compute the base fee:

  • PreviousBaseFee: This is the base fee from the previous block. This must be a value that is greater than 0.
  • TargetBlockSize: This is the target block size in bytes. This must be a value that is greater than 0.
  • PreviousBlockSize: This is the block size from the previous block.

The calculation for the updated base fee for the next block is as follows:

currentBaseFee := previousBaseFee * (1 + 0.125 * (currentBlockSize - targetBlockSize) / targetBlockSize)
AIMD EIP-1559

AIMD EIP-1559 introduces a few new parameters to the EIP-1559 fee market:

  • Alpha: This is the amount we additively increase the learning rate when the target utilization is less than the current utilization i.e. the block was more full than the target size. This must be a value that is greater than 0.0.
  • Beta: This is the amount we multiplicatively decrease the learning rate when the target utilization is greater than the current utilization i.e. the block was less full than the target size. This must be a value that is greater than 0.0.
  • Window: This is the number of blocks we look back to compute the current utilization. This must be a value that is greater than 0. Instead of only utilizing the previous block's utilization, we now consider the utilization of the previous Window blocks.
  • Gamma: This determines whether you are additively increase or multiplicatively decreasing the learning rate based on the target and current block utilization. This must be a value that is between [0, 1]. For example, if Gamma = 0.25, then we multiplicatively decrease the learning rate if the average ratio of current block size to max block size over some window of blocks is within (0.25, 0.75) and additively increase it if outside that range.
  • MaxLearningRate: This is the maximum learning rate that can be applied to the base fee. This must be a value that is between [0, 1].
  • MinLearningRate: This is the minimum learning rate that can be applied to the base fee. This must be a value that is between [0, 1].
  • Delta: This is a trailing constant that is used to smooth the learning rate. In order to further converge the long term net gas usage and net gas goal, we introduce another integral term which tracks how much gas off from 0 gas we’re at. We add a constant c which basically forces the fee to slowly trend in some direction until this has gone to 0.

The calculation for the updated base fee for the next block is as follows:


// sumBlockSizesInWindow returns the sum of the block sizes in the window.
blockConsumption := sumBlockSizesInWindow(window) / (window * maxBlockSize)

if blockConsumption < gamma || blockConsumption > 1 - gamma {
    // MAX_LEARNING_RATE is a constant that configured by the chain developer
    newLearningRate := min(MaxLearningRate, alpha + currencyLearningRate)
} else {
    // MIN_LEARNING_RATE is a constant that configured by the chain developer
    newLearningRate := max(MinLearningRate, beta * currencyLearningRate)
}

// netGasDelta returns the net gas difference between every block in the window and the target block size.
newBaseFee := currentBaseFee * (1 + newLearningRate * (currentBlockSize - targetBlockSize) / targetBlockSize) + delta * netGasDelta(window)

Examples

Assume the following parameters:

  • TargetBlockSize = 50
  • MaxBlockSize = 100
  • Window = 1
  • Alpha = 0.025
  • Beta = 0.95
  • Gamma = 0.25
  • MAX_LEARNING_RATE = 1.0
  • MIN_LEARNING_RATE = 0.0125
  • Current Learning Rate = 0.125
  • Previous Base Fee = 10
  • Delta = 0
Block is Completely Empty

In this example, we expect the learning rate to additively increase and the base fee to decrease.

blockConsumption := sumBlockSizesInWindow(1) / (1 * 100) == 0
maxLearningRate := min(1.0, 0.025 + 0.125) == 0.15
newBaseFee := 10 * (1 + 0.15 * (0 - 50) / 50) == 8.5

As we can see, the base fee decreased by 1.5 and the learning rate increases.

Block is Completely Full

In this example, we expect the learning rate to multiplicatively increase and the base fee to increase.

blockConsumption := sumBlockSizesInWindow(1) / (1 * 100) == 1
maxLearningRate := min(1.0, 0.025 + 0.125) == 0.15
newBaseFee := 10 * (1 + 0.95 * 0.125) == 11.875

As we can see, the base fee increased by 1.875 and the learning rate increases.

Block is at Target Utilization

In this example, we expect the learning rate to decrease and the base fee to remain the same.

blockConsumption := sumBlockSizesInWindow(1) / (1 * 100) == 0.5
maxLearningRate := max(0.0125, 0.95 * 0.125) == 0.11875
newBaseFee := 10 * (1 + 0.11875 * (0 - 50) / 50) == 10

As we can see, the base fee remained the same and the learning rate decreased.

Default EIP-1559 With AIMD EIP-1559

It is entirely possible to implement the default EIP-1559 fee market with the AIMD EIP-1559 fee market. This can be done by setting the following parameters:

  • Alpha = 0.0
  • Beta = 1.0
  • Gamma = 1.0
  • MAX_LEARNING_RATE = 0.125
  • MIN_LEARNING_RATE = 0.125
  • Delta = 0
  • Window = 1

Documentation

Index

Constants

View Source
const ConsensusVersion = 1

ConsensusVersion is the x/feemarket module's consensus version identifier.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule represents an application module for the x/feemarket module.

func NewAppModule

func NewAppModule(cdc codec.Codec, k keeper.Keeper) AppModule

NewAppModule returns an application module for the x/feemarket module.

func (AppModule) ConsensusVersion

func (AppModule) ConsensusVersion() uint64

ConsensusVersion implements AppModule/ConsensusVersion.

func (AppModule) EndBlock

func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate

EndBlock returns an endblocker for the x/feemarket module.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage

ExportGenesis returns the feemarket module's exported genesis state as raw JSON bytes. This method panics on any error.

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate

InitGenesis performs the genesis initialization for the x/feemarket module. This method returns no validator set updates. This method panics on any errors.

func (AppModule) IsAppModule

func (am AppModule) IsAppModule()

IsAppModule implements the appmodule.AppModule interface.

func (AppModule) IsOnePerModuleType

func (am AppModule) IsOnePerModuleType()

IsOnePerModuleType implements the depinject.OnePerModuleType interface.

func (AppModule) RegisterServices

func (am AppModule) RegisterServices(cfc module.Configurator)

RegisterServices registers the module's services with the app's module configurator.

type AppModuleBasic

type AppModuleBasic struct {
	// contains filtered or unexported fields
}

AppModuleBasic defines the base interface that the x/feemarket module exposes to the application.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage

DefaultGenesis returns default genesis state as raw bytes for the feemarket module.

func (AppModuleBasic) GetQueryCmd

func (amb AppModuleBasic) GetQueryCmd() *cobra.Command

GetQueryCmd returns the x/feemarket module base query cli-command.

func (AppModuleBasic) GetTxCmd

func (amb AppModuleBasic) GetTxCmd() *cobra.Command

GetTxCmd is a no-op, as no txs are registered for submission (apart from messages that can only be executed by governance).

func (AppModuleBasic) Name

func (amb AppModuleBasic) Name() string

Name returns the name of x/feemarket module.

func (AppModuleBasic) RegisterGRPCGatewayRoutes

func (amb AppModuleBasic) RegisterGRPCGatewayRoutes(cliCtx client.Context, mux *runtime.ServeMux)

RegisterGRPCGatewayRoutes registers the necessary REST routes for the GRPC-gateway to the x/feemarket module QueryService on mux. This method panics on failure.

func (AppModuleBasic) RegisterInterfaces

func (amb AppModuleBasic) RegisterInterfaces(ir codectypes.InterfaceRegistry)

RegisterInterfaces registers the necessary implementations / interfaces in the x/feemarket module w/ the interface-registry.

func (AppModuleBasic) RegisterLegacyAminoCodec

func (amb AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)

RegisterLegacyAminoCodec registers the necessary types from the x/feemarket module for amino serialization.

func (AppModuleBasic) ValidateGenesis

ValidateGenesis performs genesis state validation for the feemarket module.

type Inputs

type Inputs struct {
	depinject.In

	Config        *modulev1.Module
	Cdc           codec.Codec
	Key           *store.KVStoreKey
	AccountKeeper types.AccountKeeper
}

type Outputs

type Outputs struct {
	depinject.Out

	Keeper keeper.Keeper
	Module appmodule.AppModule
}

func ProvideModule

func ProvideModule(in Inputs) Outputs

Directories

Path Synopsis
client
cli
Package types is a reverse proxy.
Package types is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL