From fdf769359820a2eb90ee4eeccb2d32f448619ace Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Wed, 6 Dec 2023 18:02:03 +0100 Subject: [PATCH] `update_allowed_conversions` to publish the updated convert anchor --- core/src/ledger/masp_conversions.rs | 15 ++++++++++++++- core/src/types/token.rs | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/ledger/masp_conversions.rs b/core/src/ledger/masp_conversions.rs index 371e8a5ec9..c3d32ae180 100644 --- a/core/src/ledger/masp_conversions.rs +++ b/core/src/ledger/masp_conversions.rs @@ -16,7 +16,7 @@ use crate::ledger::storage_api::token::read_denom; use crate::ledger::storage_api::{StorageRead, StorageWrite}; use crate::types::address::{Address, MASP}; use crate::types::dec::Dec; -use crate::types::storage::Epoch; +use crate::types::storage::{Epoch, Key, KeySeg}; use crate::types::token; use crate::types::token::MaspDenom; use crate::types::uint::Uint; @@ -211,6 +211,7 @@ where use rayon::prelude::ParallelSlice; use crate::types::address; + use crate::types::token::MASP_CONVERT_ANCHOR_PREFIX; // The derived conversions will be placed in MASP address space let masp_addr = MASP; @@ -454,6 +455,18 @@ where // obtained wl_storage.storage.conversion_state.tree = FrozenCommitmentTree::merge(&tree_parts); + // Publish the new anchor in storage + let anchor_key = Key::from(MASP.to_db_key()) + .push(&MASP_CONVERT_ANCHOR_PREFIX.to_owned()) + .expect("Cannot obtain a storage key") + .push(&crate::types::hash::Hash( + masp_primitives::bls12_381::Scalar::from( + wl_storage.storage.conversion_state.tree.root(), + ) + .to_bytes(), + )) + .expect("Cannot obtain a storage key"); + wl_storage.write(&anchor_key, ())?; // Add purely decoding entries to the assets map. These will be // overwritten before the creation of the next commitment tree diff --git a/core/src/types/token.rs b/core/src/types/token.rs index b5737120d8..086f6b23ac 100644 --- a/core/src/types/token.rs +++ b/core/src/types/token.rs @@ -906,6 +906,8 @@ pub const MASP_NULLIFIERS_KEY_PREFIX: &str = "nullifiers"; pub const MASP_NOTE_COMMITMENT_TREE_KEY: &str = "commitment_tree"; /// Key segment prefix for the note commitment anchor pub const MASP_NOTE_COMMITMENT_ANCHOR_PREFIX: &str = "note_commitment_anchor"; +/// Key segment prefix for the convert anchor +pub const MASP_CONVERT_ANCHOR_PREFIX: &str = "convert_anchor"; /// Last calculated inflation value handed out pub const MASP_LAST_INFLATION_KEY: &str = "last_inflation"; /// The last locked ratio @@ -1133,7 +1135,8 @@ pub fn is_masp_key(key: &Key) -> bool { || key.starts_with(PIN_KEY_PREFIX) || key.starts_with(MASP_NULLIFIERS_KEY_PREFIX) || key == MASP_NOTE_COMMITMENT_TREE_KEY - || key.starts_with(MASP_NOTE_COMMITMENT_ANCHOR_PREFIX))) + || key.starts_with(MASP_NOTE_COMMITMENT_ANCHOR_PREFIX) + || key.starts_with(MASP_CONVERT_ANCHOR_PREFIX))) } /// Check if the given storage key is a masp nullifier key