Skip to content
Snippets Groups Projects
Commit 77a4185f authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

tuxmain review

parent 001c7c82
No related branches found
No related tags found
1 merge request!168gtest genesis new format
...@@ -95,7 +95,7 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> { ...@@ -95,7 +95,7 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> {
// return chainspecs // return chainspecs
Ok(ChainSpec::from_genesis( Ok(ChainSpec::from_genesis(
// Name // Name
test Development", Test Development",
// ID // ID
"gtest_dev", "gtest_dev",
// chain type // chain type
...@@ -139,7 +139,7 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> { ...@@ -139,7 +139,7 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> {
// generated genesis // generated genesis
Ok(ChainSpec::from_genesis( Ok(ChainSpec::from_genesis(
// Name // Name
test Development", Test Development",
// ID // ID
"gtest_dev", "gtest_dev",
// chain type // chain type
...@@ -192,7 +192,7 @@ pub fn local_testnet_config( ...@@ -192,7 +192,7 @@ pub fn local_testnet_config(
Ok(ChainSpec::from_genesis( Ok(ChainSpec::from_genesis(
// Name // Name
test Local Testnet", Test Local Testnet",
// ID // ID
"gtest_local", "gtest_local",
ChainType::Local, ChainType::Local,
......
...@@ -185,7 +185,7 @@ pub fn build_genesis( ...@@ -185,7 +185,7 @@ pub fn build_genesis(
for (pubkey, balance) in &genesis_data.wallets { for (pubkey, balance) in &genesis_data.wallets {
// check existential deposit // check existential deposit
if balance < &EXISTENTIAL_DEPOSIT { if balance < &EXISTENTIAL_DEPOSIT {
log::warn!("wallet {pubkey} has {balance} which is below {EXISTENTIAL_DEPOSIT}"); log::warn!("wallet {pubkey} has {balance} cǦT which is below {EXISTENTIAL_DEPOSIT}");
fatal = true; fatal = true;
} }
...@@ -193,6 +193,7 @@ pub fn build_genesis( ...@@ -193,6 +193,7 @@ pub fn build_genesis(
monetary_mass += balance; monetary_mass += balance;
wallet_index += 1; wallet_index += 1;
// json prevents duplicate wallets
accounts.insert( accounts.insert(
pubkey.clone(), pubkey.clone(),
GenesisAccountData { GenesisAccountData {
...@@ -210,7 +211,33 @@ pub fn build_genesis( ...@@ -210,7 +211,33 @@ pub fn build_genesis(
return Err(format!("Identity name '{}' is invalid", &name)); return Err(format!("Identity name '{}' is invalid", &name));
} }
// check existential deposit
if identity.balance < EXISTENTIAL_DEPOSIT {
if identity.membership_expire_on != 0 {
log::warn!(
"expired identity {name} has {} cǦT which is below {EXISTENTIAL_DEPOSIT}",
identity.balance
);
fatal = true;
} else {
// member identities can still be below existential deposit thanks to sufficient
log::info!(
"identity {name} has {} cǦT which is below {EXISTENTIAL_DEPOSIT}",
identity.balance
);
}
}
// Money // Money
// check that wallet with same owner_key does not exist
if accounts.get(&identity.owner_key).is_some() {
log::warn!(
"{name} owner_key {} already exists as a simple wallet",
identity.owner_key
);
fatal = true;
}
// insert as an account
accounts.insert( accounts.insert(
identity.owner_key.clone(), identity.owner_key.clone(),
GenesisAccountData { GenesisAccountData {
...@@ -274,7 +301,8 @@ pub fn build_genesis( ...@@ -274,7 +301,8 @@ pub fn build_genesis(
if let Some(identity) = &genesis_data.identities.get(name) { if let Some(identity) = &genesis_data.identities.get(name) {
technical_committee_members.push(identity.owner_key.clone()); technical_committee_members.push(identity.owner_key.clone());
} else { } else {
return Err(format!("Identity '{}' not exist", name)); log::error!("Identity '{}' does not exist", name);
fatal = true;
} }
} }
...@@ -282,24 +310,21 @@ pub fn build_genesis( ...@@ -282,24 +310,21 @@ pub fn build_genesis(
for (_, identity) in &genesis_data.identities { for (_, identity) in &genesis_data.identities {
let mut certs = BTreeMap::new(); let mut certs = BTreeMap::new();
for (issuer, expire_on) in &identity.certs_received { for (issuer, expire_on) in &identity.certs_received {
let issuer_index = &genesis_data if let Some(issuer) = &genesis_data.identities.get(issuer) {
.identities certs.insert(issuer.index, Some(expire_on.clone()));
.get(issuer)
.ok_or(format!("Identity '{}' not exist", issuer))?
.index;
certs.insert(*issuer_index, Some(expire_on.clone()));
counter_cert += 1; counter_cert += 1;
} else {
log::error!("Identity '{}' does not exist", issuer);
fatal = true;
};
} }
certs_by_receiver.insert(identity.index, certs); certs_by_receiver.insert(identity.index, certs);
} }
// SMITHS SUB-WOT // // SMITHS SUB-WOT //
for (name, smith_data) in &genesis_data.smiths { for (name, smith_data) in &genesis_data.smiths {
let identity = &genesis_data // check that smith exists
.identities if let Some(identity) = &genesis_data.identities.get(&name.clone()) {
.get(&name.clone())
.ok_or(format!("Identity '{}' not exist", &name))?;
// Initial authorities and session keys // Initial authorities and session keys
let session_keys_bytes = if let Some(declared_session_keys) = &smith_data.session_keys { let session_keys_bytes = if let Some(declared_session_keys) = &smith_data.session_keys {
counter_online_authorities += 1; counter_online_authorities += 1;
...@@ -348,6 +373,10 @@ pub fn build_genesis( ...@@ -348,6 +373,10 @@ pub fn build_genesis(
expire_on: GENESIS_SMITH_MEMBERSHIP_EXPIRE_ON, expire_on: GENESIS_SMITH_MEMBERSHIP_EXPIRE_ON,
}, },
); );
} else {
log::error!("Smith '{}' does not correspond to exising identity", &name);
fatal = true;
}
} }
// Verify certifications coherence (can be ignored for old users) // Verify certifications coherence (can be ignored for old users)
...@@ -394,30 +423,9 @@ pub fn build_genesis( ...@@ -394,30 +423,9 @@ pub fn build_genesis(
fatal = true; fatal = true;
} }
// some more checks
assert_eq!(identities.len(), memberships.len());
assert_eq!(smith_memberships.len(), initial_authorities.len());
assert_eq!(smith_memberships.len(), session_keys_map.len());
assert_eq!(
identity_index.len(),
identities.len() + inactive_identities.len()
);
assert_eq!(
accounts.len(),
identity_index.len() + &genesis_data.wallets.len()
);
// no inactive tech comm
for tech_com_member in &genesis_data.technical_committee {
assert!(!inactive_identities.values().any(|&v| v == tech_com_member));
}
// no inactive smith
for (smith, _) in &genesis_data.smiths {
assert!(!inactive_identities.values().any(|&v| v == smith));
}
// give genesis info // give genesis info
log::info!( log::info!(
"inserted genesis with: "prepared genesis with:
- {} accounts ({} identities, {} simple wallets) - {} accounts ({} identities, {} simple wallets)
- {} total identities ({} active, {} inactive) - {} total identities ({} active, {} inactive)
- {} smiths - {} smiths
...@@ -438,8 +446,30 @@ pub fn build_genesis( ...@@ -438,8 +446,30 @@ pub fn build_genesis(
technical_committee_members.len(), technical_committee_members.len(),
); );
// some more checks
assert_eq!(identities.len(), memberships.len());
assert_eq!(smith_memberships.len(), initial_authorities.len());
assert_eq!(smith_memberships.len(), session_keys_map.len());
assert_eq!(
identity_index.len(),
identities.len() + inactive_identities.len()
);
assert_eq!(
accounts.len(),
identity_index.len() + &genesis_data.wallets.len()
);
// no inactive tech comm
for tech_com_member in &genesis_data.technical_committee {
assert!(!inactive_identities.values().any(|&v| v == tech_com_member));
}
// no inactive smith
for (smith, _) in &genesis_data.smiths {
assert!(!inactive_identities.values().any(|&v| v == smith));
}
// check the logs to see all the fatal error preventing from starting gtest currency // check the logs to see all the fatal error preventing from starting gtest currency
if fatal { if fatal {
log::error!("some previously logged error prevent from building a sane genesis");
panic!(); panic!();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment