diff --git a/builder/files/genesis-mainnet-v1.json b/builder/files/genesis-mainnet-v1.json index d3f0d02206..e6ed7c8efc 100644 --- a/builder/files/genesis-mainnet-v1.json +++ b/builder/files/genesis-mainnet-v1.json @@ -15,6 +15,7 @@ "londonBlock": 23850000, "bor": { "jaipurBlock": 23850000, + "delhiBlock": 36507200, "period": { "0": 2 }, diff --git a/builder/files/genesis-testnet-v4.json b/builder/files/genesis-testnet-v4.json index 8a0af45088..c7efb7ef63 100644 --- a/builder/files/genesis-testnet-v4.json +++ b/builder/files/genesis-testnet-v4.json @@ -15,6 +15,7 @@ "londonBlock": 22640000, "bor": { "jaipurBlock": 22770000, + "delhiBlock": 29392500, "period": { "0": 2, "25275000": 5 diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index 8fca0fdc70..f620f9504e 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -59,9 +59,10 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { } var ( - parentGasTarget = parent.GasLimit / params.ElasticityMultiplier - parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget) - baseFeeChangeDenominator = new(big.Int).SetUint64(params.BaseFeeChangeDenominator) + parentGasTarget = parent.GasLimit / params.ElasticityMultiplier + parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget) + baseFeeChangeDenominatorUint64 = params.BaseFeeChangeDenominator(config.Bor, parent.Number.Uint64()) + baseFeeChangeDenominator = new(big.Int).SetUint64(baseFeeChangeDenominatorUint64) ) // If the parent gasUsed is the same as the target, the baseFee remains unchanged. if parent.GasUsed == parentGasTarget { diff --git a/consensus/misc/eip1559_test.go b/consensus/misc/eip1559_test.go index 23cd9023de..0d757105c7 100644 --- a/consensus/misc/eip1559_test.go +++ b/consensus/misc/eip1559_test.go @@ -20,7 +20,6 @@ import ( "math/big" "testing" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/params" ) @@ -47,12 +46,14 @@ func copyConfig(original *params.ChainConfig) *params.ChainConfig { TerminalTotalDifficulty: original.TerminalTotalDifficulty, Ethash: original.Ethash, Clique: original.Clique, + Bor: original.Bor, } } func config() *params.ChainConfig { config := copyConfig(params.TestChainConfig) config.LondonBlock = big.NewInt(5) + config.Bor.DelhiBlock = 8 return config } @@ -117,10 +118,12 @@ func TestCalcBaseFee(t *testing.T) { {params.InitialBaseFee, 20000000, 10000000, params.InitialBaseFee}, // usage == target {params.InitialBaseFee, 20000000, 9000000, 987500000}, // usage below target {params.InitialBaseFee, 20000000, 11000000, 1012500000}, // usage above target + {params.InitialBaseFee, 20000000, 20000000, 1125000000}, // usage full + {params.InitialBaseFee, 20000000, 0, 875000000}, // usage 0 } for i, test := range tests { parent := &types.Header{ - Number: common.Big32, + Number: big.NewInt(6), GasLimit: test.parentGasLimit, GasUsed: test.parentGasUsed, BaseFee: big.NewInt(test.parentBaseFee), @@ -130,3 +133,38 @@ func TestCalcBaseFee(t *testing.T) { } } } + +// TestCalcBaseFee assumes all blocks are 1559-blocks post Delhi Hard Fork +func TestCalcBaseFeeDelhi(t *testing.T) { + + testConfig := copyConfig(config()) + + // Test Delhi Hard Fork + // Hard fork kicks in at block 8 + + tests := []struct { + parentBaseFee int64 + parentGasLimit uint64 + parentGasUsed uint64 + expectedBaseFee int64 + }{ + {params.InitialBaseFee, 20000000, 10000000, params.InitialBaseFee}, // usage == target + {params.InitialBaseFee, 20000000, 9000000, 993750000}, // usage below target + {params.InitialBaseFee, 20000000, 11000000, 1006250000}, // usage above target + {params.InitialBaseFee, 20000000, 20000000, 1062500000}, // usage full + {params.InitialBaseFee, 20000000, 0, 937500000}, // usage 0 + + } + for i, test := range tests { + parent := &types.Header{ + Number: big.NewInt(8), + GasLimit: test.parentGasLimit, + GasUsed: test.parentGasUsed, + BaseFee: big.NewInt(test.parentBaseFee), + } + if have, want := CalcBaseFee(testConfig, parent), big.NewInt(test.expectedBaseFee); have.Cmp(want) != 0 { + t.Errorf("test %d: have %d want %d, ", i, have, want) + } + } + +} diff --git a/internal/cli/server/chains/mainnet.go b/internal/cli/server/chains/mainnet.go index 20ff8bc9f2..bd41733704 100644 --- a/internal/cli/server/chains/mainnet.go +++ b/internal/cli/server/chains/mainnet.go @@ -30,6 +30,7 @@ var mainnetBor = &Chain{ LondonBlock: big.NewInt(23850000), Bor: ¶ms.BorConfig{ JaipurBlock: 23850000, + DelhiBlock: 36507200, Period: map[string]uint64{ "0": 2, }, diff --git a/internal/cli/server/chains/mumbai.go b/internal/cli/server/chains/mumbai.go index 9015e1b82b..29e33a283a 100644 --- a/internal/cli/server/chains/mumbai.go +++ b/internal/cli/server/chains/mumbai.go @@ -30,6 +30,7 @@ var mumbaiTestnet = &Chain{ LondonBlock: big.NewInt(22640000), Bor: ¶ms.BorConfig{ JaipurBlock: 22770000, + DelhiBlock: 29392500, Period: map[string]uint64{ "0": 2, "25275000": 5, diff --git a/params/config.go b/params/config.go index fe17f31bb0..2c99c4fb4c 100644 --- a/params/config.go +++ b/params/config.go @@ -350,6 +350,7 @@ var ( LondonBlock: big.NewInt(22640000), Bor: &BorConfig{ JaipurBlock: 22770000, + DelhiBlock: 29392500, Period: map[string]uint64{ "0": 2, "25275000": 5, @@ -399,6 +400,7 @@ var ( LondonBlock: big.NewInt(23850000), Bor: &BorConfig{ JaipurBlock: 23850000, + DelhiBlock: 36507200, Period: map[string]uint64{ "0": 2, }, @@ -577,6 +579,7 @@ type BorConfig struct { BlockAlloc map[string]interface{} `json:"blockAlloc"` BurntContract map[string]string `json:"burntContract"` // governance contract where the token will be sent to and burnt in london fork JaipurBlock uint64 `json:"jaipurBlock"` // Jaipur switch block (nil = no fork, 0 = already on jaipur) + DelhiBlock uint64 `json:"delhiBlock"` // Delhi switch block (nil = no fork, 0 = already on delhi) } // String implements the stringer interface, returning the consensus engine details. @@ -604,6 +607,10 @@ func (c *BorConfig) IsJaipur(number uint64) bool { return number >= c.JaipurBlock } +func (c *BorConfig) IsDelhi(number uint64) bool { + return number >= c.DelhiBlock +} + func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uint64) uint64 { keys := make([]string, 0, len(field)) for k := range field { diff --git a/params/protocol_params.go b/params/protocol_params.go index 5f154597a7..d65f9420a8 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -119,9 +119,11 @@ const ( // Introduced in Tangerine Whistle (Eip 150) CreateBySelfdestructGas uint64 = 25000 - BaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks. - ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have. - InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks. + BaseFeeChangeDenominatorPreDelhi = 8 // Bounds the amount the base fee can change between blocks before Delhi Hard Fork. + BaseFeeChangeDenominatorPostDelhi = 16 // Bounds the amount the base fee can change between blocks after Delhi Hard Fork. + + ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have. + InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks. MaxCodeSize = 24576 // Maximum bytecode to permit for a contract @@ -168,3 +170,11 @@ var ( MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be. DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. ) + +func BaseFeeChangeDenominator(borConfig *BorConfig, number uint64) uint64 { + if borConfig.IsDelhi(number) { + return BaseFeeChangeDenominatorPostDelhi + } else { + return BaseFeeChangeDenominatorPreDelhi + } +} diff --git a/tests/bor/testdata/genesis.json b/tests/bor/testdata/genesis.json index 87a7ea0b98..cbae055a0a 100644 --- a/tests/bor/testdata/genesis.json +++ b/tests/bor/testdata/genesis.json @@ -15,6 +15,7 @@ "londonBlock": 1, "bor": { "jaipurBlock": 2, + "delhiBlock" :3, "period": { "0": 1 }, diff --git a/tests/bor/testdata/genesis_21val.json b/tests/bor/testdata/genesis_21val.json index 2f67e56073..e2c604b1dc 100644 --- a/tests/bor/testdata/genesis_21val.json +++ b/tests/bor/testdata/genesis_21val.json @@ -15,6 +15,7 @@ "londonBlock": 0, "bor": { "jaipurBlock": 0, + "delhiBlock" :0, "period": { "0": 1 }, diff --git a/tests/bor/testdata/genesis_2val.json b/tests/bor/testdata/genesis_2val.json index 4ff647dde4..5ce5fbcd4e 100644 --- a/tests/bor/testdata/genesis_2val.json +++ b/tests/bor/testdata/genesis_2val.json @@ -15,6 +15,7 @@ "londonBlock": 1, "bor": { "jaipurBlock": 2, + "delhiBlock" :3, "period": { "0": 1 }, diff --git a/tests/bor/testdata/genesis_7val.json b/tests/bor/testdata/genesis_7val.json index 7fd5d08057..97982a3deb 100644 --- a/tests/bor/testdata/genesis_7val.json +++ b/tests/bor/testdata/genesis_7val.json @@ -15,6 +15,7 @@ "londonBlock": 0, "bor": { "jaipurBlock": 0, + "delhiBlock" :0, "period": { "0": 1 }, diff --git a/tests/bor/testdata/genesis_sprint_length_change.json b/tests/bor/testdata/genesis_sprint_length_change.json index ce6a2cb5f4..cb6eb2a729 100644 --- a/tests/bor/testdata/genesis_sprint_length_change.json +++ b/tests/bor/testdata/genesis_sprint_length_change.json @@ -15,6 +15,7 @@ "londonBlock": 1, "bor": { "jaipurBlock": 2, + "delhiBlock" :3, "period": { "0": 1 },