Skip to content

Commit

Permalink
[feature] #2627, #2589, #2614: Config finalisation, proxy entrypoint,…
Browse files Browse the repository at this point in the history
… kagami docgen

Signed-off-by: Ilia Churin <[email protected]>
  • Loading branch information
ilchu committed Sep 21, 2022
1 parent 085bebc commit 6432890
Show file tree
Hide file tree
Showing 38 changed files with 663 additions and 594 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

13 changes: 7 additions & 6 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use std::{panic, path::PathBuf, sync::Arc};

use color_eyre::eyre::{eyre, Result, WrapErr};
use iroha_actor::{broker::*, prelude::*};
use iroha_config::iroha::Configuration;
use iroha_config::{
base::proxy::{LoadFromDisk, LoadFromEnv},
iroha::{Configuration, ConfigurationProxy},
};
use iroha_core::{
block_sync::{BlockSynchronizer, BlockSynchronizerTrait},
genesis::{GenesisNetwork, GenesisNetworkTrait, RawGenesisBlock},
Expand Down Expand Up @@ -124,11 +127,9 @@ where
query_judge: QueryJudgeBoxed,
) -> Result<Self> {
let broker = Broker::new();
let mut config = match Configuration::from_path(&args.config_path) {
Ok(config) => config,
Err(_) => Configuration::default(),
};
config.load_environment()?;
let mut proxy = ConfigurationProxy::from_path(&args.config_path)?;
proxy.load_environment()?;
let config = proxy.build()?;

let telemetry = iroha_logger::init(&config.logger)?;
iroha_logger::info!("Hyperledgerいろは2にようこそ!");
Expand Down
97 changes: 46 additions & 51 deletions cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
use std::{collections::HashSet, str::FromStr};

use iroha_config::{
block_sync::Configuration as BlockSyncConfiguration,
genesis::Configuration as GenesisConfiguration,
iroha::Configuration,
kura::Configuration as KuraConfiguration,
queue::Configuration as QueueConfiguration,
sumeragi::{Configuration as SumeragiConfiguration, TrustedPeers},
torii::{Configuration as ToriiConfiguration, DEFAULT_TORII_P2P_ADDR},
wasm::Configuration as WasmConfiguration,
wsv::Configuration as WsvConfiguration,
iroha::{Configuration, ConfigurationProxy},
sumeragi::TrustedPeers,
torii::{uri::DEFAULT_API_URL, DEFAULT_TORII_P2P_ADDR, DEFAULT_TORII_TELEMETRY_URL},
};
use iroha_crypto::{KeyPair, PublicKey};
use iroha_data_model::peer::Id as PeerId;
Expand Down Expand Up @@ -65,48 +59,49 @@ pub fn get_config(trusted_peers: HashSet<PeerId>, key_pair: Option<KeyPair>) ->
.into(),
};
iroha_logger::info!(?public_key);
Configuration {
public_key: public_key.clone(),
private_key: private_key.clone(),
kura: KuraConfiguration {
init_mode: iroha_config::kura::Mode::Strict,
..KuraConfiguration::default()
},
sumeragi: SumeragiConfiguration {
key_pair: KeyPair::new(public_key.clone(), private_key.clone())
.expect("Key pair mismatch"),
peer_id: PeerId::new(DEFAULT_TORII_P2P_ADDR, &public_key),
trusted_peers: TrustedPeers {
ConfigurationProxy {
public_key: Some(public_key.clone()),
private_key: Some(private_key.clone()),
sumeragi: Some(iroha_config::sumeragi::ConfigurationProxy {
key_pair: Some(
KeyPair::new(public_key.clone(), private_key.clone()).expect("Key pair mismatch"),
),
peer_id: Some(PeerId::new(DEFAULT_TORII_P2P_ADDR, &public_key)),
trusted_peers: Some(TrustedPeers {
peers: trusted_peers,
},
gossip_period_ms: 500,
..SumeragiConfiguration::default()
},
torii: ToriiConfiguration {
max_transaction_size: 0x8000,
..ToriiConfiguration::default()
},
block_sync: BlockSyncConfiguration {
block_batch_size: 1,
gossip_period_ms: 5000,
..BlockSyncConfiguration::default()
},
queue: QueueConfiguration {
maximum_transactions_in_block: 2,
..QueueConfiguration::default()
},
genesis: GenesisConfiguration {
account_public_key: public_key,
account_private_key: Some(private_key),
..GenesisConfiguration::default()
},
wsv: WsvConfiguration {
wasm_runtime_config: WasmConfiguration {
fuel_limit: 10_000_000,
..WasmConfiguration::default()
},
..WsvConfiguration::default()
},
..Configuration::default()
}),
..iroha_config::sumeragi::ConfigurationProxy::default()
}),
torii: Some(iroha_config::torii::ConfigurationProxy {
p2p_addr: Some(DEFAULT_TORII_P2P_ADDR.to_owned()),
api_url: Some(DEFAULT_API_URL.to_owned()),
telemetry_url: Some(DEFAULT_TORII_TELEMETRY_URL.to_owned()),
max_transaction_size: Some(0x8000),
..iroha_config::torii::ConfigurationProxy::default()
}),
block_sync: Some(iroha_config::block_sync::ConfigurationProxy {
block_batch_size: Some(1),
gossip_period_ms: Some(500),
..iroha_config::block_sync::ConfigurationProxy::default()
}),
queue: Some(iroha_config::queue::ConfigurationProxy {
maximum_transactions_in_block: Some(2),
..iroha_config::queue::ConfigurationProxy::default()
}),
genesis: Some(iroha_config::genesis::ConfigurationProxy {
account_private_key: Some(Some(private_key)),
account_public_key: Some(public_key),
..iroha_config::genesis::ConfigurationProxy::default()
}),
wsv: Some(iroha_config::wsv::ConfigurationProxy {
wasm_runtime_config: Some(iroha_config::wasm::ConfigurationProxy {
fuel_limit: Some(10_000_000),
..iroha_config::wasm::ConfigurationProxy::default()
}),
..iroha_config::wsv::ConfigurationProxy::default()
}),
..ConfigurationProxy::default()
}
.build()
.expect("Iroha config should build as all required fields were provided")
}
53 changes: 42 additions & 11 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,11 @@ mod tests {
#![allow(clippy::restriction)]
use std::str::FromStr;

use iroha_config::client::{BasicAuth, WebLogin};
use iroha_config::{
base::proxy::Builder,
client::{BasicAuth, ConfigurationProxy, WebLogin},
torii::{uri::DEFAULT_API_URL, DEFAULT_TORII_TELEMETRY_URL},
};

use super::*;

Expand All @@ -1375,12 +1379,21 @@ mod tests {
fn txs_same_except_for_nonce_have_different_hashes() {
let (public_key, private_key) = KeyPair::generate().unwrap().into();

let cfg = Configuration {
public_key,
private_key,
add_transaction_nonce: true,
..Configuration::default()
};
let cfg = ConfigurationProxy {
public_key: Some(public_key),
private_key: Some(private_key),
account_id: Some(
"alice@wonderland"
.parse()
.expect("Account ID should not fail"),
),
torii_api_url: Some(SmallStr::from_str(DEFAULT_API_URL)),
torii_telemetry_url: Some(SmallStr::from_str(DEFAULT_TORII_TELEMETRY_URL)),
add_transaction_nonce: Some(true),
..ConfigurationProxy::default()
}
.build()
.expect("Client config should build as all required fields were provided");
let client = Client::new(&cfg).expect("Invalid client configuration");

let build_transaction = || {
Expand All @@ -1404,10 +1417,28 @@ mod tests {
password: SmallStr::from_str(PASSWORD),
};

let cfg = Configuration {
basic_auth: Some(basic_auth),
..Configuration::default()
};
let cfg = ConfigurationProxy {
public_key: Some(
"ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
.parse()
.expect("Public key not in mulithash format"),
),
private_key: Some(iroha_crypto::PrivateKey::from_hex(
iroha_crypto::Algorithm::Ed25519,
"9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0"
).expect("Private key not hex encoded")),
account_id: Some(
"alice@wonderland"
.parse()
.expect("Account ID should not fail"),
),
torii_api_url: Some(SmallStr::from_str(DEFAULT_API_URL)),
torii_telemetry_url: Some(SmallStr::from_str(DEFAULT_TORII_TELEMETRY_URL)),
basic_auth: Some(Some(basic_auth)),
..ConfigurationProxy::default()
}
.build()
.expect("Client config should build as all required fields were provided");
let client = Client::new(&cfg).expect("Invalid client configuration");

let value = client
Expand Down
30 changes: 19 additions & 11 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Crate contains iroha client which talks to iroha network via http
pub use iroha_config::client::Configuration;

/// Module with iroha client itself
pub mod client;
/// Module with general communication primitives like an HTTP request builder.
Expand All @@ -10,21 +8,31 @@ mod http_default;

/// Module containing sample configurations for tests and benchmarks.
pub mod samples {
use iroha_config::torii::uri;
use iroha_config::{
base::proxy::Builder,
client::{Configuration, ConfigurationProxy},
torii::{uri::DEFAULT_API_URL, DEFAULT_TORII_TELEMETRY_URL},
};
use iroha_crypto::KeyPair;

use super::Configuration;
use iroha_primitives::small::SmallStr;

/// Get sample client configuration.
#[allow(clippy::expect_used)]
pub fn get_client_config(key_pair: &KeyPair) -> Configuration {
let (public_key, private_key) = key_pair.clone().into();
Configuration {
public_key,
private_key,
account_id: "alice@wonderland".parse().expect("Should not fail."),
torii_api_url: iroha_primitives::small::SmallStr::from_str(uri::DEFAULT_API_URL),
..Configuration::default()
ConfigurationProxy {
public_key: Some(public_key),
private_key: Some(private_key),
account_id: Some(
"alice@wonderland"
.parse()
.expect("Account ID should not fail"),
),
torii_api_url: Some(SmallStr::from_str(DEFAULT_API_URL)),
torii_telemetry_url: Some(SmallStr::from_str(DEFAULT_TORII_TELEMETRY_URL)),
..ConfigurationProxy::default()
}
.build()
.expect("Client config should build as all required fields were provided")
}
}
18 changes: 12 additions & 6 deletions client/tests/integration/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use test_network::*;

use super::Configuration;
use super::{Builder, Configuration, ConfigurationProxy};

#[test]
fn get_config() {
Expand All @@ -13,10 +13,16 @@ fn get_config() {
let field = test_client.get_config_docs(&["torii"]).unwrap().unwrap();
assert!(field.contains("IROHA_TORII"));

let cfg: Configuration =
serde_json::from_value(test_client.get_config_value().unwrap()).unwrap();
let test = Configuration::test();
assert_eq!(cfg.block_sync, test.block_sync);
assert_eq!(cfg.network, test.network);
assert_eq!(cfg.telemetry, test.telemetry);
let cfg_proxy: ConfigurationProxy =
serde_json::from_value(test_client.get_config_value().unwrap()).unwrap();
assert_eq!(
cfg_proxy.block_sync.unwrap().build().unwrap(),
test.block_sync
);
assert_eq!(cfg_proxy.network.unwrap().build().unwrap(), test.network);
assert_eq!(
cfg_proxy.telemetry.unwrap().build().unwrap(),
test.telemetry
);
}
5 changes: 4 additions & 1 deletion client/tests/integration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pub use iroha_config::iroha::Configuration;
pub use iroha_config::{
base::proxy::Builder,
iroha::{Configuration, ConfigurationProxy},
};

mod add_account;
mod add_domain;
Expand Down
Loading

0 comments on commit 6432890

Please sign in to comment.