aboutsummaryrefslogtreecommitdiffstats
path: root/core/block_validator.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-11-15 20:46:47 +0800
committerGitHub <noreply@github.com>2016-11-15 20:46:47 +0800
commit81d9d7d38555a63602b9da3d07955ad4e5a62f02 (patch)
tree9ce0d55bfe182f6493867ea5497bf2c8cd9e8523 /core/block_validator.go
parentef9265d0d7abf6614c1d2fb977989ab0d400a590 (diff)
parent822355f8a6e8826561433392fd94a8bde7e4dbf3 (diff)
downloadgo-tangerine-1.4.19.tar
go-tangerine-1.4.19.tar.gz
go-tangerine-1.4.19.tar.bz2
go-tangerine-1.4.19.tar.lz
go-tangerine-1.4.19.tar.xz
go-tangerine-1.4.19.tar.zst
go-tangerine-1.4.19.zip
Merge pull request #3252 from obscuren/release/1.4v1.4.19
1.4 HF
Diffstat (limited to 'core/block_validator.go')
-rw-r--r--core/block_validator.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/core/block_validator.go b/core/block_validator.go
index a7c7f76dd..520877c65 100644
--- a/core/block_validator.go
+++ b/core/block_validator.go
@@ -41,13 +41,13 @@ var (
//
// BlockValidator implements Validator.
type BlockValidator struct {
- config *ChainConfig // Chain configuration options
- bc *BlockChain // Canonical block chain
- Pow pow.PoW // Proof of work used for validating
+ config *params.ChainConfig // Chain configuration options
+ bc *BlockChain // Canonical block chain
+ Pow pow.PoW // Proof of work used for validating
}
// NewBlockValidator returns a new block validator which is safe for re-use
-func NewBlockValidator(config *ChainConfig, blockchain *BlockChain, pow pow.PoW) *BlockValidator {
+func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, pow pow.PoW) *BlockValidator {
validator := &BlockValidator{
config: config,
Pow: pow,
@@ -128,7 +128,7 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
}
// Validate the state root against the received state root and throw
// an error if they don't match.
- if root := statedb.IntermediateRoot(); header.Root != root {
+ if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
return fmt.Errorf("invalid merkle root: header=%x computed=%x", header.Root, root)
}
return nil
@@ -203,7 +203,7 @@ func (v *BlockValidator) ValidateHeader(header, parent *types.Header, checkPow b
// Validates a header. Returns an error if the header is invalid.
//
// See YP section 4.3.4. "Block Header Validity"
-func ValidateHeader(config *ChainConfig, pow pow.PoW, header *types.Header, parent *types.Header, checkPow, uncle bool) error {
+func ValidateHeader(config *params.ChainConfig, pow pow.PoW, header *types.Header, parent *types.Header, checkPow, uncle bool) error {
if big.NewInt(int64(len(header.Extra))).Cmp(params.MaximumExtraDataSize) == 1 {
return fmt.Errorf("Header extra data too long (%d)", len(header.Extra))
}
@@ -248,13 +248,21 @@ func ValidateHeader(config *ChainConfig, pow pow.PoW, header *types.Header, pare
}
}
// If all checks passed, validate the extra-data field for hard forks
- return ValidateDAOHeaderExtraData(config, header)
+ if err := ValidateDAOHeaderExtraData(config, header); err != nil {
+ return err
+ }
+ if config.EIP150Block != nil && config.EIP150Block.Cmp(header.Number) == 0 {
+ if config.EIP150Hash != (common.Hash{}) && config.EIP150Hash != header.Hash() {
+ return ValidationError("Homestead gas reprice fork hash mismatch: have 0x%x, want 0x%x", header.Hash(), config.EIP150Hash)
+ }
+ }
+ return nil
}
// CalcDifficulty is the difficulty adjustment algorithm. It returns
// the difficulty that a new block should have when created at time
// given the parent block's time and difficulty.
-func CalcDifficulty(config *ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
+func CalcDifficulty(config *params.ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
if config.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) {
return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff)
} else {