Skip to content

Commit

Permalink
delay fundingCoins delete until after RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Feb 22, 2023
1 parent dcdc4c4 commit 185a489
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2168,9 +2168,14 @@ func (btc *baseWallet) ReturnCoins(unspents asset.Coins) error {
return fmt.Errorf("error converting coin: %w", err)
}
ops = append(ops, op)
}
if err := btc.node.lockUnspent(true, ops); err != nil {
return err // could it have unlocked some of them? we may want to loop instead if that's the case
}
for _, op := range ops {
delete(btc.fundingCoins, op.pt)
}
return btc.node.lockUnspent(true, ops)
return nil
}

// rawWalletTx gets the raw bytes of a transaction and the number of
Expand Down
11 changes: 9 additions & 2 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,14 +1921,21 @@ func (dcr *ExchangeWallet) returnCoins(unspents asset.Coins) ([]*fundingCoin, er
ops = append(ops, op.wireOutPoint()) // op.tree may be wire.TxTreeUnknown, but that's fine since wallet.LockUnspent doesn't rely on it
if fCoin, ok := dcr.fundingCoins[op.pt]; ok {
fundingCoins = append(fundingCoins, fCoin)
delete(dcr.fundingCoins, op.pt)
} else {
dcr.log.Warnf("returning coin %s that is not cached as a funding coin", op)
fundingCoins = append(fundingCoins, &fundingCoin{op: op})
}
}

return fundingCoins, dcr.wallet.LockUnspent(dcr.ctx, true, ops)
if err := dcr.wallet.LockUnspent(dcr.ctx, true, ops); err != nil {
return nil, err
}

for _, fCoin := range fundingCoins {
delete(dcr.fundingCoins, fCoin.op.pt)
}

return fundingCoins, nil
}

// FundingCoins gets funding coins for the coin IDs. The coins are locked. This
Expand Down

0 comments on commit 185a489

Please sign in to comment.