Skip to content

Commit

Permalink
Merge branch 'main' into convert-time
Browse files Browse the repository at this point in the history
  • Loading branch information
hollermay authored Jun 28, 2024
2 parents 931e72a + b69230b commit 222ec4e
Show file tree
Hide file tree
Showing 172 changed files with 3,426 additions and 4,141 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ parity-scale-codec = { version = "3.6.12", default-features = false }
json5 = "0.4.1"
toml = "0.8.14"

storage = { git = "https://github.com/Erigara/storage.git", rev = "6bd9fdd95220da7626471d190b17b2f5b8815c47" }
storage = { git = "https://github.com/Erigara/storage.git", rev = "cf82588d20494a1c1613ea2f4faa1e66bd827b5c" }

[workspace.lints]
rustdoc.private_doc_tests = "deny"
Expand Down
6 changes: 2 additions & 4 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,16 @@ You may deploy Iroha as a [native binary](#native-binary) or by using [Docker](#

3. Start an Iroha peer.

You can do this either with `--genesis` parameter to specify `genesis.json` location or without. Pay attention that for multi-peer setup only one peer should be started with `--genesis` parameter.

```bash
cd deploy
./irohad --submit-genesis
./irohad
```

### Docker

We provide a sample configuration for Docker in [`docker-compose.yml`](../configs/swarm/docker-compose.yml). We highly recommend that you adjust the `config.json` to include a set of new key pairs.

[Generate the keys](#generating-keys) and put them into `services.*.environment` in `docker-compose.yml`. Don't forget to update the public keys of `TRUSTED_PEERS`.
[Generate the keys](#generating-keys) and put them into `services.*.environment` in `docker-compose.yml`. Don't forget to update the public keys of `SUMERAGI_TRUSTED_PEERS`.

- Build images:

Expand Down
43 changes: 8 additions & 35 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ impl Iroha {
None
}
}.unwrap_or_else(|| {
State::from_config(
config.chain_wide,
State::new(
world,
Arc::clone(&kura),
live_query_store_handle.clone(),
Expand Down Expand Up @@ -614,7 +613,7 @@ pub fn read_config_and_genesis(
None
};

validate_config(&config, args.submit_genesis)?;
validate_config(&config)?;

let logger_config = LoggerInitConfig::new(config.logger, args.terminal_colors);

Expand All @@ -628,7 +627,7 @@ fn read_genesis(path: &Path) -> Result<GenesisBlock, ConfigError> {
Ok(GenesisBlock(genesis))
}

fn validate_config(config: &Config, submit_genesis: bool) -> Result<(), ConfigError> {
fn validate_config(config: &Config) -> Result<(), ConfigError> {
let mut emitter = Emitter::new();

// These cause race condition in tests, due to them actually binding TCP listeners
Expand All @@ -643,13 +642,12 @@ fn validate_config(config: &Config, submit_genesis: bool) -> Result<(), ConfigEr
// maybe validate only if snapshot mode is enabled
validate_directory_path(&mut emitter, &config.snapshot.store_dir);

if !submit_genesis && !config.sumeragi.contains_other_trusted_peers() {
if config.genesis.signed_file.is_none() && !config.sumeragi.contains_other_trusted_peers() {
emitter.emit(Report::new(ConfigError::LonePeer).attach_printable("\
Reason: the network consists from this one peer only (no `sumeragi.trusted_peers` provided).\n\
Since `--submit-genesis` is not set, there is no way to receive the genesis block.\n\
Either provide the genesis by setting `--submit-genesis` argument\n\
and `genesis.signed_file` configuration parameter, or increase the number of trusted peers in\n\
the network using `sumeragi.trusted_peers` configuration parameter.\
Since `genesis.signed_file` is not set, there is no way to receive the genesis block.\n\
Either provide the genesis by setting `genesis.signed_file` configuration parameter,\n\
or increase the number of trusted peers in the network using `sumeragi.trusted_peers` configuration parameter.\
").attach_printable(config.sumeragi.trusted_peers.clone().into_attachment().display_as_debug()));
}

Expand Down Expand Up @@ -771,19 +769,6 @@ pub struct Args {
num_args(0..=1),
)]
pub terminal_colors: bool,
/// Whether the current peer should submit the genesis block or not
///
/// Only one peer in the network should submit the genesis block.
///
/// This argument must be set alongside with `genesis.signed_file` configuration option.
/// If not, Iroha will exit with an error.
///
/// In case when the network consists only of this one peer, i.e. the amount of trusted
/// peers in the configuration (`sumeragi.trusted_peers`) is less than 2, this peer must
/// submit the genesis, since there are no other peers who can provide it. In this case, Iroha
/// will exit with an error if `--submit-genesis` is not set.
#[arg(long)]
pub submit_genesis: bool,
}

#[cfg(test)]
Expand Down Expand Up @@ -879,7 +864,6 @@ mod tests {

let (config, _logger, genesis) = read_config_and_genesis(&Args {
config: Some(config_path),
submit_genesis: true,
terminal_colors: false,
trace_config: false,
})
Expand Down Expand Up @@ -920,28 +904,18 @@ mod tests {
// Given

let genesis_key_pair = KeyPair::random();
let genesis = GenesisBuilder::default().build_and_sign(
dummy_executor(),
ChainId::from("00000000-0000-0000-0000-000000000000"),
&genesis_key_pair,
vec![],
);

let mut config = config_factory(genesis_key_pair.public_key());
iroha_config::base::toml::Writer::new(&mut config)
.write(["genesis", "signed_file"], "./genesis.signed.scale");
iroha_config::base::toml::Writer::new(&mut config);

let dir = tempfile::tempdir()?;
std::fs::write(dir.path().join("config.toml"), toml::to_string(&config)?)?;
std::fs::write(dir.path().join("genesis.signed.scale"), genesis.0.encode())?;
std::fs::write(dir.path().join("executor.wasm"), "")?;
let config_path = dir.path().join("config.toml");

// When & Then

let report = read_config_and_genesis(&Args {
config: Some(config_path),
submit_genesis: false,
terminal_colors: false,
trace_config: false,
})
Expand All @@ -962,7 +936,6 @@ mod tests {
let args = Args::try_parse_from(["test"]).unwrap();

assert_eq!(args.terminal_colors, is_coloring_supported());
assert_eq!(args.submit_genesis, false);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ pub fn get_config_toml(
.write(["sumeragi", "trusted_peers"], peers)
.write(["network", "address"], DEFAULT_P2P_ADDR)
.write(["network", "block_gossip_period_ms"], 500)
.write(["network", "block_gossip_max_size"], 1)
.write(["network", "block_gossip_size"], 1)
.write(["torii", "address"], DEFAULT_TORII_ADDR)
.write(["chain_wide", "max_transactions_in_block"], 2)
.write(["genesis", "public_key"], genesis_public_key)
.write(
["genesis", "signed_file"],
Expand Down
18 changes: 5 additions & 13 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iroha::{
crypto::KeyPair,
data_model::{
events::pipeline::{BlockEventFilter, BlockStatus},
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
parameter::BlockParameter,
prelude::*,
},
};
Expand All @@ -22,7 +22,7 @@ pub struct Config {
pub peers: u32,
/// Interval in microseconds between transactions to reduce load
pub interval_us_per_tx: u64,
pub max_txs_per_block: u32,
pub block_limits: BlockParameter,
pub blocks: u32,
pub sample_size: u32,
pub genesis_max_retries: u32,
Expand All @@ -33,11 +33,7 @@ impl fmt::Display for Config {
write!(
f,
"{}peers-{}interval_µs-{}max_txs-{}blocks-{}samples",
self.peers,
self.interval_us_per_tx,
self.max_txs_per_block,
self.blocks,
self.sample_size,
self.peers, self.interval_us_per_tx, self.block_limits, self.blocks, self.sample_size,
)
}
}
Expand All @@ -55,11 +51,7 @@ impl Config {
let clients = network.clients();
wait_for_genesis_committed_with_max_retries(&clients, 0, self.genesis_max_retries);

client.submit_all_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, self.max_txs_per_block)?
.into_set_parameters(),
)?;
client.submit_blocking(SetParameter::new(Parameter::Block(self.block_limits)))?;

let unit_names = (UnitName::MIN..).take(self.peers as usize);
let units = clients
Expand Down Expand Up @@ -110,7 +102,7 @@ impl Config {

let blocks_out_of_measure = 2 + MeasurerUnit::PREPARATION_BLOCKS_NUMBER * self.peers;
let state_view = network
.genesis
.first_peer
.irohad
.as_ref()
.expect("Must be some")
Expand Down
2 changes: 1 addition & 1 deletion client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn generate_genesis(
.account(signatory_alice.clone())
.asset(
format!("xor-{i}").parse().expect("Valid"),
AssetValueType::Numeric(NumericSpec::default()),
AssetType::Numeric(NumericSpec::default()),
)
.finish_domain();
}
Expand Down
35 changes: 21 additions & 14 deletions client/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//! Example of registering multiple triggers
//! Used to show Iroha's trigger deduplication capabilities
use std::num::NonZeroU64;

use iroha::{
client::Client,
crypto::KeyPair,
data_model::{prelude::*, trigger::TriggerId},
};
use iroha_data_model::parameter::{Parameter, SmartContractParameter};
use iroha_genesis::{GenesisBlock, GenesisBuilder};
use iroha_primitives::unique_vec;
use irohad::samples::{construct_executor, get_config};
Expand All @@ -18,17 +22,24 @@ use tokio::runtime::Runtime;
fn generate_genesis(
num_triggers: u32,
chain_id: ChainId,
genesis_key_pair: &iroha_crypto::KeyPair,
genesis_key_pair: &KeyPair,
topology: Vec<PeerId>,
) -> Result<GenesisBlock, Box<dyn std::error::Error>> {
let builder = GenesisBuilder::default();
let builder = GenesisBuilder::default()
.append_instruction(SetParameter::new(Parameter::Executor(
SmartContractParameter::Fuel(NonZeroU64::MAX),
)))
.append_instruction(SetParameter::new(Parameter::Executor(
SmartContractParameter::Memory(NonZeroU64::MAX),
)));

let wasm =
iroha_wasm_builder::Builder::new("tests/integration/smartcontracts/mint_rose_trigger")
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = iroha_wasm_builder::Builder::new(
"client/tests/integration/smartcontracts/mint_rose_trigger",
)
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);
let (account_id, _account_keypair) = gen_account_in("wonderland");

Expand All @@ -54,7 +65,7 @@ fn generate_genesis(
})
.fold(builder, GenesisBuilder::append_instruction);

let executor = construct_executor("../default_executor").expect("Failed to construct executor");
let executor = construct_executor("default_executor").expect("Failed to construct executor");
Ok(builder.build_and_sign(executor, chain_id, genesis_key_pair, topology))
}

Expand All @@ -64,17 +75,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let chain_id = get_chain_id();
let genesis_key_pair = get_key_pair(test_network::Signatory::Genesis);
let topology = vec![peer.id.clone()];
let mut configuration = get_config(
let configuration = get_config(
unique_vec![peer.id.clone()],
chain_id.clone(),
get_key_pair(test_network::Signatory::Peer),
genesis_key_pair.public_key(),
);

// Increase executor limits for large genesis
configuration.chain_wide.executor_runtime.fuel_limit = u64::MAX;
configuration.chain_wide.executor_runtime.max_memory = u32::MAX.into();

let genesis = generate_genesis(1_000_u32, chain_id, &genesis_key_pair, topology)?;

let builder = PeerBuilder::new()
Expand Down
8 changes: 4 additions & 4 deletions client/examples/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn domain_registration_test(config: Config) -> Result<(), Error> {
use iroha::{
client::Client,
data_model::{
metadata::UnlimitedMetadata,
metadata::Metadata,
prelude::{Domain, DomainId, InstructionBox, Register},
},
};
Expand All @@ -57,7 +57,7 @@ fn domain_registration_test(config: Config) -> Result<(), Error> {

// #region domain_register_example_prepare_tx
// Prepare a transaction
let metadata = UnlimitedMetadata::default();
let metadata = Metadata::default();
let instructions: Vec<InstructionBox> = vec![create_looking_glass.into()];
let tx = iroha.build_transaction(instructions, metadata);
// #endregion domain_register_example_prepare_tx
Expand Down Expand Up @@ -101,7 +101,7 @@ fn account_registration_test(config: Config) -> Result<(), Error> {
client::Client,
crypto::KeyPair,
data_model::{
metadata::UnlimitedMetadata,
metadata::Metadata,
prelude::{Account, AccountId, InstructionBox, Register},
},
};
Expand All @@ -127,7 +127,7 @@ fn account_registration_test(config: Config) -> Result<(), Error> {
// #region register_account_prepare_tx
// Prepare a transaction using the
// Account's RegisterBox
let metadata = UnlimitedMetadata::new();
let metadata = Metadata::default();
let instructions: Vec<InstructionBox> = vec![create_account.into()];
let tx = iroha.build_transaction(instructions, metadata);
// #endregion register_account_prepare_tx
Expand Down
Loading

0 comments on commit 222ec4e

Please sign in to comment.