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
  • Loading branch information
frol committed Feb 3, 2020
1 parent bc71a14 commit 4dd1bd7
Show file tree
Hide file tree
Showing 57 changed files with 617 additions and 476 deletions.
44 changes: 43 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 @@ -34,7 +35,7 @@ use near_store::Store;
use crate::metrics;
use crate::sync::{BlockSync, HeaderSync, StateSync, StateSyncResult};
use crate::types::{Error, ShardSyncDownload};
use crate::{BlockProducer, ClientConfig, SyncStatus};
use crate::{BlockProducer, 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 @@ -14,6 +14,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::{AnnounceAccount, NetworkInfo, PeerId, ReasonForBan, StateResponseInfo};
use near_network::{
Expand All @@ -31,8 +32,8 @@ use crate::client::Client;
use crate::info::InfoHelper;
use crate::sync::{highest_height_peer, StateSyncResult};
use crate::types::{
BlockProducer, ClientConfig, Error, GetNetworkInfo, NetworkInfoResponse, ShardSyncDownload,
ShardSyncStatus, Status, StatusSyncInfo, SyncStatus,
BlockProducer, Error, GetNetworkInfo, NetworkInfoResponse, ShardSyncDownload, ShardSyncStatus,
Status, StatusSyncInfo, SyncStatus,
};
use crate::StatusResponse;
use near_chain::test_utils::format_hash;
Expand Down
3 changes: 2 additions & 1 deletion chain/client/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use serde_json::json;
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, PeerId};
use near_primitives::serialize::to_base;
use near_primitives::types::Version;
use near_telemetry::{telemetry, TelemetryActor};

use crate::types::{BlockProducer, ClientConfig, ShardSyncStatus, SyncStatus};
use crate::types::{BlockProducer, ShardSyncStatus, SyncStatus};
use near_primitives::types::Gas;
use std::cmp::min;

Expand Down
5 changes: 2 additions & 3 deletions chain/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ extern crate lazy_static;
pub use crate::client::Client;
pub use crate::client_actor::ClientActor;
pub use crate::types::{
BlockProducer, ClientConfig, Error, GetBlock, GetChunk, GetGasPrice, GetKeyValueChanges,
GetNetworkInfo, GetNextLightClientBlock, GetValidatorInfo, Query, Status, StatusResponse,
SyncStatus, TxStatus,
BlockProducer, 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 @@ -11,6 +11,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::types::{
AccountOrPeerIdOrHash, NetworkInfo, NetworkViewClientMessages, NetworkViewClientResponses,
Expand All @@ -29,7 +30,7 @@ use near_store::test_utils::create_test_store;
use near_store::Store;
use near_telemetry::TelemetryActor;

use crate::{BlockProducer, Client, ClientActor, ClientConfig, SyncStatus, ViewClientActor};
use crate::{BlockProducer, Client, ClientActor, SyncStatus, ViewClientActor};
use near_network::routing::EdgeInfo;
use near_primitives::hash::{hash, CryptoHash};
use std::ops::Bound::{Excluded, Included, Unbounded};
Expand Down
Loading

0 comments on commit 4dd1bd7

Please sign in to comment.