@@ -213,7 +213,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
213
213
txs := block .Transactions ()
214
214
215
215
// Block validation
216
- if err = ValidateHeader (sm .Pow , header , parent , false , false ); err != nil {
216
+ if err = ValidateHeader (sm .Pow , header , parent . Header () , false , false ); err != nil {
217
217
return
218
218
}
219
219
@@ -337,7 +337,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
337
337
return UncleError ("uncle[%d](%x)'s parent is not ancestor (%x)" , i , hash [:4 ], uncle .ParentHash [0 :4 ])
338
338
}
339
339
340
- if err := ValidateHeader (sm .Pow , uncle , ancestors [uncle .ParentHash ], true , true ); err != nil {
340
+ if err := ValidateHeader (sm .Pow , uncle , ancestors [uncle .ParentHash ]. Header () , true , true ); err != nil {
341
341
return ValidationError (fmt .Sprintf ("uncle[%d](%x) header invalid: %v" , i , hash [:4 ], err ))
342
342
}
343
343
}
@@ -367,52 +367,50 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
367
367
}
368
368
369
369
// See YP section 4.3.4. "Block Header Validity"
370
- // Validates a block . Returns an error if the block is invalid.
371
- func ValidateHeader (pow pow.PoW , block * types.Header , parent * types.Block , checkPow , uncle bool ) error {
372
- if big .NewInt (int64 (len (block .Extra ))).Cmp (params .MaximumExtraDataSize ) == 1 {
373
- return fmt .Errorf ("Block extra data too long (%d)" , len (block .Extra ))
370
+ // Validates a header . Returns an error if the header is invalid.
371
+ func ValidateHeader (pow pow.PoW , header * types.Header , parent * types.Header , checkPow , uncle bool ) error {
372
+ if big .NewInt (int64 (len (header .Extra ))).Cmp (params .MaximumExtraDataSize ) == 1 {
373
+ return fmt .Errorf ("Header extra data too long (%d)" , len (header .Extra ))
374
374
}
375
375
376
376
if uncle {
377
- if block .Time .Cmp (common .MaxBig ) == 1 {
377
+ if header .Time .Cmp (common .MaxBig ) == 1 {
378
378
return BlockTSTooBigErr
379
379
}
380
380
} else {
381
- if block .Time .Cmp (big .NewInt (time .Now ().Unix ())) == 1 {
381
+ if header .Time .Cmp (big .NewInt (time .Now ().Unix ())) == 1 {
382
382
return BlockFutureErr
383
383
}
384
384
}
385
- if block .Time .Cmp (parent .Time () ) != 1 {
385
+ if header .Time .Cmp (parent .Time ) != 1 {
386
386
return BlockEqualTSErr
387
387
}
388
388
389
- expd := CalcDifficulty (block .Time .Uint64 (), parent .Time () .Uint64 (), parent .Number () , parent .Difficulty () )
390
- if expd .Cmp (block .Difficulty ) != 0 {
391
- return fmt .Errorf ("Difficulty check failed for block %v, %v" , block .Difficulty , expd )
389
+ expd := CalcDifficulty (header .Time .Uint64 (), parent .Time .Uint64 (), parent .Number , parent .Difficulty )
390
+ if expd .Cmp (header .Difficulty ) != 0 {
391
+ return fmt .Errorf ("Difficulty check failed for header %v, %v" , header .Difficulty , expd )
392
392
}
393
393
394
- var a , b * big.Int
395
- a = parent .GasLimit ()
396
- a = a .Sub (a , block .GasLimit )
394
+ a := new (big.Int ).Set (parent .GasLimit )
395
+ a = a .Sub (a , header .GasLimit )
397
396
a .Abs (a )
398
- b = parent .GasLimit ( )
397
+ b := new (big. Int ). Set ( parent .GasLimit )
399
398
b = b .Div (b , params .GasLimitBoundDivisor )
400
- if ! (a .Cmp (b ) < 0 ) || (block .GasLimit .Cmp (params .MinGasLimit ) == - 1 ) {
401
- return fmt .Errorf ("GasLimit check failed for block %v (%v > %v)" , block .GasLimit , a , b )
399
+ if ! (a .Cmp (b ) < 0 ) || (header .GasLimit .Cmp (params .MinGasLimit ) == - 1 ) {
400
+ return fmt .Errorf ("GasLimit check failed for header %v (%v > %v)" , header .GasLimit , a , b )
402
401
}
403
402
404
- num := parent .Number ( )
405
- num .Sub (block .Number , num )
403
+ num := new (big. Int ). Set ( parent .Number )
404
+ num .Sub (header .Number , num )
406
405
if num .Cmp (big .NewInt (1 )) != 0 {
407
406
return BlockNumberErr
408
407
}
409
408
410
409
if checkPow {
411
- // Verify the nonce of the block . Return an error if it's not valid
412
- if ! pow .Verify (types .NewBlockWithHeader (block )) {
413
- return ValidationError ("Block 's nonce is invalid (= %x)" , block .Nonce )
410
+ // Verify the nonce of the header . Return an error if it's not valid
411
+ if ! pow .Verify (types .NewBlockWithHeader (header )) {
412
+ return ValidationError ("Header 's nonce is invalid (= %x)" , header .Nonce )
414
413
}
415
414
}
416
-
417
415
return nil
418
416
}
0 commit comments