-
Notifications
You must be signed in to change notification settings - Fork 245
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
Add a workaround for waiting till node is synced with network #565
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"time" | ||
|
||
"github.com/status-im/status-go/geth/common" | ||
"github.com/status-im/status-go/geth/log" | ||
"github.com/status-im/status-go/geth/params" | ||
|
||
_ "github.com/stretchr/testify/suite" // required to register testify flags | ||
|
@@ -113,22 +114,32 @@ func EnsureNodeSync(nodeManager common.NodeManager) { | |
defer timeout.Stop() | ||
ticker := time.NewTicker(1 * time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-timeout.C: | ||
panic("timeout during node synchronization") | ||
case <-ticker.C: | ||
downloader := les.Downloader() | ||
|
||
if downloader != nil { | ||
isSyncing := downloader.Synchronising() | ||
progress := downloader.Progress() | ||
|
||
if !isSyncing && progress.HighestBlock > 0 && progress.CurrentBlock >= progress.HighestBlock { | ||
return | ||
} | ||
if downloader == nil { | ||
continue | ||
} | ||
if nodeManager.PeerCount() == 0 { | ||
log.Debug("No establishished connections with a peers, continue waiting for a sync") | ||
continue | ||
} | ||
if downloader.Synchronising() { | ||
log.Debug("synchronization is in progress") | ||
continue | ||
} | ||
progress := downloader.Progress() | ||
if progress.CurrentBlock >= progress.HighestBlock { | ||
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. I would recommend running Maybe these checks are good, though but it would be great to confirm. 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. It uses the same source of info as we are https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L79-L94, so I just printed the progress:
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. This looks good. Let's stay with this then. |
||
return | ||
} | ||
log.Debug( | ||
fmt.Sprintf("synchronization is not finished yet: current block %d < highest block %d", | ||
progress.CurrentBlock, progress.HighestBlock), | ||
) | ||
|
||
} | ||
} | ||
} | ||
|
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.
m.node
andm.node.Server()
may benil
. In such cases, I would return0
.