Skip to content

Commit

Permalink
target block space percent
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jan 8, 2024
1 parent 4df6ee2 commit d148048
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions x/txfees/keeper/mempool-1559/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ var (

// Max increase per block is a factor of 1.06, max decrease is 9/10
// If recovering at ~30M gas per block, decrease is .94
MaxBlockChangeRate = sdk.NewDec(1).Quo(sdk.NewDec(10))
TargetGas = int64(75_000_000)
MaxBlockChangeRate = sdk.NewDec(1).Quo(sdk.NewDec(10))
TargetGas = int64(187_500_000)
TargetBlockSpacePercent = sdk.MustNewDecFromStr("0.625")
// In face of continuous spam, will take ~19 blocks from base fee > spam cost, to mempool eviction
// ceil(log_{1.06}(RecheckFeeConstant))
// So potentially 1.8 minutes of impaired UX from 1559 nodes on top of time to get to base fee > spam.
Expand Down
2 changes: 1 addition & 1 deletion x/txfees/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (am AppModule) CheckAndSetTargetGas(ctx sdk.Context) {
return
}

newBlockMaxGas := newConsensusParams.Block.MaxGas
newBlockMaxGas := mempool1559.TargetBlockSpacePercent.Mul(sdk.NewDec(newConsensusParams.Block.MaxGas)).TruncateInt().Int64()
mempool1559.TargetGas = newBlockMaxGas
return
}
Expand Down
10 changes: 5 additions & 5 deletions x/txfees/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ func TestBeginBlock(t *testing.T) {
)

// Begin block hasn't happened yet, target gas should be equal to hard coded default value
hardCodedGasTarget := int64(75_000_000)
hardCodedGasTarget := int64(187_500_000)
require.Equal(t, hardCodedGasTarget, mempool1559.TargetGas)

// Run begin block
ctx = RunBeginBlock(ctx, app)

// Target gas should be updated to the value set in InitChain
defaultBlockMaxGas := sims.DefaultConsensusParams.Block.MaxGas
require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas)
defaultBlockTargetGas := mempool1559.TargetBlockSpacePercent.Mul(sdk.NewDec(sims.DefaultConsensusParams.Block.MaxGas)).TruncateInt().Int64()
require.Equal(t, defaultBlockTargetGas, mempool1559.TargetGas)

// Run begin block again, should not update target gas
ctx = RunBeginBlock(ctx, app)
require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas)
require.Equal(t, defaultBlockTargetGas, mempool1559.TargetGas)

// Update the consensus params
newDefaultBlockMaxGas := int64(300_000_000)
Expand All @@ -83,7 +83,7 @@ func TestBeginBlock(t *testing.T) {
app.ConsensusParamsKeeper.Set(ctx, &newConsensusParams)

// Ensure that the consensus params have not been updated yet
require.Equal(t, defaultBlockMaxGas, mempool1559.TargetGas)
require.Equal(t, defaultBlockTargetGas, mempool1559.TargetGas)

// Run begin block again, should update target gas
RunBeginBlock(ctx, app)
Expand Down

0 comments on commit d148048

Please sign in to comment.