@@ -46,12 +46,12 @@ import (
46
46
47
47
// Cuckoo proof-of-work protocol constants.
48
48
var (
49
- FrontierBlockReward * big.Int = big .NewInt (7e+18 ) // Block reward in wei for successfully mining a block
50
- ByzantiumBlockReward * big.Int = big .NewInt (7e+18 ) // Block reward in wei for successfully mining a block upward from Byzantium
51
- ConstantinopleBlockReward = big .NewInt (7e+18 )
52
- maxUncles = 2 // Maximum number of uncles allowed in a single block
53
- allowedFutureBlockTime = 15 * time . Second // Max time from current time allowed for blocks, before they're considered future blocks
54
- FixHashes = map [common.Hash ]bool {
49
+ FrontierBlockReward * big.Int = big .NewInt (7e+18 ) // Block reward in wei for successfully mining a block
50
+ ByzantiumBlockReward * big.Int = big .NewInt (7e+18 ) // Block reward in wei for successfully mining a block upward from Byzantium
51
+ ConstantinopleBlockReward = big .NewInt (7e+18 )
52
+ maxUncles = 2 // Maximum number of uncles allowed in a single block
53
+ allowedFutureBlockTimeSeconds = int64 ( 15 )
54
+ FixHashes = map [common.Hash ]bool {
55
55
common .HexToHash ("0x367e111f0f274d54f357ed3dc2d16107b39772c3a767138b857f5c02b5c30607" ): true ,
56
56
common .HexToHash ("0xbde83a87b6d526ada5a02e394c5f21327acb080568f7cc6f8fff423620f0eec3" ): true ,
57
57
}
@@ -107,7 +107,7 @@ func (cuckoo *Cuckoo) VerifyHeader(chain consensus.ChainHeaderReader, header *ty
107
107
return consensus .ErrUnknownAncestor
108
108
}
109
109
// Sanity checks passed, do a proper verification
110
- return cuckoo .verifyHeader (chain , header , parent , false , seal )
110
+ return cuckoo .verifyHeader (chain , header , parent , false , seal , time . Now (). Unix () )
111
111
}
112
112
113
113
// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
@@ -135,11 +135,12 @@ func (cuckoo *Cuckoo) VerifyHeaders(chain consensus.ChainHeaderReader, headers [
135
135
done = make (chan int , workers )
136
136
errors = make ([]error , len (headers ))
137
137
abort = make (chan struct {})
138
+ utcNow = time .Now ().Unix ()
138
139
)
139
140
for i := 0 ; i < workers ; i ++ {
140
141
go func () {
141
142
for index := range inputs {
142
- errors [index ] = cuckoo .verifyHeaderWorker (chain , headers , seals , index )
143
+ errors [index ] = cuckoo .verifyHeaderWorker (chain , headers , seals , index , utcNow )
143
144
done <- index
144
145
}
145
146
}()
@@ -175,7 +176,7 @@ func (cuckoo *Cuckoo) VerifyHeaders(chain consensus.ChainHeaderReader, headers [
175
176
return abort , errorsOut
176
177
}
177
178
178
- func (cuckoo * Cuckoo ) verifyHeaderWorker (chain consensus.ChainHeaderReader , headers []* types.Header , seals []bool , index int ) error {
179
+ func (cuckoo * Cuckoo ) verifyHeaderWorker (chain consensus.ChainHeaderReader , headers []* types.Header , seals []bool , index int , utcNow int64 ) error {
179
180
var parent * types.Header
180
181
if index == 0 {
181
182
parent = chain .GetHeader (headers [0 ].ParentHash , headers [0 ].Number .Uint64 ()- 1 )
@@ -185,10 +186,7 @@ func (cuckoo *Cuckoo) verifyHeaderWorker(chain consensus.ChainHeaderReader, head
185
186
if parent == nil {
186
187
return consensus .ErrUnknownAncestor
187
188
}
188
- if chain .GetHeader (headers [index ].Hash (), headers [index ].Number .Uint64 ()) != nil {
189
- return nil // known block
190
- }
191
- return cuckoo .verifyHeader (chain , headers [index ], parent , false , seals [index ])
189
+ return cuckoo .verifyHeader (chain , headers [index ], parent , false , seals [index ], utcNow )
192
190
}
193
191
194
192
// VerifyUncles verifies that the given block's uncles conform to the consensus
@@ -240,7 +238,7 @@ func (cuckoo *Cuckoo) VerifyUncles(chain consensus.ChainReader, block *types.Blo
240
238
if ancestors [uncle .ParentHash ] == nil || uncle .ParentHash == block .ParentHash () {
241
239
return errDanglingUncle
242
240
}
243
- if err := cuckoo .verifyHeader (chain , uncle , ancestors [uncle .ParentHash ], true , true ); err != nil {
241
+ if err := cuckoo .verifyHeader (chain , uncle , ancestors [uncle .ParentHash ], true , true , time . Now (). Unix () ); err != nil {
244
242
return err
245
243
}
246
244
}
@@ -250,14 +248,14 @@ func (cuckoo *Cuckoo) VerifyUncles(chain consensus.ChainReader, block *types.Blo
250
248
// verifyHeader checks whether a header conforms to the consensus rules of the
251
249
// stock Cortex cuckoo engine.
252
250
// See YP section 4.3.4. "Block Header Validity"
253
- func (cuckoo * Cuckoo ) verifyHeader (chain consensus.ChainHeaderReader , header , parent * types.Header , uncle , seal bool ) error {
251
+ func (cuckoo * Cuckoo ) verifyHeader (chain consensus.ChainHeaderReader , header , parent * types.Header , uncle , seal bool , utcNow int64 ) error {
254
252
// Ensure that the header's extra-data section is of a reasonable size
255
253
if uint64 (len (header .Extra )) > params .MaximumExtraDataSize {
256
254
return fmt .Errorf ("extra-data too long: %d > %d" , len (header .Extra ), params .MaximumExtraDataSize )
257
255
}
258
256
// Verify the header's timestamp
259
257
if ! uncle {
260
- if header .Time > uint64 (time . Now (). Add ( allowedFutureBlockTime ). Unix () ) {
258
+ if header .Time > uint64 (utcNow + allowedFutureBlockTimeSeconds ) {
261
259
return consensus .ErrFutureBlock
262
260
}
263
261
}
0 commit comments