Skip to content

Commit fe24470

Browse files
committed
params: better handle nil and large timestamps
1 parent fc9e216 commit fe24470

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

params/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp *big.Int) Rule
10201020
IsBerlin: c.IsBerlin(num),
10211021
IsLondon: c.IsLondon(num),
10221022
IsMerge: isMerge,
1023-
IsShanghai: timestamp.IsUint64() && c.IsShanghai(timestamp.Uint64()),
1024-
isCancun: timestamp.IsUint64() && c.IsCancun(timestamp.Uint64()),
1025-
isPrague: timestamp.IsUint64() && c.IsPrague(timestamp.Uint64()),
1023+
IsShanghai: timestamp != nil && (!timestamp.IsUint64() || c.IsShanghai(timestamp.Uint64())),
1024+
isCancun: timestamp != nil && (!timestamp.IsUint64() || c.IsCancun(timestamp.Uint64())),
1025+
isPrague: timestamp != nil && (!timestamp.IsUint64() || c.IsPrague(timestamp.Uint64())),
10261026
}
10271027
}

params/config_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,25 @@ func TestCheckCompatible(t *testing.T) {
116116
}
117117
}
118118
}
119+
120+
func TestConfigRules(t *testing.T) {
121+
c := &ChainConfig{
122+
ShanghaiTime: big.NewInt(500),
123+
}
124+
var stamp *big.Int
125+
if r := c.Rules(big.NewInt(0), true, stamp); r.IsShanghai {
126+
t.Errorf("expected %v to not be shanghai", stamp)
127+
}
128+
stamp = big.NewInt(0)
129+
if r := c.Rules(big.NewInt(0), true, stamp); r.IsShanghai {
130+
t.Errorf("expected %v to not be shanghai", stamp)
131+
}
132+
stamp = big.NewInt(500)
133+
if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai {
134+
t.Errorf("expected %v to be shanghai", stamp)
135+
}
136+
stamp, _ = big.NewInt(0).SetString("0xffffffff0000000000000000000000000000000000000000", 0)
137+
if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai {
138+
t.Errorf("expected %v to be shanghai", stamp)
139+
}
140+
}

0 commit comments

Comments
 (0)