Skip to content

Conversation

jfrain99
Copy link

@jfrain99 jfrain99 commented Aug 12, 2025

Allows for POST /compute call which calls dryrun in the genesis wasm cu.

To simulate a legacy net dryrun, POST compute without an assignment. This can be done using the as=execution key. Example call:
/<process-id>[email protected]/as=execution/compute<tags>/[email protected], where for example with Action: Info tags are action=info

@jfrain99
Copy link
Author

Relevant connect PR: permaweb/ao#1238

@jfrain99 jfrain99 changed the title feat: add dryrun codepath for post computes [WIP] feat: add dryrun codepath for post computes Aug 13, 2025
@jfrain99 jfrain99 force-pushed the feat/dryrun-genesis-wasm branch from 3f0630d to 27c500e Compare August 14, 2025 22:31
@jfrain99 jfrain99 changed the title [WIP] feat: add dryrun codepath for post computes feat: add dryrun codepath for post computes Aug 14, 2025
Copy link

@jyeshe jyeshe left a comment

Choose a reason for hiding this comment

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

From what I can get from the flow, the code looks great with 2 minor refactor opportunities and 1 error handling that can be added.

Comment on lines +129 to +133
RawProcessID = dev_process:process_id(Msg1, #{}, Opts),
case RawProcessID of
not_found -> hb_ao:get(<<"process-id">>, Msg2, Opts);
ProcID -> ProcID
end.
Copy link

Choose a reason for hiding this comment

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

This is about idioms but the maybe expression, which is enabled by default in OTP 27+, is very handy for handling a single case:

maybe not_found ?= dev_process:process_id(Msg1, #{}, Opts),
    hb_ao:get(<<"process-id">>, Msg2, Opts)
end.

Copy link

Choose a reason for hiding this comment

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

This will take a transition on erlang idiomatic expressions but the team can have multiple benefits while adopting it. Analysing for this case (and we can extrapolate to many other ones), it helps making clear right away somes points:

  • prevents giving two names for the same thing: RawProcessID and ProcID
  • that hb_ao:get does not use the output of dev_process:process_id
  • subsequent function calls will be made only if all previous conditions are met. This is especially helpful for multiple nested handling.
  • as a consequence of the previous point, engineers interested only the case when the process_id is found don't need to look at any other line of code.

Copy link

Choose a reason for hiding this comment

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

@twilson63 This might be out of scope for now, but it would be great if we could discuss adopting (or not) this idiom with the team and Sam at a later time, given the benefits mentioned above.

Choose a reason for hiding this comment

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

Yep, we use maybe in other places but I think we format the syntax differently - but maybe is something we have been using so if it fits here, that would be a good change, @jfrain99 I would look at other code examples of maybe to get the formatting correct.

Copy link
Author

Choose a reason for hiding this comment

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

I could not find any other cases of maybe being used in the codebase - since we are trying to get this across the line, I think now is not the best time to introduce it. It definitely seems like something that should be worked in in the future, though. Thanks!

Comment on lines +115 to +121
extract_json_res(Response, Opts) ->
case Response of
{ok, Res} ->
JSONRes = hb_ao:get(<<"body">>, Res, Opts),
?event({
delegated_compute_res_metadata,
{req, hb_maps:without([<<"body">>], Response, Opts)}
{req, hb_maps:without([<<"body">>], Res, Opts)}
Copy link

Choose a reason for hiding this comment

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

Sorry this is a nitpick Jack. I love the way you've refactored it, extracting the code into functions.
I would only keep the previous names/terminology (Res for Results and Response for the second element of the ok tuple).

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I am not sure I understand - which variable should be Res / Response? The second element of the ok tuple?

Copy link

Choose a reason for hiding this comment

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

Res (for Result) having the whole tuple and Response for the element of the tuple 🙏

<<"hash-chain">> => hb_util:id(HashChain),
<<"body">> => OnlyAttested
<<"body">> => OnlyAttested,
<<"type">> => <<"assignment">>
Copy link

Choose a reason for hiding this comment

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

Got it, nice tagging! What about moving <<"type">> to a maps:put inside the commit_assignment so that all commits (this and future ones) of this kind receive this type attribute?
Nvm, all these fields are here to define the assignment, to apply the logic above more fields would need to the moved.

@jyeshe
Copy link

jyeshe commented Aug 25, 2025

@jfrain99 would you mind adding to the description of the PR, the steps that I can follow to test it with a curl POST request? I see I should hit "/dry-run?process-id="but I am not sure about the body.

@twilson63
Copy link

@jfrain99 ran tests and all appear to be passing

@jfrain99 jfrain99 force-pushed the feat/dryrun-genesis-wasm branch from 5398394 to 11dfdae Compare August 26, 2025 17:13
@jfrain99 jfrain99 force-pushed the feat/dryrun-genesis-wasm branch from 11dfdae to 8a431cf Compare August 26, 2025 17:23
@samcamwilliams samcamwilliams merged commit 19c468a into edge Aug 27, 2025
@samcamwilliams samcamwilliams deleted the feat/dryrun-genesis-wasm branch August 27, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants