Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVM: Improve error handling and execution time #3612

Merged
merged 16 commits into from
Mar 15, 2022

Conversation

jannotti
Copy link
Contributor

@jannotti jannotti commented Feb 11, 2022

This reworks the opcode function interface to return errors directly instead of setting cx.err which was error-prone.

It also makes a couple small optimizations.

@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2022

Codecov Report

Merging #3612 (6a025ea) into master (5978c3d) will increase coverage by 0.08%.
The diff coverage is 55.55%.

@@            Coverage Diff             @@
##           master    #3612      +/-   ##
==========================================
+ Coverage   49.76%   49.84%   +0.08%     
==========================================
  Files         392      392              
  Lines       68766    68670      -96     
==========================================
+ Hits        34219    34227       +8     
+ Misses      30785    30690      -95     
+ Partials     3762     3753       -9     
Impacted Files Coverage Δ
data/transactions/logic/eval.go 89.68% <ø> (+3.35%) ⬆️
data/transactions/logic/fields.go 49.23% <ø> (+1.46%) ⬆️
data/transactions/logic/opcodes.go 100.00% <ø> (ø)
data/transactions/logic/debugger.go 56.70% <42.85%> (ø)
data/transactions/logic/assembler.go 79.90% <100.00%> (-0.03%) ⬇️
cmd/tealdbg/debugger.go 71.42% <0.00%> (-0.99%) ⬇️
data/transactions/verify/txn.go 44.15% <0.00%> (-0.87%) ⬇️
catchup/service.go 69.38% <0.00%> (ø)
network/wsNetwork.go 62.99% <0.00%> (ø)
network/wsPeer.go 68.88% <0.00%> (+0.27%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5978c3d...6a025ea. Read the comment docs.

Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, couple suggestions/questions

@@ -656,7 +641,7 @@ func eval(program []byte, cx *EvalContext) (pass bool, err error) {
defer func() {
// Ensure we update the debugger before exiting
if cx.Debugger != nil {
errDbg := cx.Debugger.Complete(cx.refreshDebugState())
errDbg := cx.Debugger.Complete(cx.refreshDebugState(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is the only where refreshDebugState receives non-nil err, on other two cases below they are would not be even called if err != nil. So maybe

Suggested change
errDbg := cx.Debugger.Complete(cx.refreshDebugState(err))
ds := cx.refreshDebugState()
ds.Error = err
errDbg := cx.Debugger.Complete(ds)

last := len(cx.stack) - 1 // value
prev := last - 1 // state key
pprev := prev - 1 // account

sv := cx.stack[last]
key := string(cx.stack[prev].Bytes)

if cx.Ledger == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is a repetitive check... is it prereq now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, EvalContract does the check when first entering stateful evaluation, so it seems pointless to keep checking it in the stateful ops.

@jannotti jannotti changed the title AVM error handling AVM: Improve error handling and execution time Mar 9, 2022
Also some benchmarks that show relative costs for the CPU part of
processing transactions
cx.Ledger !=nil is checked in EvalContract().  There's no reason to
check it again in stateful teal ops.
Tests more opcodes, including branches and others that have not return
values.  Automates handling of more opcodes by understanding immediate
arguments.  Fixes the ordering of return value testing.
jannotti and others added 2 commits March 15, 2022 11:49
…refactor

Refactor TestReturnTypes to generate a test case for each opcode
Copy link
Contributor

@michaeldiamant michaeldiamant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jannotti I'm leaving approval with the following notes:

  • I most closely reviewed renames and changes to data/transactions/logic/evalStateful_test.go.
  • I scanned other changes, but didn't scrutinize all of them. Since I'm new to the codebase, I leave it at your discretion if you believe a 2nd approval is warranted prior to merging.

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, I did another scan of eval.go and didn't find anything problematic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants