-
Notifications
You must be signed in to change notification settings - Fork 64
feat: add dryrun codepath for post computes #423
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
Conversation
Relevant connect PR: permaweb/ao#1238 |
3f0630d
to
27c500e
Compare
There was a problem hiding this 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.
RawProcessID = dev_process:process_id(Msg1, #{}, Opts), | ||
case RawProcessID of | ||
not_found -> hb_ao:get(<<"process-id">>, Msg2, Opts); | ||
ProcID -> ProcID | ||
end. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
andProcID
- that
hb_ao:get
does not use the output ofdev_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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
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)} |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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">> |
There was a problem hiding this comment.
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.
@jfrain99 would you mind adding to the description of the PR, the steps that I can follow to test it with a |
@jfrain99 ran tests and all appear to be passing |
5398394
to
11dfdae
Compare
Rather than determining whether a compute request is a genesis_wasm result/dryrun based on the method, now test if their is an assignment
This reverts commit ba24085.
11dfdae
to
8a431cf
Compare
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 areaction=info