@@ -213,7 +213,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
213213 txs := block .Transactions ()
214214
215215 // 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 {
217217 return
218218 }
219219
@@ -337,7 +337,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
337337 return UncleError ("uncle[%d](%x)'s parent is not ancestor (%x)" , i , hash [:4 ], uncle .ParentHash [0 :4 ])
338338 }
339339
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 {
341341 return ValidationError (fmt .Sprintf ("uncle[%d](%x) header invalid: %v" , i , hash [:4 ], err ))
342342 }
343343 }
@@ -367,52 +367,50 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
367367}
368368
369369// 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 ))
374374 }
375375
376376 if uncle {
377- if block .Time .Cmp (common .MaxBig ) == 1 {
377+ if header .Time .Cmp (common .MaxBig ) == 1 {
378378 return BlockTSTooBigErr
379379 }
380380 } else {
381- if block .Time .Cmp (big .NewInt (time .Now ().Unix ())) == 1 {
381+ if header .Time .Cmp (big .NewInt (time .Now ().Unix ())) == 1 {
382382 return BlockFutureErr
383383 }
384384 }
385- if block .Time .Cmp (parent .Time () ) != 1 {
385+ if header .Time .Cmp (parent .Time ) != 1 {
386386 return BlockEqualTSErr
387387 }
388388
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 )
392392 }
393393
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 )
397396 a .Abs (a )
398- b = parent .GasLimit ( )
397+ b := new (big. Int ). Set ( parent .GasLimit )
399398 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 )
402401 }
403402
404- num := parent .Number ( )
405- num .Sub (block .Number , num )
403+ num := new (big. Int ). Set ( parent .Number )
404+ num .Sub (header .Number , num )
406405 if num .Cmp (big .NewInt (1 )) != 0 {
407406 return BlockNumberErr
408407 }
409408
410409 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 )
414413 }
415414 }
416-
417415 return nil
418416}
0 commit comments