Skip to content

Commit

Permalink
optimize in memory store
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Dec 9, 2023
1 parent f5db08d commit fd954fc
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions engine/execution/storehouse/in_memory_register_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,18 @@ func (s *InMemoryRegisterStore) IsBlockExecuted(height uint64, blockID flow.Iden
defer s.RUnlock()

// finalized and executed blocks are pruned
if height <= s.prunedHeight {
// so if the height is below pruned height, in memory register store is not sure if
// it's executed or not
if height < s.prunedHeight {
return false, fmt.Errorf("below pruned height")
}

// if the height is the pruned height, then it's executed only if the blockID is the prunedID
// since the pruned block must be finalized and executed.
if height == s.prunedHeight {
return blockID == s.prunedID, nil
}

_, ok := s.registersByBlockID[blockID]
return ok, nil
}
Expand All @@ -260,9 +268,18 @@ func (s *InMemoryRegisterStore) findFinalizedFork(height uint64, blockID flow.Id
s.RLock()
defer s.RUnlock()

if height <= s.prunedHeight {
if height < s.prunedHeight {
return nil, fmt.Errorf("cannot find finalized fork at height %d, it is pruned (prunedHeight: %v)", height, s.prunedHeight)
}

if height == s.prunedHeight {
if blockID != s.prunedID {
return nil, fmt.Errorf("cannot find finalized fork at height %d, it is pruned (prunedHeight: %v, prunedID: %v)", height, s.prunedHeight, s.prunedID)
}

return nil, nil
}

prunedHeight := height
block := blockID

Expand Down

0 comments on commit fd954fc

Please sign in to comment.