Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 25, 2024
1 parent ac5ba22 commit dda9d01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions indexer/beacon/forkcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (cache *forkCache) addFork(fork *Fork) {
cache.forkMap[fork.forkId] = fork
}

// getForkByLeaf retrieves a fork from the cache by its leaf root.
func (cache *forkCache) getForkByLeaf(leafRoot phase0.Root) *Fork {
cache.cacheMutex.Lock()
defer cache.cacheMutex.Unlock()
Expand All @@ -90,6 +91,7 @@ func (cache *forkCache) getForkByLeaf(leafRoot phase0.Root) *Fork {
return nil
}

// getForkByBase retrieves forks from the cache by their base root.
func (cache *forkCache) getForkByBase(baseRoot phase0.Root) []*Fork {
cache.cacheMutex.Lock()
defer cache.cacheMutex.Unlock()
Expand All @@ -112,6 +114,7 @@ func (cache *forkCache) removeFork(forkId ForkKey) {
delete(cache.forkMap, forkId)
}

// getParentForkIds returns the parent fork ids of the given fork.
func (cache *forkCache) getParentForkIds(forkId ForkKey) []ForkKey {
parentForks := []ForkKey{forkId}

Expand Down
7 changes: 4 additions & 3 deletions indexer/beacon/forkdetection.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (cache *forkCache) processBlock(block *Block) error {
parentIsProcessed := false
parentIsFinalized := false

parentBlock := cache.indexer.blockCache.getBlockByRoot(*parentRoot)
if parentBlock == nil {
if parentBlock := cache.indexer.blockCache.getBlockByRoot(*parentRoot); parentBlock == nil {
// parent block might already be finalized, check if it's in the database
blockHead := db.GetBlockHeadByRoot((*parentRoot)[:])
if blockHead != nil {
parentForkId = ForkKey(blockHead.ForkId)
Expand Down Expand Up @@ -102,9 +102,10 @@ func (cache *forkCache) processBlock(block *Block) error {
}

if !parentIsFinalized && len(otherChildren) == 1 {
// parent (a) is not finalized and our new detected fork the first fork based on this parent (c)
// parent (a) is not finalized and our new detected fork is the first fork based on this parent (c)
// we need to create another fork for the other chain that starts from our fork base (b1, b2, )
// and update the blocks building on top of it
// we don't need to care about this if there are other forks already based on the parent
// b2
// |
// b1 c
Expand Down

0 comments on commit dda9d01

Please sign in to comment.