Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper
futureMsgs: newFutureMsgCache(maxFutureMessages),
quit: make(chan struct{}),
chanPolicyUpdates: make(chan *chanPolicyUpdateRequest),
prematureChannelUpdates: lru.NewCache[uint64, *cachedNetworkMsg]( //nolint: ll
prematureChannelUpdates: lru.NewCache[uint64, *cachedNetworkMsg]( //nolint:ll
maxPrematureUpdates,
),
channelMtx: multimutex.NewMutex[uint64](),
Expand Down Expand Up @@ -1473,7 +1473,15 @@ func (d *AuthenticatedGossiper) networkHandler(ctx context.Context) {
d.cfg.RetransmitTicker.Resume()
defer d.cfg.RetransmitTicker.Stop()

trickleTimer := time.NewTicker(d.cfg.TrickleDelay)
trickleDelay := d.cfg.TrickleDelay
if trickleDelay <= 0 {
log.Infof("TrickleDelay is non-positive (%v), setting to 1ns",
trickleDelay)

trickleDelay = 1
}

trickleTimer := time.NewTicker(trickleDelay)
Comment on lines +1476 to +1484

Choose a reason for hiding this comment

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

medium

While this fix correctly prevents the panic, the logic for validating and defaulting the TrickleDelay configuration would be better placed in the New constructor. This keeps the networkHandler focused on its runtime logic and centralizes configuration adjustments at initialization.

I suggest moving this block to the New function, around line 581:

// discovery/gossiper.go:580
func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper {
    if cfg.TrickleDelay <= 0 {
        log.Infof("TrickleDelay is non-positive (%v), setting to 1ns",
            cfg.TrickleDelay)
        cfg.TrickleDelay = 1
    }

    gossiper := &AuthenticatedGossiper{
        // ...

And reverting this part of the change.

Suggested change
trickleDelay := d.cfg.TrickleDelay
if trickleDelay <= 0 {
log.Infof("TrickleDelay is non-positive (%v), setting to 1ns",
trickleDelay)
trickleDelay = 1
}
trickleTimer := time.NewTicker(trickleDelay)
trickleTimer := time.NewTicker(d.cfg.TrickleDelay)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good suggestion, will fix this.

defer trickleTimer.Stop()

// To start, we'll first check to see if there are any stale channel or
Expand Down
Loading