@@ -41,13 +41,13 @@ var (
4141//
4242// BlockValidator implements Validator.
4343type BlockValidator struct {
44- config * ChainConfig // Chain configuration options
45- bc * BlockChain // Canonical block chain
46- Pow pow.PoW // Proof of work used for validating
44+ config * params. ChainConfig // Chain configuration options
45+ bc * BlockChain // Canonical block chain
46+ Pow pow.PoW // Proof of work used for validating
4747}
4848
4949// NewBlockValidator returns a new block validator which is safe for re-use
50- func NewBlockValidator (config * ChainConfig , blockchain * BlockChain , pow pow.PoW ) * BlockValidator {
50+ func NewBlockValidator (config * params. ChainConfig , blockchain * BlockChain , pow pow.PoW ) * BlockValidator {
5151 validator := & BlockValidator {
5252 config : config ,
5353 Pow : pow ,
@@ -128,7 +128,7 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
128128 }
129129 // Validate the state root against the received state root and throw
130130 // an error if they don't match.
131- if root := statedb .IntermediateRoot (); header .Root != root {
131+ if root := statedb .IntermediateRoot (v . config . IsEIP158 ( header . Number ) ); header .Root != root {
132132 return fmt .Errorf ("invalid merkle root: header=%x computed=%x" , header .Root , root )
133133 }
134134 return nil
@@ -203,7 +203,7 @@ func (v *BlockValidator) ValidateHeader(header, parent *types.Header, checkPow b
203203// Validates a header. Returns an error if the header is invalid.
204204//
205205// See YP section 4.3.4. "Block Header Validity"
206- func ValidateHeader (config * ChainConfig , pow pow.PoW , header * types.Header , parent * types.Header , checkPow , uncle bool ) error {
206+ func ValidateHeader (config * params. ChainConfig , pow pow.PoW , header * types.Header , parent * types.Header , checkPow , uncle bool ) error {
207207 if big .NewInt (int64 (len (header .Extra ))).Cmp (params .MaximumExtraDataSize ) == 1 {
208208 return fmt .Errorf ("Header extra data too long (%d)" , len (header .Extra ))
209209 }
@@ -248,13 +248,21 @@ func ValidateHeader(config *ChainConfig, pow pow.PoW, header *types.Header, pare
248248 }
249249 }
250250 // If all checks passed, validate the extra-data field for hard forks
251- return ValidateDAOHeaderExtraData (config , header )
251+ if err := ValidateDAOHeaderExtraData (config , header ); err != nil {
252+ return err
253+ }
254+ if config .EIP150Block != nil && config .EIP150Block .Cmp (header .Number ) == 0 {
255+ if config .EIP150Hash != (common.Hash {}) && config .EIP150Hash != header .Hash () {
256+ return ValidationError ("Homestead gas reprice fork hash mismatch: have 0x%x, want 0x%x" , header .Hash (), config .EIP150Hash )
257+ }
258+ }
259+ return nil
252260}
253261
254262// CalcDifficulty is the difficulty adjustment algorithm. It returns
255263// the difficulty that a new block should have when created at time
256264// given the parent block's time and difficulty.
257- func CalcDifficulty (config * ChainConfig , time , parentTime uint64 , parentNumber , parentDiff * big.Int ) * big.Int {
265+ func CalcDifficulty (config * params. ChainConfig , time , parentTime uint64 , parentNumber , parentDiff * big.Int ) * big.Int {
258266 if config .IsHomestead (new (big.Int ).Add (parentNumber , common .Big1 )) {
259267 return calcDifficultyHomestead (time , parentTime , parentNumber , parentDiff )
260268 } else {
0 commit comments