fix : jaipurFork & baseFeeChangeDenom hardfork num to bigInt

This commit is contained in:
Shivam Sharma 2022-11-14 17:52:55 +05:30
parent f768136102
commit 7d92be2f17
9 changed files with 23 additions and 23 deletions

View file

@ -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)
}

View file

@ -125,20 +125,20 @@ func TestEncodeSigHeaderJaipur(t *testing.T) {
)
// Jaipur NOT enabled and BaseFee not set
hash := SealHash(h, &params.BorConfig{JaipurBlock: 10})
hash := SealHash(h, &params.BorConfig{JaipurBlock: big.NewInt(10)})
require.Equal(t, hash, hashWithoutBaseFee)
// Jaipur enabled (Jaipur=0) and BaseFee not set
hash = SealHash(h, &params.BorConfig{JaipurBlock: 0})
hash = SealHash(h, &params.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, &params.BorConfig{JaipurBlock: 1})
hash = SealHash(h, &params.BorConfig{JaipurBlock: common.Big1})
require.Equal(t, hash, hashWithBaseFee)
// Jaipur NOT enabled and BaseFee set
hash = SealHash(h, &params.BorConfig{JaipurBlock: 10})
hash = SealHash(h, &params.BorConfig{JaipurBlock: big.NewInt(10)})
require.Equal(t, hash, hashWithoutBaseFee)
}

View file

@ -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.

View file

@ -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
}

View file

@ -29,8 +29,8 @@ var mainnetBor = &Chain{
BerlinBlock: big.NewInt(14750000),
LondonBlock: big.NewInt(23850000),
Bor: &params.BorConfig{
JaipurBlock: 23850000,
DelhiBlock: 36507200,
JaipurBlock: big.NewInt(23850000),
DelhiBlock: big.NewInt(36507200),
Period: map[string]uint64{
"0": 2,
},

View file

@ -29,8 +29,8 @@ var mumbaiTestnet = &Chain{
BerlinBlock: big.NewInt(13996000),
LondonBlock: big.NewInt(22640000),
Bor: &params.BorConfig{
JaipurBlock: 22770000,
DelhiBlock: 29392500,
JaipurBlock: big.NewInt(22770000),
DelhiBlock: big.NewInt(29392500),
Period: map[string]uint64{
"0": 2,
"25275000": 5,

View file

@ -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 {

View file

@ -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 {

View file

@ -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)
}