mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
init : baseFeeChangeDenom HardFork Changes
This commit is contained in:
parent
3da2f650cb
commit
f768136102
13 changed files with 73 additions and 8 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
"londonBlock": 23850000,
|
"londonBlock": 23850000,
|
||||||
"bor": {
|
"bor": {
|
||||||
"jaipurBlock": 23850000,
|
"jaipurBlock": 23850000,
|
||||||
|
"delhiBlock": 36507200,
|
||||||
"period": {
|
"period": {
|
||||||
"0": 2
|
"0": 2
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
"londonBlock": 22640000,
|
"londonBlock": 22640000,
|
||||||
"bor": {
|
"bor": {
|
||||||
"jaipurBlock": 22770000,
|
"jaipurBlock": 22770000,
|
||||||
|
"delhiBlock": 29392500,
|
||||||
"period": {
|
"period": {
|
||||||
"0": 2,
|
"0": 2,
|
||||||
"25275000": 5
|
"25275000": 5
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,10 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
parentGasTarget = parent.GasLimit / params.ElasticityMultiplier
|
parentGasTarget = parent.GasLimit / params.ElasticityMultiplier
|
||||||
parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget)
|
parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget)
|
||||||
baseFeeChangeDenominator = new(big.Int).SetUint64(params.BaseFeeChangeDenominator)
|
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 the parent gasUsed is the same as the target, the baseFee remains unchanged.
|
||||||
if parent.GasUsed == parentGasTarget {
|
if parent.GasUsed == parentGasTarget {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
@ -47,12 +46,14 @@ func copyConfig(original *params.ChainConfig) *params.ChainConfig {
|
||||||
TerminalTotalDifficulty: original.TerminalTotalDifficulty,
|
TerminalTotalDifficulty: original.TerminalTotalDifficulty,
|
||||||
Ethash: original.Ethash,
|
Ethash: original.Ethash,
|
||||||
Clique: original.Clique,
|
Clique: original.Clique,
|
||||||
|
Bor: original.Bor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func config() *params.ChainConfig {
|
func config() *params.ChainConfig {
|
||||||
config := copyConfig(params.TestChainConfig)
|
config := copyConfig(params.TestChainConfig)
|
||||||
config.LondonBlock = big.NewInt(5)
|
config.LondonBlock = big.NewInt(5)
|
||||||
|
config.Bor.DelhiBlock = 8
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,10 +118,12 @@ func TestCalcBaseFee(t *testing.T) {
|
||||||
{params.InitialBaseFee, 20000000, 10000000, params.InitialBaseFee}, // usage == target
|
{params.InitialBaseFee, 20000000, 10000000, params.InitialBaseFee}, // usage == target
|
||||||
{params.InitialBaseFee, 20000000, 9000000, 987500000}, // usage below target
|
{params.InitialBaseFee, 20000000, 9000000, 987500000}, // usage below target
|
||||||
{params.InitialBaseFee, 20000000, 11000000, 1012500000}, // usage above 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 {
|
for i, test := range tests {
|
||||||
parent := &types.Header{
|
parent := &types.Header{
|
||||||
Number: common.Big32,
|
Number: big.NewInt(6),
|
||||||
GasLimit: test.parentGasLimit,
|
GasLimit: test.parentGasLimit,
|
||||||
GasUsed: test.parentGasUsed,
|
GasUsed: test.parentGasUsed,
|
||||||
BaseFee: big.NewInt(test.parentBaseFee),
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ var mainnetBor = &Chain{
|
||||||
LondonBlock: big.NewInt(23850000),
|
LondonBlock: big.NewInt(23850000),
|
||||||
Bor: ¶ms.BorConfig{
|
Bor: ¶ms.BorConfig{
|
||||||
JaipurBlock: 23850000,
|
JaipurBlock: 23850000,
|
||||||
|
DelhiBlock: 36507200,
|
||||||
Period: map[string]uint64{
|
Period: map[string]uint64{
|
||||||
"0": 2,
|
"0": 2,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ var mumbaiTestnet = &Chain{
|
||||||
LondonBlock: big.NewInt(22640000),
|
LondonBlock: big.NewInt(22640000),
|
||||||
Bor: ¶ms.BorConfig{
|
Bor: ¶ms.BorConfig{
|
||||||
JaipurBlock: 22770000,
|
JaipurBlock: 22770000,
|
||||||
|
DelhiBlock: 29392500,
|
||||||
Period: map[string]uint64{
|
Period: map[string]uint64{
|
||||||
"0": 2,
|
"0": 2,
|
||||||
"25275000": 5,
|
"25275000": 5,
|
||||||
|
|
|
||||||
|
|
@ -350,6 +350,7 @@ var (
|
||||||
LondonBlock: big.NewInt(22640000),
|
LondonBlock: big.NewInt(22640000),
|
||||||
Bor: &BorConfig{
|
Bor: &BorConfig{
|
||||||
JaipurBlock: 22770000,
|
JaipurBlock: 22770000,
|
||||||
|
DelhiBlock: 29392500,
|
||||||
Period: map[string]uint64{
|
Period: map[string]uint64{
|
||||||
"0": 2,
|
"0": 2,
|
||||||
"25275000": 5,
|
"25275000": 5,
|
||||||
|
|
@ -399,6 +400,7 @@ var (
|
||||||
LondonBlock: big.NewInt(23850000),
|
LondonBlock: big.NewInt(23850000),
|
||||||
Bor: &BorConfig{
|
Bor: &BorConfig{
|
||||||
JaipurBlock: 23850000,
|
JaipurBlock: 23850000,
|
||||||
|
DelhiBlock: 36507200,
|
||||||
Period: map[string]uint64{
|
Period: map[string]uint64{
|
||||||
"0": 2,
|
"0": 2,
|
||||||
},
|
},
|
||||||
|
|
@ -577,6 +579,7 @@ type BorConfig struct {
|
||||||
BlockAlloc map[string]interface{} `json:"blockAlloc"`
|
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
|
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)
|
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.
|
// 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
|
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 {
|
func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uint64) uint64 {
|
||||||
keys := make([]string, 0, len(field))
|
keys := make([]string, 0, len(field))
|
||||||
for k := range field {
|
for k := range field {
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,11 @@ const (
|
||||||
// Introduced in Tangerine Whistle (Eip 150)
|
// Introduced in Tangerine Whistle (Eip 150)
|
||||||
CreateBySelfdestructGas uint64 = 25000
|
CreateBySelfdestructGas uint64 = 25000
|
||||||
|
|
||||||
BaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
|
BaseFeeChangeDenominatorPreDelhi = 8 // Bounds the amount the base fee can change between blocks before Delhi Hard Fork.
|
||||||
ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
|
BaseFeeChangeDenominatorPostDelhi = 16 // Bounds the amount the base fee can change between blocks after Delhi Hard Fork.
|
||||||
InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.
|
|
||||||
|
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
|
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.
|
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.
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
1
tests/bor/testdata/genesis.json
vendored
1
tests/bor/testdata/genesis.json
vendored
|
|
@ -15,6 +15,7 @@
|
||||||
"londonBlock": 1,
|
"londonBlock": 1,
|
||||||
"bor": {
|
"bor": {
|
||||||
"jaipurBlock": 2,
|
"jaipurBlock": 2,
|
||||||
|
"delhiBlock" :3,
|
||||||
"period": {
|
"period": {
|
||||||
"0": 1
|
"0": 1
|
||||||
},
|
},
|
||||||
|
|
|
||||||
1
tests/bor/testdata/genesis_21val.json
vendored
1
tests/bor/testdata/genesis_21val.json
vendored
|
|
@ -15,6 +15,7 @@
|
||||||
"londonBlock": 0,
|
"londonBlock": 0,
|
||||||
"bor": {
|
"bor": {
|
||||||
"jaipurBlock": 0,
|
"jaipurBlock": 0,
|
||||||
|
"delhiBlock" :0,
|
||||||
"period": {
|
"period": {
|
||||||
"0": 1
|
"0": 1
|
||||||
},
|
},
|
||||||
|
|
|
||||||
1
tests/bor/testdata/genesis_2val.json
vendored
1
tests/bor/testdata/genesis_2val.json
vendored
|
|
@ -15,6 +15,7 @@
|
||||||
"londonBlock": 1,
|
"londonBlock": 1,
|
||||||
"bor": {
|
"bor": {
|
||||||
"jaipurBlock": 2,
|
"jaipurBlock": 2,
|
||||||
|
"delhiBlock" :3,
|
||||||
"period": {
|
"period": {
|
||||||
"0": 1
|
"0": 1
|
||||||
},
|
},
|
||||||
|
|
|
||||||
1
tests/bor/testdata/genesis_7val.json
vendored
1
tests/bor/testdata/genesis_7val.json
vendored
|
|
@ -15,6 +15,7 @@
|
||||||
"londonBlock": 0,
|
"londonBlock": 0,
|
||||||
"bor": {
|
"bor": {
|
||||||
"jaipurBlock": 0,
|
"jaipurBlock": 0,
|
||||||
|
"delhiBlock" :0,
|
||||||
"period": {
|
"period": {
|
||||||
"0": 1
|
"0": 1
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
"londonBlock": 1,
|
"londonBlock": 1,
|
||||||
"bor": {
|
"bor": {
|
||||||
"jaipurBlock": 2,
|
"jaipurBlock": 2,
|
||||||
|
"delhiBlock" :3,
|
||||||
"period": {
|
"period": {
|
||||||
"0": 1
|
"0": 1
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue