diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-30 20:48:07 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-04-01 19:32:42 +0800 |
commit | 82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d (patch) | |
tree | 6d286d1ba2aad4234efd16f87024f287ce12106a /core | |
parent | d677190f3916c5bee276d9abba69814022ab967f (diff) | |
download | dexon-82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d.tar dexon-82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d.tar.gz dexon-82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d.tar.bz2 dexon-82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d.tar.lz dexon-82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d.tar.xz dexon-82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d.tar.zst dexon-82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d.zip |
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
Diffstat (limited to 'core')
-rw-r--r-- | core/types/block.go | 27 |
1 files changed, 12 insertions, 15 deletions
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 */} } |