From 7d92be2f176f5ee0196ae8f68357225ffdbd58ad Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Mon, 14 Nov 2022 17:52:55 +0530 Subject: [PATCH] fix : jaipurFork & baseFeeChangeDenom hardfork num to bigInt --- consensus/bor/bor.go | 2 +- consensus/bor/bor_test.go | 8 ++++---- consensus/misc/eip1559.go | 2 +- consensus/misc/eip1559_test.go | 2 +- internal/cli/server/chains/mainnet.go | 4 ++-- internal/cli/server/chains/mumbai.go | 4 ++-- params/config.go | 20 ++++++++++---------- params/protocol_params.go | 2 +- tests/bor/bor_test.go | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 3cc8c68ec2..1b4ddec45d 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -169,7 +169,7 @@ func encodeSigHeader(w io.Writer, header *types.Header, c *params.BorConfig) { header.Nonce, } - if c.IsJaipur(header.Number.Uint64()) { + if c.IsJaipur(header.Number) { if header.BaseFee != nil { enc = append(enc, header.BaseFee) } diff --git a/consensus/bor/bor_test.go b/consensus/bor/bor_test.go index fc2d59520d..9ca361a18d 100644 --- a/consensus/bor/bor_test.go +++ b/consensus/bor/bor_test.go @@ -125,20 +125,20 @@ func TestEncodeSigHeaderJaipur(t *testing.T) { ) // Jaipur NOT enabled and BaseFee not set - hash := SealHash(h, ¶ms.BorConfig{JaipurBlock: 10}) + hash := SealHash(h, ¶ms.BorConfig{JaipurBlock: big.NewInt(10)}) require.Equal(t, hash, hashWithoutBaseFee) // Jaipur enabled (Jaipur=0) and BaseFee not set - hash = SealHash(h, ¶ms.BorConfig{JaipurBlock: 0}) + hash = SealHash(h, ¶ms.BorConfig{JaipurBlock: common.Big0}) require.Equal(t, hash, hashWithoutBaseFee) h.BaseFee = big.NewInt(2) // Jaipur enabled (Jaipur=Header block) and BaseFee set - hash = SealHash(h, ¶ms.BorConfig{JaipurBlock: 1}) + hash = SealHash(h, ¶ms.BorConfig{JaipurBlock: common.Big1}) require.Equal(t, hash, hashWithBaseFee) // Jaipur NOT enabled and BaseFee set - hash = SealHash(h, ¶ms.BorConfig{JaipurBlock: 10}) + hash = SealHash(h, ¶ms.BorConfig{JaipurBlock: big.NewInt(10)}) require.Equal(t, hash, hashWithoutBaseFee) } diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index f620f9504e..193a5b84e2 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -61,7 +61,7 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { var ( parentGasTarget = parent.GasLimit / params.ElasticityMultiplier parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget) - baseFeeChangeDenominatorUint64 = params.BaseFeeChangeDenominator(config.Bor, parent.Number.Uint64()) + baseFeeChangeDenominatorUint64 = params.BaseFeeChangeDenominator(config.Bor, parent.Number) baseFeeChangeDenominator = new(big.Int).SetUint64(baseFeeChangeDenominatorUint64) ) // If the parent gasUsed is the same as the target, the baseFee remains unchanged. diff --git a/consensus/misc/eip1559_test.go b/consensus/misc/eip1559_test.go index 0d757105c7..2509105306 100644 --- a/consensus/misc/eip1559_test.go +++ b/consensus/misc/eip1559_test.go @@ -53,7 +53,7 @@ func copyConfig(original *params.ChainConfig) *params.ChainConfig { func config() *params.ChainConfig { config := copyConfig(params.TestChainConfig) config.LondonBlock = big.NewInt(5) - config.Bor.DelhiBlock = 8 + config.Bor.DelhiBlock = big.NewInt(8) return config } diff --git a/internal/cli/server/chains/mainnet.go b/internal/cli/server/chains/mainnet.go index bd41733704..485188983e 100644 --- a/internal/cli/server/chains/mainnet.go +++ b/internal/cli/server/chains/mainnet.go @@ -29,8 +29,8 @@ var mainnetBor = &Chain{ BerlinBlock: big.NewInt(14750000), LondonBlock: big.NewInt(23850000), Bor: ¶ms.BorConfig{ - JaipurBlock: 23850000, - DelhiBlock: 36507200, + JaipurBlock: big.NewInt(23850000), + DelhiBlock: big.NewInt(36507200), Period: map[string]uint64{ "0": 2, }, diff --git a/internal/cli/server/chains/mumbai.go b/internal/cli/server/chains/mumbai.go index 29e33a283a..efed582061 100644 --- a/internal/cli/server/chains/mumbai.go +++ b/internal/cli/server/chains/mumbai.go @@ -29,8 +29,8 @@ var mumbaiTestnet = &Chain{ BerlinBlock: big.NewInt(13996000), LondonBlock: big.NewInt(22640000), Bor: ¶ms.BorConfig{ - JaipurBlock: 22770000, - DelhiBlock: 29392500, + JaipurBlock: big.NewInt(22770000), + DelhiBlock: big.NewInt(29392500), Period: map[string]uint64{ "0": 2, "25275000": 5, diff --git a/params/config.go b/params/config.go index 2c99c4fb4c..4786053f6a 100644 --- a/params/config.go +++ b/params/config.go @@ -349,8 +349,8 @@ var ( BerlinBlock: big.NewInt(13996000), LondonBlock: big.NewInt(22640000), Bor: &BorConfig{ - JaipurBlock: 22770000, - DelhiBlock: 29392500, + JaipurBlock: big.NewInt(22770000), + DelhiBlock: big.NewInt(29392500), Period: map[string]uint64{ "0": 2, "25275000": 5, @@ -399,8 +399,8 @@ var ( BerlinBlock: big.NewInt(14750000), LondonBlock: big.NewInt(23850000), Bor: &BorConfig{ - JaipurBlock: 23850000, - DelhiBlock: 36507200, + JaipurBlock: big.NewInt(23850000), + DelhiBlock: big.NewInt(36507200), Period: map[string]uint64{ "0": 2, }, @@ -578,8 +578,8 @@ type BorConfig struct { OverrideStateSyncRecords map[string]int `json:"overrideStateSyncRecords"` // override state records count 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) + JaipurBlock *big.Int `json:"jaipurBlock"` // Jaipur switch block (nil = no fork, 0 = already on jaipur) + DelhiBlock *big.Int `json:"delhiBlock"` // Delhi switch block (nil = no fork, 0 = already on delhi) } // String implements the stringer interface, returning the consensus engine details. @@ -603,12 +603,12 @@ func (c *BorConfig) CalculatePeriod(number uint64) uint64 { return c.calculateBorConfigHelper(c.Period, number) } -func (c *BorConfig) IsJaipur(number uint64) bool { - return number >= c.JaipurBlock +func (c *BorConfig) IsJaipur(number *big.Int) bool { + return isForked(c.JaipurBlock, number) } -func (c *BorConfig) IsDelhi(number uint64) bool { - return number >= c.DelhiBlock +func (c *BorConfig) IsDelhi(number *big.Int) bool { + return isForked(c.DelhiBlock, number) } func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uint64) uint64 { diff --git a/params/protocol_params.go b/params/protocol_params.go index d65f9420a8..d468af5d3c 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -171,7 +171,7 @@ var ( 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 { +func BaseFeeChangeDenominator(borConfig *BorConfig, number *big.Int) uint64 { if borConfig.IsDelhi(number) { return BaseFeeChangeDenominatorPostDelhi } else { diff --git a/tests/bor/bor_test.go b/tests/bor/bor_test.go index 0b339b04d1..0e8129d0b3 100644 --- a/tests/bor/bor_test.go +++ b/tests/bor/bor_test.go @@ -1109,7 +1109,7 @@ func testEncodeSigHeader(w io.Writer, header *types.Header, c *params.BorConfig) header.MixDigest, header.Nonce, } - if c.IsJaipur(header.Number.Uint64()) { + if c.IsJaipur(header.Number) { if header.BaseFee != nil { enc = append(enc, header.BaseFee) }