les: fix TxStatus message format

This commit is contained in:
Zsolt Felfoldi 2018-01-23 17:14:36 +01:00
parent 92580d69d3
commit 81d871e103
4 changed files with 12 additions and 9 deletions

View file

@ -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})
}
}
}

View file

@ -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) {})

View file

@ -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 {

View file

@ -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
}