@@ -214,7 +214,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
214214 txs := block .Transactions ()
215215
216216 // 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 {
218218 return
219219 }
220220
@@ -338,7 +338,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
338338 return UncleError ("uncle[%d](%x)'s parent is not ancestor (%x)" , i , hash [:4 ], uncle .ParentHash [0 :4 ])
339339 }
340340
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 {
342342 return ValidationError (fmt .Sprintf ("uncle[%d](%x) header invalid: %v" , i , hash [:4 ], err ))
343343 }
344344 }
@@ -368,52 +368,50 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
368368}
369369
370370// 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 ))
375375 }
376376
377377 if uncle {
378- if block .Time .Cmp (common .MaxBig ) == 1 {
378+ if header .Time .Cmp (common .MaxBig ) == 1 {
379379 return BlockTSTooBigErr
380380 }
381381 } else {
382- if block .Time .Cmp (big .NewInt (time .Now ().Unix ())) == 1 {
382+ if header .Time .Cmp (big .NewInt (time .Now ().Unix ())) == 1 {
383383 return BlockFutureErr
384384 }
385385 }
386- if block .Time .Cmp (parent .Time () ) != 1 {
386+ if header .Time .Cmp (parent .Time ) != 1 {
387387 return BlockEqualTSErr
388388 }
389389
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 )
393393 }
394394
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 )
398397 a .Abs (a )
399- b = parent .GasLimit ( )
398+ b := new (big. Int ). Set ( parent .GasLimit )
400399 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 )
403402 }
404403
405- num := parent .Number ( )
406- num .Sub (block .Number , num )
404+ num := new (big. Int ). Set ( parent .Number )
405+ num .Sub (header .Number , num )
407406 if num .Cmp (big .NewInt (1 )) != 0 {
408407 return BlockNumberErr
409408 }
410409
411410 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 )
415414 }
416415 }
417-
418416 return nil
419417}
0 commit comments