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

Broadcast gossip announcements in sub batches #2985

Merged
merged 3 commits into from
May 29, 2019

Conversation

johng
Copy link
Contributor

@johng johng commented Apr 21, 2019

In this PR we split a list of announcements in the gossiper into sub batches. These are broadcasted at regular intervals instead of all at once.

See #2979

Pull Request Checklist

  • If this is your first time contributing, we recommend you read the Code
    Contribution Guidelines
  • All changes are Go version 1.12 compliant
  • The code being submitted is commented according to Code Documentation and Commenting
  • For new code: Code is accompanied by tests which exercise both
    the positive and negative (error paths) conditions (if applicable)
  • For bug fixes: Code is accompanied by new tests which trigger
    the bug being fixed to prevent regressions
  • Any new logging statements use an appropriate subsystem and
    logging level
  • Code has been formatted with go fmt
  • For code and documentation: lines are wrapped at 80 characters
    (the tab character should be counted as 8 characters, not 4, as some IDEs do
    per default)
  • Running make check does not fail any tests
  • Running go vet does not report any issues
  • Running make lint does not report any new issues that did not
    already exist
  • All commits build properly and pass tests. Only in exceptional
    cases it can be justifiable to violate this condition. In that case, the
    reason should be stated in the commit message.
  • Commits have a logical structure according to Ideal Git Commit Structure

@johng johng changed the title Broadcast gossip announcements into subbatches Broadcast gossip announcements into sub batches Apr 21, 2019
@johng johng changed the title Broadcast gossip announcements into sub batches Broadcast gossip announcements in sub batches Apr 21, 2019
Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

@johng thanks for the PR, great work!! i've completed an initial first pass, and the functionality seems to be correct. apart from one or two reliability comments, the rest are mostly around simplifications and adhering to the style guidelines :)

discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Show resolved Hide resolved
discovery/gossiper.go Show resolved Hide resolved
discovery/gossiper_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

@johng thanks for the quick turn around. completed another pass, mostly nits and bringing the PR in line with the style guidelines. appreciate the thorough testing of the batch splits 👍

go.sum Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper_test.go Outdated Show resolved Hide resolved
discovery/gossiper.go Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
discovery/gossiper_test.go Show resolved Hide resolved
@cfromknecht
Copy link
Contributor

Thanks @johng! This looks pretty good to me, would be good to get a second review from @wpaulino or @halseth

@cfromknecht
Copy link
Contributor

Gonna start running this patch on my node and see how it fairs

@wpaulino
Copy link
Contributor

@johng could you squash the fixup commits and rebase?

discovery/gossiper.go Outdated Show resolved Hide resolved
@johng johng force-pushed the sub-batch branch 2 times, most recently from 6ec82ec to a9d3db7 Compare April 27, 2019 10:56
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Mostly just nits from me on commit structure.

@@ -204,6 +205,14 @@ type Config struct {
// activeSyncer due to the current one not completing its state machine
// within the timeout.
ActiveSyncerTimeoutTicker ticker.Ticker

// MinimumBatchSize is the minimum size of each sub batches of gossip
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: s/batches/batch/

// decomposes it into sub batches controlled by the `subBatchSize`.
func splitAnnouncementBatches(subBatchSize int,
announcementBatch []msgWithSenders) [][]msgWithSenders {
var splitAnnouncementBatch [][]msgWithSenders
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: renaming these to annBatch and splitAnnBatch can help gain some more line space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I thought the more read able variable name is more important here

Copy link
Contributor

Choose a reason for hiding this comment

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

I think ann is a reasonable abbreviation for announcement but fine with me either way.

server.go Show resolved Hide resolved
discovery/gossiper.go Outdated Show resolved Hide resolved
@@ -3571,15 +3571,76 @@ func TestSplitAnnouncementsCorrectSubBatches(t *testing.T) {
announcementBatch := make([]msgWithSenders, batchSize)

splitAnnouncementBatch := splitAnnouncementBatches(
subBatchSize,
announcementBatch)
subBatchSize, announcementBatch,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: looks like the TestSplitAnnouncementCorrectSubBatches changes are a fixup of f4a9edc?

AnnSigner: &mockSigner{nodeKeyPriv1},
SubBatchDelay: time.Second * 5,
MinimumBatchSize: 10,
Router: router,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this fixup should be applied to f4a9edca7e107e9af31ad8b44c8ed9c5f78c2792 since that's where the changes were originally introduced.

@johng
Copy link
Contributor Author

johng commented Apr 30, 2019

@wpaulino following your comments, and since this was a small change for the gossiper I've combined the two testing commits into one so that all commits compile.

@wpaulino wpaulino added this to the 0.7 milestone May 8, 2019
Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

@johng been testing this for a bit on my node, everything appears to be working smoothly! one final comment from me, see inline


ratio := float64(subBatchDelay) / float64(totalDelay)

subBatchSize := int(math.Ceil(float64(batchSize) * ratio))
Copy link
Contributor

Choose a reason for hiding this comment

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

i think it'd be preferable to do this computation entirely using integer arithmetic, instead of using floating points and math lib functions. current calculation does ceil(batchSize * subBatchDelay / totalDelay), which is equivalent to using ceiling integer division:

subBatchSize := (batchSize*subBatchDelay + totalDelay - 1) / totalDelay

typically we try to avoid using floats when possible, as behavior the is less consistent across architectures

@cfromknecht
Copy link
Contributor

thanks @johng latest changes lgtm! ready to be squashed

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

Awesome work @johng! Really happy with how this turned out. LGTM 🍻

Will need one more rebase (there were some issues with our build that have now been fixed), if you pull in master it should get a clean run on travis and be merge-ready. Thanks!

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

LGTM 🎱

A few non-blocking nits left inline -- would prefer if the commits were squashed into one as we generally favor each commit being able to build on its own.

// decomposes it into sub batches controlled by the `subBatchSize`.
func splitAnnouncementBatches(subBatchSize int,
announcementBatch []msgWithSenders) [][]msgWithSenders {
var splitAnnouncementBatch [][]msgWithSenders
Copy link
Contributor

Choose a reason for hiding this comment

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

I think ann is a reasonable abbreviation for announcement but fine with me either way.

return batchSize
}

subBatchSize := (int(batchSize)*int(subBatchDelay) + int(totalDelay) - 1) /
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: unnecessary cast on batchSize.

@cfromknecht cfromknecht merged commit f8287b0 into lightningnetwork:master May 29, 2019
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.

3 participants