|
|
@ -214,7 +214,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st |
|
|
|
txs := block.Transactions() |
|
|
|
txs := block.Transactions() |
|
|
|
|
|
|
|
|
|
|
|
// Block validation
|
|
|
|
// Block validation
|
|
|
|
if err = ValidateHeader(sm.Pow, header, parent, false, false); err != nil { |
|
|
|
if err = ValidateHeader(sm.Pow, header, parent.Header(), false, false); err != nil { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -338,7 +338,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty |
|
|
|
return UncleError("uncle[%d](%x)'s parent is not ancestor (%x)", i, hash[:4], uncle.ParentHash[0:4]) |
|
|
|
return UncleError("uncle[%d](%x)'s parent is not ancestor (%x)", i, hash[:4], uncle.ParentHash[0:4]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := ValidateHeader(sm.Pow, uncle, ancestors[uncle.ParentHash], true, true); err != nil { |
|
|
|
if err := ValidateHeader(sm.Pow, uncle, ancestors[uncle.ParentHash].Header(), true, true); err != nil { |
|
|
|
return ValidationError(fmt.Sprintf("uncle[%d](%x) header invalid: %v", i, hash[:4], err)) |
|
|
|
return ValidationError(fmt.Sprintf("uncle[%d](%x) header invalid: %v", i, hash[:4], err)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -368,52 +368,50 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// See YP section 4.3.4. "Block Header Validity"
|
|
|
|
// See YP section 4.3.4. "Block Header Validity"
|
|
|
|
// Validates a block. Returns an error if the block is invalid.
|
|
|
|
// Validates a header. Returns an error if the header is invalid.
|
|
|
|
func ValidateHeader(pow pow.PoW, block *types.Header, parent *types.Block, checkPow, uncle bool) error { |
|
|
|
func ValidateHeader(pow pow.PoW, header *types.Header, parent *types.Header, checkPow, uncle bool) error { |
|
|
|
if big.NewInt(int64(len(block.Extra))).Cmp(params.MaximumExtraDataSize) == 1 { |
|
|
|
if big.NewInt(int64(len(header.Extra))).Cmp(params.MaximumExtraDataSize) == 1 { |
|
|
|
return fmt.Errorf("Block extra data too long (%d)", len(block.Extra)) |
|
|
|
return fmt.Errorf("Header extra data too long (%d)", len(header.Extra)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if uncle { |
|
|
|
if uncle { |
|
|
|
if block.Time.Cmp(common.MaxBig) == 1 { |
|
|
|
if header.Time.Cmp(common.MaxBig) == 1 { |
|
|
|
return BlockTSTooBigErr |
|
|
|
return BlockTSTooBigErr |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if block.Time.Cmp(big.NewInt(time.Now().Unix())) == 1 { |
|
|
|
if header.Time.Cmp(big.NewInt(time.Now().Unix())) == 1 { |
|
|
|
return BlockFutureErr |
|
|
|
return BlockFutureErr |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if block.Time.Cmp(parent.Time()) != 1 { |
|
|
|
if header.Time.Cmp(parent.Time) != 1 { |
|
|
|
return BlockEqualTSErr |
|
|
|
return BlockEqualTSErr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
expd := CalcDifficulty(block.Time.Uint64(), parent.Time().Uint64(), parent.Number(), parent.Difficulty()) |
|
|
|
expd := CalcDifficulty(header.Time.Uint64(), parent.Time.Uint64(), parent.Number, parent.Difficulty) |
|
|
|
if expd.Cmp(block.Difficulty) != 0 { |
|
|
|
if expd.Cmp(header.Difficulty) != 0 { |
|
|
|
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd) |
|
|
|
return fmt.Errorf("Difficulty check failed for header %v, %v", header.Difficulty, expd) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var a, b *big.Int |
|
|
|
a := new(big.Int).Set(parent.GasLimit) |
|
|
|
a = parent.GasLimit() |
|
|
|
a = a.Sub(a, header.GasLimit) |
|
|
|
a = a.Sub(a, block.GasLimit) |
|
|
|
|
|
|
|
a.Abs(a) |
|
|
|
a.Abs(a) |
|
|
|
b = parent.GasLimit() |
|
|
|
b := new(big.Int).Set(parent.GasLimit) |
|
|
|
b = b.Div(b, params.GasLimitBoundDivisor) |
|
|
|
b = b.Div(b, params.GasLimitBoundDivisor) |
|
|
|
if !(a.Cmp(b) < 0) || (block.GasLimit.Cmp(params.MinGasLimit) == -1) { |
|
|
|
if !(a.Cmp(b) < 0) || (header.GasLimit.Cmp(params.MinGasLimit) == -1) { |
|
|
|
return fmt.Errorf("GasLimit check failed for block %v (%v > %v)", block.GasLimit, a, b) |
|
|
|
return fmt.Errorf("GasLimit check failed for header %v (%v > %v)", header.GasLimit, a, b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
num := parent.Number() |
|
|
|
num := new(big.Int).Set(parent.Number) |
|
|
|
num.Sub(block.Number, num) |
|
|
|
num.Sub(header.Number, num) |
|
|
|
if num.Cmp(big.NewInt(1)) != 0 { |
|
|
|
if num.Cmp(big.NewInt(1)) != 0 { |
|
|
|
return BlockNumberErr |
|
|
|
return BlockNumberErr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if checkPow { |
|
|
|
if checkPow { |
|
|
|
// Verify the nonce of the block. Return an error if it's not valid
|
|
|
|
// Verify the nonce of the header. Return an error if it's not valid
|
|
|
|
if !pow.Verify(types.NewBlockWithHeader(block)) { |
|
|
|
if !pow.Verify(types.NewBlockWithHeader(header)) { |
|
|
|
return ValidationError("Block's nonce is invalid (= %x)", block.Nonce) |
|
|
|
return ValidationError("Header's nonce is invalid (= %x)", header.Nonce) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|