-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multi: implement spec-compliant coop close #6760
Changes from 1 commit
b1c0c12
39f29c0
3d016f9
3e0220d
ee1cfd2
1a68e24
88406e7
1365e6c
e6b067f
26513f9
21f83f1
0ac5d69
e22bae3
d4c3b35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -972,6 +972,47 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint, | |
return err | ||
} | ||
|
||
chanID := lnwire.NewChanIDFromOutPoint(chanPoint) | ||
|
||
// If we need to retransmit Shutdown, create a ChanCloser and give it | ||
// the Shutdown message. | ||
retransmitShutdown := lnChan.State().HasSentShutdown() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to retransmit shutdown when the channel has sent shutdown? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will retransmit shutdown if we've ever sent shutdown in the past There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it mean we are sending multiple shutdowns? Suppose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is ok as long as it's not in the same p2p connection |
||
if retransmitShutdown { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do |
||
feePerKw, err := p.cfg.FeeEstimator.EstimateFeePerKW( | ||
yyforyongyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
p.cfg.CoopCloseTargetConfs, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Since we've sent Shutdown, the delivery script is already | ||
// persisted. We won't know if it's locally initiated or not. | ||
// At this stage, this is fine so we set it to true. | ||
chanCloser, err := p.createChanCloser( | ||
lnChan, lnChan.LocalUpfrontShutdownScript(), feePerKw, | ||
nil, true, | ||
) | ||
if err != nil { | ||
peerLog.Errorf("unable to create chan closer: %v", err) | ||
return err | ||
} | ||
|
||
p.activeChanCloses[chanID] = chanCloser | ||
|
||
shutdownMsg := lnwire.NewShutdown( | ||
chanID, lnChan.LocalUpfrontShutdownScript(), | ||
) | ||
|
||
// Give the Shutdown message to the ChanCloser without sending | ||
// it. The link will send it during retransmission. | ||
_, _, err = chanCloser.ProcessCloseMsg(shutdownMsg, false) | ||
if err != nil { | ||
peerLog.Errorf("unable to process shutdown: %v", err) | ||
delete(p.activeChanCloses, chanID) | ||
return err | ||
} | ||
} | ||
|
||
//nolint:lll | ||
linkCfg := htlcswitch.ChannelLinkConfig{ | ||
Peer: p, | ||
|
@@ -1014,13 +1055,13 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint, | |
DeliveryAddr: deliveryAddr, | ||
NotifySendingShutdown: p.HandleLocalCloseChanReqs, | ||
NotifyCoopReady: p.HandleCoopReady, | ||
RetransmitShutdown: retransmitShutdown, | ||
} | ||
|
||
// Before adding our new link, purge the switch of any pending or live | ||
// links going by the same channel id. If one is found, we'll shut it | ||
// down to ensure that the mailboxes are only ever under the control of | ||
// one link. | ||
chanID := lnwire.NewChanIDFromOutPoint(chanPoint) | ||
p.cfg.Switch.RemoveLink(chanID) | ||
|
||
// With the channel link created, we'll now notify the htlc switch so | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we need to check
l.shutdownInit == true
to test if it's retransmitted.