Skip to content

Conversation

@starius
Copy link
Collaborator

@starius starius commented Mar 28, 2025

Option WithInitialDelay now accepts a function returning initialDelay depending on sweep's data.

This is needed to be able to wait longer for sweeps with low priority, but still sweeping high priority sweeps soon.

Pull Request Checklist

  • Update release_notes.md if your PR contains major features, breaking changes or bugfixes

@starius starius marked this pull request as ready for review March 28, 2025 03:44
@starius starius changed the title [WIP] sweepbatcher: customize initialDelay per sweep sweepbatcher: customize initialDelay per sweep Mar 28, 2025
@starius starius force-pushed the sweepbatcher-initial-delay-func branch from 921714b to 798c32c Compare March 28, 2025 17:55
Copy link
Member

@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, nice! I think this greedy logic will help batches a lot! 🎉

// (especially important in case of a crashloop). If a sweep is about to
// expire (time until timeout is less that 2x initialDelay), then
// waiting is skipped.
initialDelayProvider InitialDelayProvider
Copy link
Member

Choose a reason for hiding this comment

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

nit: as this isn't really about init, but the first publish, for clarity we could rename it to firstPublishDelayProvider (and the firstPublishDelay below in the runloop). wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer the current name. We also have another option called PublishDelay. It could be confused with firstPublishDelayProvider if it is renamed. Also if we grep by PublishDelay, we would find both options.

@starius starius force-pushed the sweepbatcher-initial-delay-func branch from 798c32c to 535f619 Compare March 29, 2025 11:44
@starius
Copy link
Collaborator Author

starius commented Mar 29, 2025

Changed InitialDelayProvider signature: added the number of sweeps as an argument.

Copy link
Collaborator

@hieblmi hieblmi left a comment

Choose a reason for hiding this comment

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

LGTM!

type FeeRateProvider func(ctx context.Context,
swapHash lntypes.Hash) (chainfee.SatPerKWeight, error)

// InitialDelayProvider returns the duration after new batch creation before it
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: InitialDelayProvider returns the duration after which a newly created batch is first published.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed! Thanks!

b.primarySweepID[0:6], len(b.sweeps))

for {
// If the batch if not empty, find earliest initialDelay.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: is not empty

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

ctx, len(b.sweeps), totalSweptAmt,
)
if err != nil {
b.Warnf("initialDelayProvider failed: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

add to the warning that we use no initial delay in publishing this batch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

initialDelay = 0
}
if initialDelay < 0 {
b.Warnf("negative delay: %v", initialDelay)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Option WithInitialDelay now accepts a function returning initialDelay
depending on sweep's data.

This is needed to be able to wait longer for sweeps with low priority, but
still sweeping high priority sweeps soon.
@starius starius force-pushed the sweepbatcher-initial-delay-func branch from 535f619 to 472bec0 Compare April 3, 2025 12:23
@starius starius merged commit dc7261b into lightninglabs:master Apr 3, 2025
4 checks passed
@starius starius deleted the sweepbatcher-initial-delay-func branch April 3, 2025 12:42
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