From 89fad4638de10402965ea08605b8773c47d03fe2 Mon Sep 17 00:00:00 2001 From: Artur Yurii Korchynskyi <42449190+akorchyn@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:34:56 +0300 Subject: [PATCH] [chore] Reduced dependencies for various near_* crates (#11639) Compilation unit reduction: * near-jsonrpc-primitives: 324 -> **181** * near-chain-configs: 321 -> **170** * near-chain-primitives: 325 -> **170** * near-client-primitives: 325 -> **215** * near-store: 414 -> **407** (this is actually not that great, but still an improvement. Also, I think we can extract metrics into a feature to improve compile time :) --- Cargo.lock | 30 ++--- chain/chain-primitives/Cargo.toml | 2 +- chain/chain-primitives/src/error.rs | 2 +- chain/client-primitives/Cargo.toml | 8 +- chain/client-primitives/src/debug.rs | 2 +- chain/client/Cargo.toml | 2 +- chain/jsonrpc/fuzz/Cargo.toml | 2 +- .../fuzz_targets_disabled/fuzz_target_1.rs | 2 +- chain/jsonrpc/jsonrpc-tests/Cargo.toml | 5 +- chain/jsonrpc/jsonrpc-tests/src/lib.rs | 4 +- .../jsonrpc/jsonrpc-tests/tests/http_query.rs | 2 +- .../jsonrpc/jsonrpc-tests/tests/rpc_query.rs | 2 +- .../jsonrpc-tests/tests/rpc_transactions.rs | 2 +- chain/rosetta-rpc/Cargo.toml | 4 +- chain/rosetta-rpc/src/adapters/mod.rs | 2 +- core/async/Cargo.toml | 1 + core/chain-configs/Cargo.toml | 4 +- core/chain-configs/src/client_config.rs | 14 +-- core/chain-configs/src/genesis_config.rs | 2 +- core/chain-configs/src/test_genesis.rs | 2 +- core/chain-configs/src/test_utils.rs | 2 +- core/chain-configs/src/updateable_config.rs | 6 +- core/dyn-configs/Cargo.toml | 4 +- core/dyn-configs/src/lib.rs | 2 +- core/primitives/Cargo.toml | 2 +- core/primitives/src/block.rs | 30 ++--- core/primitives/src/block_header.rs | 21 ++-- core/primitives/src/upgrade_schedule.rs | 1 + core/primitives/src/version.rs | 4 +- core/primitives/tests/crate-limit-test.rs | 61 ---------- core/store/Cargo.toml | 9 +- core/store/src/metrics.rs | 4 +- core/time/Cargo.toml | 1 - genesis-tools/genesis-populate/Cargo.toml | 4 +- genesis-tools/genesis-populate/src/lib.rs | 2 +- integration-tests/Cargo.toml | 1 + integration-tests/src/tests/dependencies.rs | 106 ++++++++++++++++++ integration-tests/src/tests/mod.rs | 1 + tools/amend-genesis/Cargo.toml | 4 +- tools/amend-genesis/src/lib.rs | 2 +- tools/mock-node/Cargo.toml | 2 +- tools/mock-node/src/lib.rs | 3 +- tools/mock-node/src/setup.rs | 2 +- tools/ping/Cargo.toml | 4 +- tools/ping/src/csv.rs | 3 +- tools/ping/src/lib.rs | 35 +++--- tools/speedy_sync/Cargo.toml | 2 +- tools/speedy_sync/src/main.rs | 2 +- tools/state-parts/Cargo.toml | 4 +- tools/state-parts/src/lib.rs | 12 +- tools/state-viewer/Cargo.toml | 4 +- tools/state-viewer/src/apply_chunk.rs | 2 +- tools/state-viewer/src/latest_witnesses.rs | 2 +- tools/state-viewer/src/state_parts.rs | 2 +- 54 files changed, 236 insertions(+), 204 deletions(-) delete mode 100644 core/primitives/tests/crate-limit-test.rs create mode 100644 integration-tests/src/tests/dependencies.rs diff --git a/Cargo.lock b/Cargo.lock index 559b35ad97f..afa8887d880 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2652,7 +2652,6 @@ dependencies = [ "borsh 1.0.0", "clap", "indicatif", - "near-async", "near-chain", "near-chain-configs", "near-crypto", @@ -2660,6 +2659,7 @@ dependencies = [ "near-primitives", "near-store", "near-test-contracts", + "near-time", "near-vm-runner", "nearcore", "node-runtime", @@ -3188,6 +3188,7 @@ dependencies = [ "primitive-types 0.10.1", "rand", "reed-solomon-erasure", + "regex", "rlp", "serde", "serde_json", @@ -3721,7 +3722,6 @@ dependencies = [ "clap", "futures", "near-actix-test-utils", - "near-async", "near-chain", "near-chain-configs", "near-chunks", @@ -3736,6 +3736,7 @@ dependencies = [ "near-primitives", "near-store", "near-telemetry", + "near-time", "nearcore", "pin-project", "rand", @@ -3797,11 +3798,11 @@ dependencies = [ "anyhow", "borsh 1.0.0", "clap", - "near-async", "near-chain-configs", "near-crypto", "near-primitives", "near-primitives-core", + "near-time", "num-rational 0.3.2", "serde", "serde_json", @@ -3906,12 +3907,12 @@ dependencies = [ "bytesize", "chrono", "derive_more", - "near-async", "near-config-utils", "near-crypto", "near-o11y", "near-parameters", "near-primitives", + "near-time", "num-rational 0.3.2", "once_cell", "serde", @@ -3926,9 +3927,9 @@ dependencies = [ name = "near-chain-primitives" version = "0.0.0" dependencies = [ - "near-async", "near-crypto", "near-primitives", + "near-time", "thiserror", "time", "tracing", @@ -4041,12 +4042,12 @@ version = "0.0.0" dependencies = [ "actix", "chrono", - "near-async", "near-chain-configs", "near-chain-primitives", "near-chunks-primitives", "near-crypto", "near-primitives", + "near-time", "serde", "serde_json", "strum", @@ -4122,11 +4123,11 @@ name = "near-dyn-configs" version = "0.0.0" dependencies = [ "anyhow", - "near-async", "near-chain-configs", "near-crypto", "near-o11y", "near-primitives", + "near-time", "once_cell", "prometheus", "serde", @@ -4323,11 +4324,11 @@ dependencies = [ "arbitrary", "awc", "libfuzzer-sys", - "near-async", "near-jsonrpc", "near-jsonrpc-primitives", "near-jsonrpc-tests", "near-primitives", + "near-time", "once_cell", "serde", "serde_json", @@ -4369,6 +4370,7 @@ dependencies = [ "near-o11y", "near-primitives", "near-store", + "near-time", "once_cell", "serde", "serde_json", @@ -4569,11 +4571,11 @@ dependencies = [ "anyhow", "chrono", "clap", - "near-async", "near-jsonrpc", "near-network", "near-o11y", "near-primitives", + "near-time", "once_cell", "prometheus", "tokio", @@ -4675,7 +4677,6 @@ dependencies = [ "insta", "near-account-id", "near-actix-test-utils", - "near-async", "near-chain-configs", "near-client", "near-client-primitives", @@ -4684,6 +4685,7 @@ dependencies = [ "near-o11y", "near-parameters", "near-primitives", + "near-time", "node-runtime", "paperclip", "serde", @@ -4721,12 +4723,12 @@ dependencies = [ "anyhow", "chrono", "clap", - "near-async", "near-jsonrpc", "near-network", "near-o11y", "near-ping", "near-primitives", + "near-time", "once_cell", "sha2 0.10.6", "time", @@ -4781,7 +4783,6 @@ dependencies = [ "itertools", "itoa", "lru 0.12.3", - "near-async", "near-chain", "near-chain-configs", "near-chunks", @@ -4791,6 +4792,7 @@ dependencies = [ "near-parameters", "near-primitives", "near-stdx", + "near-time", "near-vm-runner", "num_cpus", "once_cell", @@ -7265,13 +7267,13 @@ version = "0.0.0" dependencies = [ "borsh 1.0.0", "clap", - "near-async", "near-chain", "near-chain-configs", "near-chain-primitives", "near-epoch-manager", "near-primitives", "near-store", + "near-time", "nearcore", "serde", "serde_json", @@ -7314,7 +7316,6 @@ dependencies = [ "cloud-storage", "insta", "itertools", - "near-async", "near-chain", "near-chain-configs", "near-client", @@ -7326,6 +7327,7 @@ dependencies = [ "near-primitives-core", "near-store", "near-test-contracts", + "near-time", "nearcore", "node-runtime", "once_cell", diff --git a/chain/chain-primitives/Cargo.toml b/chain/chain-primitives/Cargo.toml index 14f92ce6309..d37b76b74de 100644 --- a/chain/chain-primitives/Cargo.toml +++ b/chain/chain-primitives/Cargo.toml @@ -16,7 +16,7 @@ thiserror.workspace = true time.workspace = true tracing.workspace = true -near-async.workspace = true +near-time.workspace = true near-primitives.workspace = true near-crypto.workspace = true diff --git a/chain/chain-primitives/src/error.rs b/chain/chain-primitives/src/error.rs index a201710170e..6458b1b1b58 100644 --- a/chain/chain-primitives/src/error.rs +++ b/chain/chain-primitives/src/error.rs @@ -1,10 +1,10 @@ -use near_async::time::Utc; use near_primitives::block::BlockValidityError; use near_primitives::challenge::{ChunkProofs, ChunkState}; use near_primitives::errors::{EpochError, StorageError}; use near_primitives::shard_layout::ShardLayoutError; use near_primitives::sharding::{ChunkHash, ShardChunkHeader}; use near_primitives::types::{BlockHeight, EpochId, ShardId}; +use near_time::Utc; use std::io; #[derive(thiserror::Error, Debug)] diff --git a/chain/client-primitives/Cargo.toml b/chain/client-primitives/Cargo.toml index 803d566e950..d2ad45f7b5a 100644 --- a/chain/client-primitives/Cargo.toml +++ b/chain/client-primitives/Cargo.toml @@ -22,7 +22,7 @@ time.workspace = true tracing.workspace = true yansi.workspace = true -near-async.workspace = true +near-time.workspace = true near-chain-primitives.workspace = true near-chain-configs.workspace = true near-chunks-primitives.workspace = true @@ -31,17 +31,13 @@ near-primitives.workspace = true [features] nightly_protocol = [ - "near-async/nightly_protocol", "near-chain-configs/nightly_protocol", "near-primitives/nightly_protocol", ] nightly = [ - "near-async/nightly", "near-chain-configs/nightly", "near-primitives/nightly", "nightly_protocol", ] sandbox = [] -test_features = [ - "near-primitives/test_features", -] +test_features = ["near-primitives/test_features"] diff --git a/chain/client-primitives/src/debug.rs b/chain/client-primitives/src/debug.rs index 61c3c2647c7..aacf1128e06 100644 --- a/chain/client-primitives/src/debug.rs +++ b/chain/client-primitives/src/debug.rs @@ -1,7 +1,6 @@ //! Structs in this module are used for debug purposes, and might change at any time //! without backwards compatibility of JSON encoding. use crate::types::StatusError; -use near_async::time::Utc; use near_primitives::congestion_info::CongestionInfo; use near_primitives::types::EpochId; use near_primitives::views::{ @@ -15,6 +14,7 @@ use near_primitives::{ types::{AccountId, BlockHeight}, views::ValidatorInfo, }; +use near_time::Utc; use std::collections::HashMap; #[derive(serde::Serialize, serde::Deserialize, Debug)] diff --git a/chain/client/Cargo.toml b/chain/client/Cargo.toml index 35b7227ccf7..2d0b35d7445 100644 --- a/chain/client/Cargo.toml +++ b/chain/client/Cargo.toml @@ -60,7 +60,7 @@ near-parameters.workspace = true near-performance-metrics-macros.workspace = true near-performance-metrics.workspace = true near-pool.workspace = true -near-primitives.workspace = true +near-primitives = { workspace = true, features = ["clock"] } near-store.workspace = true near-telemetry.workspace = true near-vm-runner.workspace = true diff --git a/chain/jsonrpc/fuzz/Cargo.toml b/chain/jsonrpc/fuzz/Cargo.toml index 2dd5ec01ca5..c9f439a9ce0 100644 --- a/chain/jsonrpc/fuzz/Cargo.toml +++ b/chain/jsonrpc/fuzz/Cargo.toml @@ -24,7 +24,7 @@ serde.workspace = true serde_json.workspace = true tokio.workspace = true -near-async.workspace = true +near-time.workspace = true near-jsonrpc.workspace = true near-jsonrpc-primitives.workspace = true near-jsonrpc-tests.workspace = true diff --git a/chain/jsonrpc/fuzz/fuzz_targets_disabled/fuzz_target_1.rs b/chain/jsonrpc/fuzz/fuzz_targets_disabled/fuzz_target_1.rs index ba1f53d5f32..2f29dd5eedd 100644 --- a/chain/jsonrpc/fuzz/fuzz_targets_disabled/fuzz_target_1.rs +++ b/chain/jsonrpc/fuzz/fuzz_targets_disabled/fuzz_target_1.rs @@ -1,7 +1,7 @@ #![no_main] use actix::System; use libfuzzer_sys::{arbitrary, fuzz_target}; -use near_async::time::Clock; +use near_time::Clock; use serde::ser::{Serialize, Serializer}; use serde_json::json; use tokio; diff --git a/chain/jsonrpc/jsonrpc-tests/Cargo.toml b/chain/jsonrpc/jsonrpc-tests/Cargo.toml index 3f1f015c4a7..81e391b3acd 100644 --- a/chain/jsonrpc/jsonrpc-tests/Cargo.toml +++ b/chain/jsonrpc/jsonrpc-tests/Cargo.toml @@ -20,6 +20,7 @@ borsh.workspace = true serde.workspace = true serde_json.workspace = true +near-time.workspace = true near-async.workspace = true near-chain-configs.workspace = true near-crypto.workspace = true @@ -61,7 +62,5 @@ nightly_protocol = [ "near-primitives/nightly_protocol", "near-store/nightly_protocol", ] -statelessnet_protocol = [ - "near-primitives/statelessnet_protocol", -] +statelessnet_protocol = ["near-primitives/statelessnet_protocol"] sandbox = ["near-jsonrpc/sandbox", "near-o11y/sandbox"] diff --git a/chain/jsonrpc/jsonrpc-tests/src/lib.rs b/chain/jsonrpc/jsonrpc-tests/src/lib.rs index 176e73cf3e1..af940f9db64 100644 --- a/chain/jsonrpc/jsonrpc-tests/src/lib.rs +++ b/chain/jsonrpc/jsonrpc-tests/src/lib.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use actix::Addr; use futures::{future, future::LocalBoxFuture, FutureExt, TryFutureExt}; -use near_async::time::Clock; use near_async::{ actix::AddrWithAutoSpanContextExt, messaging::{noop, IntoMultiSender}, @@ -17,6 +16,7 @@ use near_jsonrpc_primitives::{ }; use near_network::tcp; use near_primitives::types::NumBlocks; +use near_time::Clock; use once_cell::sync::Lazy; use serde_json::json; @@ -72,7 +72,7 @@ macro_rules! test_with_client { near_actix_test_utils::run_actix(async { let (_view_client_addr, addr) = - test_utils::start_all(near_async::time::Clock::real(), $node_type); + test_utils::start_all(near_time::Clock::real(), $node_type); let $client = new_client(&format!("http://{}", addr)); diff --git a/chain/jsonrpc/jsonrpc-tests/tests/http_query.rs b/chain/jsonrpc/jsonrpc-tests/tests/http_query.rs index d7abf885314..0d87af34e7f 100644 --- a/chain/jsonrpc/jsonrpc-tests/tests/http_query.rs +++ b/chain/jsonrpc/jsonrpc-tests/tests/http_query.rs @@ -2,9 +2,9 @@ use actix::System; use futures::{future, FutureExt}; use near_actix_test_utils::run_actix; -use near_async::time::Clock; use near_jsonrpc::client::new_http_client; use near_o11y::testonly::init_test_logger; +use near_time::Clock; use near_jsonrpc_tests as test_utils; diff --git a/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs b/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs index 347c7ffcb53..9ae48513c05 100644 --- a/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs +++ b/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs @@ -6,7 +6,6 @@ use futures::{future, FutureExt}; use serde_json::json; use near_actix_test_utils::run_actix; -use near_async::time::Clock; use near_crypto::{KeyType, PublicKey, Signature}; use near_jsonrpc::client::{new_client, ChunkId}; use near_jsonrpc_primitives::types::query::QueryResponseKind; @@ -17,6 +16,7 @@ use near_primitives::account::{AccessKey, AccessKeyPermission}; use near_primitives::hash::CryptoHash; use near_primitives::types::{BlockId, BlockReference, EpochId, SyncCheckpoint}; use near_primitives::views::QueryRequest; +use near_time::Clock; use near_jsonrpc_tests::{self as test_utils, test_with_client}; diff --git a/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs b/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs index 6cb02647bb0..69b10403d84 100644 --- a/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs +++ b/chain/jsonrpc/jsonrpc-tests/tests/rpc_transactions.rs @@ -5,7 +5,6 @@ use actix::{Actor, System}; use futures::{future, FutureExt, TryFutureExt}; use near_actix_test_utils::run_actix; -use near_async::time::Clock; use near_crypto::{InMemorySigner, KeyType}; use near_jsonrpc::client::new_client; use near_jsonrpc_primitives::types::transactions::{RpcTransactionStatusRequest, TransactionInfo}; @@ -16,6 +15,7 @@ use near_primitives::serialize::to_base64; use near_primitives::transaction::SignedTransaction; use near_primitives::types::BlockReference; use near_primitives::views::{FinalExecutionStatus, TxExecutionStatus}; +use near_time::Clock; use near_jsonrpc_tests::{self as test_utils, test_with_client}; diff --git a/chain/rosetta-rpc/Cargo.toml b/chain/rosetta-rpc/Cargo.toml index be1940000be..577d09262e6 100644 --- a/chain/rosetta-rpc/Cargo.toml +++ b/chain/rosetta-rpc/Cargo.toml @@ -41,13 +41,12 @@ node-runtime.workspace = true [dev-dependencies] insta.workspace = true near-actix-test-utils.workspace = true -near-async.workspace = true +near-time.workspace = true [features] protocol_feature_nonrefundable_transfer_nep491 = [] nightly_protocol = [ "near-actix-test-utils/nightly_protocol", - "near-async/nightly_protocol", "near-chain-configs/nightly_protocol", "near-client-primitives/nightly_protocol", "near-client/nightly_protocol", @@ -59,7 +58,6 @@ nightly_protocol = [ ] nightly = [ "near-actix-test-utils/nightly", - "near-async/nightly", "near-chain-configs/nightly", "near-client-primitives/nightly", "near-client/nightly", diff --git a/chain/rosetta-rpc/src/adapters/mod.rs b/chain/rosetta-rpc/src/adapters/mod.rs index ac92f44f9c8..5437430499c 100644 --- a/chain/rosetta-rpc/src/adapters/mod.rs +++ b/chain/rosetta-rpc/src/adapters/mod.rs @@ -848,12 +848,12 @@ mod tests { use super::*; use actix::System; use near_actix_test_utils::run_actix; - use near_async::time::Clock; 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::transaction::{Action, TransferAction}; + use near_time::Clock; #[test] fn test_convert_block_changes_to_transactions() { diff --git a/core/async/Cargo.toml b/core/async/Cargo.toml index a948baa5613..b949ca17296 100644 --- a/core/async/Cargo.toml +++ b/core/async/Cargo.toml @@ -23,6 +23,7 @@ tokio = { workspace = true, features = ["rt", "macros"] } tracing.workspace = true near-async-derive.workspace = true +# TODO(#11652): we use it only for logging. i think, it's a bit too much... near-o11y.workspace = true near-performance-metrics.workspace = true near-time = { workspace = true, features = ["clock"] } diff --git a/core/chain-configs/Cargo.toml b/core/chain-configs/Cargo.toml index 60e3a241943..9a34387c69d 100644 --- a/core/chain-configs/Cargo.toml +++ b/core/chain-configs/Cargo.toml @@ -25,7 +25,7 @@ smart-default.workspace = true time.workspace = true tracing.workspace = true -near-async.workspace = true +near-time.workspace = true near-crypto.workspace = true near-o11y = { workspace = true, optional = true } near-parameters.workspace = true @@ -35,13 +35,11 @@ near-config-utils.workspace = true [features] protocol_feature_nonrefundable_transfer_nep491 = [] nightly_protocol = [ - "near-async/nightly_protocol", "near-o11y/nightly_protocol", "near-parameters/nightly_protocol", "near-primitives/nightly_protocol", ] nightly = [ - "near-async/nightly", "near-o11y/nightly", "near-parameters/nightly", "near-primitives/nightly", diff --git a/core/chain-configs/src/client_config.rs b/core/chain-configs/src/client_config.rs index c85ca75154f..20d53cb1fdf 100644 --- a/core/chain-configs/src/client_config.rs +++ b/core/chain-configs/src/client_config.rs @@ -2,11 +2,11 @@ use crate::ExternalStorageLocation::GCS; use crate::MutableConfigValue; use bytesize::ByteSize; -use near_async::time::Duration; use near_primitives::types::{ AccountId, BlockHeight, BlockHeightDelta, Gas, NumBlocks, NumSeats, ShardId, }; use near_primitives::version::Version; +use near_time::Duration; use std::cmp::{max, min}; use std::path::PathBuf; use std::sync::atomic::AtomicBool; @@ -48,7 +48,7 @@ pub struct GCConfig { pub gc_num_epochs_to_keep: u64, /// How often gc should be run - #[serde(with = "near_async::time::serde_duration_as_std")] + #[serde(with = "near_time::serde_duration_as_std")] pub gc_step_period: Duration, } @@ -120,7 +120,7 @@ pub struct DumpConfig { /// Feel free to set to `None`, defaults are sensible. #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] - #[serde(with = "near_async::time::serde_opt_duration_as_std")] + #[serde(with = "near_time::serde_opt_duration_as_std")] pub iteration_delay: Option, /// Location of a json file with credentials allowing write access to the bucket. #[serde(skip_serializing_if = "Option::is_none")] @@ -192,23 +192,23 @@ pub struct ReshardingConfig { /// The delay between writing batches to the db. The batch delay can be /// increased if resharding is consuming too many resources and interfering /// with regular node operation. - #[serde(with = "near_async::time::serde_duration_as_std")] + #[serde(with = "near_time::serde_duration_as_std")] pub batch_delay: Duration, /// The delay between attempts to start resharding while waiting for the /// state snapshot to become available. - #[serde(with = "near_async::time::serde_duration_as_std")] + #[serde(with = "near_time::serde_duration_as_std")] pub retry_delay: Duration, /// The delay between the resharding request is received and when the actor /// actually starts working on it. This delay should only be used in tests. - #[serde(with = "near_async::time::serde_duration_as_std")] + #[serde(with = "near_time::serde_duration_as_std")] pub initial_delay: Duration, /// The maximum time that the actor will wait for the snapshot to be ready, /// before starting resharding. Do not wait indefinitely since we want to /// report error early enough for the node maintainer to have time to recover. - #[serde(with = "near_async::time::serde_duration_as_std")] + #[serde(with = "near_time::serde_duration_as_std")] pub max_poll_time: Duration, } diff --git a/core/chain-configs/src/genesis_config.rs b/core/chain-configs/src/genesis_config.rs index 214d282d35f..810de152981 100644 --- a/core/chain-configs/src/genesis_config.rs +++ b/core/chain-configs/src/genesis_config.rs @@ -101,7 +101,7 @@ fn default_max_kickout_stake_threshold() -> u8 { } fn default_genesis_time() -> DateTime { - let time = near_async::time::Utc::now_utc(); + let time = near_time::Utc::now_utc(); DateTime::from_timestamp(time.unix_timestamp(), time.nanosecond()).unwrap_or_default() } diff --git a/core/chain-configs/src/test_genesis.rs b/core/chain-configs/src/test_genesis.rs index fca3409fa3c..255896fe63b 100644 --- a/core/chain-configs/src/test_genesis.rs +++ b/core/chain-configs/src/test_genesis.rs @@ -1,6 +1,5 @@ use std::collections::{HashMap, HashSet}; -use near_async::time::Clock; use near_crypto::PublicKey; use near_primitives::account::{AccessKey, Account}; use near_primitives::hash::CryptoHash; @@ -13,6 +12,7 @@ use near_primitives::types::{ }; use near_primitives::utils::from_timestamp; use near_primitives::version::PROTOCOL_VERSION; +use near_time::Clock; use num_rational::Rational32; use crate::{Genesis, GenesisConfig, GenesisContents, GenesisRecords}; diff --git a/core/chain-configs/src/test_utils.rs b/core/chain-configs/src/test_utils.rs index 9400c5aad78..8df1fd78eb6 100644 --- a/core/chain-configs/src/test_utils.rs +++ b/core/chain-configs/src/test_utils.rs @@ -1,4 +1,3 @@ -use near_async::time::Clock; use near_crypto::{InMemorySigner, KeyType, PublicKey}; use near_primitives::account::{AccessKey, Account}; use near_primitives::hash::CryptoHash; @@ -9,6 +8,7 @@ use near_primitives::types::{ }; use near_primitives::utils::{from_timestamp, generate_random_string}; use near_primitives::version::PROTOCOL_VERSION; +use near_time::Clock; use num_rational::Ratio; use crate::{ diff --git a/core/chain-configs/src/updateable_config.rs b/core/chain-configs/src/updateable_config.rs index 283e7ddc64f..ebace65d3ec 100644 --- a/core/chain-configs/src/updateable_config.rs +++ b/core/chain-configs/src/updateable_config.rs @@ -1,7 +1,7 @@ -#[cfg(feature = "metrics")] -use near_async::time::Clock; use near_primitives::types::BlockHeight; use near_primitives::validator_signer::ValidatorSigner; +#[cfg(feature = "metrics")] +use near_time::Clock; use serde::{Deserialize, Serialize, Serializer}; use std::fmt::Debug; use std::sync::{Arc, Mutex}; @@ -106,7 +106,7 @@ pub struct UpdateableClientConfig { /// Time limit for adding transactions in produce_chunk() #[serde(default)] - #[serde(with = "near_async::time::serde_opt_duration_as_std")] + #[serde(with = "near_time::serde_opt_duration_as_std")] pub produce_chunk_add_transactions_time_limit: Option, } diff --git a/core/dyn-configs/Cargo.toml b/core/dyn-configs/Cargo.toml index 36ca12db087..ffdbff591e6 100644 --- a/core/dyn-configs/Cargo.toml +++ b/core/dyn-configs/Cargo.toml @@ -21,7 +21,7 @@ thiserror.workspace = true tokio.workspace = true tracing.workspace = true -near-async.workspace = true +near-time.workspace = true near-chain-configs.workspace = true near-crypto.workspace = true near-o11y.workspace = true @@ -29,14 +29,12 @@ near-primitives.workspace = true [features] nightly = [ - "near-async/nightly", "near-chain-configs/nightly", "near-o11y/nightly", "near-primitives/nightly", "nightly_protocol", ] nightly_protocol = [ - "near-async/nightly_protocol", "near-chain-configs/nightly_protocol", "near-o11y/nightly_protocol", "near-primitives/nightly_protocol", diff --git a/core/dyn-configs/src/lib.rs b/core/dyn-configs/src/lib.rs index f9d19ba13b7..320e44dec8c 100644 --- a/core/dyn-configs/src/lib.rs +++ b/core/dyn-configs/src/lib.rs @@ -1,9 +1,9 @@ #![doc = include_str!("../README.md")] -use near_async::time::Clock; use near_chain_configs::UpdateableClientConfig; use near_o11y::log_config::LogConfig; use near_primitives::validator_signer::ValidatorSigner; +use near_time::Clock; use std::path::PathBuf; use std::sync::Arc; use tokio::sync::broadcast::Sender; diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index cd1d8a35e6c..49200983d43 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -41,7 +41,7 @@ tracing.workspace = true zstd.workspace = true enum-map.workspace = true -near-time.workspace = true +near-time = { workspace = true } near-crypto.workspace = true near-fmt.workspace = true near-primitives-core.workspace = true diff --git a/core/primitives/src/block.rs b/core/primitives/src/block.rs index d005dbe99ad..433d060f7f9 100644 --- a/core/primitives/src/block.rs +++ b/core/primitives/src/block.rs @@ -4,19 +4,17 @@ use crate::block::BlockValidityError::{ }; use crate::block_body::{BlockBody, BlockBodyV1, ChunkEndorsementSignatures}; pub use crate::block_header::*; -use crate::challenge::{Challenges, ChallengesResult}; +use crate::challenge::Challenges; use crate::checked_feature; -use crate::congestion_info::{BlockCongestionInfo, CongestionInfo, ExtendedCongestionInfo}; -use crate::hash::{hash, CryptoHash}; +use crate::congestion_info::{BlockCongestionInfo, ExtendedCongestionInfo}; +use crate::hash::CryptoHash; use crate::merkle::{merklize, verify_path, MerklePath}; use crate::num_rational::Rational32; use crate::sharding::{ChunkHashHeight, ShardChunkHeader, ShardChunkHeaderV1}; -use crate::types::{Balance, BlockHeight, EpochId, Gas, NumBlocks}; -use crate::validator_signer::ValidatorSigner; +use crate::types::{Balance, BlockHeight, EpochId, Gas}; use crate::version::{ProtocolVersion, SHARD_CHUNK_HEADER_UPGRADE_VERSION}; use borsh::{BorshDeserialize, BorshSerialize}; -use near_crypto::Signature; -use near_time::{Clock, Duration, Utc}; +use near_time::Utc; use primitive_types::U256; use std::collections::BTreeMap; use std::ops::Index; @@ -92,7 +90,7 @@ type ShardChunkReedSolomon = reed_solomon_erasure::galois_8::ReedSolomon; #[cfg(feature = "solomon")] pub fn genesis_chunks( state_roots: Vec, - congestion_infos: Vec>, + congestion_infos: Vec>, shard_ids: &[crate::types::ShardId], initial_gas_limit: Gas, genesis_height: BlockHeight, @@ -143,7 +141,7 @@ fn genesis_chunk( initial_gas_limit: u64, shard_id: u64, state_root: CryptoHash, - congestion_info: Option, + congestion_info: Option, ) -> crate::sharding::EncodedShardChunk { let (encoded_chunk, _) = crate::sharding::EncodedShardChunk::new( CryptoHash::default(), @@ -276,30 +274,32 @@ impl Block { } /// Produces new block from header of previous block, current state root and set of transactions. + #[cfg(feature = "clock")] pub fn produce( this_epoch_protocol_version: ProtocolVersion, next_epoch_protocol_version: ProtocolVersion, prev: &BlockHeader, height: BlockHeight, - block_ordinal: NumBlocks, + block_ordinal: crate::types::NumBlocks, chunks: Vec, chunk_endorsements: Vec, epoch_id: EpochId, next_epoch_id: EpochId, epoch_sync_data_hash: Option, - approvals: Vec>>, + approvals: Vec>>, gas_price_adjustment_rate: Rational32, min_gas_price: Balance, max_gas_price: Balance, minted_amount: Option, - challenges_result: ChallengesResult, + challenges_result: crate::challenge::ChallengesResult, challenges: Challenges, - signer: &ValidatorSigner, + signer: &crate::validator_signer::ValidatorSigner, next_bp_hash: CryptoHash, block_merkle_root: CryptoHash, - clock: Clock, - sandbox_delta_time: Option, + clock: near_time::Clock, + sandbox_delta_time: Option, ) -> Self { + use crate::hash::hash; // Collect aggregate of validators and gas usage/limits from chunks. let mut prev_validator_proposals = vec![]; let mut gas_used = 0; diff --git a/core/primitives/src/block_header.rs b/core/primitives/src/block_header.rs index 52962ca9b50..e6989c7dfb8 100644 --- a/core/primitives/src/block_header.rs +++ b/core/primitives/src/block_header.rs @@ -5,10 +5,10 @@ use crate::network::PeerId; use crate::types::validator_stake::{ValidatorStake, ValidatorStakeIter, ValidatorStakeV1}; use crate::types::{AccountId, Balance, BlockHeight, EpochId, MerkleHash, NumBlocks}; use crate::validator_signer::ValidatorSigner; -use crate::version::{get_protocol_version, ProtocolVersion, PROTOCOL_VERSION}; +use crate::version::ProtocolVersion; use borsh::{BorshDeserialize, BorshSerialize}; use near_crypto::{KeyType, PublicKey, Signature}; -use near_time::{Clock, Utc}; +use near_time::Utc; use std::sync::Arc; #[derive( @@ -407,6 +407,7 @@ impl BlockHeader { combine_hash(&hash_inner, &prev_hash) } + #[cfg(feature = "clock")] pub fn new( this_epoch_protocol_version: ProtocolVersion, next_epoch_protocol_version: ProtocolVersion, @@ -437,7 +438,7 @@ impl BlockHeader { next_bp_hash: CryptoHash, block_merkle_root: CryptoHash, prev_height: BlockHeight, - clock: Clock, + clock: near_time::Clock, ) -> Self { let inner_lite = BlockHeaderInnerLite { height, @@ -476,7 +477,7 @@ impl BlockHeader { last_final_block, last_ds_final_block, approvals, - latest_protocol_version: PROTOCOL_VERSION, + latest_protocol_version: crate::version::PROTOCOL_VERSION, }; let (hash, signature) = signer.sign_block_header_parts( prev_hash, @@ -508,7 +509,7 @@ impl BlockHeader { last_final_block, last_ds_final_block, approvals, - latest_protocol_version: PROTOCOL_VERSION, + latest_protocol_version: crate::version::PROTOCOL_VERSION, }; let (hash, signature) = signer.sign_block_header_parts( prev_hash, @@ -540,7 +541,10 @@ impl BlockHeader { prev_height, epoch_sync_data_hash, approvals, - latest_protocol_version: get_protocol_version(next_epoch_protocol_version, clock), + latest_protocol_version: crate::version::get_protocol_version( + next_epoch_protocol_version, + clock, + ), }; let (hash, signature) = signer.sign_block_header_parts( prev_hash, @@ -573,7 +577,10 @@ impl BlockHeader { prev_height, epoch_sync_data_hash, approvals, - latest_protocol_version: get_protocol_version(next_epoch_protocol_version, clock), + latest_protocol_version: crate::version::get_protocol_version( + next_epoch_protocol_version, + clock, + ), }; let (hash, signature) = signer.sign_block_header_parts( prev_hash, diff --git a/core/primitives/src/upgrade_schedule.rs b/core/primitives/src/upgrade_schedule.rs index 842db451148..09f55c203b0 100644 --- a/core/primitives/src/upgrade_schedule.rs +++ b/core/primitives/src/upgrade_schedule.rs @@ -100,6 +100,7 @@ impl ProtocolUpgradeVotingSchedule { } /// This method returns the protocol version that the node should vote for. + #[cfg(feature = "clock")] pub(crate) fn get_protocol_version( &self, now: DateTime, diff --git a/core/primitives/src/version.rs b/core/primitives/src/version.rs index da203fa6afc..4a366459749 100644 --- a/core/primitives/src/version.rs +++ b/core/primitives/src/version.rs @@ -1,5 +1,4 @@ use crate::types::Balance; -use near_time::Clock; use once_cell::sync::Lazy; /// Data structure for semver version and github tag or commit. @@ -88,9 +87,10 @@ pub const PROTOCOL_UPGRADE_SCHEDULE: Lazy = Lazy: /// Gives new clients an option to upgrade without announcing that they support /// the new version. This gives non-validator nodes time to upgrade. See /// +#[cfg(feature = "clock")] pub fn get_protocol_version( next_epoch_protocol_version: ProtocolVersion, - clock: Clock, + clock: near_time::Clock, ) -> ProtocolVersion { let now = clock.now_utc(); let chrono = chrono::DateTime::from_timestamp(now.unix_timestamp(), now.nanosecond()); diff --git a/core/primitives/tests/crate-limit-test.rs b/core/primitives/tests/crate-limit-test.rs deleted file mode 100644 index f38242544ad..00000000000 --- a/core/primitives/tests/crate-limit-test.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::collections::HashSet; -use std::process::{Command, Output}; -use std::str; - -// when you compile you see line similar to the next one: -// Building [======= ] 50/100: near-primitives v0.1.0 -// The 100 is not actually the number of dependencies, but the number of crates that are being built. -// This threshhold represents the number of dependencies -const THRESHOLD_DEFAULT: usize = 150; -const THRESHOLD_NO_DEFAULT: usize = 115; - -fn process_output(output: Output, threshold: usize) { - assert!(output.status.success(), "Cargo tree failed"); - - let output_str = str::from_utf8(&output.stdout).expect("Failed to convert output to string"); - - let re = regex::Regex::new(r"([\w-]+) v([\d.]+(?:-\w+)?)").unwrap(); - - let mut unique_crates = HashSet::new(); - - for cap in re.captures_iter(output_str) { - let crate_name = &cap[1]; - let crate_version = &cap[2]; - let crate_str = format!("{}-{}", crate_name, crate_version); - unique_crates.insert(crate_str); - } - println!("{:#?}", unique_crates); - let crate_count = unique_crates.len(); - println!("Unique crate count: {}", crate_count); - - assert!(crate_count < threshold, "Crate count is too high: {} > {}", crate_count, threshold); -} - -#[test] -fn test_crate_count() { - // Run `cargo tree -p near-primitives --edges=normal` and capture the output - let output = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_string())) - .arg("tree") - .arg("-p") - .arg("near-primitives") - .arg("--edges=normal") - .output() - .expect("Failed to execute cargo tree"); - - process_output(output, THRESHOLD_DEFAULT); -} - -#[test] -fn test_crate_count_no_default() { - // Run `cargo tree -p near-primitives --edges=normal` and capture the output - let output = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_string())) - .arg("tree") - .arg("-p") - .arg("near-primitives") - .arg("--no-default-features") - .arg("--edges=normal") - .output() - .expect("Failed to execute cargo tree"); - - process_output(output, THRESHOLD_NO_DEFAULT); -} diff --git a/core/store/Cargo.toml b/core/store/Cargo.toml index 915b0fe040a..4ae2190d87e 100644 --- a/core/store/Cargo.toml +++ b/core/store/Cargo.toml @@ -42,7 +42,7 @@ thiserror.workspace = true tokio.workspace = true tracing.workspace = true -near-async.workspace = true +near-time.workspace = true near-chain-configs = { workspace = true, features = ["metrics"] } near-crypto.workspace = true near-fmt.workspace = true @@ -80,8 +80,8 @@ single_thread_rocksdb = [] # Deactivate RocksDB IO background threads test_features = ["near-vm-runner/test_features"] new_epoch_sync = [] +# TODO(#11639): extract metrics into separate feature nightly_protocol = [ - "near-async/nightly_protocol", "near-chain-configs/nightly_protocol", "near-chain/nightly_protocol", "near-chunks/nightly_protocol", @@ -92,7 +92,6 @@ nightly_protocol = [ "near-vm-runner/nightly_protocol", ] nightly = [ - "near-async/nightly", "near-chain-configs/nightly", "near-chain/nightly", "near-chunks/nightly", @@ -103,6 +102,4 @@ nightly = [ "near-vm-runner/nightly", "nightly_protocol", ] -statelessnet_protocol = [ - "near-primitives/statelessnet_protocol", -] +statelessnet_protocol = ["near-primitives/statelessnet_protocol"] diff --git a/core/store/src/metrics.rs b/core/store/src/metrics.rs index a72506d74f7..dac5cd3279b 100644 --- a/core/store/src/metrics.rs +++ b/core/store/src/metrics.rs @@ -1,12 +1,12 @@ use crate::rocksdb_metrics::export_stats_as_metrics; use crate::{NodeStorage, Store, Temperature}; use actix_rt::ArbiterHandle; -use near_async::time::Duration; use near_o11y::metrics::{ exponential_buckets, try_create_histogram, try_create_histogram_vec, try_create_histogram_with_buckets, try_create_int_counter_vec, try_create_int_gauge, try_create_int_gauge_vec, Histogram, HistogramVec, IntCounterVec, IntGauge, IntGaugeVec, }; +use near_time::Duration; use once_cell::sync::Lazy; pub(crate) static DATABASE_OP_LATENCY_HIST: Lazy = Lazy::new(|| { @@ -584,8 +584,8 @@ mod test { use crate::metadata::{DbKind, DB_VERSION}; use crate::test_utils::create_test_node_storage_with_cold; use actix; - use near_async::time::Duration; use near_o11y::testonly::init_test_logger; + use near_time::Duration; use super::spawn_db_metrics_loop; diff --git a/core/time/Cargo.toml b/core/time/Cargo.toml index fc47f8ae836..f3bcb23119a 100644 --- a/core/time/Cargo.toml +++ b/core/time/Cargo.toml @@ -21,6 +21,5 @@ serde = { workspace = true, optional = true } serde_json.workspace = true [features] -default = ["clock", "serde"] clock = ["tokio", "once_cell"] serde = ["dep:serde", "time/serde"] diff --git a/genesis-tools/genesis-populate/Cargo.toml b/genesis-tools/genesis-populate/Cargo.toml index 4e1a9ab8a6e..f333daf7444 100644 --- a/genesis-tools/genesis-populate/Cargo.toml +++ b/genesis-tools/genesis-populate/Cargo.toml @@ -18,7 +18,7 @@ indicatif.workspace = true tempfile.workspace = true nearcore.workspace = true -near-async.workspace = true +near-time.workspace = true near-chain-configs.workspace = true near-crypto.workspace = true near-epoch-manager.workspace = true @@ -31,7 +31,6 @@ node-runtime.workspace = true [features] nightly_protocol = [ - "near-async/nightly_protocol", "near-chain-configs/nightly_protocol", "near-chain/nightly_protocol", "near-epoch-manager/nightly_protocol", @@ -42,7 +41,6 @@ nightly_protocol = [ "node-runtime/nightly_protocol", ] nightly = [ - "near-async/nightly", "near-chain-configs/nightly", "near-chain/nightly", "near-epoch-manager/nightly", diff --git a/genesis-tools/genesis-populate/src/lib.rs b/genesis-tools/genesis-populate/src/lib.rs index 9bddbedf0ff..62b5096eaf2 100644 --- a/genesis-tools/genesis-populate/src/lib.rs +++ b/genesis-tools/genesis-populate/src/lib.rs @@ -4,7 +4,6 @@ pub mod state_dump; use crate::state_dump::StateDump; use indicatif::{ProgressBar, ProgressStyle}; -use near_async::time::Utc; use near_chain::chain::get_genesis_congestion_infos; use near_chain::types::RuntimeAdapter; use near_chain::{Block, Chain, ChainStore}; @@ -26,6 +25,7 @@ use near_store::genesis::{compute_storage_usage, initialize_genesis_state}; use near_store::{ get_account, get_genesis_state_roots, set_access_key, set_account, set_code, Store, TrieUpdate, }; +use near_time::Utc; use near_vm_runner::logic::ProtocolVersion; use near_vm_runner::ContractCode; use nearcore::{NearConfig, NightshadeRuntime, NightshadeRuntimeExt}; diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index ef82ec6126b..ea94995cc96 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -77,6 +77,7 @@ insta.workspace = true near-undo-block.workspace = true rlp.workspace = true sha3.workspace = true +regex.workspace = true [features] performance_stats = [ diff --git a/integration-tests/src/tests/dependencies.rs b/integration-tests/src/tests/dependencies.rs new file mode 100644 index 00000000000..a1ab72dd7a3 --- /dev/null +++ b/integration-tests/src/tests/dependencies.rs @@ -0,0 +1,106 @@ +/* + * This test is designed to ensure that the public libraries in the project do not exceed a specified number of unique dependencies. + * Please note that this test doesn't care about total compilation units that are displayed during cargo build + * The output of the `cargo build` shows compilation units. Compilation unit is a either a external dependency or a file from the source + * + * The `LIBS_THRESHOLDS` constant defines a list of libraries along with their respective maximum allowed unique dependency counts. + * The `THRESHOLD_IS_TOO_GENEROUS` constant is used to determine if the threshold for any library is too lenient, suggesting it might need to be restricted even futher. + * + * The `get_and_assert_crate_dependencies` function takes a library name and a threshold, runs the `cargo tree` command to get the dependency tree for the library, + * extracts unique dependencies using a regex, and checks if the count of unique dependencies is below the threshold. + * + * The purpose of this test is to maintain a lean dependency graph, promoting better performance, security, and maintainability. + * As well, as limit the total amount of dependencies for public facing libraries + */ + +use std::collections::HashSet; +use std::process::Command; +use std::str; + +const LIBS_THRESHOLDS: [(&str, usize); 9] = [ + ("near-primitives", 115), + ("near-jsonrpc-primitives", 130), + ("near-chain-configs", 130), + ("near-chain-primitives", 130), + ("near-client-primitives", 150), + ("near-parameters", 65), + ("near-crypto", 75), + ("near-primitives-core", 60), + ("near-time", 30), +]; + +const THRESHOLD_IS_TOO_GENEROUS: usize = 30; + +fn get_and_assert_crate_dependencies(name: &str, threshold: usize) -> usize { + let output: std::process::Output = + Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_string())) + .arg("tree") + .arg("-p") + .arg(name) + .arg("--edges=normal") + .output() + .unwrap_or_else(|_| panic!("Failed to execute cargo tree for {name}")); + + assert!( + output.status.success(), + "Cargo tree failed for {name} with: {}", + str::from_utf8(&output.stderr).unwrap() + ); + + let output_str = str::from_utf8(&output.stdout).expect("Failed to convert output to string"); + + // The `cargo tree` command outputs the dependency tree of a given crate. An example line of the output might look like: + // │ ├── actix_derive v0.6.0 (proc-macro) + // This line indicates that the crate `actix_derive` version `0.6.0` is a dependency. + // + // The regex `([\w-]+) v([\d.]+(?:-\w+)?)` is used to extract the crate name and version from each line of the `cargo tree` output. + // - `([\w-]+)` captures the crate name, which can include alphanumeric characters and hyphens. + // - `v` matches the literal character 'v' that precedes the version number. + // - `([\d.]+(?:-\w+)?)` captures the version number, which can include digits, dots, and optional pre-release identifiers. + let re = regex::Regex::new(r"([\w-]+) v([\d.]+(?:-\w+)?)").unwrap(); + + let mut unique_crates = HashSet::new(); + + for cap in re.captures_iter(output_str) { + let crate_name = &cap[1]; + let crate_version = &cap[2]; + let crate_str = format!("{}-{}", crate_name, crate_version); + unique_crates.insert(crate_str); + } + let crate_count = unique_crates.len(); + + assert!( + crate_count < threshold, + "Dependencies number is too high for {name}: {} > {}", + crate_count, + threshold + ); + crate_count +} + +#[derive(Debug, Clone, PartialEq)] +#[allow(unused)] +struct CrateDeps { + pub crate_name: String, + pub crate_deps: usize, + pub suggested_new_threshold: usize, +} + +#[test] +fn test_public_libs_are_small_enough() { + let results = LIBS_THRESHOLDS + .into_iter() + .map(|(name, limit)| (name, get_and_assert_crate_dependencies(name, limit), limit)); + let mut libs_to_fix = vec![]; + for (name, result, limit) in results { + if limit - result > THRESHOLD_IS_TOO_GENEROUS { + libs_to_fix.push(CrateDeps { + crate_name: name.to_owned(), + crate_deps: result, + suggested_new_threshold: result + 10, + }); + } + } + + assert_eq!(libs_to_fix, vec![], "Good job on reducing dependency count, but it's time to review that thresholds for next components"); +} diff --git a/integration-tests/src/tests/mod.rs b/integration-tests/src/tests/mod.rs index cdbbc04fe11..2ad0910d6a2 100644 --- a/integration-tests/src/tests/mod.rs +++ b/integration-tests/src/tests/mod.rs @@ -1,4 +1,5 @@ mod client; +mod dependencies; mod genesis_helpers; mod nearcore; mod nearcore_utils; diff --git a/tools/amend-genesis/Cargo.toml b/tools/amend-genesis/Cargo.toml index c64a4050793..cca0042923d 100644 --- a/tools/amend-genesis/Cargo.toml +++ b/tools/amend-genesis/Cargo.toml @@ -20,11 +20,11 @@ serde.workspace = true serde_json.workspace = true tracing.workspace = true -near-async.workspace = true +near-time.workspace = true near-chain-configs.workspace = true near-crypto.workspace = true near-primitives.workspace = true near-primitives-core.workspace = true [dev-dependencies] -tempfile.workspace = true \ No newline at end of file +tempfile.workspace = true diff --git a/tools/amend-genesis/src/lib.rs b/tools/amend-genesis/src/lib.rs index 47baaff9812..b4b71d9e301 100644 --- a/tools/amend-genesis/src/lib.rs +++ b/tools/amend-genesis/src/lib.rs @@ -430,7 +430,6 @@ pub fn amend_genesis( #[cfg(test)] mod test { use anyhow::Context; - use near_async::time::Clock; use near_chain_configs::{get_initial_supply, Genesis, GenesisConfig, NEAR_BASE}; use near_primitives::hash::CryptoHash; use near_primitives::shard_layout::ShardLayout; @@ -440,6 +439,7 @@ mod test { use near_primitives::version::PROTOCOL_VERSION; use near_primitives_core::account::{AccessKey, Account}; use near_primitives_core::types::{Balance, StorageUsage}; + use near_time::Clock; use num_rational::Rational32; use std::collections::{HashMap, HashSet}; use std::str::FromStr; diff --git a/tools/mock-node/Cargo.toml b/tools/mock-node/Cargo.toml index ef4501f6d59..31d216a96de 100644 --- a/tools/mock-node/Cargo.toml +++ b/tools/mock-node/Cargo.toml @@ -27,7 +27,7 @@ tokio.workspace = true tracing.workspace = true near-actix-test-utils.workspace = true -near-async.workspace = true +near-time.workspace = true near-chain.workspace = true near-chain-configs.workspace = true near-client.workspace = true diff --git a/tools/mock-node/src/lib.rs b/tools/mock-node/src/lib.rs index 0fbe713a66b..c6b026caf3f 100644 --- a/tools/mock-node/src/lib.rs +++ b/tools/mock-node/src/lib.rs @@ -2,7 +2,6 @@ //! components of the mock network. use anyhow::{anyhow, Context as AnyhowContext}; -use near_async::time; use near_chain::{Block, Chain, ChainStoreAccess, Error}; use near_client::sync::header::MAX_BLOCK_HEADERS; use near_crypto::SecretKey; @@ -305,7 +304,7 @@ impl MockPeer { network_start_height, (0..num_shards).collect(), archival, - 30 * time::Duration::SECOND, + 30 * near_time::Duration::SECOND, ) .await?; let incoming_requests = diff --git a/tools/mock-node/src/setup.rs b/tools/mock-node/src/setup.rs index 36de5dc4e38..99dba008def 100644 --- a/tools/mock-node/src/setup.rs +++ b/tools/mock-node/src/setup.rs @@ -2,7 +2,6 @@ use crate::{MockNetworkConfig, MockPeer}; use anyhow::Context; -use near_async::time::Clock; use near_chain::types::RuntimeAdapter; use near_chain::ChainStoreUpdate; use near_chain::{Chain, ChainGenesis, ChainStore, ChainStoreAccess, DoomslugThresholdMode}; @@ -17,6 +16,7 @@ use near_primitives::state_part::PartId; use near_primitives::state_sync::get_num_state_parts; use near_primitives::types::{BlockHeight, NumShards, ShardId}; use near_store::test_utils::create_test_store; +use near_time::Clock; use nearcore::{NearConfig, NightshadeRuntime, NightshadeRuntimeExt}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use std::cmp::min; diff --git a/tools/ping/Cargo.toml b/tools/ping/Cargo.toml index b752b290368..ab1216215e5 100644 --- a/tools/ping/Cargo.toml +++ b/tools/ping/Cargo.toml @@ -21,7 +21,7 @@ prometheus.workspace = true tokio.workspace = true tracing.workspace = true -near-async.workspace = true +near-time.workspace = true near-jsonrpc.workspace = true near-network.workspace = true near-o11y.workspace = true @@ -29,7 +29,6 @@ near-primitives.workspace = true [features] nightly = [ - "near-async/nightly", "near-jsonrpc/nightly", "near-network/nightly", "near-o11y/nightly", @@ -37,7 +36,6 @@ nightly = [ "nightly_protocol", ] nightly_protocol = [ - "near-async/nightly_protocol", "near-jsonrpc/nightly_protocol", "near-network/nightly_protocol", "near-o11y/nightly_protocol", diff --git a/tools/ping/src/csv.rs b/tools/ping/src/csv.rs index d7d9115cc5b..47f0610bde9 100644 --- a/tools/ping/src/csv.rs +++ b/tools/ping/src/csv.rs @@ -1,4 +1,3 @@ -use near_async::time; use near_primitives::network::PeerId; use near_primitives::types::AccountId; use std::fs::{File, OpenOptions}; @@ -74,7 +73,7 @@ impl LatenciesCsv { &mut self, peer_id: &PeerId, account_id: Option<&AccountId>, - latency: time::Duration, + latency: near_time::Duration, ) -> io::Result<()> { let id = account_id.map_or_else(|| format!("{}", peer_id), |a| format!("{}", a)); write!( diff --git a/tools/ping/src/lib.rs b/tools/ping/src/lib.rs index 6d89d2e24ac..5701e0f4549 100644 --- a/tools/ping/src/lib.rs +++ b/tools/ping/src/lib.rs @@ -2,7 +2,6 @@ use actix_web::cookie::time::ext::InstantExt as _; use actix_web::{web, App, HttpServer}; use anyhow::Context; pub use cli::PingCommand; -use near_async::time; use near_network::raw::{ConnectError, Connection, DirectMessage, Message, RoutedMessage}; use near_network::types::HandshakeFailureReason; use near_primitives::hash::CryptoHash; @@ -26,16 +25,16 @@ struct PingStats { pongs_received: usize, // TODO: these latency stats could be separated into time to first byte // + time to last byte, etc. - min_latency: time::Duration, - max_latency: time::Duration, - average_latency: time::Duration, + min_latency: near_time::Duration, + max_latency: near_time::Duration, + average_latency: near_time::Duration, } impl PingStats { - fn pong_received(&mut self, latency: time::Duration) { + fn pong_received(&mut self, latency: near_time::Duration) { self.pongs_received += 1; - if self.min_latency == time::Duration::ZERO || self.min_latency > latency { + if self.min_latency == near_time::Duration::ZERO || self.min_latency > latency { self.min_latency = latency; } if self.max_latency < latency { @@ -51,7 +50,7 @@ type Nonce = u64; #[derive(Debug, Eq, PartialEq)] struct PingTarget { peer_id: PeerId, - last_pinged: Option, + last_pinged: Option, } impl PartialOrd for PingTarget { @@ -81,7 +80,7 @@ impl Ord for PingTarget { struct PingTimeout { peer_id: PeerId, nonce: u64, - timeout: time::Instant, + timeout: near_time::Instant, } impl PartialOrd for PingTimeout { @@ -103,18 +102,18 @@ fn peer_str(peer_id: &PeerId, account_id: Option<&AccountId>) -> String { } const MAX_PINGS_IN_FLIGHT: usize = 10; -const PING_TIMEOUT: time::Duration = time::Duration::seconds(100); +const PING_TIMEOUT: near_time::Duration = near_time::Duration::seconds(100); #[derive(Debug)] struct PingState { stats: PingStats, - last_pinged: Option, + last_pinged: Option, account_id: Option, } struct PingTimes { - sent_at: time::Instant, - timeout: time::Instant, + sent_at: near_time::Instant, + timeout: near_time::Instant, } struct AppInfo { @@ -148,7 +147,7 @@ impl AppInfo { } fn ping_sent(&mut self, peer_id: &PeerId, nonce: u64, chain_id: &str) { - let timestamp = time::Instant::now(); + let timestamp = near_time::Instant::now(); let timeout = timestamp + PING_TIMEOUT; let account_id = self.peer_id_to_account_id(&peer_id); @@ -202,8 +201,8 @@ impl AppInfo { &mut self, peer_id: &PeerId, nonce: u64, - received_at: time::Instant, - ) -> Option<(time::Duration, Option<&AccountId>)> { + received_at: near_time::Instant, + ) -> Option<(near_time::Duration, Option<&AccountId>)> { match self.stats.get_mut(peer_id) { Some(state) => { let pending_pings = self @@ -316,7 +315,7 @@ impl AppInfo { fn handle_message( app_info: &mut AppInfo, msg: Message, - received_at: time::Instant, + received_at: near_time::Instant, latencies_csv: Option<&mut crate::csv::LatenciesCsv>, ) -> anyhow::Result<()> { match msg { @@ -391,7 +390,7 @@ async fn ping_via_node( app_info.add_peer(peer_id.clone(), None); - let clock = time::Clock::real(); + let clock = near_time::Clock::real(); let mut peer = match Connection::connect( &clock, @@ -402,7 +401,7 @@ async fn ping_via_node( genesis_hash, head_height, vec![0], - time::Duration::seconds(recv_timeout_seconds.into())).await { + near_time::Duration::seconds(recv_timeout_seconds.into())).await { Ok(p) => p, Err(ConnectError::HandshakeFailure(reason)) => { match reason { diff --git a/tools/speedy_sync/Cargo.toml b/tools/speedy_sync/Cargo.toml index b74b3feacf3..864dc208844 100644 --- a/tools/speedy_sync/Cargo.toml +++ b/tools/speedy_sync/Cargo.toml @@ -12,7 +12,7 @@ publish = false workspace = true [dependencies] -near-async.workspace = true +near-time.workspace = true near-store.workspace = true near-chain-primitives.workspace = true near-primitives.workspace = true diff --git a/tools/speedy_sync/src/main.rs b/tools/speedy_sync/src/main.rs index d1320a5b6e9..02ad33e590e 100644 --- a/tools/speedy_sync/src/main.rs +++ b/tools/speedy_sync/src/main.rs @@ -1,5 +1,4 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use near_async::time::Clock; use near_chain::rayon_spawner::RayonAsyncComputationSpawner; use near_chain::types::{ChainConfig, Tip}; use near_chain::{Chain, ChainGenesis, DoomslugThresholdMode}; @@ -18,6 +17,7 @@ use near_primitives::types::EpochId; use near_primitives::utils::index_to_bytes; use near_store::HEADER_HEAD_KEY; use near_store::{DBCol, Mode, NodeStorage, Store, StoreUpdate}; +use near_time::Clock; use nearcore::{NightshadeRuntime, NightshadeRuntimeExt}; use std::fs; use std::path::Path; diff --git a/tools/state-parts/Cargo.toml b/tools/state-parts/Cargo.toml index 3265dd758be..48141677696 100644 --- a/tools/state-parts/Cargo.toml +++ b/tools/state-parts/Cargo.toml @@ -21,7 +21,7 @@ time.workspace = true tokio.workspace = true tracing.workspace = true -near-async.workspace = true +near-time.workspace = true near-jsonrpc.workspace = true near-network.workspace = true near-o11y.workspace = true @@ -30,7 +30,6 @@ near-primitives.workspace = true [features] nightly = [ - "near-async/nightly", "near-jsonrpc/nightly", "near-network/nightly", "near-o11y/nightly", @@ -39,7 +38,6 @@ nightly = [ "nightly_protocol", ] nightly_protocol = [ - "near-async/nightly_protocol", "near-jsonrpc/nightly_protocol", "near-network/nightly_protocol", "near-o11y/nightly_protocol", diff --git a/tools/state-parts/src/lib.rs b/tools/state-parts/src/lib.rs index db9f51b591e..616612432eb 100644 --- a/tools/state-parts/src/lib.rs +++ b/tools/state-parts/src/lib.rs @@ -1,12 +1,12 @@ use ::time::ext::InstantExt as _; use anyhow::Context; -use near_async::time::{self, Instant}; use near_network::raw::{ConnectError, Connection, DirectMessage, Message}; use near_network::types::HandshakeFailureReason; use near_primitives::hash::CryptoHash; use near_primitives::network::PeerId; use near_primitives::types::{BlockHeight, ShardId}; use near_primitives::version::ProtocolVersion; +use near_time::Instant; use sha2::Digest; use sha2::Sha256; use std::collections::HashMap; @@ -16,7 +16,7 @@ use std::net::SocketAddr; pub mod cli; struct AppInfo { - pub requests_sent: HashMap, + pub requests_sent: HashMap, } impl AppInfo { @@ -28,7 +28,7 @@ impl AppInfo { fn handle_message( app_info: &mut AppInfo, msg: &Message, - received_at: time::Instant, + received_at: near_time::Instant, ) -> anyhow::Result<()> { match &msg { Message::Direct(DirectMessage::VersionedStateResponse(response)) => { @@ -90,7 +90,7 @@ async fn state_parts_from_node( assert!(start_part_id < num_parts && num_parts > 0, "{}/{}", start_part_id, num_parts); let mut app_info = AppInfo::new(); - let clock = time::Clock::real(); + let clock = near_time::Clock::real(); let mut peer = match Connection::connect( &clock, @@ -101,7 +101,7 @@ async fn state_parts_from_node( genesis_hash, head_height, vec![0], - time::Duration::seconds(recv_timeout_seconds.into())).await { + near_time::Duration::seconds(recv_timeout_seconds.into())).await { Ok(p) => p, Err(ConnectError::HandshakeFailure(reason)) => { match reason { @@ -137,7 +137,7 @@ async fn state_parts_from_node( let msg = DirectMessage::StateRequestPart(shard_id, block_hash, part_id); tracing::info!(target: "state-parts", ?target, shard_id, ?block_hash, part_id, ttl, "Sending a request"); result = peer.send_message(msg).await.with_context(|| format!("Failed sending State Part Request to {:?}", target)); - app_info.requests_sent.insert(part_id, time::Instant::now()); + app_info.requests_sent.insert(part_id, near_time::Instant::now()); tracing::info!(target: "state-parts", ?result); if result.is_err() { break; diff --git a/tools/state-viewer/Cargo.toml b/tools/state-viewer/Cargo.toml index 6d354678d96..7de2eea99e6 100644 --- a/tools/state-viewer/Cargo.toml +++ b/tools/state-viewer/Cargo.toml @@ -35,7 +35,7 @@ thiserror.workspace = true tracing.workspace = true yansi.workspace = true -near-async.workspace = true +near-time.workspace = true near-chain-configs.workspace = true near-chain.workspace = true near-client.workspace = true @@ -67,7 +67,6 @@ protocol_feature_nonrefundable_transfer_nep491 = [ ] nightly = [ - "near-async/nightly", "near-chain-configs/nightly", "near-chain/nightly", "near-client/nightly", @@ -84,7 +83,6 @@ nightly = [ "testlib/nightly", ] nightly_protocol = [ - "near-async/nightly_protocol", "near-chain-configs/nightly_protocol", "near-chain/nightly_protocol", "near-client/nightly_protocol", diff --git a/tools/state-viewer/src/apply_chunk.rs b/tools/state-viewer/src/apply_chunk.rs index 75544296657..c0ffb7468ee 100644 --- a/tools/state-viewer/src/apply_chunk.rs +++ b/tools/state-viewer/src/apply_chunk.rs @@ -482,7 +482,6 @@ pub(crate) fn apply_receipt( #[cfg(test)] mod test { - use near_async::time::Clock; use near_chain::{ChainStore, ChainStoreAccess, Provenance}; use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; @@ -495,6 +494,7 @@ mod test { use near_primitives::utils::get_num_seats_per_shard; use near_store::genesis::initialize_genesis_state; use near_store::test_utils::create_test_store; + use near_time::Clock; use nearcore::NightshadeRuntime; use rand::rngs::StdRng; use rand::SeedableRng; diff --git a/tools/state-viewer/src/latest_witnesses.rs b/tools/state-viewer/src/latest_witnesses.rs index 28baa58d791..634a99ac900 100644 --- a/tools/state-viewer/src/latest_witnesses.rs +++ b/tools/state-viewer/src/latest_witnesses.rs @@ -1,7 +1,6 @@ use std::path::{Path, PathBuf}; use std::rc::Rc; -use near_async::time::Clock; use near_chain::runtime::NightshadeRuntime; use near_chain::stateless_validation::processing_tracker::ProcessingDoneTracker; use near_chain::{Chain, ChainGenesis, ChainStore, DoomslugThresholdMode}; @@ -10,6 +9,7 @@ use near_epoch_manager::EpochManager; use near_primitives::stateless_validation::ChunkStateWitness; use near_primitives::types::EpochId; use near_store::Store; +use near_time::Clock; use nearcore::NearConfig; use nearcore::NightshadeRuntimeExt; diff --git a/tools/state-viewer/src/state_parts.rs b/tools/state-viewer/src/state_parts.rs index f950bdec1b9..742d7319219 100644 --- a/tools/state-viewer/src/state_parts.rs +++ b/tools/state-viewer/src/state_parts.rs @@ -1,6 +1,5 @@ use crate::epoch_info::iterate_and_filter; use borsh::{BorshDeserialize, BorshSerialize}; -use near_async::time::Clock; use near_chain::{Chain, ChainGenesis, ChainStoreAccess, DoomslugThresholdMode}; use near_client::sync::external::{ create_bucket_readonly, create_bucket_readwrite, external_storage_location, @@ -18,6 +17,7 @@ use near_primitives::types::{EpochId, StateRoot}; use near_primitives_core::hash::CryptoHash; use near_primitives_core::types::{BlockHeight, EpochHeight, ShardId}; use near_store::{PartialStorage, Store, Trie}; +use near_time::Clock; use nearcore::{NearConfig, NightshadeRuntime, NightshadeRuntimeExt}; use std::ops::Range; use std::path::{Path, PathBuf};