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: start lifting contract preparation up through tx runtime layers #11810

Merged
merged 16 commits into from
Jul 23, 2024

Conversation

nagisa
Copy link
Collaborator

@nagisa nagisa commented Jul 18, 2024

Best reviewed commit-by-commit.

This ultimately lifts the contract preparation up through a several function call layers in the transaction runtime up to the layer where all the currently necessary data are available.

This PR also establishes in broad strokes where the pipelining decisions will be made (ApplyProcessingReceiptState) and makes some minor changes to the type to have it contain local receipts (in addition to the previously contained delayed receipts etc) in a queue of sorts which would allow the pipelining code to look-ahead of the ongoing processing work and queue-up preparation of the upcoming contracts there.

This work so far is intended to have no functional changes.

Part of #11319

nagisa added 7 commits July 9, 2024 15:40
With this all receipts are accounted for within this structure.

Next up will be moving the iteration over receipts to happen internally
within this structure, which would then allow us to also peek, etc.
This now allows introducing some hooks for pipelined preparation into
the receipt execution loop.
It appears that having the contract code access bundled into Externals
wasn't particularly helping with lifting the contract preparation up. As
a demo I have lifted the preparation to happen before the RuntimeExt is
constructed...
@nagisa nagisa requested a review from a team as a code owner July 18, 2024 12:21
@nagisa nagisa requested a review from wacban July 18, 2024 12:21
@wacban
Copy link
Contributor

wacban commented Jul 18, 2024

@nagisa Hey, sorry, I won't have time to review this PR today, I'm going on PTO tomorrow and I'll be gone for a week. Can you find another reviewer or ping me again in a week?

@nagisa
Copy link
Collaborator Author

nagisa commented Jul 18, 2024

I'll find somebody else, enjoy your time off!

@nagisa nagisa requested a review from Ekleog-NEAR July 18, 2024 14:06
@frol
Copy link
Collaborator

frol commented Jul 19, 2024

@nagisa Sorry for jumping in, I'd like to invite you to participate in the Race of Sloths. Just mention @race-of-sloths user in your github comment or PR description to join!

See how the flow works here: #11778

@nagisa
Copy link
Collaborator Author

nagisa commented Jul 19, 2024

@race-of-sloths

@race-of-sloths
Copy link

race-of-sloths commented Jul 19, 2024

@nagisa Thank you for your contribution! Your pull request is now a part of the Race of Sloths!
New Sloth joined the Race! Welcome!

Shows profile picture for the author of the PR

Current status: executed

@nagisa check out your results on the Race of Sloths Leaderboard! and in the profile

What is the Race of Sloths

Race of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow

For contributors:

  • Tag @race-of-sloths inside your pull requests
  • Wait for the maintainer to review and score your pull request
  • Check out your position in the Leaderboard
  • Keep weekly and monthly streaks to reach higher positions
  • Boast your contributions with a dynamic picture of your Profile

For maintainers:

  • Score pull requests that participate in the Race of Sloths
  • Engage contributors with fair scoring and fast responses so they keep their streaks
  • Promote the Race to the point where the Race starts promoting you
  • Grow the community of your contributors

Feel free to check our website for additional details!

Bot commands
  • For contributors
    • Include a PR: @race-of-sloths include to enter the Race with your PR
  • For maintainers:
    • Assign points: @race-of-sloths score [1/2/3/5/8/13] to award points based on your assessment.
    • Reject this PR: @race-of-sloths exclude to send this PR back to the drawing board.
    • Exclude repo: @race-of-sloths pause to stop bot activity in this repo until @race-of-sloths unpause command is called

Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 94.42897% with 20 lines in your changes missing coverage. Please review.

Project coverage is 71.80%. Comparing base (41f6554) to head (79170bc).
Report is 61 commits behind head on master.

Files Patch % Lines
runtime/near-vm-runner/src/wasmer_runner.rs 77.41% 2 Missing and 5 partials ⚠️
...ntime/runtime-params-estimator/src/gas_metering.rs 55.55% 4 Missing ⚠️
runtime/near-vm-runner/src/wasmer2_runner.rs 90.00% 2 Missing and 1 partial ⚠️
runtime/near-vm-runner/src/wasmtime_runner.rs 95.83% 2 Missing and 1 partial ⚠️
...time/runtime-params-estimator/src/function_call.rs 60.00% 2 Missing ⚠️
runtime/near-vm-runner/fuzz/src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11810      +/-   ##
==========================================
+ Coverage   71.78%   71.80%   +0.02%     
==========================================
  Files         792      796       +4     
  Lines      162617   163325     +708     
  Branches   162617   163325     +708     
