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:
Wilmer Paulino committed 2020-06-12 11:22:29 -07:00
1 parent 9d9e54f83e
commit c2f1fe26c1
4 files changed
+44 -4

No files matched your search

+11 -1
View File
@@ -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
}