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 12, 2023
2 parents 9958e1e + 09bb331 commit 5f29be1
Show file tree
Hide file tree
Showing 16 changed files with 941 additions and 384 deletions.
36 changes: 0 additions & 36 deletions proto/feemarket/eip1559/v1/aimd_eip_1559.proto

This file was deleted.

47 changes: 47 additions & 0 deletions proto/feemarket/eip1559/v1/feemarket.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
syntax = "proto3";
package feemarket.eip1559.v1;

option go_package = "github.com/skip-mev/feemarket/x/feemarket/plugins/eip1559/types";

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "feemarket/eip1559/v1/params.proto";

// EIP1559 is the contains the Additive Increase Multiplicative Decrease
// (AIMD) EIP-1559 fee market parameters and state. This can be utilized
// to implement AIMD EIP-1559 and legacy EIP-1559 fee market.
message EIP1559 {
option (cosmos_proto.implements_interface) =
"feemarket.feemarket.v1.FeeMarketImplementation";

// Params are the parameters of the AIMD fee market.
Params params = 1 [ (gogoproto.nullable) = false ];

// State is the current state of the AIMD fee market.
State state = 2 [ (gogoproto.nullable) = false ];
}

// State contains the current state of the AIMD fee market.
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 = 2 [
(cosmos_proto.scalar) = "cosmos.Legacy",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// BlockUtilizationWindow contains a list of the last blocks' utilization
// values. This is used to calculate the next base fee.
repeated uint64 block_utilization_window = 3;

// Index is the index of the current block in the block utilization window.
uint64 index = 4;
}
118 changes: 60 additions & 58 deletions proto/feemarket/eip1559/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,74 @@ import "gogoproto/gogo.proto";
// Params contains the required set of parameters for the EIP1559 fee market
// plugin implementation.
message Params {
// Window determines the number of previous blocks to consider when
// calculating block utilization.
uint64 window = 1;
// Window determines the number of previous blocks to consider when
// calculating block utilization.
uint64 window = 1;

// Alpha is the amount we additively increase the learninig rate
// when it is above or below the target +/- threshold.
string alpha = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// Alpha is the amount we additively increase the learninig rate
// when it is above or below the target +/- threshold.
string alpha = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// Beta is the amount we multiplicatively decrease the learning rate
// when it is within the target +/- threshold.
string beta = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// Beta is the amount we multiplicatively decrease the learning rate
// when it is within the target +/- threshold.
string beta = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// Theta is the threshold for the learning rate. If the learning rate is
// above or below the target +/- threshold, we additively increase the
// learning rate by Alpha. Otherwise, we multiplicatively decrease the
// learning rate by Beta.
string theta = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// Theta is the threshold for the learning rate. If the learning rate is
// above or below the target +/- threshold, we additively increase the
// learning rate by Alpha. Otherwise, we multiplicatively decrease the
// learning rate by Beta.
string theta = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// Delta is the amount we additively increase/decrease the base fee when the
// net block utilization difference in the window is above/below the target utilization.
string delta = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// Delta is the amount we additively increase/decrease the base fee when the
// net block utilization difference in the window is above/below the target
// utilization.
string delta = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// TargetBlockSize is the target block utilization rate. This is denominated in
// gas units consumed.
uint64 target_block_size = 6;
// TargetBlockSize is the target block utilization rate. This is denominated
// in
// gas units consumed.
uint64 target_block_size = 6;

// MaxBlockSize is the upper bound for the block size. This is denominated in
// gas units consumed.
uint64 max_block_size = 7;
// MaxBlockSize is the upper bound for the block size. This is denominated in
// gas units consumed.
uint64 max_block_size = 7;

// MinBaseFee determines the initial base fee of the module and the global minimum
// for the network. This is denominated in fee per gas unit.
string min_base_fee = 8 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// MinBaseFee determines the initial base fee of the module and the global
// minimum
// for the network. This is denominated in fee per gas unit.
string min_base_fee = 8 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];


// MinLearningRate is the lower bound for the learning rate.
string min_learning_rate = 9 [
(cosmos_proto.scalar) = "cosmos.Dec",
// MinLearningRate is the lower bound for the learning rate.
string min_learning_rate = 9 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
(gogoproto.nullable) = false
];

// MaxLearningRate is the upper bound for the learning rate.
string max_learning_rate = 10 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// MaxLearningRate is the upper bound for the learning rate.
string max_learning_rate = 10 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
7 changes: 2 additions & 5 deletions proto/feemarket/feemarket/v1/panic.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ message PanicMarket {
option (cosmos_proto.implements_interface) =
"feemarket.feemarket.v1.FeeMarketImplementation";

// State1 represents arbitrary data stored in the implementation.
string stateA = 1;

// State2 represents arbitrary data stored in the implementation.
string stateB = 2;
// Data represents arbitrary data stored in the implementation.
bytes data = 1;
}
8 changes: 4 additions & 4 deletions x/feemarket/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func (k *Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) {
panic(err)
}

