diff --git a/rpcserver.go b/rpcserver.go index 2615bd6d..87666983 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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) // Keep track of all the sendrawtransaction request txns so that they // can be rebroadcast if they don't make their way into a block. - iv := wire.NewInvVect(wire.InvTypeTx, tx.Hash()) - s.server.AddRebroadcastInventory(iv, tx) + txD := acceptedTxs[0] + iv := wire.NewInvVect(wire.InvTypeTx, txD.Tx.Hash()) + s.server.AddRebroadcastInventory(iv, txD) return tx.Hash().String(), nil } diff --git a/server.go b/server.go index 7ba594e1..ac701409 100644 --- a/server.go +++ b/server.go @@ -1367,8 +1367,9 @@ func (s *server) handleRelayInvMsg(state *peerState, msg relayMsg) { txD, ok := msg.data.(*mempool.TxDesc) if !ok { - peerLog.Warnf("Underlying data for tx" + - " inv relay is not a *mempool.TxDesc") + peerLog.Warnf("Underlying data for tx inv "+ + "relay is not a *mempool.TxDesc: %T", + msg.data) return }