Skip to content

Commit

Permalink
Merge branch 'main' into aljo242/module
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Nov 14, 2023
2 parents a503fef + 880569e commit 788645c
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 250 deletions.
31 changes: 16 additions & 15 deletions proto/feemarket/feemarket/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,33 @@ message GenesisState {
// and the AIMD EIP-1559 fee market.
Params params = 1 [ (gogoproto.nullable) = false ];

// BaseFee is the current base fee. This is denominated in the fee
// per gas unit.
string base_fee = 2 [
// State contains the current state of the AIMD fee market.
State state = 2 [ (gogoproto.nullable) = false ];
}

// State is utilized to track the current state of the fee market. This includes
// the current base fee, learning rate, and block utilization within the
// specified AIMD window.
message State {
// BaseFee is the current base fee. This is denominated in the fee per gas
// unit.
string base_fee = 1 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];

// LearningRate is the current learning rate.
string learning_rate = 3 [
string learning_rate = 2 [
(cosmos_proto.scalar) = "cosmos.Legacy",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// Utilization contains the current state of the AIMD fee market.
BlockUtilization utilization = 4 [ (gogoproto.nullable) = false ];
}

// BlockUtilization contains the current state of the AIMD fee market. This
// structure tracks total block utilization within a window of blocks.
message BlockUtilization {
// Window contains a list of the last blocks' utilization
// values. This is used to calculate the next base fee. This
// stores the number of units of gas consumed per block.
repeated uint64 window = 1;
// Window contains a list of the last blocks' utilization values. This is used
// to calculate the next base fee. This stores the number of units of gas
// consumed per block.
repeated uint64 window = 3;

// Index is the index of the current block in the block utilization window.
uint64 index = 4;
Expand Down
24 changes: 0 additions & 24 deletions x/feemarket/types/block_utilization.go

This file was deleted.

16 changes: 5 additions & 11 deletions x/feemarket/types/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,15 @@ func DefaultParams() Params {
)
}

// DefaultBlockUtilization returns a default block utilization instance
// that implements the EIP-1559 fee market implementation without the
// AIMD learning rate adjustment algorithm.
func DefaultBlockUtilization() BlockUtilization {
return NewBlockUtilization(DefaultWindow)
// DefaultState returns the default state for the EIP-1559 fee market
// implementation without the AIMD learning rate adjustment algorithm.
func DefaultState() State {
return NewState(DefaultWindow, DefaultMinBaseFee, DefaultMinLearningRate)
}

// DefaultGenesisState returns a default genesis state that implements
// the EIP-1559 fee market implementation without the AIMD learning
// rate adjustment algorithm.
func DefaultGenesisState() *GenesisState {
return NewGenesisState(
DefaultParams(),
DefaultMinBaseFee,
DefaultMinLearningRate,
DefaultBlockUtilization(),
)
return NewGenesisState(DefaultParams(), DefaultState())
}
17 changes: 7 additions & 10 deletions x/feemarket/types/eip1559_aimd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,16 @@ func DefaultAIMDParams() Params {
)
}

// DefaultAIMDBlockUtilization returns a default block utilization instance
// that implements the AIMD EIP-1559 fee market implementation.
func DefaultAIMDBlockUtilization() BlockUtilization {
return NewBlockUtilization(DefaultAIMDWindow)
// DefaultAIMDState returns the default state for the AIMD EIP-1559 fee market
// implementation. This implementation uses a sliding window to track the
// block utilization and dynamically adjusts the learning rate based on the
// utilization within the window.
func DefaultAIMDState() State {
return NewState(DefaultAIMDWindow, DefaultAIMDMinBaseFee, DefaultAIMDMinLearningRate)
}

// DefaultAIMDGenesisState returns a default genesis state that implements
// the AIMD EIP-1559 fee market implementation.
func DefaultAIMDGenesisState() *GenesisState {
return NewGenesisState(
DefaultAIMDParams(),
DefaultAIMDMinBaseFee,
DefaultAIMDMinLearningRate,
DefaultAIMDBlockUtilization(),
)
return NewGenesisState(DefaultAIMDParams(), DefaultAIMDState())
}
27 changes: 4 additions & 23 deletions x/feemarket/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ package types

import (
"encoding/json"
fmt "fmt"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
)

// NewGenesisState returns a new genesis state for the module.
func NewGenesisState(
params Params,
baseFee math.Int,
learningRate math.LegacyDec,
utilization BlockUtilization,
state State,
) *GenesisState {
return &GenesisState{
Params: params,
BaseFee: baseFee,
LearningRate: learningRate,
Utilization: utilization,
Params: params,
State: state,
}
}

Expand All @@ -29,20 +23,7 @@ func (gs *GenesisState) ValidateBasic() error {
if err := gs.Params.ValidateBasic(); err != nil {
return err
}

if err := gs.Utilization.ValidateBasic(); err != nil {
return err
}

if gs.BaseFee.IsNil() || gs.BaseFee.IsNegative() {
return fmt.Errorf("base fee cannot be nil or negative")
}

if gs.LearningRate.IsNil() || gs.LearningRate.IsNegative() {
return fmt.Errorf("learning rate cannot be nil or negative")
}

return nil
return gs.State.ValidateBasic()
}

// GetGenesisStateFromAppState returns x/feemarket GenesisState given raw application
Expand Down
Loading

0 comments on commit 788645c

Please sign in to comment.