aperture icon indicating copy to clipboard operation
aperture copied to clipboard

Question about duplicate Start() calls in LndChallenger initialization

Open shaojunda opened this issue 7 months ago • 4 comments
trafficstars

Description:

I noticed that the Start() method of LndChallenger is called twice during initialization:

  1. First call in NewLndChallenger (lnd.go#L68)
  2. The second call in NewLNCChallenger (lnc.go#L44)

While analyzing the Start() method implementation, I found that it:

  • Initializes invoice state tracking
  • Creates invoice subscriptions
  • Starts background goroutines

Questions:

  1. Is this double initialization intentional?
  2. If not, should we remove the Start() call from NewLndChallenger and let the caller handle initialization?

I'd appreciate any clarification on the design decision behind this pattern.

shaojunda avatar Apr 15 '25 08:04 shaojunda

Those are two different kinds of challengers. One uses an lnd backend directly (over gRPC), the other uses an LNC connection. So depending on which one the user configures, either one is created and therefore also needs to be started.

guggero avatar Apr 15 '25 09:04 guggero

I understand that these are two different challengers (direct LND and LNC), but in the case of LNCChallenger, it actually creates and starts the same LndChallenger instance twice:

  1. First Start() is called inside NewLndChallenger
  2. Then the same LndChallenger instance's Start() is called again in NewLNCChallenger

This means we're calling Start() on the same LndChallenger instance twice.

shaojunda avatar Apr 15 '25 09:04 shaojunda

To be more specific, in NewLNCChallenger, we first create a LndChallenger through NewLndChallenger, and then call Start() on that same instance again. This is why the same LndChallenger instance's Start() method gets called twice.

shaojunda avatar Apr 15 '25 09:04 shaojunda

Ah yeah, sorry. Looked at the code too superficially. I think it makes sense to remove the explicit call to lndChallenger.Start() within NewLNCChallenger.

guggero avatar Apr 15 '25 10:04 guggero