Skip to content

Commit

Permalink
Merge pull request #8167 from ProofOfKeags/bugfix/htlc-flush-shutdown
Browse files Browse the repository at this point in the history
Bugfix/htlc flush shutdown
  • Loading branch information
Roasbeef authored Jan 24, 2024
2 parents e31d159 + 69ef1b2 commit 1caca81
Show file tree
Hide file tree
Showing 25 changed files with 4,374 additions and 3,668 deletions.
4 changes: 4 additions & 0 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,10 @@ func executeChannelClose(ctxc context.Context, client lnrpc.LightningClient,
}

switch update := resp.Update.(type) {
case *lnrpc.CloseStatusUpdate_CloseInstant:
if req.NoWait {
return nil
}
case *lnrpc.CloseStatusUpdate_ClosePending:
closingHash := update.ClosePending.Txid
txid, err := chainhash.NewHash(closingHash)
Expand Down
11 changes: 11 additions & 0 deletions docs/release-notes/release-notes-0.18.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
* [Properly handle un-acked updates for exhausted watchtower
sessions](https://github.com/lightningnetwork/lnd/pull/8233)

* [Allow `shutdown`s while HTLCs are in-flight](https://github.com/lightningnetwork/lnd/pull/8167).
This change fixes an issue where we would force-close channels when receiving
a `shutdown` message if there were currently HTLCs on the channel. After this
change, the shutdown procedure should be compliant with BOLT2 requirements.

# New Features
## Functional Enhancements

Expand Down Expand Up @@ -126,6 +131,12 @@
file](https://github.com/lightningnetwork/lnd/pull/8188). The corresponding
`lncli getdebuginfo` command was also added.

* Add a [new flag](https://github.com/lightningnetwork/lnd/pull/8167) to the
`CloseChannel` RPC method that instructs the client to not wait for the
closing transaction to be negotiated. This should be used if you don't care
about the txid and don't want the calling code to block while the channel
drains the active HTLCs.

## lncli Additions

* Deprecate `bumpclosefee` for `bumpforceclosefee` to accommodate for the fact
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/clock v1.1.1
github.com/lightningnetwork/lnd/fn v1.0.0
github.com/lightningnetwork/lnd/fn v1.0.1
github.com/lightningnetwork/lnd/healthcheck v1.2.3
github.com/lightningnetwork/lnd/kvdb v1.4.4
github.com/lightningnetwork/lnd/queue v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bq
github.com/lightningnetwork/lnd/clock v1.0.1/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg=
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
github.com/lightningnetwork/lnd/clock v1.1.1/go.mod h1:mGnAhPyjYZQJmebS7aevElXKTFDuO+uNFFfMXK1W8xQ=
github.com/lightningnetwork/lnd/fn v1.0.0 h1:I5VG9AD63mOQ89RMQEu7HRI1r68wn8yz539LoylUIKM=
github.com/lightningnetwork/lnd/fn v1.0.0/go.mod h1:XV+0vBXSnh3aUjskJUv58TOpsveiXQ+ac8rEnXZDGFc=
github.com/lightningnetwork/lnd/fn v1.0.1 h1:4nAxKpGKgk4/xRQKxvim3BW0QM34S4BH6QghWZVjsko=
github.com/lightningnetwork/lnd/fn v1.0.1/go.mod h1:XV+0vBXSnh3aUjskJUv58TOpsveiXQ+ac8rEnXZDGFc=
github.com/lightningnetwork/lnd/healthcheck v1.2.3 h1:oqhOOy8WmIEa6RBkYKC0mmYZkhl8T2kGD97n9jpML8o=
github.com/lightningnetwork/lnd/healthcheck v1.2.3/go.mod h1:eDxH3dEwV9DeBW/6inrmlVh1qBOFV0AI14EEPnGt9gc=
github.com/lightningnetwork/lnd/kvdb v1.4.4 h1:bCv63rVCvzqj1BkagN/EWTov6NDDgYEG/t0z2HepRMk=
Expand Down
51 changes: 47 additions & 4 deletions htlcswitch/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,55 @@ type ChannelUpdateHandler interface {
// parameter.
MayAddOutgoingHtlc(lnwire.MilliSatoshi) error

// ShutdownIfChannelClean shuts the link down if the channel state is
// clean. This can be used with dynamic commitment negotiation or coop
// close negotiation which require a clean channel state.
ShutdownIfChannelClean() error
// EnableAdds sets the ChannelUpdateHandler state to allow
// UpdateAddHtlc's in the specified direction. It returns an error if
// the state already allowed those adds.
EnableAdds(direction LinkDirection) error

// DiableAdds sets the ChannelUpdateHandler state to allow
// UpdateAddHtlc's in the specified direction. It returns an error if
// the state already disallowed those adds.
DisableAdds(direction LinkDirection) error

// IsFlushing returns true when UpdateAddHtlc's are disabled in the
// direction of the argument.
IsFlushing(direction LinkDirection) bool

// OnFlushedOnce adds a hook that will be called the next time the
// channel state reaches zero htlcs. This hook will only ever be called
// once. If the channel state already has zero htlcs, then this will be
// called immediately.
OnFlushedOnce(func())

// OnCommitOnce adds a hook that will be called the next time a
// CommitSig message is sent in the argument's LinkDirection. This hook
// will only ever be called once. If no CommitSig is owed in the
// argument's LinkDirection, then we will call this hook immediately.
OnCommitOnce(LinkDirection, func())
}

// CommitHookID is a value that is used to uniquely identify hooks in the
// ChannelUpdateHandler's commitment update lifecycle. You should never need to
// construct one of these by hand, nor should you try.
type CommitHookID uint64

// FlushHookID is a value that is used to uniquely identify hooks in the
// ChannelUpdateHandler's flush lifecycle. You should never need to construct
// one of these by hand, nor should you try.
type FlushHookID uint64

// LinkDirection is used to query and change any link state on a per-direction
// basis.
type LinkDirection bool

const (
// Incoming is the direction from the remote peer to our node.
Incoming LinkDirection = false

// Outgoing is the direction from our node to the remote peer.
Outgoing LinkDirection = true
)

// ChannelLink is an interface which represents the subsystem for managing the
// incoming htlc requests, applying the changes to the channel, and also
// propagating/forwarding it to htlc switch.
Expand Down
Loading

0 comments on commit 1caca81

Please sign in to comment.