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

vm: split preparation and running of a contract #11667

Merged
merged 5 commits into from
Jul 1, 2024
Merged

Conversation

nagisa
Copy link
Collaborator

@nagisa nagisa commented Jun 26, 2024

This is a very exciting step forward! Finally we got up to the point where we can do some work in preparing the contract to run separately from actual running of the contract. And all of this is encapsulated in a very neat API that gives out Send + 'static types for users to pass around between threads or whatever so that they can pipeline these processes.

It will remain to see whether the requirement to have &External and &VMContext in both calls is a problem, and how much of a problem it is, but that might be very well solvable with some scoped threads or smart use of channels, or even just Arc<Mutex>, especially since both of these structures generally tend to be unique to a contract execution...

Part of #11319

This is a small one.

`VMContext` already contains information specific to a single function
call, most notably the input "arguments". So it seems only sensible that
it would also include the method to be called, largely encapsulating
everything[^1] that's part of the inputs to the function call.

(I think `promise_results` should also be a part of that, so maybe not
quite *everything* yet, that's the next commit...)
Topically this is very similar to the `input`, even down to the detail
that this is exposed via similar means to the contract. So it makes a
lot of sense that it is treated in a very similar way in code as well.
This now technically kinda allows us to pipeline these two steps
externally. Finally!
@nagisa nagisa requested a review from Ekleog-NEAR June 26, 2024 12:55
@nagisa nagisa requested a review from a team as a code owner June 26, 2024 12:55
compute_usage = tracing::field::Empty,
))]
pub fn prepare(
ext: &(dyn External + Send),
Copy link
Collaborator Author

@nagisa nagisa Jun 26, 2024

Choose a reason for hiding this comment

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

This actually no longer requires Send from this API specifically, but External will need to be sendable if we want to allow preparing in a different thread anyway. So I'm keeping this bound here to make sure implementors of this type don't go rogue...

In a future change it may be possible to pass in a different trait that's focused on contract loading specifically. We could implement that for "just" TrieUpdate rather than the whole of Externals implementation.

Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 78.06691% with 59 lines in your changes missing coverage. Please review.

Project coverage is 71.79%. Comparing base (2b6030c) to head (d9154d9).
Report is 22 commits behind head on master.

Files Patch % Lines
runtime/near-vm-runner/src/wasmtime_runner.rs 77.64% 16 Missing and 3 partials ⚠️
runtime/near-vm-runner/src/wasmer_runner.rs 65.38% 14 Missing and 4 partials ⚠️
runtime/near-vm-runner/src/wasmer2_runner.rs 86.79% 4 Missing and 3 partials ⚠️
...ntime/runtime-params-estimator/src/gas_metering.rs 53.33% 7 Missing ⚠️
runtime/near-vm-runner/fuzz/src/lib.rs 0.00% 3 Missing ⚠️
...time/runtime-params-estimator/src/function_call.rs 57.14% 3 Missing ⚠️
...untime/near-vm-runner/src/near_vm_runner/runner.rs 97.36% 0 Missing and 1 partial ⚠️
runtime/near-vm-runner/src/runner.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11667      +/-   ##
==========================================
+ Coverage   71.62%   71.79%   +0.16%     
==========================================
  Files         787      790       +3     
  Lines      161191   161951     +760     
  Branches   161191   161951     +760     
==========================================
+ Hits       115461   116278     +817     
+ Misses      40697    40636      -61     
- Partials     5033     5037       +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.91% <29.36%> (+0.09%) ⬆️
linux 69.15% <78.06%> (+0.14%) ⬆️
linux-nightly 71.31% <78.06%> (+0.17%) ⬆️
macos 51.02% <72.44%> (-0.36%) ⬇️
pytests 1.58% <0.00%> (-0.01%) ⬇️
sanity-checks 1.38% <0.00%> (-0.01%) ⬇️
unittests 66.33% <74.34%> (+0.08%) ⬆️
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.

Copy link
Collaborator

@Ekleog-NEAR Ekleog-NEAR left a comment

Choose a reason for hiding this comment

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

LGTM! And happy to learn that contract preparation pipelining is coming soon 🎉

@@ -71,7 +66,9 @@ fn get_context() -> VMContext {
signer_account_id: "bob.near".parse().unwrap(),
signer_account_pk: vec![0, 1, 2, 3, 4],
predecessor_account_id: "carol.near".parse().unwrap(),
method: "VMLogicBuilder::method_not_specified".into(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should get_context take a method parameter to avoid hardcoding this, or are there known use cases where the method does not make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pretty much none of the VMLogic tests use the method at all, so it is just a noise.

runtime/near-vm-runner/src/near_vm_runner/runner.rs Outdated Show resolved Hide resolved
@nagisa nagisa enabled auto-merge July 1, 2024 09:08
@nagisa nagisa added this pull request to the merge queue Jul 1, 2024
Merged via the queue into near:master with commit d152288 Jul 1, 2024
29 of 30 checks passed
@nagisa nagisa deleted the baah branch July 1, 2024 09:43
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.

2 participants