diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-30 22:21:41 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-04-01 19:32:42 +0800 |
commit | 6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e (patch) | |
tree | 7a8b1a60915ef36b66a36ccaacc62b2f7db4f878 | |
parent | 82da6bf4d213784cfc7ba45432f9f96c2d6b4d9d (diff) | |
download | dexon-6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e.tar dexon-6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e.tar.gz dexon-6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e.tar.bz2 dexon-6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e.tar.lz dexon-6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e.tar.xz dexon-6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e.tar.zst dexon-6ffea34d8bf19fb358c1a7f01e20bf25f1061c5e.zip |
check TxMsg
- add validation on TxMsg checking for nil
- add test for nil transaction
- add test for zero value transaction (no extra validation needed)
-rw-r--r-- | core/types/block.go | 6 | ||||
-rw-r--r-- | eth/protocol.go | 5 | ||||
-rw-r--r-- | eth/protocol_test.go | 39 |
3 files changed, 46 insertions, 4 deletions
diff --git a/core/types/block.go b/core/types/block.go index a40bac42c..d5cd8a21e 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -250,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 */} } diff --git a/eth/protocol.go b/eth/protocol.go index f0a749d33..214eed875 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -185,7 +185,10 @@ func (self *ethProtocol) handle() error { if err := msg.Decode(&txs); err != nil { return self.protoError(ErrDecode, "msg %v: %v", msg, err) } - for _, tx := range txs { + for i, tx := range txs { + if tx == nil { + return self.protoError(ErrDecode, "transaction %d is nil", i) + } jsonlogger.LogJson(&logger.EthTxReceived{ TxHash: tx.Hash().Hex(), RemoteId: self.peer.ID().String(), diff --git a/eth/protocol_test.go b/eth/protocol_test.go index 6a8eedadd..2228fa0ec 100644 --- a/eth/protocol_test.go +++ b/eth/protocol_test.go @@ -359,3 +359,42 @@ func TestBlockMsg(t *testing.T) { eth.checkError(ErrDecode, delay) } + +func TestTransactionsMsg(t *testing.T) { + logInit() + eth := newEth(t) + txs := make(chan *types.Transaction) + + eth.txPool.addTransactions = func(t []*types.Transaction) { + for _, tx := range t { + txs <- tx + } + } + go eth.run() + + eth.handshake(t, true) + err := p2p.ExpectMsg(eth, TxMsg, []interface{}{}) + if err != nil { + t.Errorf("transactions expected, got %v", err) + } + + var delay = 3 * time.Second + tx := &types.Transaction{} + + go p2p.Send(eth, TxMsg, []interface{}{tx, tx}) + timer := time.After(delay) + for i := int64(0); i < 2; i++ { + select { + case <-txs: + case <-timer: + return + case err := <-eth.quit: + t.Errorf("no error expected, got %v", err) + return + } + } + + go p2p.Send(eth, TxMsg, []interface{}{[]interface{}{}}) + eth.checkError(ErrDecode, delay) + +} |