From 9b7489f82dcd495a6ee238027920cf318101d7b7 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Mon, 11 May 2026 16:05:13 -0600 Subject: [PATCH] propagation: enforce node stamp costs --- crates/lxmf-core/src/propagation_node.rs | 25 ++++++++++++++++++++++-- crates/lxmf-tools/src/commands/lxmd.rs | 10 +++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/lxmf-core/src/propagation_node.rs b/crates/lxmf-core/src/propagation_node.rs index c7569b2..d832dcb 100644 --- a/crates/lxmf-core/src/propagation_node.rs +++ b/crates/lxmf-core/src/propagation_node.rs @@ -18,8 +18,8 @@ use crate::sync::{OfferResponse, SyncGet, SyncOffer, SyncSession}; pub struct PropagationNodeConfig { pub max_storage: usize, pub max_message_age: u64, - /// Messages below this stamp value are rejected. Matches Python - /// `propagation_stamp_cost` (production default PROPAGATION_COST = 16). + /// Messages below this effective stamp value are rejected. Python derives + /// this from `propagation_stamp_cost - propagation_stamp_cost_flexibility`. pub min_stamp_cost: u8, pub peering_cost: u8, pub max_message_size: usize, @@ -170,6 +170,9 @@ impl PropagationNode { if lxmf_data.len() < DESTINATION_LENGTH + 1 { return false; } + if self.config.min_stamp_cost > 0 && stamp_value < self.config.min_stamp_cost { + return false; + } let full = rns_crypto::sha::full_hash(lxmf_data); let mut transient_id = [0u8; 16]; @@ -1624,6 +1627,24 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + #[test] + fn test_accept_propagated_blob_enforces_min_stamp_cost() { + let config = PropagationNodeConfig { + min_stamp_cost: 8, + ..Default::default() + }; + let mut node = PropagationNode::new(config, [0xAA; 16]); + + let mut lxmf_data = vec![0xBB; 16]; + lxmf_data.extend_from_slice(&[0xCC; 128]); + + assert!(!node.accept_propagated_blob(&lxmf_data, 7)); + assert_eq!(node.message_count(), 0); + + assert!(node.accept_propagated_blob(&lxmf_data, 8)); + assert_eq!(node.message_count(), 1); + } + #[test] fn test_opaque_propagated_blob_reload_preserves_destination() { let dir = std::env::temp_dir().join("lxmf_test_propagated_blob_reload"); diff --git a/crates/lxmf-tools/src/commands/lxmd.rs b/crates/lxmf-tools/src/commands/lxmd.rs index 648eba7..a113a87 100644 --- a/crates/lxmf-tools/src/commands/lxmd.rs +++ b/crates/lxmf-tools/src/commands/lxmd.rs @@ -404,7 +404,9 @@ impl LxmdRunner { .unwrap_or(config.propagation_limit_kb * 1024), max_message_size: config.propagation_limit_kb * 1024, max_message_age: lxmf_core::constants::MESSAGE_EXPIRY, - min_stamp_cost: config.propagation_stamp_cost, + min_stamp_cost: config + .propagation_stamp_cost + .saturating_sub(config.propagation_stamp_flex), ..Default::default() }; let prop_storage_path = paths.propagation_store_dir.clone(); @@ -423,7 +425,9 @@ impl LxmdRunner { .unwrap_or(config.propagation_limit_kb * 1024), max_message_size: config.propagation_limit_kb * 1024, max_message_age: lxmf_core::constants::MESSAGE_EXPIRY, - min_stamp_cost: config.propagation_stamp_cost, + min_stamp_cost: config + .propagation_stamp_cost + .saturating_sub(config.propagation_stamp_flex), ..Default::default() }, propagation_dest_hash, @@ -1244,7 +1248,7 @@ impl LxmdRunner { let min_cost = self .config .propagation_stamp_cost - .saturating_sub(lxmf_core::constants::PROPAGATION_COST_FLEX); + .saturating_sub(self.config.propagation_stamp_flex); let mut accepted = 0usize; let mut rejected = 0usize;