Skip to content

Conversation

@hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Dec 24, 2025

This PR defaults the peer gossip trickle delay to 1 if its config value is set to <=0.

Observing the following error if --trickledelay=0:

panic: non-positive interval for NewTicker


goroutine 2212 [running]:

time.NewTicker(0x4000b47160?)

	time/tick.go:38 +0xc0

github.com/lightningnetwork/lnd/discovery.(*AuthenticatedGossiper).networkHandler(0x400086b2b0, {0x27384c8, 0x4002832b40})

	github.com/lightningnetwork/lnd/discovery/gossiper.go:1466 +0xd8

created by github.com/lightningnetwork/lnd/discovery.(*AuthenticatedGossiper).start in goroutine 2057

	github.com/lightningnetwork/lnd/discovery/gossiper.go:697 +0x15c

@hieblmi hieblmi marked this pull request as draft December 24, 2025 09:05
@gemini-code-assist
Copy link

Summary of Changes

Hello @hieblmi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial fix to enhance the stability of the network's gossip mechanism. It addresses a specific scenario where an invalid configuration for the TrickleDelay could lead to a program crash. By ensuring that the delay is always a positive duration, the change prevents panics and guarantees the continuous operation of the peer gossip handler, improving overall system robustness.

Highlights

  • Panic Prevention: This pull request resolves a critical runtime panic that occurred when the peer gossip TrickleDelay configuration was set to a non-positive value (e.g., 0s), which caused time.NewTicker to fail.
  • Defaulting TrickleDelay: A safeguard has been implemented in the networkHandler to check the TrickleDelay value. If it is found to be less than or equal to 0, it is now automatically defaulted to 1 nanosecond, ensuring a valid duration for time.NewTicker.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a panic that occurs when trickledelay is set to a non-positive value. The change introduces a check to ensure the delay is positive before creating a ticker. My review includes a suggestion to refactor this validation logic into the constructor for better code organization.

Comment on lines +1476 to +1484
trickleDelay := d.cfg.TrickleDelay
if trickleDelay <= 0 {
log.Infof("TrickleDelay is non-positive (%v), setting to 1ns",
trickleDelay)

trickleDelay = 1
}

trickleTimer := time.NewTicker(trickleDelay)

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.

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.

1 participant