Skip to content

Commit

Permalink
style: remove cyclic dependency between primitives & vm-runner (#10343)
Browse files Browse the repository at this point in the history
Everything related to parameters and configurations has been moved into
a low-dependency `near-parameters` crate. Thus now any tests that depend
on the parameters can do so easily without introducing dependencies on
crates that may depend on the crate being tested in the first place
(such as `near-vm-runner`.)

One thing of note is that some VM structures pertinent to configuration
were moved out of `near-vm-runner` into `near-parameters` as well, so
that `near-parameters` is largely a self-contained crate for all things
protocol config.

Fixes #10339
  • Loading branch information
nagisa authored Dec 19, 2023
1 parent 07a4743 commit 82b7979
Show file tree
Hide file tree
Showing 191 changed files with 1,992 additions and 2,188 deletions.
38 changes: 35 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"core/crypto",
"core/dyn-configs",
"core/o11y",
"core/parameters",
"core/primitives",
"core/primitives-core",
"core/store",
Expand Down Expand Up @@ -219,6 +220,7 @@ near-mainnet-res = { path = "utils/mainnet-res" }
near-mirror = { path = "tools/mirror" }
near-network = { path = "chain/network" }
near-o11y = { path = "core/o11y" }
near-parameters = { path = "core/parameters" }
near-performance-metrics = { path = "utils/near-performance-metrics" }
near-performance-metrics-macros = { path = "utils/near-performance-metrics-macros" }
near-ping = { path = "tools/ping" }
Expand Down
3 changes: 3 additions & 0 deletions chain/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ near-o11y.workspace = true
near-performance-metrics-macros.workspace = true
near-performance-metrics.workspace = true
near-pool.workspace = true
near-parameters.workspace = true
near-primitives.workspace = true
near-store.workspace = true
near-telemetry.workspace = true
Expand Down Expand Up @@ -83,6 +84,7 @@ nightly_protocol = [
"near-epoch-manager/nightly_protocol",
"near-network/nightly_protocol",
"near-o11y/nightly_protocol",
"near-parameters/nightly_protocol",
"near-pool/nightly_protocol",
"near-primitives/nightly_protocol",
"near-store/nightly_protocol",
Expand All @@ -99,6 +101,7 @@ nightly = [
"near-epoch-manager/nightly",
"near-network/nightly",
"near-o11y/nightly",
"near-parameters/nightly",
"near-pool/nightly",
"near-primitives/nightly",
"near-store/nightly",
Expand Down
2 changes: 1 addition & 1 deletion chain/client/src/test_utils/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use near_network::types::NetworkRequests;
use near_network::types::PeerManagerMessageRequest;
use near_network::types::{PartialEncodedChunkRequestMsg, PartialEncodedChunkResponseMsg};
use near_o11y::testonly::TracingCapture;
use near_parameters::RuntimeConfig;
use near_primitives::action::delegate::{DelegateAction, NonDelegateAction, SignedDelegateAction};
use near_primitives::block::Block;
use near_primitives::chunk_validation::ChunkEndorsementMessage;
use near_primitives::epoch_manager::RngSeed;
use near_primitives::errors::InvalidTxError;
use near_primitives::hash::CryptoHash;
use near_primitives::runtime::config::RuntimeConfig;
use near_primitives::sharding::PartialEncodedChunk;
use near_primitives::test_utils::create_test_signer;
use near_primitives::transaction::{Action, FunctionCallAction, SignedTransaction};
Expand Down
18 changes: 8 additions & 10 deletions chain/client/src/test_utils/test_env_builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use super::setup::{setup_client_with_runtime, setup_synchronous_shards_manager};
use super::test_env::TestEnv;
use super::{AccountIndices, TEST_SEED};
use actix_rt::System;
use itertools::{multizip, Itertools};
use near_primitives::runtime::config_store::RuntimeConfigStore;
use near_store::config::StateSnapshotType;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;

use near_async::messaging::IntoSender;
use near_chain::state_snapshot_actor::SnapshotCallbacks;
use near_chain::test_utils::{KeyValueRuntime, MockEpochManager, ValidatorSchedule};
Expand All @@ -16,14 +13,15 @@ use near_chunks::test_utils::MockClientAdapterForShardsManager;
use near_epoch_manager::shard_tracker::{ShardTracker, TrackedConfig};
use near_epoch_manager::{EpochManager, EpochManagerAdapter, EpochManagerHandle};
use near_network::test_utils::MockPeerManagerAdapter;
use near_parameters::RuntimeConfigStore;
use near_primitives::epoch_manager::{AllEpochConfigTestOverrides, RngSeed};
use near_primitives::types::{AccountId, NumShards};
use near_store::config::StateSnapshotType;
use near_store::test_utils::create_test_store;
use near_store::{NodeStorage, ShardUId, Store, StoreConfig, TrieConfig};

use super::setup::{setup_client_with_runtime, setup_synchronous_shards_manager};
use super::test_env::TestEnv;
use super::{AccountIndices, TEST_SEED};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;

#[derive(derive_more::From, Clone)]
enum EpochManagerKind {
Expand Down
3 changes: 3 additions & 0 deletions chain/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ near-dyn-configs.workspace = true
near-crypto.workspace = true
near-indexer-primitives.workspace = true
near-o11y.workspace = true
near-parameters.workspace = true
near-primitives.workspace = true
near-store.workspace = true
node-runtime.workspace = true
Expand All @@ -41,6 +42,7 @@ nightly_protocol = [
"near-dyn-configs/nightly_protocol",
"near-indexer-primitives/nightly_protocol",
"near-o11y/nightly_protocol",
"near-parameters/nightly_protocol",
"near-primitives/nightly_protocol",
"near-store/nightly_protocol",
"nearcore/nightly_protocol",
Expand All @@ -54,6 +56,7 @@ nightly = [
"near-dyn-configs/nightly",
"near-indexer-primitives/nightly",
"near-o11y/nightly",
"near-parameters/nightly",
"near-primitives/nightly",
"near-store/nightly",
"nearcore/nightly",
Expand Down
37 changes: 16 additions & 21 deletions chain/indexer/src/streamer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
use std::time::Duration;

use self::errors::FailedToFetchData;
use self::fetchers::{
fetch_block, fetch_block_by_height, fetch_block_chunks, fetch_latest_block, fetch_outcomes,
fetch_state_changes, fetch_status,
};
use self::utils::convert_transactions_sir_into_local_receipts;
use crate::streamer::fetchers::fetch_protocol_config;
use crate::INDEXER;
use crate::{AwaitForNodeSyncedEnum, IndexerConfig};
use actix::Addr;
use async_recursion::async_recursion;
use node_runtime::config::RuntimeConfig;
use rocksdb::DB;
use tokio::sync::mpsc;
use tokio::time;
use tracing::{debug, info};

use near_indexer_primitives::{
IndexerChunkView, IndexerExecutionOutcomeWithOptionalReceipt,
IndexerExecutionOutcomeWithReceipt, IndexerShard, IndexerTransactionWithOutcome,
StreamerMessage,
};
use near_parameters::RuntimeConfig;
use near_primitives::hash::CryptoHash;
use near_primitives::views;

use crate::{AwaitForNodeSyncedEnum, IndexerConfig};

use self::errors::FailedToFetchData;
use self::fetchers::{
fetch_block, fetch_block_by_height, fetch_block_chunks, fetch_latest_block, fetch_outcomes,
fetch_state_changes, fetch_status,
};
use self::utils::convert_transactions_sir_into_local_receipts;
use crate::streamer::fetchers::fetch_protocol_config;
use crate::INDEXER;
use rocksdb::DB;
use std::time::Duration;
use tokio::sync::mpsc;
use tokio::time;
use tracing::{debug, info};

mod errors;
mod fetchers;
Expand Down Expand Up @@ -79,8 +75,7 @@ async fn build_streamer_message(
let num_shards = protocol_config_view.num_block_producer_seats_per_shard.len()
as near_primitives::types::NumShards;

let runtime_config_store =
near_primitives::runtime::config_store::RuntimeConfigStore::new(None);
let runtime_config_store = near_parameters::RuntimeConfigStore::new(None);
let runtime_config = runtime_config_store.get_config(protocol_config_view.protocol_version);

let mut shards_outcomes = fetch_outcomes(&client, block.header.hash).await?;
Expand Down
3 changes: 2 additions & 1 deletion chain/indexer/src/streamer/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use actix::Addr;

use near_indexer_primitives::IndexerTransactionWithOutcome;
use near_parameters::RuntimeConfig;
use near_primitives::views;
use node_runtime::config::{tx_cost, RuntimeConfig};
use node_runtime::config::tx_cost;

use super::errors::FailedToFetchData;
use super::fetchers::fetch_block;
Expand Down
3 changes: 3 additions & 0 deletions chain/rosetta-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ near-client.workspace = true
near-crypto.workspace = true
near-network.workspace = true
near-o11y.workspace = true
near-parameters.workspace = true
near-primitives.workspace = true
node-runtime.workspace = true

Expand All @@ -49,6 +50,7 @@ nightly_protocol = [
"near-client/nightly_protocol",
"near-network/nightly_protocol",
"near-o11y/nightly_protocol",
"near-parameters/nightly_protocol",
"near-primitives/nightly_protocol",
"node-runtime/nightly_protocol",
]
Expand All @@ -59,6 +61,7 @@ nightly = [
"near-client/nightly",
"near-network/nightly",
"near-o11y/nightly",
"near-parameters/nightly",
"near-primitives/nightly",
"node-runtime/nightly",
]
3 changes: 1 addition & 2 deletions chain/rosetta-rpc/src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,9 @@ mod tests {
use near_actix_test_utils::run_actix;
use near_client::test_utils::setup_no_network;
use near_crypto::{KeyType, SecretKey};
use near_parameters::{RuntimeConfig, RuntimeConfigView};
use near_primitives::action::delegate::{DelegateAction, SignedDelegateAction};
use near_primitives::runtime::config::RuntimeConfig;
use near_primitives::transaction::{Action, TransferAction};
use near_primitives::views::RuntimeConfigView;

#[test]
fn test_convert_block_changes_to_transactions() {
Expand Down
Loading

0 comments on commit 82b7979

Please sign in to comment.