Skip to content

Commit

Permalink
adding basic funcs to state obj
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay committed Nov 14, 2023
1 parent 262a657 commit 5ccdd8f
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 345 deletions.
8 changes: 7 additions & 1 deletion proto/feemarket/eip1559/v1/feemarket.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ message State {
// values. This is used to calculate the next base fee.
repeated uint64 block_utilization_window = 3;

// TargetBlockUtilization is the target block utilization.
uint64 target_block_utilization = 4;

// MaxBlockUtilization is the maximum block utilization.
uint64 max_block_utilization = 5;

// Index is the index of the current block in the block utilization window.
uint64 index = 4;
uint64 index = 6;
}
26 changes: 7 additions & 19 deletions proto/feemarket/eip1559/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ 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 [
string alpha = 1 [
(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 [
string beta = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
Expand All @@ -33,46 +29,38 @@ message Params {
// 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 [
string theta = 3 [
(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 [
string delta = 4 [
(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 [
string min_base_fee = 5 [
(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 [
string min_learning_rate = 6 [
(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 [
string max_learning_rate = 7 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
Expand Down
5 changes: 2 additions & 3 deletions x/feemarket/plugins/eip1559/types/aimd_eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ var (
// within the window.
func DefaultAIMDParams() Params {
return NewParams(
DefaultAIMDWindow,
DefaultAIMDAlpha,
DefaultAIMDBeta,
DefaultAIMDTheta,
DefaultAIMDDelta,
DefaultAIMDTargetBlockSize,
DefaultAIMDMaxBlockSize,
DefaultAIMDMinBaseFee,
DefaultAIMDMinLearningRate,
DefaultAIMDMaxLearningRate,
Expand All @@ -81,5 +78,7 @@ func DefaultAIMDState() State {
DefaultAIMDMinBaseFee,
DefaultAIMDMinLearningRate,
DefaultAIMDWindow,
DefaultAIMDTargetBlockSize,
DefaultAIMDMaxBlockSize,
)
}
5 changes: 2 additions & 3 deletions x/feemarket/plugins/eip1559/types/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ var (
// rate adjustment algorithm.
func DefaultParams() Params {
return NewParams(
DefaultWindow,
DefaultAlpha,
DefaultBeta,
DefaultTheta,
DefaultDelta,
DefaultTargetBlockSize,
DefaultMaxBlockSize,
DefaultMinBaseFee,
DefaultMinLearningRate,
DefaultMaxLearningRate,
Expand All @@ -69,5 +66,7 @@ func DefaultState() State {
DefaultMinBaseFee,
DefaultMinLearningRate,
DefaultWindow,
DefaultTargetBlockSize,
DefaultMaxBlockSize,
)
}
134 changes: 104 additions & 30 deletions x/feemarket/plugins/eip1559/types/feemarket.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions x/feemarket/plugins/eip1559/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@ import (
// NewParams instantiates a new EIP-1559 Params object. This params object is utilized
// to implement both the base EIP-1559 fee and AIMD EIP-1559 fee market implementations.
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,
Expand All @@ -36,10 +30,6 @@ func NewParams(

// ValidateBasic performs basic validation on the parameters.
func (p *Params) ValidateBasic() error {
if p.Window == 0 {
return fmt.Errorf("window cannot be zero")
}

if p.Alpha.IsNil() || p.Alpha.IsNegative() {
return fmt.Errorf("alpha cannot be nil must be between [0, inf)")
}
Expand All @@ -56,18 +46,6 @@ func (p *Params) ValidateBasic() error {
return fmt.Errorf("delta cannot be nil and must be between [0, inf)")
}

if p.TargetBlockSize == 0 {
return fmt.Errorf("target block size cannot be zero")
}

if p.MaxBlockSize == 0 {
return fmt.Errorf("max block size cannot be zero")
}

if p.TargetBlockSize > p.MaxBlockSize {
return fmt.Errorf("target block size cannot be greater than max block size")
}

if p.MinBaseFee.IsNil() || !p.MinBaseFee.GTE(math.ZeroInt()) {
return fmt.Errorf("min base fee cannot be nil and must be greater than or equal to zero")
}
Expand Down
Loading

0 comments on commit 5ccdd8f

Please sign in to comment.