mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 22:46:40 +01:00
htlcswitch: ability to start link in shutdown mode
In this commit, we add the ability to start a link in shutdown mode. This means that we immediately disable any new HTLC adds in the outgoing direction and that we queue up a Shutdown message after the next CommitSig message is sent (or immediately if no CommitSig message is owed).
This commit is contained in:
parent
dc25b425c0
commit
5de7792520
1 changed files with 28 additions and 0 deletions
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||||
"github.com/lightningnetwork/lnd/invoices"
|
"github.com/lightningnetwork/lnd/invoices"
|
||||||
|
@ -271,6 +272,14 @@ type ChannelLinkConfig struct {
|
||||||
// GetAliases is used by the link and switch to fetch the set of
|
// GetAliases is used by the link and switch to fetch the set of
|
||||||
// aliases for a given link.
|
// aliases for a given link.
|
||||||
GetAliases func(base lnwire.ShortChannelID) []lnwire.ShortChannelID
|
GetAliases func(base lnwire.ShortChannelID) []lnwire.ShortChannelID
|
||||||
|
|
||||||
|
// PreviouslySentShutdown is an optional value that is set if, at the
|
||||||
|
// time of the link being started, persisted shutdown info was found for
|
||||||
|
// the channel. This value being set means that we previously sent a
|
||||||
|
// Shutdown message to our peer, and so we should do so again on
|
||||||
|
// re-establish and should not allow anymore HTLC adds on the outgoing
|
||||||
|
// direction of the link.
|
||||||
|
PreviouslySentShutdown fn.Option[lnwire.Shutdown]
|
||||||
}
|
}
|
||||||
|
|
||||||
// channelLink is the service which drives a channel's commitment update
|
// channelLink is the service which drives a channel's commitment update
|
||||||
|
@ -1190,6 +1199,25 @@ func (l *channelLink) htlcManager() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a shutdown message has previously been sent on this link, then we
|
||||||
|
// need to make sure that we have disabled any HTLC adds on the outgoing
|
||||||
|
// direction of the link and that we re-resend the same shutdown message
|
||||||
|
// that we previously sent.
|
||||||
|
l.cfg.PreviouslySentShutdown.WhenSome(func(shutdown lnwire.Shutdown) {
|
||||||
|
// Immediately disallow any new outgoing HTLCs.
|
||||||
|
if !l.DisableAdds(Outgoing) {
|
||||||
|
l.log.Warnf("Outgoing link adds already disabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-send the shutdown message the peer. Since syncChanStates
|
||||||
|
// would have sent any outstanding CommitSig, it is fine for us
|
||||||
|
// to immediately queue the shutdown message now.
|
||||||
|
err := l.cfg.Peer.SendMessage(false, &shutdown)
|
||||||
|
if err != nil {
|
||||||
|
l.log.Warnf("Error sending shutdown message: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// We've successfully reestablished the channel, mark it as such to
|
// We've successfully reestablished the channel, mark it as such to
|
||||||
// allow the switch to forward HTLCs in the outbound direction.
|
// allow the switch to forward HTLCs in the outbound direction.
|
||||||
l.markReestablished()
|
l.markReestablished()
|
||||||
|
|
Loading…
Add table
Reference in a new issue