lnd: add optional change output index to check reserved wallet balance

This commit is contained in:
Bjarne Magnussen
2021-09-30 13:02:35 +02:00
parent 32fa48df7d
commit a5a477e311
2 changed files with 65 additions and 7 deletions

View File

@ -1009,7 +1009,14 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
return nil, err
}
_, err = r.server.cc.Wallet.CheckReservedValueTx(authoredTx.Tx)
// Check the authored transaction and use the explicitly set change index
// to make sure that the wallet reserved balance is not invalidated.
_, err = r.server.cc.Wallet.CheckReservedValueTx(
lnwallet.CheckReservedValueTxReq{
Tx: authoredTx.Tx,
ChangeIndex: &authoredTx.ChangeIndex,
},
)
if err != nil {
return nil, err
}
@ -1242,7 +1249,9 @@ func (r *rpcServer) SendCoins(ctx context.Context,
err = wallet.WithCoinSelectLock(func() error {
var err error
reservedVal, err = wallet.CheckReservedValueTx(
sweepTxPkg.SweepTx,
lnwallet.CheckReservedValueTxReq{
Tx: sweepTxPkg.SweepTx,
},
)
return err
})
@ -1292,7 +1301,9 @@ func (r *rpcServer) SendCoins(ctx context.Context,
// Sanity check the new tx by re-doing the check.
err = wallet.WithCoinSelectLock(func() error {
_, err := wallet.CheckReservedValueTx(
sweepTxPkg.SweepTx,
lnwallet.CheckReservedValueTxReq{
Tx: sweepTxPkg.SweepTx,
},
)
return err
})