-
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
channeldb: Indicate cooperative close initator #3961
channeldb: Indicate cooperative close initator #3961
Conversation
68e6073
to
2d4cdad
Compare
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.
Overall solid PR, my only wish is that it'd be great to have test for the added functionality, as in the current form tests are only patched.
2d4cdad
to
13b88cd
Compare
Don't review right now, want to check out the travis failure. |
13b88cd
to
858313a
Compare
Updated to add a new field in the db as @halseth suggested. I think it simplifies the PR nicely, and we don't use us 2 of our 3 remaining status bits. |
49c85e8
to
9402e5e
Compare
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.
Nice, last iteration looks 🔥 Just a few more things and we should be there 🙏
channeldb/channel.go
Outdated
|
||
// ChanStatusLocalCoopInitiated is set in addition to | ||
// ChanStatusCoopBroadcasted when we initiate a cooperative close. | ||
ChanStatusLocalCoopInitiated ChannelStatus = 1 << 5 |
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.
cool, I like this :) Looking at the chan statuses, we don't actually store whether we initiate a force close. This could be useful information also, like if we initiate, but the remote force close ends up in the chain. So we could make this a bit more general, and store it also in the cases where we/them force close?
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.
Updated to include force closes. Not quite the same flow for local vs remote force closes because we have some warning for local force where we can mark broadcast and set the initiator status. We only detect remote forces once they've been broadcast, and we don't mark broadcast (because we use that field for rebroadcasting on startup).
aebafec
to
94368d5
Compare
Ready for another look @bhandras! A TL;DR on the changes since you last had a look:
|
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.
lgtm 👍
|
||
// createTestChannelArbitrator returns a channel arbitrator test context which | ||
// contains a channel arbitrator with default values. These values can be | ||
// changes by providing options which overwrite the default config. |
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.
changed.
channeldb/channel.go
Outdated
// the channel. | ||
ChanStatusLocalCloseInitiator ChannelStatus = 1 << 5 | ||
|
||
// ChanStatusRemoteCloseInitiator indicates that we initiated closing |
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.
s/we/the remote node
// channel statuses which will be written to the historical channel bucket. | ||
// These statuses are used to record close initiators. | ||
func (c *OpenChannel) CloseChannel(summary *ChannelCloseSummary, | ||
statuses ...ChannelStatus) error { |
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.
oh, elegant 😀
return nil | ||
}, | ||
IsPendingClose: false, | ||
ChainArbitratorConfig: chainArbCfg, | ||
ChainEvents: chanEvents, | ||
} | ||
|
||
// Apply all custom options to the config struct. | ||
for _, o := range opts { | ||
o(arbCfg) |
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.
{o,o}
} | ||
|
||
chanArbCtx, err := createTestChannelArbitrator( | ||
t, log, withMarkClosed(alice.CloseChannel), |
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.
instead of making the dependency on the OpenChannel here, could we instead mock the CloseChannel
method, and assert it is called with the expected states set.
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.
nice, cuts down the test length too 👍
rpcserver.go
Outdated
|
||
// The channel was closed before we started storing historical | ||
// channels. Do not return an error, initiator values are unknown. | ||
case channeldb.ErrChannelNotFound: |
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.
return immediately to avoid indentation below
This commit adds two new channel statuses which indicate the party that initatited closing the channel. These statuses are set in conjunction with the existing commit broadcast status so that we do not need to migrate existing logic to handle multiple types of closes. This status is set for locally initiated force closes in this commit because they follow a similar pattern to cooparative closes, marking the commitment broadcast then proceeding with tx broadcast. Remote force closes are added in the following commit, as they are handled differently.
Add an optional channel status CloseChannel which will be stored on the hitsorical channel which is persisted at channel close. This status is used to set the close initiator for channels that do not complete the funding flow or we abandon. In follow up commits, this status will be used to record force and breach closes. The value is written to the historical channel bucket for diplay over rpc.
Add an initiator enum which allows up to display an unknown value for channels that are not in the historical chan bucket, rather than having and ambiguous false value also representing no-value. A both option is added to cover the case where both parties initiated a close on chain.
Update channel updates and subscription itest to check that close initiator is appropriately set for cooperative and force closes for the local and remote party.
94368d5
to
b3e6395
Compare
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.
LGTM 🔥
Fixes #3709.
Update channeldb to save channel statuses indicating whether the local or remote party initiated a cooperative close. These values are written to db at the time of cooperative close broadcast, and reloaded in chain watcher when we need to dispatch a cooperative close.