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

fix(#125): keep old pseudonyms and their associated idty_index

parent 229cf0a1
No related branches found
No related tags found
No related merge requests found
Pipeline #33709 waiting for manual action
......@@ -15,7 +15,9 @@
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use super::*;
use crate::chain_spec::gen_genesis_data::{AuthorityKeys, CommonParameters, SessionKeysProvider};
use crate::chain_spec::gen_genesis_data::{
AuthorityKeys, CommonParameters, GenesisIdentity, SessionKeysProvider,
};
use common_runtime::constants::*;
use common_runtime::entities::IdtyData;
use common_runtime::*;
......@@ -346,7 +348,16 @@ fn genesis_data_to_gdev_genesis_conf(
.into_iter()
.enumerate()
.map(
|(_, (idty_index, name, owner_key, old_owner_key))| GenesisIdty {
|(
_,
GenesisIdentity {
idty_index,
name,
owner_key,
old_owner_key,
active,
},
)| GenesisIdty {
index: idty_index,
name: common_runtime::IdtyName::from(name.as_str()),
value: common_runtime::IdtyValue {
......@@ -357,6 +368,7 @@ fn genesis_data_to_gdev_genesis_conf(
removable_on: 0,
status: IdtyStatus::Validated,
},
active,
},
)
.collect(),
......
......@@ -68,7 +68,7 @@ pub struct GenesisData<Parameters: DeserializeOwned, SessionKeys: Decode> {
pub certs_by_receiver: BTreeMap<u32, BTreeMap<u32, Option<u32>>>,
pub first_ud: Option<u64>,
pub first_ud_reeval: Option<u64>,
pub identities: Vec<(u32, String, AccountId, Option<AccountId>)>,
pub identities: Vec<GenesisIdentity>,
pub initial_authorities: BTreeMap<u32, (AccountId, bool)>,
pub initial_monetary_mass: u64,
pub memberships: BTreeMap<u32, MembershipData>,
......@@ -82,6 +82,15 @@ pub struct GenesisData<Parameters: DeserializeOwned, SessionKeys: Decode> {
pub ud: u64,
}
#[derive(Clone)]
pub struct GenesisIdentity {
pub idty_index: u32,
pub name: String,
pub owner_key: AccountId,
pub old_owner_key: Option<AccountId>,
pub active: bool,
}
#[derive(Deserialize, Serialize)]
struct GenesisInput<Parameters> {
first_ud: Option<u64>,
......@@ -211,6 +220,7 @@ struct GenesisMemberIdentity {
owned_key: AccountId,
old_owned_key: Option<AccountId>,
name: String,
active: bool,
}
/// generate genesis data from a json file
......@@ -593,24 +603,26 @@ where
}
identity_index.insert(identity.index, name);
let expired = identity.membership_expire_on == 0;
// only add the identity if not expired
if identity.membership_expire_on != 0 {
// N.B.: every identity on Genesis is considered to have:
if expired {
inactive_identities.insert(identity.index, name);
};
identities.push(GenesisMemberIdentity {
// N.B.: every **non-expired** identity on Genesis is considered to have:
// - removable_on: 0,
// - next_creatable_identity_on: 0,
// - status: IdtyStatus::Validated,
identities.push(GenesisMemberIdentity {
index: identity.index,
name: name.clone(),
owned_key: identity.owner_key.clone(),
old_owned_key: identity.old_owner_key.clone(),
});
} else {
inactive_identities.insert(identity.index, name);
};
index: identity.index,
name: name.clone(),
owned_key: identity.owner_key.clone(),
old_owned_key: identity.old_owner_key.clone(),
// but expired identities will just have their pseudonym reserved in the storage
active: !expired,
});
// insert the membershup data (only if not expired)
if identity.membership_expire_on != 0 {
if !expired {
memberships.insert(
identity.index,
MembershipData {
......@@ -869,10 +881,10 @@ where
- {} smith certifications
- {} members in technical committee",
accounts.len(),
identity_index.len(),
identities.len() - inactive_identities.len(),
&genesis_data.wallets.len(),
identity_index.len(),
identities.len(),
identities.len() - inactive_identities.len(),
inactive_identities.len(),
smith_memberships.len(),
counter_online_authorities,
......@@ -882,8 +894,6 @@ where
);
// give genesis info
// TODO: add all the known parameters (see https://forum.duniter.org/t/liste-des-parametres-protocolaires-de-duniter-v2s/9297)
// and add the new ones (first_ud (time), ...)
log::info!(
"currency parameters:
- existential deposit: {} {}
......@@ -1023,13 +1033,13 @@ where
}
// 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()
identities.len() - inactive_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());
assert_eq!(
accounts.len(),
identity_index.len() + genesis_data.wallets.len().sub(invalid_wallets)
......@@ -1136,7 +1146,13 @@ where
first_ud_reeval,
identities: identities
.into_iter()
.map(|i| (i.index, i.name, i.owned_key, i.old_owned_key))
.map(|i| GenesisIdentity {
idty_index: i.index,
name: i.name,
owner_key: i.owned_key,
old_owner_key: i.old_owned_key,
active: i.active,
})
.collect(),
initial_authorities,
initial_monetary_mass: genesis_data.initial_monetary_mass,
......@@ -1197,13 +1213,12 @@ where
let identities_ = initial_identities
.iter()
.enumerate()
.map(|(i, (name, owner_key))| {
(
i as u32,
String::from_utf8(name.0.clone()).unwrap(),
owner_key.clone(),
None,
)
.map(|(i, (name, owner_key))| GenesisIdentity {
idty_index: i as u32,
name: String::from_utf8(name.0.clone()).unwrap(),
owner_key: owner_key.clone(),
old_owner_key: None,
active: true,
})
.collect();
......
......@@ -15,7 +15,9 @@
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use super::*;
use crate::chain_spec::gen_genesis_data::{CommonParameters, GenesisData, SessionKeysProvider};
use crate::chain_spec::gen_genesis_data::{
CommonParameters, GenesisData, GenesisIdentity, SessionKeysProvider,
};
use common_runtime::constants::*;
use common_runtime::entities::IdtyData;
use common_runtime::*;
......@@ -291,18 +293,30 @@ fn genesis_data_to_gtest_genesis_conf(
identities: identities
.into_iter()
.enumerate()
.map(|(i, (name, owner_key, old_owner_key))| GenesisIdty {
index: i as u32 + 1,
name: common_runtime::IdtyName::from(name.as_str()),
value: common_runtime::IdtyValue {
data: IdtyData::new(),
next_creatable_identity_on: 0,
old_owner_key: old_owner_key.clone().map(|address| (address, 0)),
owner_key,
removable_on: 0,
status: IdtyStatus::Validated,
.map(
|(
i,
GenesisIdentity {
idty_index,
name,
owner_key,
old_owner_key,
active,
},
)| GenesisIdty {
index: idty_index,
name: common_runtime::IdtyName::from(name.as_str()),
value: common_runtime::IdtyValue {
data: IdtyData::new(),
next_creatable_identity_on: 0,
old_owner_key: old_owner_key.clone().map(|address| (address, 0)),
owner_key,
removable_on: 0,
status: IdtyStatus::Validated,
},
active,
},
})
)
.collect(),
},
cert: CertConfig {
......
......@@ -259,6 +259,7 @@ pub fn new_test_ext(
removable_on: 0,
status: pallet_identity::IdtyStatus::Validated,
},
active: true,
})
.collect(),
}
......
......@@ -125,6 +125,7 @@ pub mod pallet {
pub index: T::IdtyIndex,
pub name: IdtyName,
pub value: IdtyValue<T::BlockNumber, T::AccountId, T::IdtyData>,
pub active: bool,
}
#[pallet::genesis_config]
......@@ -170,9 +171,12 @@ pub mod pallet {
(idty_index, idty.value.status),
)
}
<Identities<T>>::insert(idty_index, idty.value.clone());
if idty.active {
<Identities<T>>::insert(idty_index, idty.value.clone());
IdentityIndexOf::<T>::insert(idty.value.owner_key, idty_index);
}
// Anyway, the pseudonym is kept reserved so we can map it with a user ID (idty_index)
IdentitiesNames::<T>::insert(idty.name.clone(), idty_index);
IdentityIndexOf::<T>::insert(idty.value.owner_key, idty_index);
}
}
}
......
......@@ -59,6 +59,7 @@ fn alice() -> GenesisIdty<Test> {
removable_on: 0,
status: crate::IdtyStatus::Validated,
},
active: true,
}
}
......@@ -74,6 +75,7 @@ fn bob() -> GenesisIdty<Test> {
removable_on: 0,
status: crate::IdtyStatus::Validated,
},
active: true,
}
}
......
......@@ -212,6 +212,7 @@ impl ExtBuilder {
removable_on: 0,
status: IdtyStatus::Validated,
},
active: true,
})
.collect(),
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment