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

runtime: Stabilise NEP264 #6564

Merged
merged 10 commits into from
Apr 15, 2022
Merged

runtime: Stabilise NEP264 #6564

merged 10 commits into from
Apr 15, 2022

Conversation

austinabell
Copy link
Contributor

@austinabell austinabell commented Apr 8, 2022

Issue: #6150

This stabilization comes with refactors based on suggestion #6150 (comment) where append_action_function_call and internal_promise_batch_action_function_call are removed. These were only used to be able to have consistent and non-duplicate functionality with and without this protocol feature flag, so this functionally changes nothing functionally about the existing functionality but reduces the amount of code.

@austinabell austinabell marked this pull request as ready for review April 11, 2022 17:41
@austinabell austinabell requested a review from a team as a code owner April 11, 2022 17:41
@austinabell austinabell requested review from mina86 and matklad April 11, 2022 17:41
@matklad
Copy link
Contributor

matklad commented Apr 11, 2022

So this basically look good to me! But, while working on it, I realized that there's a class of behaviors not currently covered by tests. Namely, when we create a bunch of weighted promises, and then exceed either of the two gas limits (for burnt or for total gas). I think it might be best if I add those cases, as there we'll get interraction with vm's trickly logic of gas limit processing.

To clarify, I do think that the logic we have here is correct though!

@austinabell
Copy link
Contributor Author

So this basically look good to me! But, while working on it, I realized that there's a class of behaviors not currently covered by tests. Namely, when we create a bunch of weighted promises, and then exceed either of the two gas limits (for burnt or for total gas). I think it might be best if I add those cases, as there we'll get interraction with vm's trickly logic of gas limit processing.

To clarify, I do think that the logic we have here is correct though!

Unless I'm misunderstanding what you're suggesting here, I don't see how that could be triggered. When the prepaid gas is consumed completely there would just be the error and the weight distribution would never happen? Do you just want to verify this is the case?

Feel free to push the tests to this branch if you'd like! Otherwise let me know what specifically you are trying to test for and I can push it along so this doesn't get blocked before the next release

@matklad
Copy link
Contributor

matklad commented Apr 11, 2022

When the prepaid gas is consumed completely there would just be the error and the weight distribution would never happen

I think it'll still happen -- even on exhausted gas, we still extract outcome out of VMLogic. And I think it might even be non-trivial -- if we exceeded max_burnt_gas, but not prepaied gas, we'd have some gas attached to the promises. Now, I don't think that this is going to be user visible behavior, but the code will get executed.

what specifically you are trying to test for and I can push it along so this doesn't get blocked before the next release

I am thinking about two tests, implementing via test-contract-rs:

One is:

function_call_weight(weight = 1)
gas(u64::MAX) // exceed max burn gas

Another is

function_call_weight(weight = 1)
function_call(gas=u64::MAX) // exceed prepaid gas

@austinabell
Copy link
Contributor Author

When the prepaid gas is consumed completely there would just be the error and the weight distribution would never happen

I think it'll still happen -- even on exhausted gas, we still extract outcome out of VMLogic. And I think it might even be non-trivial -- if we exceeded max_burnt_gas, but not prepaied gas, we'd have some gas attached to the promises. Now, I don't think that this is going to be user visible behavior, but the code will get executed.

what specifically you are trying to test for and I can push it along so this doesn't get blocked before the next release

I am thinking about two tests, implementing via test-contract-rs:

One is:

function_call_weight(weight = 1)
gas(u64::MAX) // exceed max burn gas

Another is

function_call_weight(weight = 1)
function_call(gas=u64::MAX) // exceed prepaid gas

Oh, I see. Maybe it would be worth considering adding a check to short circuit if unused_gas == 0? Seems like it might be worth it to avoid logic on failed transactions?

@matklad
Copy link
Contributor

matklad commented Apr 12, 2022

Oh, I see. Maybe it would be worth considering adding a check to short circuit if unused_gas == 0? Seems like it might be worth it to avoid logic on failed transactions?

I believe this check won't help with the first use case. We have two gas limits: the total gas attached to tx (which can be spend either on immediate wasm execution or atttached to promises) and a config limit on how much a single tx can burn immediatelly. If we hit the second limit, we might still have gas to burn

@mina86
Copy link
Contributor

mina86 commented Apr 14, 2022

I wouldn’t call it a chore. It’s a big feature and a protocol change.

This looks fine though I admit I don’t have deep understanding of what those functions are actually doing.

