From 9983a0a92ac709ef2b8d35c2c5f0d43c77282eb0 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 23 Oct 2013 18:29:54 -0400 Subject: [PATCH] (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. --- sockets.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sockets.go b/sockets.go index 3f8c4c0..5a81499 100644 --- a/sockets.go +++ b/sockets.go @@ -394,6 +394,14 @@ func NtfnBlockConnected(r interface{}) { // Resend any remaining transactions still left in pool. These are // 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 { n := <-NewJSONID var id interface{} = fmt.Sprintf("btcwallet(%v)", n) @@ -410,7 +418,6 @@ func NtfnBlockConnected(r interface{}) { replyHandlers.Unlock() btcdMsgs <- m } - UnminedTxs.Unlock() } // NtfnBlockDisconnected handles btcd notifications resulting from @@ -582,4 +589,7 @@ func BtcdHandshake(ws *websocket.Conn) { w.Track() } wallets.RUnlock() + + // (Re)send any unmined transactions to btcd in case of a btcd restart. + resendUnminedTxs() }