btcd: fix rebroadcasting of local txs.

This commit is contained in:
David Hill 2017-01-16 11:08:37 -05:00
parent 9bedd7720c
commit db5b9aef91
2 changed files with 21 additions and 4 deletions

View file

@ -3251,12 +3251,28 @@ func handleSendRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan st
} }
} }
// When the transaction was accepted it should be the first item in the
// returned array of accepted transactions. The only way this will not
// be true is if the API for ProcessTransaction changes and this code is
// not properly updated, but ensure the condition holds as a safeguard.
//
// Also, since an error is being returned to the caller, ensure the
// transaction is removed from the memory pool.
if len(acceptedTxs) == 0 || !acceptedTxs[0].Tx.Hash().IsEqual(tx.Hash()) {
s.server.txMemPool.RemoveTransaction(tx, true)
errStr := fmt.Sprintf("transaction %v is not in accepted list",
tx.Hash())
return nil, internalRPCError(errStr, "")
}
s.server.AnnounceNewTransactions(acceptedTxs) s.server.AnnounceNewTransactions(acceptedTxs)
// Keep track of all the sendrawtransaction request txns so that they // Keep track of all the sendrawtransaction request txns so that they
// can be rebroadcast if they don't make their way into a block. // can be rebroadcast if they don't make their way into a block.
iv := wire.NewInvVect(wire.InvTypeTx, tx.Hash()) txD := acceptedTxs[0]
s.server.AddRebroadcastInventory(iv, tx) iv := wire.NewInvVect(wire.InvTypeTx, txD.Tx.Hash())
s.server.AddRebroadcastInventory(iv, txD)
return tx.Hash().String(), nil return tx.Hash().String(), nil
} }

View file

@ -1367,8 +1367,9 @@ func (s *server) handleRelayInvMsg(state *peerState, msg relayMsg) {
txD, ok := msg.data.(*mempool.TxDesc) txD, ok := msg.data.(*mempool.TxDesc)
if !ok { if !ok {
peerLog.Warnf("Underlying data for tx" + peerLog.Warnf("Underlying data for tx inv "+
" inv relay is not a *mempool.TxDesc") "relay is not a *mempool.TxDesc: %T",
msg.data)
return return
} }