From 82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 30 Mar 2015 13:48:07 +0100 Subject: test for invalid rlp encoding of block in BlocksMsg - rename Validate -> ValidateFields not to confure consensus block validation - add nil transaction and nil uncle header validation - remove bigint field checks: rlp already decodes *big.Int to big.NewInt(0) - add test for nil header, nil transaction --- core/types/block.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'core/types/block.go') diff --git a/core/types/block.go b/core/types/block.go index c04beae5a..a40bac42c 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -148,22 +148,19 @@ func NewBlockWithHeader(header *Header) *Block { return &Block{header: header} } -func (self *Block) Validate() error { +func (self *Block) ValidateFields() error { if self.header == nil { return fmt.Errorf("header is nil") } - // check *big.Int fields - if self.header.Difficulty == nil { - return fmt.Errorf("Difficulty undefined") - } - if self.header.GasLimit == nil { - return fmt.Errorf("GasLimit undefined") - } - if self.header.GasUsed == nil { - return fmt.Errorf("GasUsed undefined") + for i, transaction := range self.transactions { + if transaction == nil { + return fmt.Errorf("transaction %d is nil", i) + } } - if self.header.Number == nil { - return fmt.Errorf("Number undefined") + for i, uncle := range self.uncles { + if uncle == nil { + return fmt.Errorf("uncle %d is nil", i) + } } return nil } @@ -253,10 +250,10 @@ func (self *Block) AddReceipt(receipt *Receipt) { } func (self *Block) RlpData() interface{} { - return []interface{}{self.header, self.transactions, self.uncles} -} + // return []interface{}{self.header, self.transactions, self.uncles} + // } -func (self *Block) RlpDataForStorage() interface{} { + // func (self *Block) RlpDataForStorage() interface{} { return []interface{}{self.header, self.transactions, self.uncles, self.Td /* TODO receipts */} } -- cgit v1.2.3