Skip to content

Commit

Permalink
fixed processing of epochs without any block
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 15, 2023
1 parent 6d30397 commit cfa286b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
3 changes: 1 addition & 2 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,7 @@ slotLoop:
}
}
if epochTarget == nil {
logger.Errorf("Error fetching epoch %v target block (no block found)", epoch)
return
logger.Warnf("Counld not find epoch %v target (no block found)", epoch)
}

epochVotes := aggregateEpochVotes(indexer.state.cachedBlocks, epoch, epochStats, epochTarget, false)
Expand Down
39 changes: 17 additions & 22 deletions indexer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,7 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) bool {
return false
}

// load epoch validators
var firstBlock *BlockInfo
lastSlot = firstSlot + (utils.Config.Chain.Config.SlotsPerEpoch) - 1
for slot := firstSlot; slot <= lastSlot; slot++ {
if sync.cachedBlocks[slot] != nil {
firstBlock = sync.cachedBlocks[slot][0]
break
}
}
if firstBlock == nil {
// TODO: How to handle a epoch without any blocks?
synclogger.Errorf("Syncing epoch %v without any block is not supported", syncEpoch)
return true
}

// load epoch stats
epochStats := EpochStats{
Assignments: epochAssignments,
Validators: &EpochValidators{
Expand All @@ -202,11 +188,9 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) bool {
ValidatorBalances: make(map[uint64]uint64),
},
}

// load epoch stats
epochValidators, err := sync.indexer.rpcClient.GetStateValidators(epochAssignments.DependendState)
if err != nil {
logger.Errorf("Error fetching epoch %v/%v validators: %v", syncEpoch, firstBlock.Header.Data.Header.Message.Slot, err)
logger.Errorf("Error fetching epoch %v validators (state: %v): %v", syncEpoch, epochAssignments.DependendState, err)
} else {
for idx := 0; idx < len(epochValidators.Data); idx++ {
validator := epochValidators.Data[idx]
Expand All @@ -224,11 +208,22 @@ func (sync *synchronizerState) syncEpoch(syncEpoch uint64) bool {
}

// process epoch vote aggregations
var firstBlock *BlockInfo
lastSlot = firstSlot + (utils.Config.Chain.Config.SlotsPerEpoch) - 1
for slot := firstSlot; slot <= lastSlot; slot++ {
if sync.cachedBlocks[slot] != nil {
firstBlock = sync.cachedBlocks[slot][0]
break
}
}

var targetRoot []byte
if uint64(firstBlock.Header.Data.Header.Message.Slot) == firstSlot {
targetRoot = firstBlock.Header.Data.Root
} else {
targetRoot = firstBlock.Header.Data.Header.Message.ParentRoot
if firstBlock != nil {
if uint64(firstBlock.Header.Data.Header.Message.Slot) == firstSlot {
targetRoot = firstBlock.Header.Data.Root
} else {
targetRoot = firstBlock.Header.Data.Header.Message.ParentRoot
}
}
epochVotes := aggregateEpochVotes(sync.cachedBlocks, syncEpoch, &epochStats, targetRoot, false)

Expand Down

0 comments on commit cfa286b

Please sign in to comment.