mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-26 21:51:27 +02:00
multi: enable RBF co-op bumps after reconnection
In this commit, we alter the existing co-op close flow to enable RBF bumps after re connection. With the new RBF close flow, it's possible that after a success round _and_ a re connection, either side wants to do another fee bump. Typically we route these requests through the switch, but in this case, the link no longer exists in the switch, so any requests to fee bump again would find that the link doesn't exist. In this commit, we implement a work around wherein if we have an RBF chan closer active, and the link isn't in the switch, then we just route the request directly to the chan closer via the peer. Once we have the chan closer, we can use the exact same flow as prior.
This commit is contained in:
@@ -5234,3 +5234,62 @@ func (p *Brontide) scaleTimeout(timeout time.Duration) time.Duration {
|
||||
|
||||
return timeout
|
||||
}
|
||||
|
||||
// CoopCloseUpdates is a struct used to communicate updates for an active close
|
||||
// to the caller.
|
||||
type CoopCloseUpdates struct {
|
||||
UpdateChan chan interface{}
|
||||
|
||||
ErrChan chan error
|
||||
}
|
||||
|
||||
// ChanHasRbfCoopCloser returns true if the channel as identifier by the channel
|
||||
// point has an active RBF chan closer.
|
||||
func (p *Brontide) ChanHasRbfCoopCloser(chanPoint wire.OutPoint) bool {
|
||||
chanID := lnwire.NewChanIDFromOutPoint(chanPoint)
|
||||
chanCloser, found := p.activeChanCloses.Load(chanID)
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
|
||||
return chanCloser.IsRight()
|
||||
}
|
||||
|
||||
// TriggerCoopCloseRbfBump given a chan ID, and the params needed to trigger a
|
||||
// new RBF co-op close update, a bump is attempted. A channel used for updates,
|
||||
// along with one used to o=communicate any errors is returned. If no chan
|
||||
// closer is found, then false is returned for the second argument.
|
||||
func (p *Brontide) TriggerCoopCloseRbfBump(ctx context.Context,
|
||||
chanPoint wire.OutPoint, feeRate chainfee.SatPerKWeight,
|
||||
deliveryScript lnwire.DeliveryAddress) (*CoopCloseUpdates, error) {
|
||||
|
||||
// If RBF coop close isn't permitted, then we'll an error.
|
||||
if !p.rbfCoopCloseAllowed() {
|
||||
return nil, fmt.Errorf("rbf coop close not enabled for " +
|
||||
"channel")
|
||||
}
|
||||
|
||||
closeUpdates := &CoopCloseUpdates{
|
||||
UpdateChan: make(chan interface{}, 1),
|
||||
ErrChan: make(chan error, 1),
|
||||
}
|
||||
|
||||
// We'll re-use the existing switch struct here, even though we're
|
||||
// bypassing the switch entirely.
|
||||
closeReq := htlcswitch.ChanClose{
|
||||
CloseType: contractcourt.CloseRegular,
|
||||
ChanPoint: &chanPoint,
|
||||
TargetFeePerKw: feeRate,
|
||||
DeliveryScript: deliveryScript,
|
||||
Updates: closeUpdates.UpdateChan,
|
||||
Err: closeUpdates.ErrChan,
|
||||
Ctx: ctx,
|
||||
}
|
||||
|
||||
err := p.startRbfChanCloser(newRPCShutdownInit(&closeReq), chanPoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return closeUpdates, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user