Skip to content

Commit

Permalink
Do not recompute intersections on good jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Apr 25, 2024
1 parent af0cf93 commit ac4105e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1235,15 +1235,25 @@ knownIntersectionStateTop cfgEnv dynEnv intEnv =
HeaderStateHistory.rewind
(AF.castPoint $ AF.headPoint $ jTheirFragment ji)
(jTheirHeaderStateHistory ji)
intersection = case AF.intersect (jOurFragment ji) (jTheirFragment ji) of
Just (po, _, _, _) -> castPoint $ AF.headPoint po
Nothing -> error "offerJump: the jumpInfo should have a valid intersection"
rewoundHistory =
fromMaybe (error "offerJump: cannot rewind history") mRewoundHistory
historyNeedsRewinding =
(/= AF.headPoint (jTheirFragment ji)) $
castPoint $
either headerStatePoint headerStatePoint $
AF.head $
HeaderStateHistory.unHeaderStateHistory $
jTheirHeaderStateHistory ji
intersection
| historyNeedsRewinding = case AF.intersect (jOurFragment ji) (jTheirFragment ji) of
Just (po, _, _, _) -> castPoint $ AF.headPoint po
Nothing -> error "offerJump: the jumpInfo should have a valid intersection"
| otherwise = jMostRecentIntersection ji
in KnownIntersectionState
{ mostRecentIntersection = intersection
, ourFrag = jOurFragment ji
, theirFrag = jTheirFragment ji
, theirHeaderStateHistory =
fromMaybe (error "offerJump: cannot rewind history") mRewoundHistory
, theirHeaderStateHistory = rewoundHistory
, kBestBlockNo = max (fromWithOrigin 0 $ AF.headBlockNo $ jTheirFragment ji) (kBestBlockNo kis)
}

Expand Down Expand Up @@ -1477,7 +1487,8 @@ updateJumpInfoSTM ::
-> STM m ()
updateJumpInfoSTM jumping kis@KnownIntersectionState{ourFrag} =
Jumping.jgUpdateJumpInfo jumping JumpInfo
{ jOurFragment = ourFrag
{ jMostRecentIntersection = mostRecentIntersection kis
, jOurFragment = ourFrag
, jTheirFragment = theirFrag kis
, jTheirHeaderStateHistory = theirHeaderStateHistory kis
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ deriving anyclass instance

-- | The ChainSync state required for jumps
data JumpInfo blk = JumpInfo
{ jOurFragment :: !(AnchoredFragment (Header blk))
{ jMostRecentIntersection :: !(Point blk)
, jOurFragment :: !(AnchoredFragment (Header blk))
, jTheirFragment :: !(AnchoredFragment (Header blk))
, jTheirHeaderStateHistory :: !(HeaderStateHistory blk)
}
Expand Down

0 comments on commit ac4105e

Please sign in to comment.