@@ -26,7 +26,6 @@ import (
26
26
"reflect"
27
27
"strings"
28
28
29
- "github.com/ethereum/go-ethereum/common"
30
29
"github.com/ethereum/go-ethereum/core/types"
31
30
"github.com/ethereum/go-ethereum/log"
32
31
"github.com/ethereum/go-ethereum/params"
@@ -78,7 +77,7 @@ func NewID(config *params.ChainConfig, genesis *types.Block, head, time uint64)
78
77
hash := crc32 .ChecksumIEEE (genesis .Hash ().Bytes ())
79
78
80
79
// Calculate the current fork checksum and the next fork block
81
- forksByBlock , forksByTime := gatherForks (config )
80
+ forksByBlock , forksByTime := gatherForks (config , genesis . Time () )
82
81
for _ , fork := range forksByBlock {
83
82
if fork <= head {
84
83
// Fork already passed, checksum the previous hash and the fork number
@@ -88,10 +87,6 @@ func NewID(config *params.ChainConfig, genesis *types.Block, head, time uint64)
88
87
return ID {Hash : checksumToBytes (hash ), Next : fork }
89
88
}
90
89
for _ , fork := range forksByTime {
91
- if fork <= genesis .Time () {
92
- // Fork active in genesis, skip in forkid calculation
93
- continue
94
- }
95
90
if fork <= time {
96
91
// Fork already passed, checksum the previous hash and fork timestamp
97
92
hash = checksumUpdate (hash , fork )
@@ -119,7 +114,7 @@ func NewIDWithChain(chain Blockchain) ID {
119
114
func NewFilter (chain Blockchain ) Filter {
120
115
return newFilter (
121
116
chain .Config (),
122
- chain .Genesis (). Hash () ,
117
+ chain .Genesis (),
123
118
func () (uint64 , uint64 ) {
124
119
head := chain .CurrentHeader ()
125
120
return head .Number .Uint64 (), head .Time
@@ -128,22 +123,22 @@ func NewFilter(chain Blockchain) Filter {
128
123
}
129
124
130
125
// NewStaticFilter creates a filter at block zero.
131
- func NewStaticFilter (config * params.ChainConfig , genesis common. Hash ) Filter {
126
+ func NewStaticFilter (config * params.ChainConfig , genesis * types. Block ) Filter {
132
127
head := func () (uint64 , uint64 ) { return 0 , 0 }
133
128
return newFilter (config , genesis , head )
134
129
}
135
130
136
131
// newFilter is the internal version of NewFilter, taking closures as its arguments
137
132
// instead of a chain. The reason is to allow testing it without having to simulate
138
133
// an entire blockchain.
139
- func newFilter (config * params.ChainConfig , genesis common. Hash , headfn func () (uint64 , uint64 )) Filter {
134
+ func newFilter (config * params.ChainConfig , genesis * types. Block , headfn func () (uint64 , uint64 )) Filter {
140
135
// Calculate the all the valid fork hash and fork next combos
141
136
var (
142
- forksByBlock , forksByTime = gatherForks (config )
137
+ forksByBlock , forksByTime = gatherForks (config , genesis . Time () )
143
138
forks = append (append ([]uint64 {}, forksByBlock ... ), forksByTime ... )
144
139
sums = make ([][4 ]byte , len (forks )+ 1 ) // 0th is the genesis
145
140
)
146
- hash := crc32 .ChecksumIEEE (genesis [:] )
141
+ hash := crc32 .ChecksumIEEE (genesis . Hash (). Bytes () )
147
142
sums [0 ] = checksumToBytes (hash )
148
143
for i , fork := range forks {
149
144
hash = checksumUpdate (hash , fork )
@@ -244,7 +239,7 @@ func checksumToBytes(hash uint32) [4]byte {
244
239
245
240
// gatherForks gathers all the known forks and creates two sorted lists out of
246
241
// them, one for the block number based forks and the second for the timestamps.
247
- func gatherForks (config * params.ChainConfig ) ([]uint64 , []uint64 ) {
242
+ func gatherForks (config * params.ChainConfig , genesis uint64 ) ([]uint64 , []uint64 ) {
248
243
// Gather all the fork block numbers via reflection
249
244
kind := reflect .TypeOf (params.ChainConfig {})
250
245
conf := reflect .ValueOf (config ).Elem ()
@@ -294,7 +289,8 @@ func gatherForks(config *params.ChainConfig) ([]uint64, []uint64) {
294
289
if len (forksByBlock ) > 0 && forksByBlock [0 ] == 0 {
295
290
forksByBlock = forksByBlock [1 :]
296
291
}
297
- if len (forksByTime ) > 0 && forksByTime [0 ] == 0 {
292
+ // Skip any forks before genesis.
293
+ for len (forksByTime ) > 0 && forksByTime [0 ] <= genesis {
298
294
forksByTime = forksByTime [1 :]
299
295
}
300
296
return forksByBlock , forksByTime
0 commit comments