Skip to content
Snippets Groups Projects
Commit f419837f authored by Cédric Moreau's avatar Cédric Moreau
Browse files

fix(#125): first working gdev_live

parent c3da2a25
No related branches found
No related tags found
No related merge requests found
Pipeline #33337 failed
......@@ -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" }
......
......@@ -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" }
......
......@@ -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();
if is_clique {
// All initial smiths are considered to be certifying all each other
smith_identities
clique_smiths
.as_ref()
.unwrap()
.iter()
.filter(|s| s.name.to_owned() != *idty_name)
.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); // TODO: put duration
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(&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,7 +715,8 @@ 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 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 {
......@@ -666,13 +725,6 @@ fn get_genesis_migration_data() -> Result<GenesisMigrationData, String> {
};
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! {},
})
}
}
fn get_genesis_timestamp() -> Result<u64, String> {
......
......@@ -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"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment