Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
- Fixed missing asset setup for full account initialization ([#1461](https://github.com/0xMiden/miden-node/pull/1461)).
- Fixed validator to use pre-stored asset witnesses from the transaction inputs instead of trying to open the partial vault ([#1490](https://github.com/0xMiden/miden-node/pull/1490)).
- Fixed `GetNetworkAccountIds` pagination to return the chain tip ([#1489](https://github.com/0xMiden/miden-node/pull/1489)).
- Fixed validator to use pre-stored asset witnesses from the transaction inputs instead of trying to open the partial vault ([#1490](https://github.com/0xMiden/miden-node/pull/1490)).
- Fixed the network monitor counter account to use the storage slot name ([#1492](https://github.com/0xMiden/miden-node/pull/1492)).

## v0.12.6

Expand Down
10 changes: 5 additions & 5 deletions bin/network-monitor/src/assets/counter_program.masm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Counter program for network monitoring with note authentication
# Storage layout:
# - Slot 0: counter value (u64)
# - Slot 1: authorized wallet account id as [prefix, suffix, 0, 0]
# - OWNER_SLOT: authorized wallet account id as [prefix, suffix, 0, 0]
# - COUNTER_SLOT: counter value (u64)

use miden::core::sys
use miden::protocol::active_account
Expand All @@ -11,14 +11,14 @@ use miden::protocol::account_id
use miden::protocol::tx


# The slot in this component's storage layout where the counter is stored.
const COUNTER_SLOT = word("miden::monitor::counter_contract::counter")
const OWNER_SLOT = word("miden::monitor::counter_contract::owner")

# Increment function with note authentication
# => []
pub proc increment
# Ensure the note sender matches the authorized wallet stored in slot 1.
push.1 exec.active_account::get_item
# Ensure the note sender matches the authorized wallet.
push.OWNER_SLOT[0..2] exec.active_account::get_item
# => [owner_prefix, owner_suffix, 0, 0]

exec.active_note::get_sender
Expand Down
13 changes: 9 additions & 4 deletions bin/network-monitor/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use tracing::{error, info, instrument, warn};

use crate::COMPONENT;
use crate::config::MonitorConfig;
use crate::deploy::counter::COUNTER_SLOT_NAME;
use crate::deploy::{MonitorDataStore, create_genesis_aware_rpc_client, get_counter_library};
use crate::status::{
CounterTrackingDetails,
Expand Down Expand Up @@ -83,7 +84,7 @@ async fn get_genesis_block_header(rpc_client: &mut RpcClient) -> Result<BlockHea
Ok(block_header)
}

/// Fetch the latest nonce of the given account from RPC.
/// Fetch the latest counter value of the given account from RPC.
async fn fetch_counter_value(
rpc_client: &mut RpcClient,
account_id: AccountId,
Expand All @@ -95,9 +96,13 @@ async fn fetch_counter_value(
let account = Account::read_from_bytes(&raw)
.map_err(|e| anyhow::anyhow!("failed to deserialize account details: {e}"))?;

let storage_slot = account.storage().slots().first().expect("storage slot is always value");
let word = storage_slot.value();
let value = word.as_elements().last().expect("a word is always 4 elements").as_int();
// Access the counter slot by name to avoid index-ordering issues
let word = account
.storage()
.get_item(&COUNTER_SLOT_NAME)
.context("failed to get counter storage slot")?;

let value = word.as_elements().first().expect("a word is always 4 elements").as_int();

Ok(Some(value))
} else {
Expand Down
4 changes: 2 additions & 2 deletions bin/network-monitor/src/deploy/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use tracing::instrument;

use crate::COMPONENT;

static OWNER_SLOT_NAME: LazyLock<StorageSlotName> = LazyLock::new(|| {
pub static OWNER_SLOT_NAME: LazyLock<StorageSlotName> = LazyLock::new(|| {
StorageSlotName::new("miden::monitor::counter_contract::owner")
.expect("storage slot name should be valid")
});

static COUNTER_SLOT_NAME: LazyLock<StorageSlotName> = LazyLock::new(|| {
pub static COUNTER_SLOT_NAME: LazyLock<StorageSlotName> = LazyLock::new(|| {
StorageSlotName::new("miden::monitor::counter_contract::counter")
.expect("storage slot name should be valid")
});
Expand Down