Skip to content

Commit

Permalink
Check if tx is unpublished on processTransactionRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 committed Dec 15, 2020
1 parent 6f45010 commit 9223745
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/vsp/vsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions wallet/chainntfns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions wallet/udb/txunmined.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9223745

Please sign in to comment.