NayDuck: https://nayduck.near.org/#/run/2457

@mina86 mina86 changed the title chore!: NEP264 stabilization runtime: Stabilise NEP264 Apr 14, 2022
@mina86
Copy link
Contributor

mina86 commented Apr 14, 2022

Could you describe a bit in the PR description what’s the deal with append_action_function_call and internal_promise_batch_action_function_call being removed and all the corresponding changes? IIUC this PR is really doing two things: stabilising the NEP and then also switches some of the code to use that NEP. That’s fine but it would be nice if we had a more detailed description of the changes.

function_call_weight distributes gas at the end of execution. It might
be the case that we run out of either prepaid_gas or max_gas_burnt
limits before that! The two added tests check these two scenarios.

If we run out of `prepaid_gas`, we have nothing to distribute. If we run
out of `max_gas_burnt` though, we still might have some leftover gas to
distribute!

That's OK though: when execution fails for any reason, we don't create
receipts, we do note used_gas, but then we use burnt_gas when creating
refunds.
@matklad
Copy link
Contributor

matklad commented Apr 14, 2022

@austinabell in the last commit, I've added the tests I was talking about.

While doing that, I've noticed a subtle thing. I think one motivation for attaching lefrover gas to the last promise was to avoid emitting a refund receipt. However, it seems that with dynamic gas pricing we need to generate a refund anyway.

@austinabell
Copy link
Contributor Author

I wouldn’t call it a chore. It’s a big feature and a protocol change.

Yep, my thinking was just that the functionality wasn't added or changed here, but just removed the feature flag.

Could you describe a bit in the PR description what’s the deal with append_action_function_call and internal_promise_batch_action_function_call being removed and all the corresponding changes? IIUC this PR is really doing two things: stabilising the NEP and then also switches some of the code to use that NEP. That’s fine but it would be nice if we had a more detailed description of the changes.

Done

While doing that, I've noticed a subtle thing. I think one motivation for attaching lefrover gas to the last promise was to avoid emitting a refund receipt. However, it seems that with dynamic gas pricing we need to generate a refund anyway.

Yes, that was the motivation. I wasn't aware of this, what would be your suggestion here now that this is the case? Should gas just be refunded or keep the logic and gas splitting of the remainder? Who else should we get input on for this?

@matklad
Copy link
Contributor

matklad commented Apr 14, 2022

what would be your suggestion here now that this is the case?

Nothing, I think it's ok! Just something I personally haven't notice before.

@austinabell could you resolve conflicts here?

@austinabell
Copy link
Contributor Author

@austinabell could you resolve conflicts here?

Yeah, it's a bit strange that the tests you've added cause unrelated tests to fail. Looking into that now

@austinabell
Copy link
Contributor Author

austinabell commented Apr 14, 2022

So, not a perfect e2e testing solution (I will work to do a cleaner and easily reproducible/automated setup soon) but to verify all APIs are connected correctly I tested it against all near-sdk-rs examples using this new host function. near/near-sdk-rs#742 (commit 94cd0d36f6074b48a5fbf5a1492f5838fc847018) was used and to repro:

# From within nearcore directory
make sandbox-release

# From within near-sdk-rs directory
NEAR_SANDBOX_BIN_PATH=<absolute path to nearcore>/n
earcore/sandbox/release/neard ./examples/test_all.sh

Workspaces does not have support to use a compiled (not prebuilt binary) version of sandbox, which seems somewhat necessary to be able to add this into test suite of nearcore. Also unclear if workspaces execution is optimized enough to add in. cc @ChaoticTempest

Would be nice if there was a way to compile sandbox and run it directly from workspaces, but seems unlikely neard crate (or slight subset) would be released anytime soon.

@matklad
Copy link
Contributor

matklad commented Apr 15, 2022

This looks good to me now!

@matklad
Copy link
Contributor

matklad commented Apr 15, 2022

As this is a feature stabilization, I'd ask someone from the reviewers to give a second approval here (we discussed informally with bowenwang1996 that, as feature stabilizations are a big deal, we want a higher bar for reviews here). @mina86 could you give a second look here?

@near-bulldozer near-bulldozer bot merged commit 30f951f into master Apr 15, 2022
@near-bulldozer near-bulldozer bot deleted the austin/nep264stab branch April 15, 2022 14:45
near-bulldozer bot pushed a commit that referenced this pull request Apr 15, 2022
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