Skip to content

contractcourt: batch startup reads and block epoch notifications #4697

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

Merged
merged 3 commits into from
Nov 14, 2020

Conversation

carlaKC
Copy link
Collaborator

@carlaKC carlaKC commented Oct 15, 2020

Fixes #4481:

  • Use a shared transaction to do initial lookups when starting our arbitrators
  • Use a single block epoch notification stream for all channel arbitrators

With the change set as is, we reduce the number of database transactions we use from 2n to 1. However, if any of these channels are no longer in default state, they will still perform additional db transactions as they advance their state in stateStep. Using a single block notification stream reduces goroutines required to deliver blocks from 2n to n.
(n = number of arbitrators)

Having some grief with the itests for these, still figuring it out.

We’ve also discussed the prospect of passing a single transaction into stateStep so that we can step all of our transactions with a single tx on block arrival and startup. Working on this for a follow up because it requires a lot of refactoring, and has some complexity because stateStep takes some actions that cannot be rolled back if committing our shared tx fails (eg, publishing close tnxs, launching resolvers) which could land us in strange states.
-> This only gives us a performance gain at startup, not for new blocks because we only state step for default state arbs, which require no db txns.

@halseth
Copy link
Contributor

halseth commented Oct 16, 2020

Please request a review when ready :)

@Roasbeef
Copy link
Member

However, if any of these channels are no longer in default state, they will still perform additional db transactions as they advance their state in stateStep

Big win either case reducing the total number of goroutines and DB transactions by such a large margin! We can possibly circle back to truly centralize the advancement of all channel arbs at a later time depending on how this PR shapes out.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Initial pass focused on high level design. I think the distance to fully concentrating all updates in a single DB transaction for normal operation isn't that far off either....at least for state transitions triggered by blocks being mined.

@carlaKC carlaKC force-pushed the 4481-batchstartandblocks branch from 0046b90 to d298d20 Compare October 22, 2020 12:50
@carlaKC carlaKC force-pushed the 4481-batchstartandblocks branch 2 times, most recently from 3ea2145 to 5c55f11 Compare October 27, 2020 19:49
@carlaKC carlaKC marked this pull request as ready for review October 28, 2020 07:50
@carlaKC carlaKC requested review from halseth and Roasbeef October 28, 2020 07:52
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.

Starting to look very smooth 🏃

// chanArbStartState starts our channel arbitrator with the state provided.
// This function should be directly called when manually starting the channel
// arbitrator with state that has been independently retrieved.
func (c *ChannelArbitrator) startWithState(state *chanArbStartState) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the regular Start method at this point?

@carlaKC carlaKC force-pushed the 4481-batchstartandblocks branch from 5c55f11 to 727f69f Compare November 2, 2020 09:03
@Roasbeef Roasbeef added this to the 0.12.0 milestone Nov 4, 2020
@carlaKC carlaKC force-pushed the 4481-batchstartandblocks branch 3 times, most recently from 28e6c10 to 00a5a80 Compare November 4, 2020 12:30
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Nice work! This doesn't go quite as far as I'd envisioned re unifying all database operations across all channel arbs, but this version as is still is quite an improvement given the reduction in start up transactions as well as goroutine as a whole!

Starting to test this on one of my nodes with 300+ channels, will report back if anything odd pops up then do likely an additional round of review afterwards.

@carlaKC carlaKC force-pushed the 4481-batchstartandblocks branch 2 times, most recently from 0f072c8 to e5649a0 Compare November 9, 2020 10:45
@carlaKC carlaKC requested review from halseth and Roasbeef November 9, 2020 10:46
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🍢

Tested this out on one of my smaller nodes (1 vCPU, 2 GB RAM) and noticed quite a nice speed up on start up. I'm sure even larger nodes (this node has 90 channels) will see a greater improvement!

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.

Apart from making sure we reset vars across db transcations, this LGTM 👍

@carlaKC carlaKC force-pushed the 4481-batchstartandblocks branch from e5649a0 to ccd49f8 Compare November 12, 2020 13:23
To allow us to grab all of the information we need for our channel arbs
in a more efficient way on startup, we add an optional tx to our lookup
functions required on start.
@carlaKC carlaKC force-pushed the 4481-batchstartandblocks branch from ccd49f8 to 697dbf7 Compare November 12, 2020 13:39
@carlaKC
Copy link
Collaborator Author

carlaKC commented Nov 12, 2020

Apart from making sure we reset vars across db transcations, this LGTM 👍

Indeed! Diff since last review here with correct db resets.

@carlaKC carlaKC requested a review from halseth November 12, 2020 13:41
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.

@Roasbeef Roasbeef merged commit c024758 into lightningnetwork:master Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

contractcourt: globally batched state steps and block notifications
3 participants