Skip to content

Commit

Permalink
minor sync fixes (#738)
Browse files Browse the repository at this point in the history
This contains a few minor sync fixes and some clean up.

In (*wiredDB).resyncDB, the following heights are kept updated: stakeDBHeight,
summaryHeight, and stakeInfoHeight.
The ticket pool info height check is now done even when found in cache.
The updateStatusChan was being sent the same value repeatedly. Changed to i,
the loop iteration. Move the chain height check to the last operation in the loop.
After the sync loop, call DBHeights one more time and display final heights, for
debugging.

Increase ticket pool cache size from 20 to 200 blocks over blocks behind.
In the secondary calls to getSyncd, auxDBHeight was not being updated.
Update it so fetchToHeight = auxDBHeight + 1 is correct even if there is a third
call to getSyncd.

Remove indent from chain monitor setup block. Something strange was happening
with the monitors and I do not want issues with them or garbage collection.
  • Loading branch information
chappjc committed Oct 16, 2018
1 parent 3a97e63 commit 59c6fbd
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 133 deletions.
6 changes: 3 additions & 3 deletions db/dcrsqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func (db *DB) RetrievePoolValAndSizeRange(ind0, ind1 int64) ([]float64, []float6
}

if len(poolsizes) != int(N) {
log.Warnf("Retrieved pool values (%d) not expected number (%d)", len(poolsizes), N)
log.Warnf("RetrievePoolValAndSizeRange: Retrieved pool values (%d) not expected number (%d)", len(poolsizes), N)
}

return poolvals, poolsizes, nil
Expand Down Expand Up @@ -534,7 +534,7 @@ func (db *DB) RetrieveAllPoolValAndSize() (*dbtypes.ChartsData, error) {
}

if len(chartsData.Time) < 1 {
log.Warnf("Retrieved pool values (%d) not expected number (%d)", len(chartsData.Time), 1)
log.Warnf("RetrieveAllPoolValAndSize: Retrieved pool values (%d) not expected number (%d)", len(chartsData.Time), 1)
}

return chartsData, nil
Expand Down Expand Up @@ -577,7 +577,7 @@ func (db *DB) RetrieveBlockFeeInfo() (*dbtypes.ChartsData, error) {
}

if len(chartsData.Count) < 1 {
log.Warnf("Retrieved pool values (%d) not expected number (%d)", len(chartsData.Count), 1)
log.Warnf("RetrieveBlockFeeInfo: Retrieved pool values (%d) not expected number (%d)", len(chartsData.Count), 1)
}

return chartsData, nil
Expand Down
46 changes: 32 additions & 14 deletions db/dcrsqlite/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (db *wiredDB) resyncDB(quit chan struct{}, blockGetter rpcutils.BlockGetter
return height, nil
}

// Initialize the progress bars on the sync status page.
if barLoad != nil && db.updateStatusSync {
barLoad <- &dbtypes.ProgressBarLoad{
Msg: InitialLoadSyncStatusMsg,
Expand Down Expand Up @@ -231,7 +232,8 @@ func (db *wiredDB) resyncDB(quit chan struct{}, blockGetter rpcutils.BlockGetter
}

// Advance stakedb height, which should always be less than or equal to
// SQLite height, as enforced by the rewinding code in this function.
// SQLite height, except when SQLite is empty since stakedb always has
// genesis, as enforced by the rewinding code in this function.
if i > stakeDBHeight {
if i != int64(db.sDB.Height()+1) {
panic(fmt.Sprintf("about to connect the wrong block: %d, %d", i, db.sDB.Height()))
Expand All @@ -240,6 +242,7 @@ func (db *wiredDB) resyncDB(quit chan struct{}, blockGetter rpcutils.BlockGetter
return i - 1, err
}
}
stakeDBHeight = int64(db.sDB.Height()) // i

if (i-1)%rescanLogBlockChunk == 0 && i-1 != startHeight || i == startHeight {
if i == 0 {
Expand Down Expand Up @@ -273,21 +276,21 @@ func (db *wiredDB) resyncDB(quit chan struct{}, blockGetter rpcutils.BlockGetter
if i <= summaryHeight && i <= stakeInfoHeight {
// update height, the end condition for the loop
if _, height, err = db.client.GetBestBlock(); err != nil {
return i - 1, fmt.Errorf("GetBestBlock failed: %v", err)
return i - 1, fmt.Errorf("rpcclient.GetBestBlock failed: %v", err)
}
continue
}

tpi, found := db.sDB.PoolInfo(blockhash)
if !found {
if i != 0 {
log.Warnf("Unable to find block (%v) in pool info cache. Resync is malfunctioning!", blockhash)
log.Errorf("Unable to find block (%v) in pool info cache. Resync is malfunctioning!", blockhash)
}
tpi = db.sDB.PoolInfoBest()
if int64(tpi.Height) != i {
log.Errorf("Ticket pool info not available for block %v.", blockhash)
tpi = nil
}
}
if int64(tpi.Height) != i {
log.Errorf("Ticket pool info not available for block %v.", blockhash)
tpi = nil
}

header := block.MsgBlock().Header
Expand All @@ -309,12 +312,13 @@ func (db *wiredDB) resyncDB(quit chan struct{}, blockGetter rpcutils.BlockGetter
if err = db.StoreBlockSummary(&blockSummary); err != nil {
return i - 1, fmt.Errorf("Unable to store block summary in database: %v", err)
}
summaryHeight = i
}

if i <= stakeInfoHeight {
// update height, the end condition for the loop
if _, height, err = db.client.GetBestBlock(); err != nil {
return i - 1, fmt.Errorf("GetBestBlock failed: %v", err)
return i - 1, fmt.Errorf("rpcclient.GetBestBlock failed: %v", err)
}
continue
}
Expand All @@ -340,20 +344,21 @@ func (db *wiredDB) resyncDB(quit chan struct{}, blockGetter rpcutils.BlockGetter
if err = db.StoreStakeInfoExtended(&si); err != nil {
return i - 1, fmt.Errorf("Unable to store stake info in database: %v", err)
}

// Update height, the end condition for the loop
if _, height, err = db.client.GetBestBlock(); err != nil {
return i, fmt.Errorf("GetBestBlock failed: %v", err)
}
stakeInfoHeight = i

// If updating explore is activated, update it at intervals of 200 blocks.
if updateExplorer != nil && i%200 == 0 && explorer.SyncExplorerUpdateStatus() && db.updateStatusSync {
updateExplorer <- &blockhash
select {
case db.updateStatusChan <- uint32(summaryHeight):
case db.updateStatusChan <- uint32(i):
default:
}
}

// Update height, the end condition for the loop.
if _, height, err = db.client.GetBestBlock(); err != nil {
return i, fmt.Errorf("rpcclient.GetBestBlock failed: %v", err)
}
}

if barLoad != nil && db.updateStatusSync {
Expand All @@ -368,6 +373,19 @@ func (db *wiredDB) resyncDB(quit chan struct{}, blockGetter rpcutils.BlockGetter

log.Infof("Rescan finished successfully at height %d.", height)

_, summaryHeight, stakeInfoHeight, stakeDBHeight, err = db.DBHeights()
if err != nil {
return -1, fmt.Errorf("DBHeights failed: %v", err)
}

log.Debug("New best block (chain server): ", height)
log.Debug("New best block (sqlite block DB): ", summaryHeight)
if stakeInfoHeight != summaryHeight {
log.Error("New best block (sqlite stake DB): ", stakeInfoHeight)
return -1, fmt.Errorf("SQLite database (dcrdata.sqlt.db) is corrupted")
}
log.Debug("New best block (stakedb): ", stakeDBHeight)

return height, nil
}

Expand Down
Loading

0 comments on commit 59c6fbd

Please sign in to comment.