Skip to content

Commit

Permalink
ensure orphaned status is displayed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 25, 2023
1 parent 3461810 commit 144a02c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
23 changes: 14 additions & 9 deletions handlers/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,21 @@ func buildSlotPageData(blockSlot int64, blockRoot []byte) (*models.SlotPageData,
blockData, err = services.GlobalBeaconService.GetSlotDetailsByBlockroot(blockRoot, false)
}

if blockData == nil && err == nil {
// check for orphaned block
if blockSlot > -1 {
dbBlocks := services.GlobalBeaconService.GetDbBlocksForSlots(uint64(blockSlot), 0, true)
if len(dbBlocks) > 0 {
blockRoot = dbBlocks[0].Root
if err == nil {
if blockData == nil {
// check for orphaned block
if blockSlot > -1 {
dbBlocks := services.GlobalBeaconService.GetDbBlocksForSlots(uint64(blockSlot), 0, true)
if len(dbBlocks) > 0 {
blockRoot = dbBlocks[0].Root
}
}
}
if blockRoot != nil {
blockData = services.GlobalBeaconService.GetOrphanedBlock(blockRoot)
if blockRoot != nil {
blockData = services.GlobalBeaconService.GetOrphanedBlock(blockRoot)
}
} else {
// check orphaned status
blockData.Orphaned = services.GlobalBeaconService.CheckBlockOrphanedStatus(blockData.Root)
}
}

Expand Down
12 changes: 12 additions & 0 deletions services/beaconservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,18 @@ func (bs *BeaconService) GetDbBlocksByParentRoot(parentRoot []byte) []*dbtypes.B
return resBlocks
}

func (bs *BeaconService) CheckBlockOrphanedStatus(blockRoot []byte) bool {
cachedBlock := bs.indexer.GetCachedBlock(blockRoot)
if cachedBlock != nil {
return !cachedBlock.IsCanonical(bs.indexer, nil)
}
dbRefs := db.GetBlockOrphanedRefs([][]byte{blockRoot})
if len(dbRefs) > 0 {
return true
}
return false
}

func (bs *BeaconService) GetValidatorActivity() (map[uint64]uint8, uint64) {
activityMap := map[uint64]uint8{}
epochLimit := uint64(3)
Expand Down
2 changes: 1 addition & 1 deletion templates/index/recentSlots.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h5 class="card-title d-flex justify-content-between align-items-center" style="
{{ else if eq .Status 1 }}
<span class="badge rounded-pill text-bg-success">Proposed</span>
{{ else if eq .Status 2 }}
<span class="badge rounded-pill text-bg-info">Missed (Orphaned)</span>
<span class="badge rounded-pill text-bg-info">Orphaned</span>
{{ else }}
<span class="badge rounded-pill text-bg-dark">Unknown</span>
{{ end }}
Expand Down

0 comments on commit 144a02c

Please sign in to comment.