From 92237458c40879670574289fe50bae2cc209d6ad Mon Sep 17 00:00:00 2001 From: vctt94 Date: Tue, 15 Dec 2020 17:03:26 -0300 Subject: [PATCH] Check if tx is unpublished on processTransactionRecord --- internal/vsp/vsp.go | 4 ++-- wallet/chainntfns.go | 9 +++++++-- wallet/udb/txunmined.go | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/vsp/vsp.go b/internal/vsp/vsp.go index aec4ca9a9..203cff2ff 100644 --- a/internal/vsp/vsp.go +++ b/internal/vsp/vsp.go @@ -375,11 +375,11 @@ func (v *VSP) Process(ctx context.Context, ticketHash chainhash.Hash, credits [] } // set fee tx as unpublished, because it will be published by the vsp. feeHash := feeTx.TxHash() - err = v.cfg.Wallet.AddTransaction(ctx, feeTx, nil) + err = v.cfg.Wallet.SetPublished(ctx, &feeHash, false) if err != nil { return nil, err } - err = v.cfg.Wallet.SetPublished(ctx, &feeHash, false) + err = v.cfg.Wallet.AddTransaction(ctx, feeTx, nil) if err != nil { return nil, err } diff --git a/wallet/chainntfns.go b/wallet/chainntfns.go index bdf782e81..c52b2fb71 100644 --- a/wallet/chainntfns.go +++ b/wallet/chainntfns.go @@ -566,8 +566,13 @@ func (w *Wallet) processTransactionRecord(ctx context.Context, dbtx walletdb.Rea } // Skip unlocking outpoints if the transaction is a vote or revocation as the lock - // is not held. - skipOutpoints := rec.TxType == stake.TxTypeSSGen || rec.TxType == stake.TxTypeSSRtx + // is not held. Also if it is an unpublished tx. + var isUnpublished bool + err = walletdb.View(ctx, w.db, func(tx walletdb.ReadTx) error { + isUnpublished = w.txStore.ExistsUnpublished(tx, &rec.Hash) + return nil + }) + skipOutpoints := rec.TxType == stake.TxTypeSSGen || rec.TxType == stake.TxTypeSSRtx || isUnpublished // Handle input scripts that contain P2PKs that we care about. for i, input := range rec.MsgTx.TxIn { diff --git a/wallet/udb/txunmined.go b/wallet/udb/txunmined.go index 4b5d45cff..10325ac4e 100644 --- a/wallet/udb/txunmined.go +++ b/wallet/udb/txunmined.go @@ -141,6 +141,12 @@ func (s *Store) SetPublished(dbtx walletdb.ReadWriteTx, txHash *chainhash.Hash, return putUnpublished(ns, txHash[:]) } +// ExistsUnpublished exported method of exists Unpublished +func (s *Store) ExistsUnpublished(dbtx walletdb.ReadTx, txHash *chainhash.Hash) bool { + ns := dbtx.ReadBucket(wtxmgrBucketKey) + return existsUnpublished(ns, txHash[:]) +} + // removeDoubleSpends checks for any unmined transactions which would introduce // a double spend if tx was added to the store (either as a confirmed or unmined // transaction). Each conflicting transaction and all transactions which spend