fundingmanager: check remote peer upfront shutdown support before reservation
This addresses a bug in which a funding reservation wasn't cleaned up properly if the remote peer didn't support upfront shutdown. Alternatively, we could just cancel the reservation on error, but instead we move the check above so that we don't attempt coin selection in the first place.
This commit is contained in:
parent
8c2647de6b
commit
f48c4cae37
@ -3078,6 +3078,27 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the peer supports upfront shutdown, and get an address
|
||||
// which should be used (either a user specified address or a new
|
||||
// address from the wallet if our node is configured to set shutdown
|
||||
// address by default).
|
||||
shutdown, err := getUpfrontShutdownScript(
|
||||
msg.peer, msg.openChanReq.shutdownScript,
|
||||
func() (lnwire.DeliveryAddress, error) {
|
||||
addr, err := f.cfg.Wallet.NewAddress(
|
||||
lnwallet.WitnessPubKey, false,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return txscript.PayToAddrScript(addr)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
msg.err <- err
|
||||
return
|
||||
}
|
||||
|
||||
// Initialize a funding reservation with the local wallet. If the
|
||||
// wallet doesn't have enough funds to commit to this channel, then the
|
||||
// request will fail, and be aborted.
|
||||
@ -3112,24 +3133,6 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check whether the peer supports upfront shutdown, and get an address which
|
||||
// should be used (either a user specified address or a new address from the
|
||||
// wallet if our node is configured to set shutdown address by default).
|
||||
shutdown, err := getUpfrontShutdownScript(
|
||||
msg.peer, msg.openChanReq.shutdownScript,
|
||||
func() (lnwire.DeliveryAddress, error) {
|
||||
addr, err := f.cfg.Wallet.NewAddress(lnwallet.WitnessPubKey, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return txscript.PayToAddrScript(addr)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
msg.err <- err
|
||||
return
|
||||
}
|
||||
|
||||
// Set our upfront shutdown address in the existing reservation.
|
||||
reservation.SetOurUpfrontShutdown(shutdown)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user