Skip to content

Commit

Permalink
fix modifying common.Big1 (#1343)
Browse files Browse the repository at this point in the history
* add regression test

* apply fix

* reorder equal params
  • Loading branch information
ceyonur authored Sep 17, 2024
1 parent 25692e9 commit 0f8cd87
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion consensus/dummy/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func CalcBaseFee(config *params.ChainConfig, feeConfig commontype.FeeConfig, par
// that has elapsed between the parent and this block.
if roll > expectedRollUp {
// Note: roll/params.RollupWindow must be greater than 1 since we've checked that roll > params.RollupWindow
baseFeeDelta = baseFeeDelta.Mul(baseFeeDelta, new(big.Int).SetUint64(roll/expectedRollUp))
baseFeeDelta = new(big.Int).Mul(baseFeeDelta, new(big.Int).SetUint64(roll/expectedRollUp))
}
baseFee.Sub(baseFee, baseFeeDelta)
}
Expand Down
31 changes: 31 additions & 0 deletions consensus/dummy/dynamic_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"github.com/ava-labs/subnet-evm/commontype"
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var testMinBaseFee = big.NewInt(75_000_000_000)
Expand Down Expand Up @@ -440,3 +442,32 @@ func TestCalcBlockGasCost(t *testing.T) {
})
}
}

func TestCalcBaseFeeRegression(t *testing.T) {
parentTimestamp := uint64(1)
timestamp := parentTimestamp + params.RollupWindow + 1000

parentHeader := &types.Header{
Time: parentTimestamp,
GasUsed: 1_000_000,
Number: big.NewInt(1),
BaseFee: big.NewInt(1),
Extra: make([]byte, params.DynamicFeeExtraDataSize),
}

testFeeConfig := commontype.FeeConfig{
GasLimit: big.NewInt(8_000_000),
TargetBlockRate: 2, // in seconds

MinBaseFee: big.NewInt(1 * params.GWei),
TargetGas: big.NewInt(15_000_000),
BaseFeeChangeDenominator: big.NewInt(100000),

MinBlockGasCost: big.NewInt(0),
MaxBlockGasCost: big.NewInt(1_000_000),
BlockGasCostStep: big.NewInt(200_000),
}
_, _, err := CalcBaseFee(params.TestChainConfig, testFeeConfig, parentHeader, timestamp)
require.NoError(t, err)
require.Equalf(t, 0, common.Big1.Cmp(big.NewInt(1)), "big1 should be 1, got %s", common.Big1)
}

0 comments on commit 0f8cd87

Please sign in to comment.