Skip to content

Commit

Permalink
fix: respect first block in count x3
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Aug 6, 2024
1 parent 29f41cd commit 29d0254
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 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 - a.Config.FirstBlock + 1)
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+1)
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 + 1)
missingBlocks := a.StateManager.GetMissingBlocksSinceLatest(a.Config.StoreBlocks - a.Config.FirstBlock - 1)
if len(missingBlocks) == 0 {
a.Logger.Info().
Int64("count", a.Config.StoreBlocks-a.Config.FirstBlock+1).
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 + 1)
count := a.StateManager.GetBlocksCountSinceLatest(a.Config.StoreBlocks - a.Config.FirstBlock - 1)

a.Logger.Info().
Int64("count", count).
Int64("required", a.Config.StoreBlocks-a.Config.FirstBlock+1).
Int64("required", a.Config.StoreBlocks-a.Config.FirstBlock-1).
Int("needed_blocks", len(chunk)).
Ints64("blocks", chunk).
Msg("Fetching more blocks...")
Expand Down
4 changes: 2 additions & 2 deletions pkg/state/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (m *Manager) GetSnapshot() (snapshotPkg.Snapshot, error) {
validators := m.state.GetValidators()
entries := make(types.Entries, len(validators))

neededBlocks := utils.MinInt64(m.config.BlocksWindow, m.GetLastBlockHeight()-m.config.FirstBlock)
neededBlocks := utils.MinInt64(m.config.BlocksWindow, m.GetLastBlockHeight()-m.config.FirstBlock-1)

for _, validator := range validators {
// Taking the active status from the last block, as there might be a case
Expand Down Expand Up @@ -238,7 +238,7 @@ func (m *Manager) GetBlockTime() time.Duration {
}

func (m *Manager) GetValidatorMissedBlocks(validator *types.Validator) (types.SignatureInto, error) {
blocksToCheck := utils.MinInt64(m.config.BlocksWindow, m.GetLastBlockHeight()-m.config.FirstBlock)
blocksToCheck := utils.MinInt64(m.config.BlocksWindow, m.GetLastBlockHeight()-m.config.FirstBlock-1)
return m.state.GetValidatorMissedBlocks(validator, blocksToCheck)
}

Expand Down

0 comments on commit 29d0254

Please sign in to comment.