From 81d871e10353e4275ef340628a2bf129be1283fb Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Tue, 23 Jan 2018 17:14:36 +0100 Subject: [PATCH] les: fix TxStatus message format --- les/handler.go | 6 +++--- les/handler_test.go | 10 +++++++--- les/peer.go | 2 +- les/protocol.go | 3 +-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/les/handler.go b/les/handler.go index d627c3e184..6e97de7f07 100644 --- a/les/handler.go +++ b/les/handler.go @@ -1014,7 +1014,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { for i, stat := range stats { if stat.Status == core.TxStatusUnknown { if errs := pm.txpool.AddRemotes([]*types.Transaction{req.Txs[i]}); errs[0] != nil { - stats[i].Error = errs[0] + stats[i].Data = []byte(errs[0].Error()) continue } stats[i] = pm.txStatus([]common.Hash{hashes[i]})[0] @@ -1055,7 +1055,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { p.Log().Trace("Received tx status response") var resp struct { ReqID, BV uint64 - Status []core.TxStatus + Status []txStatus } if err := msg.Decode(&resp); err != nil { return errResp(ErrDecode, "msg %v: %v", msg, err) @@ -1116,7 +1116,7 @@ func (pm *ProtocolManager) txStatus(hashes []common.Hash) []txStatus { if stat == core.TxStatusUnknown { if block, number, index := core.GetTxLookupEntry(pm.chainDb, hashes[i]); block != (common.Hash{}) { stats[i].Status = core.TxStatusIncluded - stats[i].Lookup = &core.TxLookupEntry{BlockHash: block, BlockIndex: number, Index: index} + stats[i].Data, _ = rlp.EncodeToBytes(core.TxLookupEntry{BlockHash: block, BlockIndex: number, Index: index}) } } } diff --git a/les/handler_test.go b/les/handler_test.go index 7d67af26a1..6acbf009e9 100644 --- a/les/handler_test.go +++ b/les/handler_test.go @@ -444,7 +444,7 @@ func TestTransactionStatusLes2(t *testing.T) { // test error status by sending an underpriced transaction tx0, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey) - test(tx0, true, txStatus{Status: core.TxStatusUnknown, Error: core.ErrUnderpriced}) + test(tx0, true, txStatus{Status: core.TxStatusUnknown, Data: []byte(core.ErrUnderpriced.Error())}) tx1, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, testBankKey) test(tx1, false, txStatus{Status: core.TxStatusUnknown}) // query before sending, should be unknown @@ -480,8 +480,12 @@ func TestTransactionStatusLes2(t *testing.T) { // check if their status is included now block1hash := core.GetCanonicalHash(db, 1) - test(tx1, false, txStatus{Status: core.TxStatusIncluded, Lookup: &core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 0}}) - test(tx2, false, txStatus{Status: core.TxStatusIncluded, Lookup: &core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 1}}) + + pos0, _ := rlp.EncodeToBytes(core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 0}) + pos1, _ := rlp.EncodeToBytes(core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 1}) + + test(tx1, false, txStatus{Status: core.TxStatusIncluded, Data: pos0}) + test(tx2, false, txStatus{Status: core.TxStatusIncluded, Data: pos1}) // create a reorg that rolls them back gchain, _ = core.GenerateChain(params.TestChainConfig, chain.GetBlockByNumber(0), ethash.NewFaker(), db, 2, func(i int, block *core.BlockGen) {}) diff --git a/les/peer.go b/les/peer.go index b72c80d35a..b3f19050c4 100644 --- a/les/peer.go +++ b/les/peer.go @@ -312,7 +312,7 @@ func (p *peer) RequestTxStatus(reqID, cost uint64, txHashes []common.Hash) error return sendRequest(p.rw, GetTxStatusMsg, reqID, cost, txHashes) } -// SendTxStatus sends a batch of transactions to be added to the remote transaction pool. +// SendTxs sends a batch of transactions to be added to the remote transaction pool. func (p *peer) SendTxs(reqID, cost uint64, txs types.Transactions) error { p.Log().Debug("Fetching batch of transactions", "count", len(txs)) switch p.version { diff --git a/les/protocol.go b/les/protocol.go index 6a7354d1c2..1003c453fb 100644 --- a/les/protocol.go +++ b/les/protocol.go @@ -224,6 +224,5 @@ type proofsData [][]rlp.RawValue type txStatus struct { Status core.TxStatus - Lookup *core.TxLookupEntry - Error error + Data []byte // RLP-encoded core.TxLookupEntry or error string }