Skip to content

Commit

Permalink
client/asset/dcr: Fix load pending transactions (#2701)
Browse files Browse the repository at this point in the history
This fixes a bug happening when the DCR wallet tried to load unconfirmed
transactions from the transaction history db.
  • Loading branch information
martonp authored Feb 16, 2024
1 parent 3af9f73 commit 81115db
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,12 @@ func (dcr *ExchangeWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)

dcr.pendingTxsMtx.Lock()
for _, tx := range pendingTxs {
var txHash chainhash.Hash
copy(txHash[:], tx.ID)
dcr.pendingTxs[txHash] = tx
txHash, err := chainhash.NewHashFromStr(tx.ID)
if err != nil {
dcr.log.Errorf("Invalid txid %v from tx history db: %v", tx.ID, err)
continue
}
dcr.pendingTxs[*txHash] = tx
}
dcr.pendingTxsMtx.Unlock()

Expand Down Expand Up @@ -5683,7 +5686,7 @@ func (dcr *ExchangeWallet) checkPendingTxs(ctx context.Context, tip uint64) {
} else {
// Leave it in the pendingPendingTxs and attempt to remove it
// again next time.
dcr.log.Errorf("Error removing tx %s from the history store: %v", txHash, err)
dcr.log.Errorf("Error removing tx %s from the history store: %v", txHash.String(), err)
}
return
}
Expand Down Expand Up @@ -5755,18 +5758,22 @@ func (dcr *ExchangeWallet) markTxAsSubmitted(txHash *chainhash.Hash) {
return
}

err := txHistoryDB.MarkTxAsSubmitted(txHash.String())
if err != nil {
dcr.log.Errorf("failed to mark tx as submitted in tx history db: %v", err)
}

dcr.pendingTxsMtx.Lock()
wt, found := dcr.pendingTxs[*txHash]
if found {
wt.Submitted = true
}
dcr.pendingTxsMtx.Unlock()

err := txHistoryDB.MarkTxAsSubmitted(txHash.String())
if err != nil {
dcr.log.Errorf("failed to mark tx as submitted in tx history db: %v", err)
if !found {
dcr.log.Errorf("Transaction %s not found in pending txs", txHash)
return
}

wt.Submitted = true

dcr.emit.TransactionNote(wt.WalletTransaction, true)
}

Expand Down

0 comments on commit 81115db

Please sign in to comment.