Skip to content

Commit

Permalink
[refactor] Extracted near-vm-runner from near-primitives (#11578)
Browse files Browse the repository at this point in the history
### Description

This pull request tries to de-couple the near-vm-runner from the
dependency list of near-primitives

### Motivation
Near-vm-runner is not a proper dependency for something primitive, but
now it's a part of many near dependencies.
Also, near-vm-runner uses rustix::fs, a blocker for any release on
Windows.

* [here](near/near-cli-rs#350) you can see that
Windows built is broken.
*
[here](https://github.com/near/nearcore/compare/1.39.2...akorchyn:nearcore:patch-defaults?expand=1)
you can see an example patch so build pass

### How is it done?
Well, I have proceeded next way:
* Moved ViewApplyState to node-runtime
* Copied ProfileV3 to near-primitives and created conversion in
node-runtime

#### TODO:
* [x] Windows CI for public libraries :)
* [x] Fix tests compilation


## For reviewers
* Please take a look at a patch that I have created
[here](https://github.com/near/nearcore/compare/1.39.2...akorchyn:nearcore:patch-defaults?expand=1).
Do you think we could rollout 0.22.2 release, so I could continue
rolling out 0.22, but go with this more proper implementation for future
0.23/0.24 release?
  • Loading branch information
akorchyn authored and marcelo-gonzalez committed Aug 13, 2024
1 parent 1e199de commit fb4d835
Show file tree
Hide file tree
Showing 18 changed files with 542 additions and 51 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,14 @@ jobs:
files: py-upgradability.json
fail_ci_if_error: true
flags: pytests,upgradability,linux

windows_public_libraries_check:
name: "Windows check for building public libraries"
runs-on: "windows-latest"
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff
with:
tool: just
- run: just check_build_public_libraries
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ with_macos_excludes := if os() == "macos" {
}
nightly_flags := "--features nightly,test_features"
statelessnet_flags := "--features statelessnet_protocol"
public_libraries := "-p near-primitives -p near-crypto -p near-jsonrpc-primitives -p near-chain-configs -p near-primitives-core"

export RUST_BACKTRACE := env("RUST_BACKTRACE", "short")
ci_hack_nextest_profile := if env("CI_HACKS", "0") == "1" { "--profile ci" } else { "" }
Expand Down Expand Up @@ -73,6 +74,11 @@ nextest-integration TYPE *FLAGS:
nextest-integration TYPE *FLAGS:
@echo "Nextest integration tests are currently disabled on macos!"

[windows]
nextest-integration TYPE *FLAGS:
@echo "Nextest integration tests are currently disabled on windows!"


doctests:
cargo test --doc

Expand Down Expand Up @@ -165,3 +171,6 @@ update-rpc-errors-schema: build-rpc-errors-schema
# check chain/jsonrpc/res/rpc_errors_schema.json
check-rpc-errors-schema: build-rpc-errors-schema
diff target/rpc_errors_schema.json chain/jsonrpc/res/rpc_errors_schema.json

check_build_public_libraries:
cargo check {{public_libraries}}
6 changes: 3 additions & 3 deletions chain/chain/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use near_primitives::types::{
use near_primitives::version::{ProtocolFeature, ProtocolVersion};
use near_primitives::views::{
AccessKeyInfoView, CallResult, ContractCodeView, QueryRequest, QueryResponse,
QueryResponseKind, ViewApplyState, ViewStateResult,
QueryResponseKind, ViewStateResult,
};
use near_store::config::StateSnapshotType;
use near_store::flat::FlatStorageManager;
Expand All @@ -50,7 +50,7 @@ use near_store::{
use near_vm_runner::ContractCode;
use near_vm_runner::{precompile_contract, ContractRuntimeCache, FilesystemContractRuntimeCache};
use node_runtime::adapter::ViewRuntimeAdapter;
use node_runtime::state_viewer::TrieViewer;
use node_runtime::state_viewer::{TrieViewer, ViewApplyState};
use node_runtime::{
validate_transaction, verify_and_charge_transaction, ApplyState, Runtime,
ValidatorAccountsUpdate,
Expand Down Expand Up @@ -1478,7 +1478,7 @@ impl node_runtime::adapter::ViewRuntimeAdapter for NightshadeRuntime {
epoch_height,
block_timestamp,
current_protocol_version,
cache: Some(Box::new(self.compiled_contract_cache.handle())),
cache: Some(self.compiled_contract_cache.handle()),
};
self.trie_viewer.call_function(
state_update,
Expand Down
7 changes: 2 additions & 5 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,24 @@ strum.workspace = true
thiserror.workspace = true
tracing.workspace = true
zstd.workspace = true
enum-map.workspace = true

near-time.workspace = true
near-crypto.workspace = true
near-fmt.workspace = true
near-primitives-core.workspace = true
near-rpc-error-macro.workspace = true
near-vm-runner.workspace = true
near-parameters.workspace = true

[features]
sandbox = ["near-vm-runner/sandbox"]
sandbox = []
test_features = []
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_fix_staking_threshold = [
"near-primitives-core/protocol_feature_fix_staking_threshold",
]
protocol_feature_fix_contract_loading_cost = [
"near-primitives-core/protocol_feature_fix_contract_loading_cost",
"near-vm-runner/protocol_feature_fix_contract_loading_cost",
]
protocol_feature_reject_blocks_with_outdated_protocol_version = [
"near-primitives-core/protocol_feature_reject_blocks_with_outdated_protocol_version",
Expand All @@ -71,7 +70,6 @@ nightly = [
"near-fmt/nightly",
"near-parameters/nightly",
"near-primitives-core/nightly",
"near-vm-runner/nightly",
"nightly_protocol",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_fix_staking_threshold",
Expand All @@ -83,7 +81,6 @@ nightly_protocol = [
"near-fmt/nightly_protocol",
"near-parameters/nightly_protocol",
"near-primitives-core/nightly_protocol",
"near-vm-runner/nightly_protocol",
]

statelessnet_protocol = ["near-primitives-core/statelessnet_protocol"]
Expand Down
1 change: 1 addition & 0 deletions core/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod errors;
pub mod merkle;
pub mod network;
pub mod profile_data_v2;
pub mod profile_data_v3;
pub mod rand;
pub mod receipt;
pub mod reed_solomon;
Expand Down
Loading

0 comments on commit fb4d835

Please sign in to comment.