Skip to content

Commit 3b179b2

Browse files
committed
Add a new handler for Booster Branching in Proxy.hs
1 parent 13b4b9e commit 3b179b2

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

booster/tools/booster/Proxy.hs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,72 @@ respondEither cfg@ProxyConfig{boosterState} booster kore req = case req of
351351
<$> accumulatedLogs
352352
)
353353
r{ExecuteRequest.state = execStateToKoreJson simplifiedBoosterState}
354-
-- if we stop for a reason in fallbackReasons (default [Aborted, Stuck],
354+
-- TODO this is an experimental code path. It needs to be guarded with an CLI option before merging
355+
-- if we stop because of branching, simplify the next states to prune them and optionally
356+
-- execute a fallback rewrite step from the pre-state in Kore con confirm the branch
357+
| boosterResult.reason == Branching -> do
358+
Booster.Log.withContext CtxProxy $
359+
Booster.Log.logMessage $
360+
"Booster " <> displayExecuteResultVerbose boosterResult
361+
prunedBoosterResult <- simplifyExecResult logSettings r._module def boosterResult
362+
case prunedBoosterResult of
363+
Left (_prunedToOneNext, _logs) -> do
364+
Booster.Log.withContext CtxProxy $
365+
Booster.Log.logMessage $
366+
"After simplification: Booster "
367+
<> displayExecuteResultVerbose boosterResult{nextStates = take 1 <$> boosterResult.nextStates}
368+
Right stillBranching ->
369+
Booster.Log.withContext CtxProxy $
370+
Booster.Log.logMessage $
371+
"After simplification: Booster " <> displayExecuteResultVerbose stillBranching
372+
373+
-- attempt to do one step in the old backend
374+
Booster.Log.withContext CtxProxy $
375+
Booster.Log.logMessage ("Executing fall-back request" :: Text)
376+
(koreResult, _kTime) <-
377+
Stats.timed $
378+
kore
379+
( Execute
380+
r
381+
{ state = execStateToKoreJson boosterResult.state
382+
, maxDepth = Just $ Depth 1
383+
, assumeStateDefined = Just True
384+
}
385+
)
386+
case koreResult of
387+
Right (Execute result) ->
388+
Booster.Log.withContext CtxProxy $
389+
Booster.Log.logMessage $
390+
"Kore " <> displayExecuteResultVerbose result
391+
_err ->
392+
Booster.Log.withContext CtxProxy $
393+
Booster.Log.withContext CtxWarn $
394+
Booster.Log.logMessage ("Kore returned error" :: Text)
395+
-- continue with the pruned Booster's result
396+
case prunedBoosterResult of
397+
Left (nextState, newLogs) -> do
398+
let prunedBoosterBranchStep
399+
| boosterResult.reason == Branching = 1
400+
| otherwise = 0
401+
executionLoop
402+
logSettings
403+
def
404+
( currentDepth + boosterResult.depth + prunedBoosterBranchStep
405+
, time + bTime
406+
, koreTime
407+
, postProcessLogs <$> combineLogs (rpcLogs : boosterResult.logs : newLogs)
408+
)
409+
r{ExecuteRequest.state = nextState}
410+
Right result -> do
411+
logStats ExecuteM (time + bTime, koreTime)
412+
pure . Right $
413+
Execute
414+
result
415+
{ depth = currentDepth + boosterResult.depth
416+
, logs = postProcessLogs <$> combineLogs [rpcLogs, result.logs]
417+
}
418+
419+
-- if we stop for a reason in fallbackReasons (default [Aborted, Stuck]),
355420
-- revert to the old backend to re-confirm and possibly proceed
356421
| boosterResult.reason `elem` cfg.fallbackReasons -> do
357422
Booster.Log.withContext CtxProxy $

0 commit comments

Comments
 (0)