-
Notifications
You must be signed in to change notification settings - Fork 122
loop: wait for chain notifier server to start #377
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package loop | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "sync" | ||
| "sync/atomic" | ||
| "time" | ||
|
|
@@ -52,10 +53,37 @@ func newExecutor(cfg *executorConfig) *executor { | |
| func (s *executor) run(mainCtx context.Context, | ||
| statusChan chan<- SwapInfo) error { | ||
|
|
||
| blockEpochChan, blockErrorChan, err := | ||
| s.lnd.ChainNotifier.RegisterBlockEpochNtfn(mainCtx) | ||
| if err != nil { | ||
| return err | ||
| var ( | ||
| err error | ||
| blockEpochChan <-chan int32 | ||
| blockErrorChan <-chan error | ||
| ) | ||
|
|
||
| for { | ||
| blockEpochChan, blockErrorChan, err = | ||
| s.lnd.ChainNotifier.RegisterBlockEpochNtfn(mainCtx) | ||
| if err != nil { | ||
| if strings.Contains(err.Error(), | ||
| "in the process of starting") { | ||
|
|
||
| log.Warnf("LND chain notifier server not " + | ||
| "ready yet, retrying with delay") | ||
|
|
||
| // Give chain notifier some time to start and | ||
| // try to re-attempt block epoch subscription. | ||
| select { | ||
| case <-time.After(500 * time.Millisecond): | ||
| continue | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add a log here that we're waiting for the chain notifier? Otherwise loop will just be hanging and user may not know why?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logging sounds good to me. And maybe increase the delay to 500ms to not spam
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah the 50ms was a bit overkill :) Log added. |
||
|
|
||
| case <-mainCtx.Done(): | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| break | ||
|
Comment on lines
+83
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to break? Couldn't we just return err here? Either it's nil or it's a non-"process of starting" error.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function continues below. So getting here means we've succeeded with the connection. |
||
| } | ||
|
|
||
| // Before starting, make sure we have an up to date block height. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could just be
Warn, but don't push again for this!