From 091ef1811d2deccdef6af6cb02b17bd7d235232d Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 18 Nov 2025 14:24:17 +0100 Subject: [PATCH 1/3] feat: cache the block tree, handle signals in the node sooner Signed-off-by: ljedrz --- node/src/client/mod.rs | 12 ++++++++++-- node/src/validator/mod.rs | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/node/src/client/mod.rs b/node/src/client/mod.rs index 30c1e62969..e67be9c0c0 100644 --- a/node/src/client/mod.rs +++ b/node/src/client/mod.rs @@ -194,6 +194,9 @@ impl> Client { shutdown: shutdown.clone(), }; + // Pass the node to the signal handler. + let _ = signal_node.set(node.clone()); + // Perform sync with CDN (if enabled). let cdn_sync = cdn.map(|base_url| { trace!("CDN sync is enabled"); @@ -229,8 +232,6 @@ impl> Client { node.initialize_execute_verification(); // Initialize the notification message loop. node.handles.lock().push(crate::start_notification_message_loop()); - // Pass the node to the signal handler. - let _ = signal_node.set(node.clone()); // Return the node. Ok(node) } @@ -617,6 +618,13 @@ impl> NodeInterface for Client { // Shut down the router. self.router.shut_down().await; + // Cache the block tree. + let ledger = self.ledger.clone(); + let _ = spawn_blocking!(ledger.cache_block_tree().map_err(|e| { + error!("Couldn't cache the block tree: {e}"); + e + })); + info!("Node has shut down."); } } diff --git a/node/src/validator/mod.rs b/node/src/validator/mod.rs index af4ddddcd3..082ec0cf79 100644 --- a/node/src/validator/mod.rs +++ b/node/src/validator/mod.rs @@ -152,6 +152,9 @@ impl> Validator { shutdown: shutdown.clone(), }; + // Pass the node to the signal handler. + let _ = signal_node.set(node.clone()); + // Perform sync with CDN (if enabled). let cdn_sync = cdn.map(|base_url| Arc::new(CdnBlockSync::new(base_url, ledger.clone(), shutdown))); @@ -187,8 +190,6 @@ impl> Validator { node.initialize_routing().await; // Initialize the notification message loop. node.handles.lock().push(crate::start_notification_message_loop()); - // Pass the node to the signal handler. - let _ = signal_node.set(node.clone()); // Return the node. Ok(node) } @@ -475,6 +476,13 @@ impl> NodeInterface for Validator { trace!("Shutting down consensus..."); self.consensus.shut_down().await; + // Cache the block tree. + let ledger = self.ledger.clone(); + let _ = spawn_blocking!(ledger.cache_block_tree().map_err(|e| { + error!("Couldn't cache the block tree: {e}"); + e + })); + info!("Node has shut down."); } } From 5f26c8bfbadbf3549d2967d91a1267b563bd5596 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 18 Nov 2025 14:25:02 +0100 Subject: [PATCH 2/3] fmt: update import formatting Signed-off-by: ljedrz --- node/src/client/mod.rs | 9 +++++++-- node/src/validator/mod.rs | 12 +++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/node/src/client/mod.rs b/node/src/client/mod.rs index e67be9c0c0..ec14a8818b 100644 --- a/node/src/client/mod.rs +++ b/node/src/client/mod.rs @@ -23,7 +23,11 @@ use snarkos_node_cdn::CdnBlockSync; use snarkos_node_network::NodeType; use snarkos_node_rest::Rest; use snarkos_node_router::{ - Heartbeat, Inbound, Outbound, Router, Routing, + Heartbeat, + Inbound, + Outbound, + Router, + Routing, messages::{Message, UnconfirmedSolution, UnconfirmedTransaction}, }; use snarkos_node_sync::{BLOCK_REQUEST_BATCH_DELAY, BlockSync, Ping, PrepareSyncRequest, locators::BlockLocators}; @@ -58,7 +62,8 @@ use std::{ sync::{ Arc, atomic::{ - AtomicBool, AtomicUsize, + AtomicBool, + AtomicUsize, Ordering::{Acquire, Relaxed}, }, }, diff --git a/node/src/validator/mod.rs b/node/src/validator/mod.rs index 082ec0cf79..6edfa49c85 100644 --- a/node/src/validator/mod.rs +++ b/node/src/validator/mod.rs @@ -24,7 +24,11 @@ use snarkos_node_consensus::Consensus; use snarkos_node_network::{NodeType, PeerPoolHandling}; use snarkos_node_rest::Rest; use snarkos_node_router::{ - Heartbeat, Inbound, Outbound, Router, Routing, + Heartbeat, + Inbound, + Outbound, + Router, + Routing, messages::{PuzzleResponse, UnconfirmedSolution, UnconfirmedTransaction}, }; use snarkos_node_sync::{BlockSync, Ping}; @@ -33,7 +37,8 @@ use snarkos_node_tcp::{ protocols::{Disconnect, Handshake, OnConnect, Reading}, }; use snarkvm::prelude::{ - Ledger, Network, + Ledger, + Network, block::{Block, Header}, puzzle::Solution, store::ConsensusStorage, @@ -491,7 +496,8 @@ impl> NodeInterface for Validator { mod tests { use super::*; use snarkvm::prelude::{ - MainnetV0, VM, + MainnetV0, + VM, store::{ConsensusStore, helpers::memory::ConsensusMemory}, }; From 11e8939d747396dcf07afd055e8faf751f471b1d Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 18 Nov 2025 17:13:32 +0100 Subject: [PATCH 3/3] temp: use an external snarkVM branch Signed-off-by: ljedrz --- Cargo.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 074ff64f9f..2aa91fd18a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,9 +45,8 @@ version = "1.0.1" default-features = false [workspace.dependencies.snarkvm] -#path = "../snarkVM" -git = "https://github.com/ProvableHQ/snarkVM.git" -rev = "fbd99608f" +git = "https://github.com/ljedrz/snarkVM.git" +branch = "perf/cache_block_tree" #version = "=4.3.0" default-features = false