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

Algod: Simulate endpoint scratch-change exposure #5563

Merged
merged 25 commits into from
Jul 20, 2023

Conversation

ahangsu
Copy link
Contributor

@ahangsu ahangsu commented Jul 12, 2023

Summary

This PR implements #5013 : we can now request simulation endpoint for writes into scratch slots, as part of the execution trace response.

Test Plan

  • one simulation eval test
  • one restClient test

@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #5563 (72d2f3b) into master (aeef625) will increase coverage by 0.01%.
The diff coverage is 62.85%.

@@            Coverage Diff             @@
##           master    #5563      +/-   ##
==========================================
+ Coverage   55.80%   55.82%   +0.01%     
==========================================
  Files         446      446              
  Lines       63417    63461      +44     
==========================================
+ Hits        35389    35426      +37     
- Misses      25663    25665       +2     
- Partials     2365     2370       +5     
Files Changed Coverage Δ
daemon/algod/api/server/v2/utils.go 8.69% <0.00%> (-0.47%) ⬇️
data/transactions/logic/opcodes.go 68.30% <ø> (+0.44%) ⬆️
data/transactions/logic/eval.go 92.27% <50.00%> (+0.07%) ⬆️
ledger/simulation/trace.go 82.75% <58.33%> (-7.44%) ⬇️
ledger/simulation/tracer.go 94.35% <93.75%> (-0.26%) ⬇️
data/transactions/logic/debugger.go 69.86% <100.00%> (ø)

... and 7 files with indirect coverage changes

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

@ahangsu ahangsu force-pushed the simulate-scratch-change branch from d59d8a2 to 1217aed Compare July 13, 2023 13:53
@ahangsu ahangsu force-pushed the simulate-scratch-change branch from d3d5399 to 3f9650a Compare July 13, 2023 14:19
@ahangsu ahangsu marked this pull request as ready for review July 13, 2023 16:10
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

I have some reservations about naming, mostly looking for simpler/shorter names, and to make sure we are as consistent as possible.

@ahangsu ahangsu requested a review from jannotti July 13, 2023 18:01
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.

No major complaints, just some comments

// and if so, it returns scratch slot id, previous value, new value to be written;
// otherwise, it indicates the current opcode is not a scratch slot chagne.
func (cx *EvalContext) CurrentScratchChange() (scratchSlot uint64, newValue basics.TealValue, isScratchChange bool) {
currentOpcodeName := opsByOpcode[cx.version][cx.program[cx.pc]].Name
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it does make sense to make these operations easier. Ideally this code would be placed in the simulation package.

Passing in the OpSpec to Before/AfterOpcode would definitely help. I can also imagine having an EvalContext.GetOpSpec(pc int) function as an alternative. Right now I have no preference between the two.

You're right in that we'd also need to expose EvalContext.program, since this code needs to figure out immediate args as well.

@ahangsu ahangsu force-pushed the simulate-scratch-change branch from 9adc169 to 697684c Compare July 18, 2023 23:19
@ahangsu ahangsu requested a review from jasonpaulos July 18, 2023 23:34
@ahangsu ahangsu force-pushed the simulate-scratch-change branch from 1130aff to fe63446 Compare July 19, 2023 04:44
if len(scratchChanges) == 0 {
return nil
}
modelSC := make([]model.ScratchChange, len(scratchChanges))
Copy link
Contributor

Choose a reason for hiding this comment

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

its so weird we have to write these

// and if so, it returns scratch slot id, previous value, new value to be written;
// otherwise, it indicates the current opcode is not a scratch slot chagne.
func (cx *EvalContext) CurrentScratchChange() (scratchSlot uint64, newValue basics.TealValue, isScratchChange bool) {
currentOpcodeName := opsByOpcode[cx.version][cx.program[cx.pc]].Name
Copy link
Contributor

Choose a reason for hiding this comment

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

how about Before/After opcode getting the OpSpec and the OpDetail extended to include a SlotsModified logic function which returns nothing except for store/stores, where it runs this logic.

bbroder-algo
bbroder-algo previously approved these changes Jul 19, 2023
jasonpaulos
jasonpaulos previously approved these changes Jul 19, 2023
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.

Feel free to make a change described in this thread if you want to, but I view it more as a nit-level issue: #5563 (comment)

@ahangsu ahangsu dismissed stale reviews from jasonpaulos and bbroder-algo via aecfb8a July 19, 2023 21:27
@ahangsu ahangsu force-pushed the simulate-scratch-change branch 2 times, most recently from eee45a4 to 0d1276b Compare July 19, 2023 21:55
@ahangsu ahangsu force-pushed the simulate-scratch-change branch from 0d1276b to ec29772 Compare July 19, 2023 22:08
@ahangsu ahangsu force-pushed the simulate-scratch-change branch from ec29772 to 72d2f3b Compare July 19, 2023 22:11
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.

Looks good!

@ahangsu ahangsu requested a review from bbroder-algo July 20, 2023 15:47
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.

4 participants