Skip to content

Commit

Permalink
Refactored *Configs into separate crates to resolve dependency cycles…
Browse files Browse the repository at this point in the history
… for #2007

PR #2078
  • Loading branch information
frol authored Feb 7, 2020
1 parent 499b0b5 commit 4799d0a
Show file tree
Hide file tree
Showing 55 changed files with 704 additions and 493 deletions.
56 changes: 55 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ edition = "2018"

[workspace]
members = [
"core/chain-configs",
"core/crypto",
"core/primitives",
"core/runtime-configs",
"core/store",
"core/metrics",
"runtime/runtime",
Expand Down Expand Up @@ -47,6 +49,7 @@ serde_json = "1.0.0"
reqwest = "0.10"
futures = "0.3"

near-chain-configs = { path = "./core/chain-configs" }
near-crypto = { path = "./core/crypto" }
near-primitives = { path = "./core/primitives" }
near-store = { path = "./core/store" }
Expand Down
1 change: 1 addition & 0 deletions chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lazy_static = "1.4"

borsh = "0.2.10"

near-chain-configs = { path = "../../core/chain-configs" }
near-crypto = { path = "../../core/crypto" }
near-primitives = { path = "../../core/primitives" }
near-store = { path = "../../core/store" }
Expand Down
16 changes: 16 additions & 0 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use chrono::prelude::{DateTime, Utc};
use chrono::Duration;
use log::{debug, error, info};

use near_chain_configs::GenesisConfig;
use near_primitives::block::{genesis_chunks, Approval};
use near_primitives::challenge::{
BlockDoubleSign, Challenge, ChallengeBody, ChallengesResult, ChunkProofs, ChunkState,
Expand Down Expand Up @@ -209,6 +210,21 @@ impl ChainGenesis {
}
}

impl From<GenesisConfig> for ChainGenesis {
fn from(genesis_config: GenesisConfig) -> Self {
ChainGenesis::new(
genesis_config.genesis_time,
genesis_config.gas_limit,
genesis_config.min_gas_price,
genesis_config.total_supply,
genesis_config.max_inflation_rate,
genesis_config.gas_price_adjustment_rate,
genesis_config.transaction_validity_period,
genesis_config.epoch_length,
)
}
}

/// Facade to the blockchain block processing and storage.
/// Provides current view on the state according to the chain state.
pub struct Chain {
Expand Down
1 change: 1 addition & 0 deletions chain/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ near-crypto = { path = "../../core/crypto" }
near-primitives = { path = "../../core/primitives" }
near-store = { path = "../../core/store" }
near-metrics = { path = "../../core/metrics" }
near-chain-configs = { path = "../../core/chain-configs" }
near-chain = { path = "../chain" }
near-network = { path = "../network" }
near-pool = { path = "../pool" }
Expand Down
3 changes: 2 additions & 1 deletion chain/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use near_chain::{
BlockStatus, Chain, ChainGenesis, ChainStoreAccess, Doomslug, DoomslugThresholdMode,
Provenance, RuntimeAdapter, Tip,
};
use near_chain_configs::ClientConfig;
use near_chunks::{ProcessPartialEncodedChunkResult, ShardsManager};
use near_network::{FullPeerInfo, NetworkAdapter, NetworkClientResponses, NetworkRequests};
use near_primitives::block::{Approval, ApprovalMessage, Block, BlockHeader};
Expand All @@ -35,7 +36,7 @@ use near_store::Store;
use crate::metrics;
use crate::sync::{BlockSync, HeaderSync, StateSync, StateSyncResult};
use crate::types::{Error, ShardSyncDownload};
use crate::{ClientConfig, SyncStatus};
use crate::SyncStatus;

pub struct Client {
pub config: ClientConfig,
Expand Down
5 changes: 3 additions & 2 deletions chain/client/src/client_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use near_chain::{
byzantine_assert, Block, BlockHeader, ChainGenesis, ChainStoreAccess, ErrorKind, Provenance,
RuntimeAdapter,
};
use near_chain_configs::ClientConfig;
use near_crypto::Signature;
use near_network::types::{NetworkInfo, ReasonForBan, StateResponseInfo};
use near_network::{
Expand All @@ -34,8 +35,8 @@ use crate::client::Client;
use crate::info::InfoHelper;
use crate::sync::{highest_height_peer, StateSyncResult};
use crate::types::{
ClientConfig, Error, GetNetworkInfo, NetworkInfoResponse, ShardSyncDownload, ShardSyncStatus,
Status, StatusSyncInfo, SyncStatus,
Error, GetNetworkInfo, NetworkInfoResponse, ShardSyncDownload, ShardSyncStatus, Status,
StatusSyncInfo, SyncStatus,
};
use crate::StatusResponse;

Expand Down
10 changes: 6 additions & 4 deletions chain/client/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ use log::info;
use sysinfo::{get_current_pid, set_open_files_limit, Pid, ProcessExt, System, SystemExt};

use near_chain::Tip;
use near_chain_configs::ClientConfig;
use near_network::types::NetworkInfo;
use near_primitives::network::PeerId;
use near_primitives::serialize::to_base;
use near_primitives::telemetry::{
TelemetryAgentInfo, TelemetryChainInfo, TelemetryInfo, TelemetrySystemInfo,
};
use near_primitives::types::Gas;
use near_primitives::types::Version;
use near_primitives::validator_signer::ValidatorSigner;
use near_telemetry::{telemetry, TelemetryActor};

use crate::types::{ClientConfig, ShardSyncStatus, SyncStatus};
use near_primitives::telemetry::{
TelemetryAgentInfo, TelemetryChainInfo, TelemetryInfo, TelemetrySystemInfo,
};
use crate::types::ShardSyncStatus;
use crate::SyncStatus;

/// A helper that prints information about current chain and reports to telemetry.
pub struct InfoHelper {
Expand Down
2 changes: 1 addition & 1 deletion chain/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate lazy_static;
pub use crate::client::Client;
pub use crate::client_actor::ClientActor;
pub use crate::types::{
ClientConfig, Error, GetBlock, GetChunk, GetGasPrice, GetKeyValueChanges, GetNetworkInfo,
Error, GetBlock, GetChunk, GetGasPrice, GetKeyValueChanges, GetNetworkInfo,
GetNextLightClientBlock, GetValidatorInfo, Query, Status, StatusResponse, SyncStatus, TxStatus,
};
pub use crate::view_client::ViewClientActor;
Expand Down
3 changes: 2 additions & 1 deletion chain/client/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rand::{thread_rng, Rng};

use near_chain::test_utils::KeyValueRuntime;
use near_chain::{Chain, ChainGenesis, DoomslugThresholdMode, Provenance, RuntimeAdapter};
use near_chain_configs::ClientConfig;
use near_crypto::{InMemorySigner, KeyType, PublicKey};
use near_network::routing::EdgeInfo;
use near_network::types::{
Expand All @@ -33,7 +34,7 @@ use near_store::test_utils::create_test_store;
use near_store::Store;
use near_telemetry::TelemetryActor;

use crate::{Client, ClientActor, ClientConfig, SyncStatus, ViewClientActor};
use crate::{Client, ClientActor, SyncStatus, ViewClientActor};

pub type NetworkMock = Mocker<PeerManagerActor>;

Expand Down
Loading

0 comments on commit 4799d0a

Please sign in to comment.