rpc: acquire global coin select lock in related RPCs
This ensures proper coin selection synchronization between lnd and users of the RPC to avoid potential double spend errors.
This commit is contained in:
4 files changed
+44
-4
No files matched your search
+11
-1
@@ -950,7 +950,17 @@ func (r *rpcServer) ListUnspent(ctx context.Context,
|
||||
|
||||
// With our arguments validated, we'll query the internal wallet for
|
||||
// the set of UTXOs that match our query.
|
||||
utxos, err := r.server.cc.wallet.ListUnspentWitness(minConfs, maxConfs)
|
||||
//
|
||||
// We'll acquire the global coin selection lock to ensure there aren't
|
||||
// any other concurrent processes attempting to lock any UTXOs which may
|
||||
// be shown available to us.
|
||||
var utxos []*lnwallet.Utxo
|
||||
err = r.server.cc.wallet.WithCoinSelectLock(func() error {
|
||||
utxos, err = r.server.cc.wallet.ListUnspentWitness(
|
||||
minConfs, maxConfs,
|
||||
)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user