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

feat: runtime: Add send_generalized #1126

Merged
merged 3 commits into from
Jan 30, 2023
Merged

feat: runtime: Add send_generalized #1126

merged 3 commits into from
Jan 30, 2023

Conversation

arajasek
Copy link
Contributor

@arajasek arajasek commented Jan 29, 2023

Extracted from next. Needs:

This PR adds a new send_generalized method to the Runtime. The key differences between send and send_generalized are that:

  • send_generalized can take an optional gas_limit that restricts the total gas usage of the send
  • send_generalized can carry optional SendFlags -- currently the only SendFlag the FVM supports is READ_ONLY
  • send_generalized segregates failures arising from the syscall prior to target invocation (returned as an ErrorNumber) and those arising from the invocation itself (returned as an ExitCode).

This PR is a pre-factor necessary for landing the changes involved in the FEVM FIPs -- it introduces new functionality, but doesn't start to use it anywhere.

@arajasek arajasek force-pushed the asr/send-generalized branch from 70bac1a to 0ea75b1 Compare January 29, 2023 18:12
runtime/src/runtime/mod.rs Outdated Show resolved Hide resolved
@arajasek arajasek requested a review from anorth January 29, 2023 18:18
@arajasek arajasek force-pushed the asr/send-generalized branch from 0ea75b1 to b711fb6 Compare January 29, 2023 19:46
@codecov-commenter
Copy link

codecov-commenter commented Jan 29, 2023

Codecov Report

Merging #1126 (a27da93) into master (46945f8) will decrease coverage by 0.03%.
The diff coverage is 88.63%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1126      +/-   ##
==========================================
- Coverage   89.07%   89.04%   -0.03%     
==========================================
  Files          94       95       +1     
  Lines       19718    19805      +87     
==========================================
+ Hits        17563    17635      +72     
- Misses       2155     2170      +15     
Impacted Files Coverage Δ
runtime/src/builtin/shared.rs 77.27% <62.50%> (-11.92%) ⬇️
runtime/src/test_utils.rs 82.22% <78.57%> (+0.38%) ⬆️
actors/miner/src/lib.rs 82.93% <79.41%> (-0.03%) ⬇️
test_vm/src/lib.rs 87.06% <93.75%> (+0.53%) ⬆️
actors/power/src/lib.rs 83.58% <96.15%> (ø)
actors/market/src/lib.rs 91.04% <98.03%> (+0.12%) ⬆️
actors/cron/src/lib.rs 95.45% <100.00%> (+7.21%) ⬆️
actors/datacap/src/lib.rs 79.29% <100.00%> (ø)
actors/init/src/lib.rs 89.28% <100.00%> (ø)
actors/multisig/src/lib.rs 94.84% <100.00%> (+0.06%) ⬆️
... and 11 more

Copy link
Member

@anorth anorth left a comment

Choose a reason for hiding this comment

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

Thanks. I'll address some of the q's you asked in Slack here too. Basically I agree with your suggestions.

I think the Runtime interface should have just a single send method, with the more general signature, and we should refactor the existing call sites.

There are two essential helper things going on:

  • default gas limit and flags
  • error number interpretation

A question is whether to combine them into one wrapper, or split in the input/output. The default params would be fine in a default impl Runtime::send_simple() method. But there's too much code in the error-number interpretation to sit nicely in a default implementation there.

So if we can separate them and then have a helper in runtime/builtin/shared or runtime/util that does the error number interpretation, the refactor will be to change most call sites to send_simple, and then adapt the result/response.

runtime/src/test_utils.rs Show resolved Hide resolved
@@ -571,6 +578,13 @@ pub struct InvocationCtx<'invocation, 'bs> {
caller_validated: bool,
policy: &'invocation Policy,
subinvocations: RefCell<Vec<InvocationTrace>>,
actor_exit: RefCell<Option<ActorExit>>,
Copy link
Member

Choose a reason for hiding this comment

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

Please document this - it's not obvious what it is, when it's set, why it's needed, etc. It should probably move above the subinvocations too.

|panic| {
if self.actor_exit.borrow().is_some() {
let exit = self.actor_exit.take().unwrap();
if exit.code == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't happen in a panic, should it? It seems wrong, and I'd rather the test crashed than let this throuhg.

@@ -660,6 +675,27 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
self.resolve_target(&self.msg.to).unwrap().1
}

fn invoke_actor(&mut self) -> Result<Option<IpldBlock>, ActorError> {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| self.invoke())).unwrap_or_else(
Copy link
Member

Choose a reason for hiding this comment

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

What's this for? I think we view a panic as always a bug in actors, so we want tests to fail.

test_vm/src/lib.rs Show resolved Hide resolved
runtime/src/runtime/mod.rs Outdated Show resolved Hide resolved
runtime/src/runtime/fvm.rs Show resolved Hide resolved
Base automatically changed from asr/delegated-addresses to master January 30, 2023 02:01
@arajasek arajasek force-pushed the asr/send-generalized branch from b711fb6 to 6e294f8 Compare January 30, 2023 18:14
@arajasek arajasek force-pushed the asr/send-generalized branch from 076e7b6 to a27da93 Compare January 30, 2023 18:31
@arajasek
Copy link
Contributor Author

@anorth I've performed the refactor as discussed. I think it's relatively clean, though I'd welcome a better name than extract_send_result.

I've also dropped the changes around actor_exit / invoke_actor. They don't belong in this PR -- I'll revisit their necessity and open a (hopefully cleaner) future PR.

Copy link
Member

@anorth anorth left a comment

Choose a reason for hiding this comment

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

Thanks. This is good and I'd be happy for it to land as-is. I think there are opportunities to improve the aesthetics, depending on your enthusiasm.

It would be nice to chain here, so we could make calls like rt.send_simple().as_result(...)? or similar. We can do this if you make a new struct SendResult(Result<fvm_shared::Response, fvm_shared::error::ErrorNumber>) to wrap the FVM type, to which you can then attach a method equivalent to extract_send_result.

It might be worth adding another helper (or method on local result type) that wraps up the deserialize_block(extract_send_result(..)) sequence that appears a few times.

@arajasek
Copy link
Contributor Author

Thanks. I'm going to merge this in the interest of time as-is.

@arajasek arajasek merged commit 4f450fd into master Jan 30, 2023
@arajasek arajasek deleted the asr/send-generalized branch January 30, 2023 21:46
shamb0 pushed a commit to shamb0/builtin-actors that referenced this pull request Jan 31, 2023
* feat: runtime: Add send_generalized

* Refactor: Runtime: Add  send_simple and extract_send_result methods

* Address review
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.

3 participants