diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..81bd63e --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,14 @@ +{ + "default": true, + "MD004": { "style": "asterisk" }, + "MD007": { "indent": 4 }, + "MD024": { "siblings_only": true }, + "MD013": false, + "MD025": false, + "MD033": false, + "MD034": false, + "MD014": false, + "no-hard-tabs": false, + "whitespace": false + } + \ No newline at end of file diff --git a/.markdownlintignore b/.markdownlintignore new file mode 100644 index 0000000..0205a42 --- /dev/null +++ b/.markdownlintignore @@ -0,0 +1,18 @@ +{ + "default": true, + "MD004": { + "style": "asterisk" + }, + "MD007": { + "indent": 4 + }, + "MD013": false, + "MD024": { + "siblings_only": true + }, + "MD025": false, + "MD033": false, + "MD034": false, + "no-hard-tabs": false, + "whitespace": false +} diff --git a/proto/feemarket/eip1559/v1/aimd_eip_1559.proto b/proto/feemarket/eip1559/v1/aimd_eip_1559.proto new file mode 100644 index 0000000..ac597b6 --- /dev/null +++ b/proto/feemarket/eip1559/v1/aimd_eip_1559.proto @@ -0,0 +1,36 @@ +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"; + +// AIMDEIP1559 is the contains the Additive Increase Multiplicative Decrease +// (AIMD) EIP-1559 fee market parameters and state. +message AIMDEIP1559 { + 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 { + // CurrentBaseFee is the current base fee. This is denominated in the fee + // per gas unit. + string current_base_fee = 1 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (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 = 2; +} \ No newline at end of file diff --git a/proto/feemarket/eip1559/v1/params.proto b/proto/feemarket/eip1559/v1/params.proto new file mode 100644 index 0000000..76c2c23 --- /dev/null +++ b/proto/feemarket/eip1559/v1/params.proto @@ -0,0 +1,80 @@ +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"; + +// 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; + + // 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 + ]; + + // 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 + ]; + + // 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; + + // 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", + (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 + ]; +} diff --git a/x/feemarket/interfaces/feemarket.go b/x/feemarket/interfaces/feemarket.go index 427d17d..c357556 100644 --- a/x/feemarket/interfaces/feemarket.go +++ b/x/feemarket/interfaces/feemarket.go @@ -45,9 +45,6 @@ type FeeMarketImplementation interface { // where the fees are being distributed, etc.). GetFeeMarketInfo(ctx sdk.Context) map[string]string - // GetID returns the identifier of the fee market - GetID() string - // ------------------- Fee Market Extraction ------------------- // // FeeAnteHandler will be called in the module AnteHandler, diff --git a/x/feemarket/plugins/README.md b/x/feemarket/plugins/README.md index 0e7364d..9775222 100644 --- a/x/feemarket/plugins/README.md +++ b/x/feemarket/plugins/README.md @@ -5,5 +5,5 @@ plugged into the `x/feemarket` module. Current implementations include: -- [Mock:](mock/feemarket.go) fee market that can be used for basic testing. +* [Mock:](mock/feemarket.go) fee market that can be used for basic testing. DO NOT use in production. diff --git a/x/feemarket/plugins/defaultmarket/feemarket.go b/x/feemarket/plugins/defaultmarket/feemarket.go index f347f8b..2c771c0 100644 --- a/x/feemarket/plugins/defaultmarket/feemarket.go +++ b/x/feemarket/plugins/defaultmarket/feemarket.go @@ -55,11 +55,6 @@ func (fm *DefaultMarket) GetFeeMarketInfo(_ sdk.Context) map[string]string { return nil } -// GetID returns the identifier of the fee market. -func (fm *DefaultMarket) GetID() string { - return "default" -} - // FeeAnteHandler will be called in the module AnteHandler. // Performs no actions. func (fm *DefaultMarket) FeeAnteHandler( diff --git a/x/feemarket/plugins/eip1559/README.md b/x/feemarket/plugins/eip1559/README.md new file mode 100644 index 0000000..98d9437 --- /dev/null +++ b/x/feemarket/plugins/eip1559/README.md @@ -0,0 +1,123 @@ +# 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](https://ieeexplore.ieee.org/document/9680496) 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: + +```golang +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: + +```golang + +// sumBlockSizesInWindow returns the sum of the block sizes in the window. +blockConsumption := sumBlockSizesInWindow(window) / (window * targetBlockSize) + +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. + +```golang +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. + +```golang +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. + +```golang +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` diff --git a/x/feemarket/plugins/eip1559/types/aimd_eip_1559.go b/x/feemarket/plugins/eip1559/types/aimd_eip_1559.go new file mode 100644 index 0000000..0f60c05 --- /dev/null +++ b/x/feemarket/plugins/eip1559/types/aimd_eip_1559.go @@ -0,0 +1,12 @@ +package types + +// NewAIMDEIP1559 instantiates a new AIMD EIP-1559 object. +func NewAIMDEIP1559( + state State, + params Params, +) AIMDEIP1559 { + return AIMDEIP1559{ + State: state, + Params: params, + } +} diff --git a/x/feemarket/plugins/eip1559/types/aimd_eip_1559.pb.go b/x/feemarket/plugins/eip1559/types/aimd_eip_1559.pb.go new file mode 100644 index 0000000..324782c --- /dev/null +++ b/x/feemarket/plugins/eip1559/types/aimd_eip_1559.pb.go @@ -0,0 +1,673 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: feemarket/eip1559/v1/aimd_eip_1559.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// AIMDEIP1559 is the contains the Additive Increase Multiplicative Decrease +// (AIMD) EIP-1559 fee market parameters and state. +type AIMDEIP1559 struct { + // Params are the parameters of the AIMD fee market. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // State is the current state of the AIMD fee market. + State State `protobuf:"bytes,2,opt,name=state,proto3" json:"state"` +} + +func (m *AIMDEIP1559) Reset() { *m = AIMDEIP1559{} } +func (m *AIMDEIP1559) String() string { return proto.CompactTextString(m) } +func (*AIMDEIP1559) ProtoMessage() {} +func (*AIMDEIP1559) Descriptor() ([]byte, []int) { + return fileDescriptor_92732f277215cba1, []int{0} +} +func (m *AIMDEIP1559) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AIMDEIP1559) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AIMDEIP1559.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AIMDEIP1559) XXX_Merge(src proto.Message) { + xxx_messageInfo_AIMDEIP1559.Merge(m, src) +} +func (m *AIMDEIP1559) XXX_Size() int { + return m.Size() +} +func (m *AIMDEIP1559) XXX_DiscardUnknown() { + xxx_messageInfo_AIMDEIP1559.DiscardUnknown(m) +} + +var xxx_messageInfo_AIMDEIP1559 proto.InternalMessageInfo + +func (m *AIMDEIP1559) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *AIMDEIP1559) GetState() State { + if m != nil { + return m.State + } + return State{} +} + +// State contains the current state of the AIMD fee market. +type State struct { + // CurrentBaseFee is the current base fee. This is denominated in the fee + // per gas unit. + CurrentBaseFee cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=current_base_fee,json=currentBaseFee,proto3,customtype=cosmossdk.io/math.Int" json:"current_base_fee"` + // BlockUtilizationWindow contains a list of the last blocks' utilization + // values. This is used to calculate the next base fee. + BlockUtilizationWindow []uint64 `protobuf:"varint,2,rep,packed,name=block_utilization_window,json=blockUtilizationWindow,proto3" json:"block_utilization_window,omitempty"` +} + +func (m *State) Reset() { *m = State{} } +func (m *State) String() string { return proto.CompactTextString(m) } +func (*State) ProtoMessage() {} +func (*State) Descriptor() ([]byte, []int) { + return fileDescriptor_92732f277215cba1, []int{1} +} +func (m *State) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *State) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_State.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *State) XXX_Merge(src proto.Message) { + xxx_messageInfo_State.Merge(m, src) +} +func (m *State) XXX_Size() int { + return m.Size() +} +func (m *State) XXX_DiscardUnknown() { + xxx_messageInfo_State.DiscardUnknown(m) +} + +var xxx_messageInfo_State proto.InternalMessageInfo + +func (m *State) GetBlockUtilizationWindow() []uint64 { + if m != nil { + return m.BlockUtilizationWindow + } + return nil +} + +func init() { + proto.RegisterType((*AIMDEIP1559)(nil), "feemarket.eip1559.v1.AIMDEIP1559") + proto.RegisterType((*State)(nil), "feemarket.eip1559.v1.State") +} + +func init() { + proto.RegisterFile("feemarket/eip1559/v1/aimd_eip_1559.proto", fileDescriptor_92732f277215cba1) +} + +var fileDescriptor_92732f277215cba1 = []byte{ + // 400 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x93, 0x75, 0x77, 0xc1, 0x59, 0x10, 0x09, 0xab, 0xc4, 0x55, 0xb2, 0xeb, 0x9e, 0x0a, + 0xd2, 0x09, 0x59, 0x59, 0xd4, 0xbd, 0x88, 0x41, 0x17, 0x72, 0x28, 0x94, 0x4a, 0x11, 0xbd, 0x84, + 0x49, 0xfa, 0x9a, 0x0e, 0xc9, 0x64, 0x86, 0xcc, 0x24, 0x55, 0x3f, 0x85, 0x47, 0x3f, 0x48, 0xf1, + 0x33, 0x14, 0x4f, 0xc5, 0x93, 0x78, 0x28, 0xd2, 0x7e, 0x91, 0x25, 0x93, 0xd0, 0xf6, 0xd0, 0xdb, + 0x7b, 0xef, 0xff, 0xfb, 0xbf, 0xf7, 0x78, 0x0f, 0x75, 0xc6, 0x00, 0x8c, 0x14, 0x29, 0x28, 0x17, + 0xa8, 0xf0, 0xae, 0xaf, 0xdf, 0xb8, 0x95, 0xe7, 0x12, 0xca, 0x46, 0x21, 0x50, 0x11, 0xd6, 0x05, + 0x2c, 0x0a, 0xae, 0xb8, 0x75, 0xba, 0x21, 0x71, 0x4b, 0xe2, 0xca, 0x3b, 0x7b, 0x12, 0x73, 0xc9, + 0xb8, 0x0c, 0x35, 0xe3, 0x36, 0x49, 0x63, 0x38, 0x3b, 0x4d, 0x78, 0xc2, 0x9b, 0x7a, 0x1d, 0xb5, + 0xd5, 0xe7, 0x7b, 0x07, 0x0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 0xf9, 0xca, 0x31, 0x17, 0x2b, 0xc7, 0xfc, + 0xbf, 0x72, 0xcc, 0x1f, 0x6b, 0xc7, 0x58, 0xac, 0x1d, 0xe3, 0xef, 0xda, 0x31, 0xbe, 0xbc, 0x4d, + 0xa8, 0x9a, 0x94, 0x11, 0x8e, 0x39, 0x73, 0x65, 0x4a, 0x45, 0x97, 0x41, 0xe5, 0x6e, 0x9f, 0xf4, + 0x75, 0x27, 0x16, 0x59, 0x99, 0xd0, 0x5c, 0x6e, 0x1e, 0xa7, 0xbe, 0x09, 0x90, 0xd1, 0xb1, 0xfe, + 0xda, 0xcb, 0xbb, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x8b, 0x36, 0x16, 0x4b, 0x02, 0x00, 0x00, +} + +func (m *AIMDEIP1559) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AIMDEIP1559) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AIMDEIP1559) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.State.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAimdEip_1559(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAimdEip_1559(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *State) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *State) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BlockUtilizationWindow) > 0 { + dAtA4 := make([]byte, len(m.BlockUtilizationWindow)*10) + var j3 int + for _, num := range m.BlockUtilizationWindow { + for num >= 1<<7 { + dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j3++ + } + dAtA4[j3] = uint8(num) + j3++ + } + i -= j3 + copy(dAtA[i:], dAtA4[:j3]) + i = encodeVarintAimdEip_1559(dAtA, i, uint64(j3)) + i-- + dAtA[i] = 0x12 + } + { + size := m.CurrentBaseFee.Size() + i -= size + if _, err := m.CurrentBaseFee.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintAimdEip_1559(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintAimdEip_1559(dAtA []byte, offset int, v uint64) int { + offset -= sovAimdEip_1559(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *AIMDEIP1559) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovAimdEip_1559(uint64(l)) + l = m.State.Size() + n += 1 + l + sovAimdEip_1559(uint64(l)) + return n +} + +func (m *State) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.CurrentBaseFee.Size() + n += 1 + l + sovAimdEip_1559(uint64(l)) + if len(m.BlockUtilizationWindow) > 0 { + l = 0 + for _, e := range m.BlockUtilizationWindow { + l += sovAimdEip_1559(uint64(e)) + } + n += 1 + sovAimdEip_1559(uint64(l)) + l + } + return n +} + +func sovAimdEip_1559(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAimdEip_1559(x uint64) (n int) { + return sovAimdEip_1559(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *AIMDEIP1559) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AIMDEIP1559: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AIMDEIP1559: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAimdEip_1559 + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAimdEip_1559 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAimdEip_1559 + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAimdEip_1559 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.State.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAimdEip_1559(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAimdEip_1559 + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *State) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: State: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: State: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentBaseFee", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAimdEip_1559 + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAimdEip_1559 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CurrentBaseFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType == 0 { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BlockUtilizationWindow = append(m.BlockUtilizationWindow, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthAimdEip_1559 + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthAimdEip_1559 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(m.BlockUtilizationWindow) == 0 { + m.BlockUtilizationWindow = make([]uint64, 0, elementCount) + } + for iNdEx < postIndex { + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BlockUtilizationWindow = append(m.BlockUtilizationWindow, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field BlockUtilizationWindow", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipAimdEip_1559(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAimdEip_1559 + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAimdEip_1559(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAimdEip_1559 + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthAimdEip_1559 + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAimdEip_1559 + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAimdEip_1559 + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAimdEip_1559 = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAimdEip_1559 = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAimdEip_1559 = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/feemarket/plugins/eip1559/types/params.go b/x/feemarket/plugins/eip1559/types/params.go new file mode 100644 index 0000000..ed0a1a3 --- /dev/null +++ b/x/feemarket/plugins/eip1559/types/params.go @@ -0,0 +1,92 @@ +package types + +import "cosmossdk.io/math" + +var ( + // DefaultWindow is the default window size for the sliding window + // used to calculate the base fee. + DefaultWindow uint64 = 8 + + // DefaultAlpha 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. + DefaultAlpha math.LegacyDec = math.LegacyMustNewDecFromStr("0.025") + + // DefaultBeta 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. + DefaultBeta math.LegacyDec = math.LegacyMustNewDecFromStr("0.95") + + // DefaultTheta 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. + DefaultTheta math.LegacyDec = math.LegacyMustNewDecFromStr("0.25") + + // DefaultDelta 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. + DefaultDelta math.LegacyDec = math.LegacyMustNewDecFromStr("0.0") + + // DefaultTargetBlockSize is the default target block size. This is the default + // on Ethereum. + DefaultTargetBlockSize uint64 = 15_000_000 + + // DefaultMaxBlockSize is the default maximum block size. This is the default + // on Ethereum. + DefaultMaxBlockSize uint64 = 30_000_000 + + // DefaultMinBaseFee is the default minimum base fee. This is the default + // on Ethereum. + DefaultMinBaseFee math.Int = math.NewInt(1_000_000_000) + + // DefaultMinLearningRate is the default minimum learning rate. + DefaultMinLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.01") + + // DefaultMaxLearningRate is the default maximum learning rate. + DefaultMaxLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.50") +) + +// NewParams instantiates a new EIP-1559 Params object. +func NewParams( + window uint64, + alpha math.LegacyDec, + beta math.LegacyDec, + theta math.LegacyDec, + delta math.LegacyDec, + targetBlockSize uint64, + maxBlockSize uint64, + minBaseFee math.Int, + minLearingRate math.LegacyDec, + maxLearningRate math.LegacyDec, +) Params { + return Params{ + Window: window, + Alpha: alpha, + Beta: beta, + Theta: theta, + Delta: delta, + TargetBlockSize: targetBlockSize, + MaxBlockSize: maxBlockSize, + MinBaseFee: minBaseFee, + MinLearningRate: minLearingRate, + MaxLearningRate: maxLearningRate, + } +} + +// DefaultParams returns a default set of parameters. +func DefaultParams() Params { + return Params{ + Window: DefaultWindow, + Alpha: DefaultAlpha, + Beta: DefaultBeta, + Theta: DefaultTheta, + Delta: DefaultDelta, + TargetBlockSize: DefaultTargetBlockSize, + MaxBlockSize: DefaultMaxBlockSize, + MinBaseFee: DefaultMinBaseFee, + MinLearningRate: DefaultMinLearningRate, + MaxLearningRate: DefaultMaxLearningRate, + } +} diff --git a/x/feemarket/plugins/eip1559/types/params.pb.go b/x/feemarket/plugins/eip1559/types/params.pb.go new file mode 100644 index 0000000..d89af0e --- /dev/null +++ b/x/feemarket/plugins/eip1559/types/params.pb.go @@ -0,0 +1,739 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: feemarket/eip1559/v1/params.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params contains the required set of parameters for the EIP1559 fee market +// plugin implementation. +type Params struct { + // Window determines the number of previous blocks to consider when + // calculating block utilization. + Window uint64 `protobuf:"varint,1,opt,name=window,proto3" json:"window,omitempty"` + // Alpha is the amount we additively increase the learninig rate + // when it is above or below the target +/- threshold. + Alpha cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=alpha,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"alpha"` + // Beta is the amount we multiplicatively decrease the learning rate + // when it is within the target +/- threshold. + Beta cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=beta,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"beta"` + // 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. + Theta cosmossdk_io_math.LegacyDec `protobuf:"bytes,4,opt,name=theta,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"theta"` + // 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. + Delta cosmossdk_io_math.LegacyDec `protobuf:"bytes,5,opt,name=delta,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"delta"` + // TargetBlockSize is the target block utilization rate. This is denominated in + // gas units consumed. + TargetBlockSize uint64 `protobuf:"varint,6,opt,name=target_block_size,json=targetBlockSize,proto3" json:"target_block_size,omitempty"` + // MaxBlockSize is the upper bound for the block size. This is denominated in + // gas units consumed. + MaxBlockSize uint64 `protobuf:"varint,7,opt,name=max_block_size,json=maxBlockSize,proto3" json:"max_block_size,omitempty"` + // MinBaseFee determines the initial base fee of the module and the global minimum + // for the network. This is denominated in fee per gas unit. + MinBaseFee cosmossdk_io_math.Int `protobuf:"bytes,8,opt,name=min_base_fee,json=minBaseFee,proto3,customtype=cosmossdk.io/math.Int" json:"min_base_fee"` + // MinLearningRate is the lower bound for the learning rate. + MinLearningRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,9,opt,name=min_learning_rate,json=minLearningRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_learning_rate"` + // MaxLearningRate is the upper bound for the learning rate. + MaxLearningRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,10,opt,name=max_learning_rate,json=maxLearningRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"max_learning_rate"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_7fc0baf05688fee5, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetWindow() uint64 { + if m != nil { + return m.Window + } + return 0 +} + +func (m *Params) GetTargetBlockSize() uint64 { + if m != nil { + return m.TargetBlockSize + } + return 0 +} + +func (m *Params) GetMaxBlockSize() uint64 { + if m != nil { + return m.MaxBlockSize + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "feemarket.eip1559.v1.Params") +} + +func init() { proto.RegisterFile("feemarket/eip1559/v1/params.proto", fileDescriptor_7fc0baf05688fee5) } + +var fileDescriptor_7fc0baf05688fee5 = []byte{ + // 430 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x6a, 0xd5, 0x40, + 0x14, 0x86, 0x6f, 0xf4, 0xde, 0x68, 0x87, 0x62, 0x69, 0xa8, 0x12, 0x2b, 0xa4, 0x55, 0x5c, 0x14, + 0xa5, 0x09, 0x41, 0xba, 0x70, 0x25, 0x84, 0xaa, 0x14, 0x2a, 0x48, 0x5c, 0x29, 0x48, 0x38, 0xc9, + 0x3d, 0x4d, 0x86, 0x64, 0x66, 0x42, 0x66, 0x7a, 0x9b, 0xf6, 0x29, 0x7c, 0x05, 0xdf, 0xc1, 0x87, + 0xe8, 0xb2, 0xb8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params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.MaxLearningRate.Size() + i -= size + if _, err := m.MaxLearningRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + { + size := m.MinLearningRate.Size() + i -= size + if _, err := m.MinLearningRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + { + size := m.MinBaseFee.Size() + i -= size + if _, err := m.MinBaseFee.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + if m.MaxBlockSize != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MaxBlockSize)) + i-- + dAtA[i] = 0x38 + } + if m.TargetBlockSize != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.TargetBlockSize)) + i-- + dAtA[i] = 0x30 + } + { + size := m.Delta.Size() + i -= size + if _, err := m.Delta.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + { + size := m.Theta.Size() + i -= size + if _, err := m.Theta.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.Beta.Size() + i -= size + if _, err := m.Beta.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.Alpha.Size() + i -= size + if _, err := m.Alpha.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.Window != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.Window)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Window != 0 { + n += 1 + sovParams(uint64(m.Window)) + } + l = m.Alpha.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.Beta.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.Theta.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.Delta.Size() + n += 1 + l + sovParams(uint64(l)) + if m.TargetBlockSize != 0 { + n += 1 + sovParams(uint64(m.TargetBlockSize)) + } + if m.MaxBlockSize != 0 { + n += 1 + sovParams(uint64(m.MaxBlockSize)) + } + l = m.MinBaseFee.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.MinLearningRate.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.MaxLearningRate.Size() + n += 1 + l + sovParams(uint64(l)) + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Window", wireType) + } + m.Window = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Window |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Alpha", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Alpha.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Beta", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Beta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Theta", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Theta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Delta", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Delta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TargetBlockSize", wireType) + } + m.TargetBlockSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TargetBlockSize |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxBlockSize", wireType) + } + m.MaxBlockSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxBlockSize |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinBaseFee", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinBaseFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinLearningRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinLearningRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxLearningRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MaxLearningRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/feemarket/plugins/eip1559/types/state.go b/x/feemarket/plugins/eip1559/types/state.go new file mode 100644 index 0000000..3108860 --- /dev/null +++ b/x/feemarket/plugins/eip1559/types/state.go @@ -0,0 +1,14 @@ +package types + +import "cosmossdk.io/math" + +// NewState instantiates a new EIP-1559 State object. +func NewState( + currentBaseFee math.Int, + window uint64, +) State { + return State{ + CurrentBaseFee: currentBaseFee, + BlockUtilizationWindow: make([]uint64, window), + } +}