Skip to content
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

Merged

Conversation

carlaKC
Copy link
Collaborator

@carlaKC carlaKC commented Jan 27, 2020

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.

@carlaKC carlaKC requested review from wpaulino and removed request for Roasbeef, halseth and joostjager January 27, 2020 07:09
@Roasbeef Roasbeef requested review from bhandras and removed request for cfromknecht January 27, 2020 23:16
@Roasbeef Roasbeef added this to the 0.10.0 milestone Jan 27, 2020
@carlaKC carlaKC force-pushed the 3709-cooperativecloseinitiator branch 2 times, most recently from 68e6073 to 2d4cdad Compare January 28, 2020 11:40
channeldb/channel.go Outdated Show resolved Hide resolved
channeldb/channel.go Outdated Show resolved Hide resolved
contractcourt/chain_watcher.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@bhandras bhandras left a 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.

@carlaKC
Copy link
Collaborator Author

carlaKC commented Jan 30, 2020

Don't review right now, want to check out the travis failure.

channeldb/channel.go Outdated Show resolved Hide resolved
@carlaKC carlaKC force-pushed the 3709-cooperativecloseinitiator branch from 13b88cd to 858313a Compare February 3, 2020 11:02
channeldb/channel.go Outdated Show resolved Hide resolved
@carlaKC
Copy link
Collaborator Author

carlaKC commented Feb 3, 2020

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.

@carlaKC carlaKC requested a review from halseth February 3, 2020 14:43
Copy link
Contributor

@halseth halseth left a 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/db_test.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved

// ChanStatusLocalCoopInitiated is set in addition to
// ChanStatusCoopBroadcasted when we initiate a cooperative close.
ChanStatusLocalCoopInitiated ChannelStatus = 1 << 5
Copy link
Contributor

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?

Copy link
Collaborator Author

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).

@carlaKC carlaKC force-pushed the 3709-cooperativecloseinitiator branch 6 times, most recently from aebafec to 94368d5 Compare February 19, 2020 12:34
@carlaKC
Copy link
Collaborator Author

carlaKC commented Feb 19, 2020

Ready for another look @bhandras!

A TL;DR on the changes since you last had a look:

  1. Went back to using channel statuses since we are increasing the size of the field
  2. The CloseSummary bucket is nasty to add fields to, channels are keys not buckets, and have a bunch of optional fields tacked on the end, decided not to use this. If we want to change it, a separate PR with full migration is in order IMO.
  3. Since this is just an aesthetic change for rpc, I decided to use the values in the historical channel bucket, since it is now written for all channels

@carlaKC carlaKC requested a review from halseth February 19, 2020 12:37
Copy link
Collaborator

@bhandras bhandras left a 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

// the channel.
ChanStatusLocalCloseInitiator ChannelStatus = 1 << 5

// ChanStatusRemoteCloseInitiator indicates that we initiated closing
Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

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),
Copy link
Contributor

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.

Copy link
Collaborator Author

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:
Copy link
Contributor

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.
@carlaKC carlaKC force-pushed the 3709-cooperativecloseinitiator branch from 94368d5 to b3e6395 Compare February 21, 2020 11:54
@carlaKC carlaKC requested a review from halseth February 21, 2020 12:50
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The closed channels list, should return who initiated the channel-close operation close_initiator
5 participants