Skip to content

Commit

Permalink
fix: respect first block in count x2
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Aug 6, 2024
1 parent 8810c54 commit 29f41cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pkg/app_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ func (a *AppManager) ProcessSnapshot(block *types.Block) {
}
}

totalBlocksCount := a.StateManager.GetBlocksCountSinceLatest(a.Config.StoreBlocks)
totalBlocksCount := a.StateManager.GetBlocksCountSinceLatest(a.Config.StoreBlocks - a.Config.FirstBlock + 1)
a.Logger.Info().
Int64("count", totalBlocksCount).
Int64("height", block.Height).
Msg("Added new Tendermint block into state")

blocksCount := a.StateManager.GetBlocksCountSinceLatest(a.Config.BlocksWindow)

neededBlocks := utils.MinInt64(a.Config.BlocksWindow, a.StateManager.GetLastBlockHeight()-a.Config.FirstBlock)
neededBlocks := utils.MinInt64(a.Config.BlocksWindow, a.StateManager.GetLastBlockHeight()-a.Config.FirstBlock+1)
hasEnoughBlocks := blocksCount >= neededBlocks

if !hasEnoughBlocks {
Expand Down Expand Up @@ -405,10 +405,10 @@ func (a *AppManager) PopulateBlocks() {
return
}

missingBlocks := a.StateManager.GetMissingBlocksSinceLatest(a.Config.StoreBlocks - a.Config.FirstBlock)
missingBlocks := a.StateManager.GetMissingBlocksSinceLatest(a.Config.StoreBlocks - a.Config.FirstBlock + 1)
if len(missingBlocks) == 0 {
a.Logger.Info().
Int64("count", a.Config.StoreBlocks).
Int64("count", a.Config.StoreBlocks-a.Config.FirstBlock+1).
Msg("Got enough blocks for populating")
a.IsPopulatingBlocks = false
return
Expand All @@ -417,11 +417,11 @@ func (a *AppManager) PopulateBlocks() {
blocksChunks := utils.SplitIntoChunks(missingBlocks, a.Config.Pagination.BlocksSearch)

for _, chunk := range blocksChunks {
count := a.StateManager.GetBlocksCountSinceLatest(a.Config.StoreBlocks - a.Config.FirstBlock)
count := a.StateManager.GetBlocksCountSinceLatest(a.Config.StoreBlocks - a.Config.FirstBlock + 1)

a.Logger.Info().
Int64("count", count).
Int64("required", a.Config.StoreBlocks).
Int64("required", a.Config.StoreBlocks-a.Config.FirstBlock+1).
Int("needed_blocks", len(chunk)).
Ints64("blocks", chunk).
Msg("Fetching more blocks...")
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ChainConfig struct {
BlocksWindow int64 `default:"10000" toml:"blocks-window"`
MinSignedPerWindow float64 `default:"0.05" toml:"min-signed-per-window"`
SnapshotsInterval int64 `default:"1" toml:"snapshots-interval"`
FirstBlock int64 `default:"0" toml:"first-block"`
FirstBlock int64 `default:"1" toml:"first-block"`
Pagination ChainPagination `toml:"pagination"`
Intervals IntervalsConfig `toml:"intervals"`

Expand Down

0 comments on commit 29f41cd

Please sign in to comment.