mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-28 02:49:35 +00:00
use vec<identifiers> in persistentaccountdataprivate to avoid the hacky workaround with identifier=0 for unused accounts
This commit is contained in:
parent
c3f47f6685
commit
f0b89f8acb
@ -70,7 +70,13 @@ impl WalletChainStore {
|
|||||||
public_tree.insert(data.account_id, data.chain_index, data.data);
|
public_tree.insert(data.account_id, data.chain_index, data.data);
|
||||||
}
|
}
|
||||||
PersistentAccountData::Private(data) => {
|
PersistentAccountData::Private(data) => {
|
||||||
private_tree.insert(data.account_id, data.chain_index, data.data);
|
let npk = data.data.value.0.nullifier_public_key;
|
||||||
|
let chain_index = data.chain_index;
|
||||||
|
for identifier in &data.identifiers {
|
||||||
|
let account_id = nssa::AccountId::from((&npk, *identifier));
|
||||||
|
private_tree.account_id_map.insert(account_id, chain_index.clone());
|
||||||
|
}
|
||||||
|
private_tree.key_map.insert(chain_index, data.data);
|
||||||
}
|
}
|
||||||
PersistentAccountData::Preconfigured(acc_data) => match acc_data {
|
PersistentAccountData::Preconfigured(acc_data) => match acc_data {
|
||||||
InitialAccountData::Public(data) => {
|
InitialAccountData::Public(data) => {
|
||||||
@ -282,10 +288,7 @@ mod tests {
|
|||||||
data: public_data,
|
data: public_data,
|
||||||
}),
|
}),
|
||||||
PersistentAccountData::Private(Box::new(PersistentAccountDataPrivate {
|
PersistentAccountData::Private(Box::new(PersistentAccountDataPrivate {
|
||||||
account_id: nssa::AccountId::from((
|
identifiers: vec![],
|
||||||
&private_data.value.0.nullifier_public_key,
|
|
||||||
0_u128,
|
|
||||||
)),
|
|
||||||
chain_index: ChainIndex::root(),
|
chain_index: ChainIndex::root(),
|
||||||
data: private_data,
|
data: private_data,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@ -28,7 +28,7 @@ pub struct PersistentAccountDataPublic {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PersistentAccountDataPrivate {
|
pub struct PersistentAccountDataPrivate {
|
||||||
pub account_id: nssa::AccountId,
|
pub identifiers: Vec<nssa_core::Identifier>,
|
||||||
pub chain_index: ChainIndex,
|
pub chain_index: ChainIndex,
|
||||||
pub data: ChildKeysPrivate,
|
pub data: ChildKeysPrivate,
|
||||||
}
|
}
|
||||||
@ -123,16 +123,6 @@ impl PersistentStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersistentAccountData {
|
|
||||||
#[must_use]
|
|
||||||
pub fn account_id(&self) -> nssa::AccountId {
|
|
||||||
match &self {
|
|
||||||
Self::Public(acc) => acc.account_id,
|
|
||||||
Self::Private(acc) => acc.account_id,
|
|
||||||
Self::Preconfigured(acc) => acc.account_id(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<PublicAccountPrivateInitialData> for InitialAccountData {
|
impl From<PublicAccountPrivateInitialData> for InitialAccountData {
|
||||||
fn from(value: PublicAccountPrivateInitialData) -> Self {
|
fn from(value: PublicAccountPrivateInitialData) -> Self {
|
||||||
|
|||||||
@ -165,41 +165,16 @@ pub fn produce_data_for_storage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let covered_private_chain_indices: std::collections::BTreeSet<_> = user_data
|
|
||||||
.private_key_tree
|
|
||||||
.account_id_map
|
|
||||||
.values()
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
for (account_id, key) in &user_data.private_key_tree.account_id_map {
|
|
||||||
if let Some(data) = user_data.private_key_tree.key_map.get(key) {
|
|
||||||
vec_for_storage.push(
|
|
||||||
PersistentAccountDataPrivate {
|
|
||||||
account_id: *account_id,
|
|
||||||
chain_index: key.clone(),
|
|
||||||
data: data.clone(),
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also persist fresh nodes that have no identifiers yet and are therefore absent from
|
|
||||||
// account_id_map. Without this, a restart before the first sync would lose the node
|
|
||||||
// entirely, making it impossible to detect incoming transfers.
|
|
||||||
for (chain_index, node) in &user_data.private_key_tree.key_map {
|
for (chain_index, node) in &user_data.private_key_tree.key_map {
|
||||||
if !covered_private_chain_indices.contains(chain_index) {
|
let identifiers = node.value.1.iter().map(|(id, _)| *id).collect();
|
||||||
let account_id = nssa::AccountId::from((&node.value.0.nullifier_public_key, 0_u128));
|
vec_for_storage.push(
|
||||||
vec_for_storage.push(
|
PersistentAccountDataPrivate {
|
||||||
PersistentAccountDataPrivate {
|
identifiers,
|
||||||
account_id,
|
chain_index: chain_index.clone(),
|
||||||
chain_index: chain_index.clone(),
|
data: node.clone(),
|
||||||
data: node.clone(),
|
}
|
||||||
}
|
.into(),
|
||||||
.into(),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (account_id, key) in &user_data.default_pub_account_signing_keys {
|
for (account_id, key) in &user_data.default_pub_account_signing_keys {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user