Skip to content
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

Improved Status Reports #69

Merged
merged 1 commit into from
Oct 30, 2019
Merged
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
32 changes: 30 additions & 2 deletions node/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (d *Pegnetd) GetCurrentSync() uint32 {
// DBlockSync iterates through dblocks and syncs the various chains
func (d *Pegnetd) DBlockSync(ctx context.Context) {
retryPeriod := d.Config.GetDuration(config.DBlockSyncRetryPeriod)
isFirstSync := true
OuterSyncLoop:
for {
if isDone(ctx) {
Expand All @@ -42,14 +43,33 @@ OuterSyncLoop:
if d.Sync.Synced >= heights.DirectoryBlock {
// We are currently synced, nothing to do. If we are above it, the factomd could
// be rebooted
if d.Sync.Synced > heights.DirectoryBlock {
log.Debugf("Factom node behind. database height = %d, factom height = %d", d.Sync.Synced, heights.DirectoryBlock)
}

if isFirstSync {
isFirstSync = false
log.WithField("height", d.Sync.Synced).Info("Node is up to date")
}

time.Sleep(retryPeriod) // TODO: Should we have a separate polling period?
continue
}

var totalDur time.Duration
var iterations int

var longSync bool
if isFirstSync || heights.DirectoryBlock-d.Sync.Synced > 1 {
log.WithFields(log.Fields{
"height": d.Sync.Synced,
"syncing-to": heights.DirectoryBlock,
}).Infof("Starting sync job of %d blocks", heights.DirectoryBlock-d.Sync.Synced)
longSync = true
}

begin := time.Now()
lastReport := begin
for d.Sync.Synced < heights.DirectoryBlock {
start := time.Now()
hLog := log.WithFields(log.Fields{"height": d.Sync.Synced + 1})
Expand Down Expand Up @@ -110,8 +130,9 @@ OuterSyncLoop:

iterations++
totalDur += elapsed
// Only print if we are > 50 behind and every 50
if iterations%50 == 0 {
// update every 15 seconds
if time.Since(lastReport) > time.Second*15 {
lastReport = time.Now()
toGo := heights.DirectoryBlock - d.Sync.Synced
avg := totalDur / time.Duration(iterations)
hLog.WithFields(log.Fields{
Expand All @@ -123,6 +144,13 @@ OuterSyncLoop:
}
}

isFirstSync = false
if longSync {
longSync = false
log.WithField("height", d.Sync.Synced).WithField("blocks-synced", iterations).Infof("Finished sync job")
} else if d.Sync.Synced%6 == 0 {
log.WithField("height", d.Sync.Synced).Infof("status report")
}
}

}
Expand Down