==========================================
+ Hits       116729   117279     +550     
- Misses      40844    40998     +154     
- Partials     5044     5048       +4     
Flag Coverage Δ
backward-compatibility 0.23% <0.00%> (+<0.01%) ⬆️
db-migration 0.23% <0.00%> (+<0.01%) ⬆️
genesis-check 1.35% <0.00%> (-0.01%) ⬇️
integration-tests 37.80% <57.66%> (-0.11%) ⬇️
linux 71.54% <94.42%> (+0.23%) ⬆️
linux-nightly 71.39% <93.59%> (+0.03%) ⬆️
macos 54.67% <58.40%> (+0.74%) ⬆️
pytests 1.62% <0.00%> (+0.04%) ⬆️
sanity-checks 1.42% <0.00%> (+0.04%) ⬆️
unittests 66.26% <87.18%> (+0.05%) ⬆️
upgradability 0.28% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

nagisa added 4 commits July 19, 2024 16:52
This avoids a problem where in order to prepare a contract the NEAR
balances of an account need to be known (in order to construct a
`VMOutcome`) but also where the balance of an account might change by
the time the VMOutcome is materialized to the caller as a result of them
calling `run`.
`method` has been very recently moved into `VMContext` with the thought
that `method` is closely related to the function call arguments which
were already inside `VMContext`. However with `prepare` having been
modified sufficiently to not rely on `VMContext`, `method` has again
moved to be passed through a function argument. Keeping another instance
of `method` inside `VMContext` would potentially allow for value
confusion, as running a different method than what has been prepared is
invalid.
@nagisa nagisa force-pushed the moves-contract-preparation branch from 8bb65dd to e6213f1 Compare July 22, 2024 11:10
@nagisa nagisa force-pushed the moves-contract-preparation branch from e6213f1 to 9b06c74 Compare July 22, 2024 11:20
nagisa added 2 commits July 22, 2024 15:10
This is not, strictly speaking dead-dead code. It is going to appear in
a future change regardless, but is unnecessary in this PR.
Copy link
Contributor

@tayfunelmas tayfunelmas left a comment

Choose a reason for hiding this comment

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

LGTM. I did not attempted to connect the commits in a bigger picture, but the changes in each commit makes sense.

@@ -359,16 +358,26 @@ impl<'a> External for RuntimeExt<'a> {
fn get_receipt_receiver(&self, receipt_index: ReceiptIndex) -> &AccountId {
self.receipt_manager.get_receipt_receiver(receipt_index)
}
}

pub(crate) struct RuntimeContractExt<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. assuming Ext suffix represents "external", what does external contract mean here? (I miss the context for the structures in ext.rs.

Copy link
Collaborator Author

@nagisa nagisa Jul 23, 2024

Choose a reason for hiding this comment

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

That's a good question. "External" here stands for the "External Interface to the Contract Runtime". For this structure it could really just also read "ContractGetter" or "ContractReader" or "ContractAccessor" or something similar to evoke the purpose of this data structure more clearly, but since we already have RuntimeExt as a precedent, I opted to go with a similar name here as well.

@nagisa nagisa added this pull request to the merge queue Jul 23, 2024
Merged via the queue into near:master with commit e883ee2 Jul 23, 2024
30 checks passed
@nagisa nagisa deleted the moves-contract-preparation branch July 23, 2024 14:56
@race-of-sloths
Copy link

🔄 The PR has been merged.

Important

This pull request is a part of the Race of Sloths and has not been scored yet. Scoring will close in 24 hours! 🕰️

@race-of-sloths
Copy link

✅ PR is finalized!

Your contribution is much appreciated with a final score of 0!
You have received 10 (0 base + 10 weekly bonus) Sloth points for this contribution

Another weekly streak completed, well done @nagisa! To keep your weekly streak and get another bonus make pull request next week! Looking forward to see you in race-of-sloths

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.

5 participants