if len(gs.Plugin) == 0 && gs.Params.Enabled {
panic("plugin must be set if feemarket is enabled")
}

// set the fee market implementation
if err := k.plugin.Unmarshal(gs.Plugin); err != nil {
panic(err)
}

if err := k.plugin.ValidateBasic(); err != nil {
panic(err)
}

if err := k.Init(ctx); err != nil {
panic(err)
}
Expand Down
13 changes: 0 additions & 13 deletions x/feemarket/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ func (s *KeeperTestSuite) TestInitGenesis() {
})
})

s.Run("0 bytes plugin bytes should panic", func() {
gs := types.GenesisState{
Plugin: make([]byte, 0),
Params: types.Params{
Enabled: true,
},
}

s.Require().Panics(func() {
s.feemarketKeeper.InitGenesis(s.ctx, gs)
})
})

s.Run("invalid plugin bytes should panic if module enabled", func() {
gs := types.GenesisState{
Plugin: []byte("invalid"),
Expand Down
85 changes: 85 additions & 0 deletions x/feemarket/plugins/eip1559/types/aimd_eip1559.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package types

import "cosmossdk.io/math"

// Note: The following constants are the default values for the AIMD EIP-1559
// fee market implementation. This implements an adjustable learning rate
// algorithm that is not present in the base EIP-1559 implementation.

var (
// DefaultAIMDWindow is the default window size for the sliding window
// used to calculate the base fee.
DefaultAIMDWindow uint64 = 8

// DefaultAIMDAlpha is the default alpha value for the learning
// rate calculation. This value determines how much we want to additively
// increase the learning rate when the target block size is exceeded.
DefaultAIMDAlpha math.LegacyDec = math.LegacyMustNewDecFromStr("0.025")

// DefaultAIMDBeta is the default beta value for the learning rate
// calculation. This value determines how much we want to multiplicatively
// decrease the learning rate when the target utilization is not met.
DefaultAIMDBeta math.LegacyDec = math.LegacyMustNewDecFromStr("0.95")

// DefaultAIMDTheta is the default threshold for determining whether
// to increase or decrease the learning rate. In this case, we increase
// the learning rate if the block utilization within the window is greater
// than 0.75 or less than 0.25. Otherwise, we multiplicatively decrease
// the learning rate.
DefaultAIMDTheta math.LegacyDec = math.LegacyMustNewDecFromStr("0.25")

// DefaultAIMDDelta is the default delta value for how much we additively
// increase or decrease the base fee when the net block utilization within
// the window is not equal to the target utilization.
DefaultAIMDDelta math.LegacyDec = math.LegacyMustNewDecFromStr("0.0")

// DefaultAIMDTargetBlockSize is the default target block utilization. This
// is the default on Ethereum. This denominated in units of gas consumed in
// a block.
DefaultAIMDTargetBlockSize uint64 = 15_000_000

// DefaultAIMDMaxBlockSize is the default maximum block utilization.
// This is the default on Ethereum. This denominated in units of gas
// consumed in a block.
DefaultAIMDMaxBlockSize uint64 = 30_000_000

// DefaultAIMDMinBaseFee is the default minimum base fee. This is the
// default on Ethereum. Note that ethereum is denominated in 1e18 wei.
// Cosmos chains will likely want to change this to 1e6.
DefaultAIMDMinBaseFee math.Int = math.NewInt(1_000_000_000)

// DefaultAIMDMinLearningRate is the default minimum learning rate.
DefaultAIMDMinLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.01")

// DefaultAIMDMaxLearningRate is the default maximum learning rate.
DefaultAIMDMaxLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.50")
)

// DefaultAIMDParams returns a default set of parameters that implements
// the AIMD EIP-1559 fee market implementation. These parameters allow for
// the learning rate to be dynamically adjusted based on the block utilization
// within the window.
func DefaultAIMDParams() Params {
return NewParams(
DefaultAIMDWindow,
DefaultAIMDAlpha,
DefaultAIMDBeta,
DefaultAIMDTheta,
DefaultAIMDDelta,
DefaultAIMDTargetBlockSize,
DefaultAIMDMaxBlockSize,
DefaultAIMDMinBaseFee,
DefaultAIMDMinLearningRate,
DefaultAIMDMaxLearningRate,
)
}

// DefaultAIMDState returns a default set of state that implements
// the AIMD EIP-1559 fee market implementation.
func DefaultAIMDState() State {
return NewState(
DefaultAIMDMinBaseFee,
DefaultAIMDMinLearningRate,
DefaultAIMDWindow,
)
}
12 changes: 0 additions & 12 deletions x/feemarket/plugins/eip1559/types/aimd_eip_1559.go

This file was deleted.

Loading

0 comments on commit 5f29be1

Please sign in to comment.