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> {
// return chainspecs
Ok(ChainSpec::from_genesis(
// Name
test Development",
Test Development",
// ID
"gtest_dev",
// chain type
......@@ -139,7 +139,7 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> {
// generated genesis
Ok(ChainSpec::from_genesis(
// Name
test Development",
Test Development",
// ID
"gtest_dev",
// chain type
......@@ -192,7 +192,7 @@ pub fn local_testnet_config(
Ok(ChainSpec::from_genesis(
// Name
test Local Testnet",
Test Local Testnet",
// ID
"gtest_local",
ChainType::Local,
......
......@@ -185,7 +185,7 @@ pub fn build_genesis(
for (pubkey, balance) in &genesis_data.wallets {
// check 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;
}
......@@ -193,6 +193,7 @@ pub fn build_genesis(
monetary_mass += balance;
wallet_index += 1;
// json prevents duplicate wallets
accounts.insert(
pubkey.clone(),
GenesisAccountData {
......@@ -210,7 +211,33 @@ pub fn build_genesis(
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
// 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(
identity.owner_key.clone(),
GenesisAccountData {
......@@ -274,7 +301,8 @@ pub fn build_genesis(
if let Some(identity) = &genesis_data.identities.get(name) {
technical_committee_members.push(identity.owner_key.clone());
} 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(
for (_, identity) in &genesis_data.identities {
let mut certs = BTreeMap::new();
for (issuer, expire_on) in &identity.certs_received {
let issuer_index = &genesis_data
.identities
.get(issuer)
.ok_or(format!("Identity '{}' not exist", issuer))?
.index;
certs.insert(*issuer_index, Some(expire_on.clone()));
if let Some(issuer) = &genesis_data.identities.get(issuer) {
certs.insert(issuer.index, Some(expire_on.clone()));
counter_cert += 1;
} else {
log::error!("Identity '{}' does not exist", issuer);
fatal = true;
};
}
certs_by_receiver.insert(identity.index, certs);
}
// SMITHS SUB-WOT //
for (name, smith_data) in &genesis_data.smiths {
let identity = &genesis_data
.identities
.get(&name.clone())
.ok_or(format!("Identity '{}' not exist", &name))?;
// check that smith exists
if let Some(identity) = &genesis_data.identities.get(&name.clone()) {
// Initial authorities and session keys
let session_keys_bytes = if let Some(declared_session_keys) = &smith_data.session_keys {
counter_online_authorities += 1;
......@@ -348,6 +373,10 @@ pub fn build_genesis(
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)
......@@ -394,30 +423,9 @@ pub fn build_genesis(
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
log::info!(
"inserted genesis with:
"prepared genesis with:
- {} accounts ({} identities, {} simple wallets)
- {} total identities ({} active, {} inactive)
- {} smiths
......@@ -438,8 +446,30 @@ pub fn build_genesis(
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
if fatal {
log::error!("some previously logged error prevent from building a sane genesis");
panic!();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment