Skip to content

Commit

Permalink
update_allowed_conversions to publish the updated convert anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Dec 6, 2023
1 parent 6276330 commit fdf7693
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion core/src/ledger/masp_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fdf7693

Please sign in to comment.