Merge pull request #540 from wpaulino/avoid-notifying-txs-not-found

wallet/chainntfns: avoid notifying txs if not found within the wallet
This commit is contained in:
Olaoluwa Osuntokun 2018-09-06 20:09:02 -07:00 committed by GitHub
commit f4ae41ce5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -302,14 +302,27 @@ func (w *Wallet) addRelevantTx(dbtx walletdb.ReadWriteTx, rec *wtxmgr.TxRecord,
details, err := w.TxStore.UniqueTxDetails(txmgrNs, &rec.Hash, nil) details, err := w.TxStore.UniqueTxDetails(txmgrNs, &rec.Hash, nil)
if err != nil { if err != nil {
log.Errorf("Cannot query transaction details for notification: %v", err) log.Errorf("Cannot query transaction details for notification: %v", err)
} else { }
// It's possible that the transaction was not found within the
// wallet's set of unconfirmed transactions due to it already
// being confirmed, so we'll avoid notifying it.
//
// TODO(wilmer): ideally we should find the culprit to why we're
// receiving an additional unconfirmed chain.RelevantTx
// notification from the chain backend.
if details != nil {
w.NtfnServer.notifyUnminedTransaction(dbtx, details) w.NtfnServer.notifyUnminedTransaction(dbtx, details)
} }
} else { } else {
details, err := w.TxStore.UniqueTxDetails(txmgrNs, &rec.Hash, &block.Block) details, err := w.TxStore.UniqueTxDetails(txmgrNs, &rec.Hash, &block.Block)
if err != nil { if err != nil {
log.Errorf("Cannot query transaction details for notification: %v", err) log.Errorf("Cannot query transaction details for notification: %v", err)
} else { }
// We'll only notify the transaction if it was found within the
// wallet's set of confirmed transactions.
if details != nil {
w.NtfnServer.notifyMinedTransaction(dbtx, details, block) w.NtfnServer.notifyMinedTransaction(dbtx, details, block)
} }
} }