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