From ab4ccacbb942e81c9017d7ddd7bb26f2a529e89a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 21 Feb 2018 16:13:31 -0800 Subject: [PATCH] wallet: extend PublishTransaction to be a general reliable broadcaster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we extend the PublishTransction method to be a more general semi reliable transaction broadcast mechanism. We do this by removing the special casing for neutrino. With this change, we’ll _always_ write any transactions to be broadcast to disk. A side effect of this, is that if the transaction doesn’t *directly* involve any outputs we control, then it’ll linger around until a restart, when we try to rebroadcast, and observe that it has bene rejected. --- wallet/wallet.go | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index d08d27e..1a6364e 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -2540,26 +2540,20 @@ func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error { return err } - switch server.(type) { - // If our chain backend is neutrino, then we'll add this as an - // unconfirmed transaction into the transaction store. Otherwise, we - // won't eve be notified of it's acceptance, meaning we won't attempt - // to re-broadcast. - case *chain.NeutrinoClient: - rec, err := wtxmgr.NewTxRecordFromMsgTx( - tx, time.Now(), - ) - if err != nil { - return err - } - err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error { - txmgrNs := tx.ReadWriteBucket(wtxmgrNamespaceKey) - - return w.TxStore.InsertTx(txmgrNs, rec, nil) - }) - if err != nil { - return err - } + // As we aim for this to be general reliable transaction broadcast API, + // we'll write this tx to disk as an unconfirmed transaction. This way, + // upon restarts, we'll always rebroadcast it, and also add it to our + // set of records. + rec, err := wtxmgr.NewTxRecordFromMsgTx(tx, time.Now()) + if err != nil { + return err + } + err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error { + txmgrNs := tx.ReadWriteBucket(wtxmgrNamespaceKey) + return w.TxStore.InsertTx(txmgrNs, rec, nil) + }) + if err != nil { + return err } _, err = server.SendRawTransaction(tx, false)