Skip to content

Commit

Permalink
Merge pull request #852 from iotaledger/fix/chain-engine-traversal
Browse files Browse the repository at this point in the history
Fix chain engine traversal
  • Loading branch information
muXxer authored Mar 20, 2024
2 parents e6f0f25 + 5bffdc9 commit c6b06db
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/protocol/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ func (c *Chain) CumulativeVerifiedWeightAt(slot iotago.SlotIndex) uint64 {
// LatestEngine returns the latest engine instance that was spawned by the chain itself or one of its ancestors.
func (c *Chain) LatestEngine() *engine.Engine {
currentChain, currentEngine := c, c.Engine.Get()
for ; currentEngine == nil; currentEngine = currentChain.Engine.Get() {
if currentChain = c.ParentChain.Get(); currentChain == nil {

// traverse the chain upwards until we find an engine
for currentEngine == nil {
if currentChain = currentChain.ParentChain.Get(); currentChain == nil {
// no parent chain and therefore no engine found
return nil
}

currentEngine = currentChain.Engine.Get()
}

return currentEngine
Expand Down

0 comments on commit c6b06db

Please sign in to comment.