|
|
|
@ -93,14 +93,14 @@ func (v *BlockValidator) ValidateBlock(block *types.Block) error { |
|
|
|
|
// Verify UncleHash before running other uncle validations
|
|
|
|
|
unclesSha := types.CalcUncleHash(block.Uncles()) |
|
|
|
|
if unclesSha != header.UncleHash { |
|
|
|
|
return fmt.Errorf("invalid uncles root hash. received=%x calculated=%x", header.UncleHash, unclesSha) |
|
|
|
|
return fmt.Errorf("invalid uncles root hash (remote: %x local: %x)", header.UncleHash, unclesSha) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// The transactions Trie's root (R = (Tr [[i, RLP(T1)], [i, RLP(T2)], ... [n, RLP(Tn)]]))
|
|
|
|
|
// can be used by light clients to make sure they've received the correct Txs
|
|
|
|
|
txSha := types.DeriveSha(block.Transactions()) |
|
|
|
|
if txSha != header.TxHash { |
|
|
|
|
return fmt.Errorf("invalid transaction root hash. received=%x calculated=%x", header.TxHash, txSha) |
|
|
|
|
return fmt.Errorf("invalid transaction root hash (remote: %x local: %x)", header.TxHash, txSha) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
@ -113,23 +113,23 @@ func (v *BlockValidator) ValidateBlock(block *types.Block) error { |
|
|
|
|
func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas *big.Int) (err error) { |
|
|
|
|
header := block.Header() |
|
|
|
|
if block.GasUsed().Cmp(usedGas) != 0 { |
|
|
|
|
return ValidationError(fmt.Sprintf("gas used error (%v / %v)", block.GasUsed(), usedGas)) |
|
|
|
|
return ValidationError(fmt.Sprintf("invalid gas used (remote: %v local: %v)", block.GasUsed(), usedGas)) |
|
|
|
|
} |
|
|
|
|
// Validate the received block's bloom with the one derived from the generated receipts.
|
|
|
|
|
// For valid blocks this should always validate to true.
|
|
|
|
|
rbloom := types.CreateBloom(receipts) |
|
|
|
|
if rbloom != header.Bloom { |
|
|
|
|
return fmt.Errorf("unable to replicate block's bloom=%x vs calculated bloom=%x", header.Bloom, rbloom) |
|
|
|
|
return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom) |
|
|
|
|
} |
|
|
|
|
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]]))
|
|
|
|
|
receiptSha := types.DeriveSha(receipts) |
|
|
|
|
if receiptSha != header.ReceiptHash { |
|
|
|
|
return fmt.Errorf("invalid receipt root hash. received=%x calculated=%x", header.ReceiptHash, receiptSha) |
|
|
|
|
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha) |
|
|
|
|
} |
|
|
|
|
// Validate the state root against the received state root and throw
|
|
|
|
|
// an error if they don't match.
|
|
|
|
|
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 fmt.Errorf("invalid merkle root (remote: %x local: %x)", header.Root, root) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
@ -223,7 +223,7 @@ func ValidateHeader(config *params.ChainConfig, pow pow.PoW, header *types.Heade |
|
|
|
|
|
|
|
|
|
expd := CalcDifficulty(config, header.Time.Uint64(), parent.Time.Uint64(), parent.Number, parent.Difficulty) |
|
|
|
|
if expd.Cmp(header.Difficulty) != 0 { |
|
|
|
|
return fmt.Errorf("Difficulty check failed for header %v, %v", header.Difficulty, expd) |
|
|
|
|
return fmt.Errorf("Difficulty check failed for header (remote: %v local: %v)", header.Difficulty, expd) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
a := new(big.Int).Set(parent.GasLimit) |
|
|
|
@ -232,7 +232,7 @@ func ValidateHeader(config *params.ChainConfig, pow pow.PoW, header *types.Heade |
|
|
|
|
b := new(big.Int).Set(parent.GasLimit) |
|
|
|
|
b = b.Div(b, params.GasLimitBoundDivisor) |
|
|
|
|
if !(a.Cmp(b) < 0) || (header.GasLimit.Cmp(params.MinGasLimit) == -1) { |
|
|
|
|
return fmt.Errorf("GasLimit check failed for header %v (%v > %v)", header.GasLimit, a, b) |
|
|
|
|
return fmt.Errorf("GasLimit check failed for header (remote: %v local_max: %v)", header.GasLimit, b) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
num := new(big.Int).Set(parent.Number) |
|
|
|
|