diff --git a/end2end-tests/cucumber-genesis/default.json b/end2end-tests/cucumber-genesis/default.json index 8d87f47301c2caded6cdb38b939f483849685136..e5b5b1e1bd679963e20c3d51a07583ccab08deff 100644 --- a/end2end-tests/cucumber-genesis/default.json +++ b/end2end-tests/cucumber-genesis/default.json @@ -59,7 +59,7 @@ "wot_min_cert_for_create_idty_right": 2, "wot_min_cert_for_membership": 2 }, - "smiths": [ + "clique_smiths": [ { "name": "Alice" }, { "name": "Bob" }, { "name": "Charlie" } diff --git a/end2end-tests/cucumber-genesis/wot.json b/end2end-tests/cucumber-genesis/wot.json index 165d69866fcae060310bf59c56e8844661f150e2..e9a53a4f3d6652de5e9329086c0e9aefb60fc270 100644 --- a/end2end-tests/cucumber-genesis/wot.json +++ b/end2end-tests/cucumber-genesis/wot.json @@ -65,7 +65,7 @@ "wot_min_cert_for_create_idty_right": 2, "wot_min_cert_for_membership": 2 }, - "smiths": [ + "clique_smiths": [ { "name": "Alice" }, { "name": "Bob" }, { "name": "Charlie" } diff --git a/node/src/chain_spec/gen_genesis_data.rs b/node/src/chain_spec/gen_genesis_data.rs index e25f2c9fcf6146e69625a39151deae5bfbf2e148..6c7628cf61cbdabc813e2ee4c5d3e56a8af1d4cc 100644 --- a/node/src/chain_spec/gen_genesis_data.rs +++ b/node/src/chain_spec/gen_genesis_data.rs @@ -62,12 +62,20 @@ struct GenesisConfig<Parameters> { #[serde(default)] parameters: Parameters, #[serde(rename = "smiths")] - smith_identities: Vec<SmithData>, + smith_identities: Option<BTreeMap<String, SmithData>>, + clique_smiths: Option<Vec<CliqueSmith>>, sudo_key: Option<AccountId>, technical_committee: Vec<String>, ud: u64, } +#[derive(Deserialize, Serialize)] +pub struct GenesisIndexerExport { + first_ud: Option<u64>, + first_ud_reeval: Option<u64>, + ud: u64, +} + #[derive(Deserialize, Serialize)] struct GenesisMigrationData { identities: BTreeMap<String, Idty>, @@ -90,6 +98,14 @@ struct Idty { struct SmithData { name: String, session_keys: Option<String>, + #[serde(default)] + certs: Vec<Cert>, +} + +#[derive(Clone, Deserialize, Serialize)] +struct CliqueSmith { + name: String, + session_keys: Option<String>, } #[derive(Clone, Deserialize, Serialize)] @@ -135,7 +151,8 @@ where }, parameters, // identities, - smith_identities, + mut smith_identities, + mut clique_smiths, technical_committee, ud, // wallets, @@ -143,6 +160,12 @@ where std::env::var("DUNITER_GENESIS_CONFIG").unwrap_or_else(|_| json_file_path.to_owned()), )?; + if smith_identities.is_some() && clique_smiths.is_some() { + return Err(format!( + "'smiths' and 'clique_smiths' cannot be both defined at the same time" + )); + } + let GenesisMigrationData { mut identities, wallets, @@ -297,7 +320,7 @@ where certs_by_receiver.remove(&idty_index); }); - // SMITHSÂ SUB-WOT // + // SMITHS SUB-WOT // let mut initial_authorities = BTreeMap::new(); let mut online_authorities_counter = 0; @@ -313,10 +336,33 @@ where .expect("Initial authority must have an identity") .to_owned() }); + + let is_clique = clique_smiths.is_some(); + // Create a single source of smiths + let smiths = if let Some(clique) = &clique_smiths { + // From a clique + clique + .into_iter() + .map(|smith| SmithData { + name: smith.name.clone(), + session_keys: smith.session_keys.clone(), + certs: vec![], + }) + .collect::<Vec<SmithData>>() + } else { + // From explicit smith WoT + smith_identities + .expect("existence has been tested earlier") + .into_iter() + .map(|(_, smith)| smith) + .collect::<Vec<SmithData>>() + }; + // Then create the smith WoT for SmithData { name: idty_name, session_keys, - } in &smith_identities + certs, + } in &smiths { let idty_index = idty_index_of .get(idty_name) @@ -374,17 +420,29 @@ where // Certifications let mut receiver_certs = BTreeMap::new(); - // All initial smiths are considered to be certifying all each other - smith_identities - .iter() - .filter(|s| s.name.to_owned() != *idty_name) - .for_each(|other_smith| { + if is_clique { + // All initial smiths are considered to be certifying all each other + clique_smiths + .as_ref() + .unwrap() + .iter() + .filter(|smith| *smith.name.as_str() != *idty_name) + .for_each(|other_smith| { + let issuer_index = idty_index_of + .get(&other_smith.name) + .ok_or(format!("Identity '{}' not exist", other_smith.name)) + .unwrap(); + receiver_certs.insert(*issuer_index, None); + }); + } else { + for cert in certs { + let (issuer, maybe_expire_on) = cert.clone().into(); let issuer_index = idty_index_of - .get(&other_smith.name) - .ok_or(format!("Identity '{}' not exist", other_smith.name)) - .unwrap(); - receiver_certs.insert(*issuer_index, None); // TODO: put duration - }); + .get(&issuer) + .ok_or(format!("Identity '{}' not exist", issuer))?; + receiver_certs.insert(*issuer_index, maybe_expire_on); + } + } smith_certs_by_receiver.insert(*idty_index, receiver_certs); // Memberships @@ -657,22 +715,16 @@ fn get_genesis_config<P: Default + DeserializeOwned>( } fn get_genesis_migration_data() -> Result<GenesisMigrationData, String> { - if let Ok(json_file_path) = std::env::var("DUNITER_GENESIS_DATA") { - let file = std::fs::File::open(&json_file_path) - .map_err(|e| format!("Error opening gen conf file `{}`: {}", json_file_path, e))?; - let bytes = unsafe { - memmap2::Mmap::map(&file) - .map_err(|e| format!("Error mmaping gen conf file `{}`: {}", json_file_path, e))? - }; - serde_json::from_slice::<GenesisMigrationData>(&bytes) - .map_err(|e| format!("Error parsing gen conf file: {}", e)) - } else { - // No data - Ok(GenesisMigrationData { - wallets: btreemap! {}, - identities: btreemap! {}, - }) - } + let json_file_path = + std::env::var("DUNITER_GENESIS_DATA").unwrap_or("./resources/g1-data.json".to_owned()); + let file = std::fs::File::open(&json_file_path) + .map_err(|e| format!("Error opening gen conf file `{}`: {}", json_file_path, e))?; + let bytes = unsafe { + memmap2::Mmap::map(&file) + .map_err(|e| format!("Error mmaping gen conf file `{}`: {}", json_file_path, e))? + }; + serde_json::from_slice::<GenesisMigrationData>(&bytes) + .map_err(|e| format!("Error parsing gen conf file: {}", e)) } fn get_genesis_timestamp() -> Result<u64, String> { diff --git a/resources/gdev.json b/resources/gdev.json index 03060c22659e8c4267be5bbe15759c68e26d92f6..33c3b5042e2466e3b27545d6261b62c5d9348b13 100644 --- a/resources/gdev.json +++ b/resources/gdev.json @@ -34,7 +34,7 @@ "wot_min_cert_for_create_idty_right": 3, "wot_min_cert_for_membership": 3 }, - "smiths": [ + "clique_smiths": [ { "name": "Pini" }, { "name": "moul" }, { "name": "HugoTrentesaux" }, @@ -42,7 +42,9 @@ { "name": "1000i100" }, { "name": "vit" }, { "name": "Maaltir" }, - { "name": "cgeek" } + { "name": "cgeek", + "session_keys": "0xc7cd153c0f8cb4d21e1f02e8bd56a0586ad36f4d4d10274f070364dea355551e2634b8ede99cb0dde4566fec9804b5c84f7923ce8f992070206b4063242c21482634b8ede99cb0dde4566fec9804b5c84f7923ce8f992070206b4063242c21482634b8ede99cb0dde4566fec9804b5c84f7923ce8f992070206b4063242c2148" + } ], "sudo_key": "5Hm8sBbwuLAU99dBezvgtnRmZCrUy9mhqmbQMFyGTaeATYg7", "technical_committee": ["Pini", "moul", "HugoTrentesaux", "tuxmain", "1000i100", "vit", "cgeek", "Maaltir"]