go-algorand icon indicating copy to clipboard operation
go-algorand copied to clipboard

Algod: Extend debugger hooks interface

Open jdtzmn opened this issue 2 years ago • 1 comments

Summary

This PR upgrades the existing logic.DebuggerHook interface to be more powerful & lightweight. To be specific:

  • New hooks are introduced for before/after transactions, before/after inner transaction groups, and after TEAL opcodes.
  • The TEAL evaluator will carry forward the debugger into any inner transaction evaluations.
  • The EvalContext.refreshDebugState function which used to be called before every TEAL op has been removed. This function copied and base64 encoded the entire stack and scratch space every time it was invoked, which is potentially expensive and not needed for the eventual simulation trace.

To preserve the behavior of existing debugger usage (e.g. tealdbg and the dryrun endpoint), a logic.LegacyDebuggerHook interface has been created. The new legacyDebuggerAdaptor struct adheres to the logic.DebuggerHook interface and replicates its old behavior for logic.LegacyDebuggerHook implementors.

What's Next

By itself this PR doesn't activate any new behavior. Instead, it defines the debugger hooks that will be necessary for the following:

  • Near term goal: return ApplyData information from simulated transactions
    • It's not necessary to use a debugger to access this info if the transactions succeed, however if a transaction fails, the block evaluator will not return the partially-completed ApplyData. To solve this without modifying the block evaluator, we can use a debugger to save a copy of the ApplyData after each operation. That's what the follow-up PR #4439 does.
  • Longer term goal: enable simulation trace collection

Test Plan

  • [x] The old debugger tests still pass, now using MakeLegacyDebuggerAdaptor
  • [x] Test BlockEvaluator.TransactionGroupWithDebugger calls debug hooks correctly
  • [x] Test verify.TxnGroupWithDebugger calls debug hooks correctly

jdtzmn avatar Aug 19 '22 23:08 jdtzmn

Codecov Report

Merging #4438 (b4e0999) into master (a1eaafb) will increase coverage by 0.07%. The diff coverage is 79.00%.

@@            Coverage Diff             @@
##           master    #4438      +/-   ##
==========================================
+ Coverage   53.48%   53.56%   +0.07%     
==========================================
  Files         429      430       +1     
  Lines       54041    54089      +48     
==========================================
+ Hits        28905    28971      +66     
+ Misses      22890    22873      -17     
+ Partials     2246     2245       -1     
Impacted Files Coverage Δ
data/transactions/logic/fields.go 75.12% <0.00%> (ø)
data/transactions/logic/opcodes.go 84.56% <ø> (ø)
cmd/tealdbg/debugger.go 72.44% <33.33%> (-1.06%) :arrow_down:
data/transactions/logic/tracer.go 37.50% <37.50%> (ø)
data/transactions/logic/debugger.go 67.18% <65.38%> (+5.71%) :arrow_up:
data/transactions/verify/txn.go 70.46% <88.88%> (+0.21%) :arrow_up:
data/transactions/logic/eval.go 90.46% <96.15%> (+0.29%) :arrow_up:
cmd/tealdbg/local.go 73.61% <100.00%> (ø)
cmd/tealdbg/remote.go 83.33% <100.00%> (+6.41%) :arrow_up:
daemon/algod/api/server/v2/dryrun.go 71.16% <100.00%> (-0.18%) :arrow_down:
... and 13 more

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Aug 25 '22 00:08 codecov[bot]