Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] #4225: Remove genesis signing #4382

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
26c90f6
Bump actions/checkout from 3 to 4 (#4435)
dependabot[bot] Apr 17, 2024
f8d0650
Bump actions/setup-java from 3.13.0 to 4.2.1 (#4436)
dependabot[bot] Apr 17, 2024
c8468e3
[chore] #4433: Reflect branch changes in files (#4450)
nxsaken Apr 16, 2024
8798ff2
[ci]: Update iroha2 main branch workflows triggers (#4452)
BAStos525 Apr 16, 2024
8390f56
[ci]: Configure Sonarqube and Defectdojo in iroha2 CI (#4414)
BAStos525 Apr 16, 2024
12da055
[feature] add genesis signing to kagami
VAmuzing Mar 20, 2024
978ac38
[fix] somewhat remove private key from everywhere possible
VAmuzing Mar 25, 2024
2dddbc6
[fix] update commit hook sample
VAmuzing Mar 25, 2024
705d6d1
[fix] change how keys deser in kagami crypto
VAmuzing Mar 26, 2024
fa5d753
[fix] address comments related to kagami
VAmuzing Mar 27, 2024
ea4f970
[fix] add all-fields eq check; some renaming
VAmuzing Mar 28, 2024
c35c941
[fix] remove algorithms where it can be derived from keys; minor fixes
VAmuzing Mar 29, 2024
aee24de
[fix] genesis to have 1 transaction: executor
VAmuzing Apr 2, 2024
c8d05c5
[fix] rollback --submit-genesis argument changes
VAmuzing Apr 3, 2024
058cefc
[fix] change how signed genesis is represented; minor fixes
VAmuzing Apr 5, 2024
abb7cb0
[fix] resolve conflicts after rebasing
VAmuzing Apr 11, 2024
1962b7e
[fix] adjust fixture tests
VAmuzing Apr 11, 2024
93b7498
[fix] address comments
VAmuzing Apr 14, 2024
2cef684
[fix] address comments
VAmuzing Apr 14, 2024
8ee6da9
[fix] address comments; add wrapper for genesis signature
VAmuzing Apr 16, 2024
ad1aff7
[fix] remote transparent_api from iroha_genesis; fix swarm/compose; f…
VAmuzing Apr 17, 2024
97e606c
[fix] compose data models; fixture tests
VAmuzing Apr 18, 2024
77117bc
[fix] round of fixes and renames
VAmuzing Apr 21, 2024
255d39c
[fix] change type in configs from string to GenesisSignatureConfig; c…
VAmuzing Apr 23, 2024
8e920f1
[fix] add parameters to swarm; fix docker-compose files and consisten…
VAmuzing Apr 24, 2024
077d5a6
[fix] after rebasing
VAmuzing Apr 24, 2024
8b515f4
Merge branch 'main' into remove_genesis_signing
VAmuzing Apr 24, 2024
d15bda1
[fix] attempt to fix broken branch
VAmuzing Apr 24, 2024
98606e0
[fix] fix compile error; add custom serialization for tests
VAmuzing Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/Cargo.toml
Expand Up @@ -61,6 +61,7 @@ tokio = { workspace = true, features = ["macros", "signal"] }
once_cell = { workspace = true }
owo-colors = { workspace = true, features = ["supports-colors"] }
supports-color = { workspace = true }
serde_json = { workspace = true }

thread-local-panic-hook = { version = "0.1.0", optional = true }

Expand Down
64 changes: 44 additions & 20 deletions cli/src/lib.rs
Expand Up @@ -521,14 +521,18 @@ pub fn read_config_and_genesis(
)
.wrap_err("failed to load configuration")?;

let genesis = if let Genesis::Full { key_pair, file } = &config.genesis {
let raw_block = RawGenesisBlock::from_path(file)?;

Some(GenesisNetwork::new(
raw_block,
&config.common.chain_id,
key_pair,
))
let genesis = if let Genesis::Full {
public_key: _,
file,
signature: signature_config,
} = &config.genesis
{
let raw_genesis = RawGenesisBlock::from_path(file)?;

Some(GenesisNetwork::try_parse(
raw_genesis,
signature_config.clone().into_genesis_signature(),
)?)
} else {
None
};
Expand Down Expand Up @@ -637,7 +641,9 @@ mod tests {
use std::path::PathBuf;

use assertables::{assert_contains, assert_contains_as_result};
use iroha_config::parameters::user::RootPartial as PartialUserConfig;
use iroha_config::parameters::{
actual::GenesisSignatureConfig, user::RootPartial as PartialUserConfig,
};
use iroha_crypto::KeyPair;
use iroha_primitives::addr::socket_addr;
use path_absolutize::Absolutize as _;
Expand All @@ -654,8 +660,7 @@ mod tests {
base.private_key.set(privkey.clone());
base.network.address.set(socket_addr!(127.0.0.1:1337));

base.genesis.public_key.set(pubkey);
base.genesis.private_key.set(privkey);
base.genesis.public_key.set(pubkey.clone());

base.torii.address.set(socket_addr!(127.0.0.1:8080));

Expand All @@ -680,28 +685,47 @@ mod tests {
fn relative_file_paths_resolution() -> Result<()> {
// Given

let dir = tempfile::tempdir()?;

let genesis = RawGenesisBlockBuilder::default()
.executor_file(PathBuf::from("./executor.wasm"))
.executor_file(PathBuf::from(
dir.path().join("config/genesis/executor.wasm"),
))
.build();

let genesis_path = dir.path().join("config/genesis/gen.json");
let executor_path = dir.path().join("config/genesis/executor.wasm");
let config_path = dir.path().join("config/config.toml");
std::fs::create_dir(dir.path().join("config"))?;
std::fs::create_dir(dir.path().join("config/genesis"))?;
std::fs::write(genesis_path, json5::to_string(&genesis)?)?;
std::fs::write(executor_path, "")?;

let config = {
let mut cfg = config_factory();
cfg.genesis.file.set("./genesis/gen.json".into());

let keypair = KeyPair::new(
cfg.public_key.clone().get().unwrap(),
cfg.private_key.clone().get().unwrap(),
)?;
let genesis_block = RawGenesisBlock::try_from(genesis.clone())?;
let genesis_signature = GenesisNetwork::new_genesis_signature(
genesis_block,
&cfg.chain_id.clone().get().unwrap(),
&keypair,
);
cfg.genesis
.signature
.set(GenesisSignatureConfig::new(genesis_signature));

cfg.kura.store_dir.set("../storage".into());
cfg.snapshot.store_dir.set("../snapshots".into());
cfg.dev_telemetry.out_file.set("../logs/telemetry".into());
config_to_toml_value(cfg)?
};

let dir = tempfile::tempdir()?;
let genesis_path = dir.path().join("config/genesis/gen.json");
let executor_path = dir.path().join("config/genesis/executor.wasm");
let config_path = dir.path().join("config/config.toml");
std::fs::create_dir(dir.path().join("config"))?;
std::fs::create_dir(dir.path().join("config/genesis"))?;
std::fs::write(config_path, toml::to_string(&config)?)?;
std::fs::write(genesis_path, json5::to_string(&genesis)?)?;
std::fs::write(executor_path, "")?;

let config_path = dir.path().join("config/config.toml");

Expand Down
12 changes: 9 additions & 3 deletions cli/src/samples.rs
Expand Up @@ -4,13 +4,14 @@ use std::{collections::HashSet, path::Path, str::FromStr, time::Duration};
use iroha_config::{
base::{HumanDuration, UnwrapPartial},
parameters::{
actual::Root as Config,
actual::{GenesisSignatureConfig, Root as Config},
user::{CliContext, RootPartial as UserConfig},
},
snapshot::Mode as SnapshotMode,
};
use iroha_crypto::{KeyPair, PublicKey};
use iroha_data_model::{peer::PeerId, prelude::*, ChainId};
use iroha_genesis::GenesisSignature;
use iroha_primitives::{
addr::{socket_addr, SocketAddr},
unique_vec::UniqueVec,
Expand Down Expand Up @@ -63,6 +64,7 @@ pub fn get_user_config(
peers: &UniqueVec<PeerId>,
chain_id: Option<ChainId>,
key_pair: Option<KeyPair>,
genesis_signature: &GenesisSignature,
) -> UserConfig {
let chain_id = chain_id.unwrap_or_else(|| ChainId::from("0"));

Expand All @@ -89,9 +91,12 @@ pub fn get_user_config(
.network
.block_gossip_period
.set(HumanDuration(Duration::from_millis(500)));
config.genesis.private_key.set(private_key);
config.genesis.public_key.set(public_key);
config.genesis.file.set("./genesis.json".into());
config
.genesis
.signature
.set(GenesisSignatureConfig::new(genesis_signature.clone()));
// There is no need in persistency in tests
// If required to should be set explicitly not to overlap with other existing tests
config.snapshot.mode.set(SnapshotMode::Disabled);
Expand All @@ -110,8 +115,9 @@ pub fn get_config(
trusted_peers: &UniqueVec<PeerId>,
chain_id: Option<ChainId>,
key_pair: Option<KeyPair>,
genesis_signature: &GenesisSignature,
) -> Config {
get_user_config(trusted_peers, chain_id, key_pair)
get_user_config(trusted_peers, chain_id, key_pair, genesis_signature)
.unwrap_partial()
.expect("config should build as all required fields were provided")
.parse(CliContext {
Expand Down
16 changes: 7 additions & 9 deletions client/benches/torii.rs
Expand Up @@ -12,7 +12,9 @@ use iroha_client::{
use iroha_genesis::{GenesisNetwork, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use iroha_version::Encode;
use test_network::{get_chain_id, get_key_pair, Peer as TestPeer, PeerBuilder, TestRuntime};
use test_network::{
get_chain_id, get_genesis_signature, get_key_pair, Peer as TestPeer, PeerBuilder, TestRuntime,
};
use tokio::runtime::Runtime;

const MINIMUM_SUCCESS_REQUEST_RATIO: f32 = 0.9;
Expand All @@ -25,6 +27,7 @@ fn query_requests(criterion: &mut Criterion) {
&unique_vec![peer.id.clone()],
Some(chain_id.clone()),
Some(get_key_pair()),
&get_genesis_signature(),
);

let rt = Runtime::test();
Expand All @@ -41,10 +44,7 @@ fn query_requests(criterion: &mut Criterion) {
)
.build(),
&chain_id,
configuration
.genesis
.key_pair()
.expect("genesis config should be full, probably a bug"),
&get_key_pair(),
);

let builder = PeerBuilder::new()
Expand Down Expand Up @@ -133,6 +133,7 @@ fn instruction_submits(criterion: &mut Criterion) {
&unique_vec![peer.id.clone()],
Some(chain_id.clone()),
Some(get_key_pair()),
&get_genesis_signature(),
);
let genesis = GenesisNetwork::new(
RawGenesisBlockBuilder::default()
Expand All @@ -147,10 +148,7 @@ fn instruction_submits(criterion: &mut Criterion) {
)
.build(),
&chain_id,
configuration
.genesis
.key_pair()
.expect("config should be full; probably a bug"),
&get_key_pair(),
);
let builder = PeerBuilder::new()
.with_config(configuration)
Expand Down
30 changes: 14 additions & 16 deletions client/examples/million_accounts_genesis.rs
Expand Up @@ -8,12 +8,12 @@ use iroha_data_model::isi::InstructionBox;
use iroha_genesis::{GenesisNetwork, RawGenesisBlock, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use test_network::{
get_chain_id, get_key_pair, wait_for_genesis_committed, Peer as TestPeer, PeerBuilder,
TestRuntime,
get_chain_id, get_genesis_signature, get_key_pair, wait_for_genesis_committed,
Peer as TestPeer, PeerBuilder, TestRuntime,
};
use tokio::runtime::Runtime;

fn generate_genesis(num_domains: u32) -> RawGenesisBlock {
fn generate_genesis(num_domains: u32) -> (RawGenesisBlock, KeyPair) {
let mut builder = RawGenesisBlockBuilder::default();

let key_pair = get_key_pair();
Expand All @@ -31,11 +31,14 @@ fn generate_genesis(num_domains: u32) -> RawGenesisBlock {
.finish_domain();
}

builder
.executor_blob(
construct_executor("../default_executor").expect("Failed to construct executor"),
)
.build()
(
builder
.executor_blob(
construct_executor("../default_executor").expect("Failed to construct executor"),
)
.build(),
key_pair,
)
}

fn main_genesis() {
Expand All @@ -46,16 +49,11 @@ fn main_genesis() {
&unique_vec![peer.id.clone()],
Some(chain_id.clone()),
Some(get_key_pair()),
&get_genesis_signature(),
);
let rt = Runtime::test();
let genesis = GenesisNetwork::new(
generate_genesis(1_000_000_u32),
&chain_id,
configuration
.genesis
.key_pair()
.expect("should be available in the config; probably a bug"),
);
let (genesis, key_pair) = generate_genesis(1_000_000_u32);
let genesis = GenesisNetwork::new(genesis, &chain_id, &key_pair);

let builder = PeerBuilder::new()
.with_into_genesis(genesis)
Expand Down
2 changes: 1 addition & 1 deletion config/iroha_test_config.toml
Expand Up @@ -8,7 +8,7 @@ address = "127.0.0.1:1337"
[genesis]
public_key = "ed01204CFFD0EE429B1BDD36B3910EC570852B8BB63F18750341772FB46BC856C5CAAF"
file = "./genesis.json"
private_key = { algorithm = "ed25519", payload = "D748E18CE60CB30DEA3E73C9019B7AF45A8D465E3D71BCC9A5EF99A008205E534CFFD0EE429B1BDD36B3910EC570852B8BB63F18750341772FB46BC856C5CAAF" }
0x009922 marked this conversation as resolved.
Show resolved Hide resolved
signature = "04306dab1d6600000000404890140400804cffd0ee429b1bdd36b3910ec570852b8bb63f18750341772fb46bc856c5caaf010167b7a7476889cccf49ed2adc1ceb8d5e09d9bed237a71e5bd18fcd90c5de2a45c17db202d2be0e9d961a41e9a7d6590f14247c184ac41dd1cc0413051ca13d06"

[torii]
address = "127.0.0.1:8080"
Expand Down
45 changes: 32 additions & 13 deletions config/src/parameters/actual.rs
Expand Up @@ -4,6 +4,7 @@
use std::{
num::NonZeroU32,
path::{Path, PathBuf},
str::FromStr,
time::Duration,
};

Expand Down Expand Up @@ -90,6 +91,31 @@ pub struct Network {
pub idle_timeout: Duration,
}

/// Wrapper around `iroha_genesis::GenesisSignature` for type-checking
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct GenesisSignatureConfig(iroha_genesis::GenesisSignature);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a newtype needed to handle parsing of GenesisSignature from the user-provided format. It's place more in the parameters::user IMO.


impl GenesisSignatureConfig {
/// Constructs `GenesisSignatureConfig` from `GenesisSignature`
pub fn new(genesis_signature: iroha_genesis::GenesisSignature) -> Self {
Self(genesis_signature)
}
/// Converts `GenesisSignatureConfig` into `iroha_genesis::GenesisSignature`
pub fn into_genesis_signature(self) -> iroha_genesis::GenesisSignature {
self.0
}
Comment on lines +104 to +106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn into_genesis_signature(self) -> iroha_genesis::GenesisSignature {
self.0
}
pub fn into_inner(self) -> iroha_genesis::GenesisSignature {
self.0
}

}

impl FromStr for GenesisSignatureConfig {
type Err = iroha_genesis::GenesisSignatureParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(GenesisSignatureConfig(
iroha_genesis::GenesisSignature::from_hex_string(&s.as_bytes())?,
))
}
}

/// Parsed genesis configuration
#[derive(Debug, Clone)]
pub enum Genesis {
Expand All @@ -100,27 +126,20 @@ pub enum Genesis {
},
/// The peer is responsible for submitting the genesis block
Full {
/// Genesis account key pair
key_pair: KeyPair,
/// Path to the [`RawGenesisBlock`]
/// Genesis account public key
public_key: PublicKey,
/// Path to the genesis file
file: PathBuf,
/// Genesis signature config with the data to reconstruct signed genesis block
signature: GenesisSignatureConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameters::actual is exposed to the rest of Iroha. Those places don't really need to know about config parsing details.

Suggested change
signature: GenesisSignatureConfig,
signature: iroha_genesis::GenesisSignature,

},
}

impl Genesis {
/// Access the public key, which is always present in the genesis config
pub fn public_key(&self) -> &PublicKey {
match self {
Self::Partial { public_key } => public_key,
Self::Full { key_pair, .. } => key_pair.public_key(),
}
}

/// Access the key pair, if present
pub fn key_pair(&self) -> Option<&KeyPair> {
match self {
Self::Partial { .. } => None,
Self::Full { key_pair, .. } => Some(key_pair),
Self::Full { public_key, .. } | Self::Partial { public_key } => public_key,
}
}
}
Expand Down