(Re)send all unmined txs on btcd connect.

In case of a btcd restart, it is necessary to send unmined
transactions back to btcd so they can be added to the tx mempool.
btcd can make a best-try effort, but It is ultimately btcwallet's
responsibility that transactions appear in blocks even if btcd is
restarted.
This commit is contained in:
Josh Rickmar 2013-10-23 18:29:54 -04:00
parent adf4970fa4
commit 9983a0a92a

View file

@ -394,6 +394,14 @@ func NtfnBlockConnected(r interface{}) {
// Resend any remaining transactions still left in pool. These are // Resend any remaining transactions still left in pool. These are
// transactions that have not yet been mined into a block. // transactions that have not yet been mined into a block.
resendUnminedTxs()
UnminedTxs.Unlock()
}
// ResendUnminedTxs resends any transactions in the unmined
// transaction pool to btcd using the 'sendrawtransaction' RPC
// command.
func resendUnminedTxs() {
for _, hextx := range UnminedTxs.m { for _, hextx := range UnminedTxs.m {
n := <-NewJSONID n := <-NewJSONID
var id interface{} = fmt.Sprintf("btcwallet(%v)", n) var id interface{} = fmt.Sprintf("btcwallet(%v)", n)
@ -410,7 +418,6 @@ func NtfnBlockConnected(r interface{}) {
replyHandlers.Unlock() replyHandlers.Unlock()
btcdMsgs <- m btcdMsgs <- m
} }
UnminedTxs.Unlock()
} }
// NtfnBlockDisconnected handles btcd notifications resulting from // NtfnBlockDisconnected handles btcd notifications resulting from
@ -582,4 +589,7 @@ func BtcdHandshake(ws *websocket.Conn) {
w.Track() w.Track()
} }
wallets.RUnlock() wallets.RUnlock()
// (Re)send any unmined transactions to btcd in case of a btcd restart.
resendUnminedTxs()
} }