From 06e70c0f080cc100dcf98eb0e7871e7ff35742c4 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Thu, 20 Sep 2018 18:53:03 -0700 Subject: [PATCH] wallet/wallet: use addRelevantTx when publishing transactions In this commit, we simplify the logic when broadcasting transactions to the greater network. Rather than special casing when running with a Neutrino backend, we'll always add the transaction to the store as relevant when attempting to broadcast it. This will properly insert it into the store and update unconfirmed balances. In the event that the transaction failed to broadcast, it can be removed from the store with no side-effects, essentially acting as if the transaction was never added to the store in the first place. --- wallet/wallet.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index 0f5d1f7..e2ee0c8 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -3312,9 +3312,8 @@ func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error { if err != nil { return err } - err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error { - txmgrNs := tx.ReadWriteBucket(wtxmgrNamespaceKey) - return w.TxStore.InsertTx(txmgrNs, txRec, nil) + err = walletdb.Update(w.db, func(dbTx walletdb.ReadWriteTx) error { + return w.addRelevantTx(dbTx, txRec, nil) }) if err != nil { return err @@ -3323,15 +3322,6 @@ func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error { _, err = server.SendRawTransaction(tx, false) switch { case err == nil: - switch w.chainClient.(type) { - // For neutrino we need to trigger adding relevant tx manually - // because for spv client - tx data isn't received from sync peer. - case *chain.NeutrinoClient: - return walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error { - return w.addRelevantTx(tx, txRec, nil) - }) - } - return nil // The following are errors returned from btcd's mempool. @@ -3348,14 +3338,12 @@ func (w *Wallet) PublishTransaction(tx *wire.MsgTx) error { case strings.Contains(err.Error(), "Missing inputs"): fallthrough case strings.Contains(err.Error(), "already in block chain"): - // If the transaction was rejected, then we'll remove it from // the txstore, as otherwise, we'll attempt to continually // re-broadcast it, and the utxo state of the wallet won't be // accurate. dbErr := walletdb.Update(w.db, func(dbTx walletdb.ReadWriteTx) error { txmgrNs := dbTx.ReadWriteBucket(wtxmgrNamespaceKey) - return w.TxStore.RemoveUnminedTx(txmgrNs, txRec) }) if dbErr != nil {