Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v0.14.8 (TBA)

- Enabled `miden-tx/concurrent` feature across all crates ([#1956](https://github.com/0xMiden/node/pull/1956)).
- Simplified network monitor counter script loading by linking the counter module directly via `with_linked_module` instead of assembling a standalone library ([#1957](https://github.com/0xMiden/node/pull/1957)).

## v0.14.7 (2026-04-15)

Expand Down
15 changes: 7 additions & 8 deletions bin/network-monitor/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use miden_node_proto::generated::rpc::BlockHeaderByNumberRequest;
use miden_node_proto::generated::transaction::ProvenTransaction;
use miden_protocol::account::auth::AuthSecretKey;
use miden_protocol::account::{Account, AccountFile, AccountHeader, AccountId};
use miden_protocol::assembly::Library;
use miden_protocol::block::{BlockHeader, BlockNumber};
use miden_protocol::crypto::dsa::falcon512_poseidon2::SecretKey;
use miden_protocol::note::{
Expand Down Expand Up @@ -46,7 +45,7 @@ const RESYNC_FAILURE_THRESHOLD: usize = 3;
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::deploy::{MonitorDataStore, create_genesis_aware_rpc_client};
use crate::status::{
CounterTrackingDetails,
IncrementDetails,
Expand Down Expand Up @@ -345,13 +344,12 @@ async fn setup_increment_task(
let block_header = get_genesis_block_header(rpc_client).await?;

// Create the increment procedure script and get the library
let (increment_script, library) = create_increment_script()?;
let increment_script = create_increment_script()?;

// Create unified data store for transaction execution
let mut data_store = MonitorDataStore::new(block_header.clone(), PartialBlockchain::default());
data_store.add_account(wallet_account.clone());
data_store.add_account(counter_account.clone());
data_store.insert_library(&library);

Ok((
details,
Expand Down Expand Up @@ -880,11 +878,12 @@ async fn create_and_submit_network_note(
}

/// Create the increment procedure script.
fn create_increment_script() -> Result<(NoteScript, Library)> {
let library = get_counter_library()?;
fn create_increment_script() -> Result<NoteScript> {
let script =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/assets/counter_program.masm"));

let script_builder = CodeBuilder::new()
.with_dynamically_linked_library(&library)
Comment on lines 886 to -887
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give some more context (correct me if I'm wrong @SantiagoPittella), this was failing due to 0xMiden/miden-vm#2986, as this CodeBuilder was not sharing the same source manager as the library. On Linux for some reason this is not failing (which is why the monitor did not show errors AFAIK) but when testing this locally on MacOS it would panic cc @bitwalker

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and regarding the review comment above this, I will add it to the existing issue of improvements)

.with_linked_module("external_contract::counter_contract", script)
.context("Failed to create script builder with library")?;

// Compile the script directly as a NoteScript
Expand All @@ -895,7 +894,7 @@ fn create_increment_script() -> Result<(NoteScript, Library)> {
)))
.context("Failed to compile note script")?;

Ok((note_script, library))
Ok(note_script)
}

/// Create a network note that targets the counter account.
Expand Down
40 changes: 1 addition & 39 deletions bin/network-monitor/src/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,11 @@ use miden_node_proto::clients::{Builder, RpcClient};
use miden_node_proto::generated::rpc::BlockHeaderByNumberRequest;
use miden_node_proto::generated::transaction::ProvenTransaction;
use miden_protocol::account::{Account, AccountId, PartialAccount, StorageMapKey};
use miden_protocol::assembly::{
DefaultSourceManager,
Library,
Module,
ModuleKind,
Path as MidenPath,
};
use miden_protocol::asset::{AssetVaultKey, AssetWitness};
use miden_protocol::block::{BlockHeader, BlockNumber};
use miden_protocol::crypto::merkle::mmr::{MmrPeaks, PartialMmr};
use miden_protocol::note::NoteScript;
use miden_protocol::transaction::{
AccountInputs,
InputNotes,
PartialBlockchain,
TransactionArgs,
TransactionKernel,
};
use miden_protocol::transaction::{AccountInputs, InputNotes, PartialBlockchain, TransactionArgs};
use miden_protocol::utils::serde::Serializable;
use miden_protocol::{MastForest, Word};
use miden_tx::auth::BasicAuthenticator;
Expand Down Expand Up @@ -218,26 +205,6 @@ pub async fn deploy_counter_account(counter_account: &Account, rpc_url: &Url) ->
Ok(())
}

pub(crate) fn get_counter_library() -> Result<Library> {
let assembler = TransactionKernel::assembler();
let source_manager = Arc::new(DefaultSourceManager::default());
let script =
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/assets/counter_program.masm"));

let library_path = MidenPath::new("external_contract::counter_contract");

let module = Module::parser(ModuleKind::Library)
.parse_str(library_path, script, source_manager)
.map_err(|e| anyhow::anyhow!("Failed to parse module: {e}"))?;

let library = assembler
.clone()
.assemble_library([module])
.map_err(|e| anyhow::anyhow!("Failed to assemble library: {e}"))?;

Ok(Arc::unwrap_or_clone(library))
}

// MONITOR DATA STORE
// ================================================================================================

Expand Down Expand Up @@ -270,11 +237,6 @@ impl MonitorDataStore {
self.add_account(account);
}

/// Insert external library procedures used by transactions.
pub fn insert_library(&mut self, library: &Library) {
self.mast_store.insert(library.mast_forest().clone());
}

/// Returns a reference to the account or a standardized "unknown account" error.
fn get_account(&self, account_id: AccountId) -> Result<&Account, DataStoreError> {
self.accounts.get(&account_id).ok_or_else(|| DataStoreError::Other {
Expand Down
Loading