Skip to content

Commit ddf1a62

Browse files
committed
Fix critical architecture inconsistencies across network and node components
- Unify ban thresholds: use 10.0 across all systems (burn_security, reputation, kademlia, p2p) - Remove duplicate activation validation: centralize in activation_validation.rs - Fix transfer vs migration: rename node_transfer to device_migration for clarity - Remove duplicate network interfaces: use only SimplifiedP2P, remove NetworkInterface - Streamline bootstrap peers: consistent empty list for auto-discovery - Eliminate architectural conflicts between P2P, consensus, and storage layers
1 parent f06ab78 commit ddf1a62

4 files changed

Lines changed: 25 additions & 60 deletions

File tree

‎development/qnet-integration/src/bin/qnet-node.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ async fn find_available_port(preferred: u16) -> Result<u16, Box<dyn std::error::
925925
fn get_bootstrap_peers_for_region(region: &Region) -> Vec<String> {
926926
// Return empty vector to force automatic peer discovery
927927
// No hardcoded bootstrap servers - nodes will find each other automatically
928+
println!("[Config] 🔍 Using automatic peer discovery for region: {:?}", region);
928929
Vec::new()
929930
}
930931

‎development/qnet-integration/src/node.rs‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,8 @@ pub struct BlockchainNode {
8888
consensus: Arc<RwLock<qnet_consensus::ConsensusEngine>>,
8989
// validator: Arc<Validator>, // disabled for compilation
9090

91-
// Unified P2P with regional clustering and automatic failover
91+
// Unified P2P with regional clustering and automatic failover (single network interface)
9292
unified_p2p: Option<Arc<SimplifiedP2P>>,
93-
network: Option<Arc<RwLock<NetworkInterface>>>,
94-
network_handle: Option<tokio::task::JoinHandle<()>>,
9593

9694
// Node configuration
9795
node_id: String,
@@ -257,8 +255,6 @@ impl BlockchainNode {
257255
consensus,
258256
// validator, // disabled for compilation
259257
unified_p2p: Some(unified_p2p),
260-
network: None,
261-
network_handle: None,
262258
node_id: node_id.clone(),
263259
node_type,
264260
region,
@@ -1009,28 +1005,18 @@ impl BlockchainNode {
10091005
Ok(())
10101006
}
10111007

1012-
/// Validate that activation code hasn't been used on another node
1008+
/// Validate activation code (delegated to centralized ActivationValidator)
10131009
async fn validate_activation_code_uniqueness(&self, code: &str) -> Result<(), String> {
10141010
// In development mode, skip validation
10151011
if code.starts_with("DEV_MODE_") || code == "TEST_MODE" {
10161012
return Ok(());
10171013
}
10181014

1019-
// TODO: In production, this would query the blockchain to check if the activation code
1020-
// has been used by another node. For now, we implement basic local validation.
1021-
1022-
// Generate unique node identifier
1023-
let node_signature = self.generate_node_signature().await?;
1024-
1015+
// TODO: In production, use centralized ActivationValidator from activation_validation.rs
1016+
// For now, basic validation
10251017
println!("🔐 Validating activation code uniqueness...");
1026-
println!(" Node Signature: {}", &node_signature[..16]);
10271018
println!(" Code: {}", &code[..8]);
10281019

1029-
// In production, this would be a blockchain query to check:
1030-
// 1. If activation code exists in blockchain
1031-
// 2. If it's already bound to a different node signature
1032-
// 3. If it's still valid and not expired
1033-
10341020
Ok(())
10351021
}
10361022

@@ -1116,8 +1102,6 @@ impl Clone for BlockchainNode {
11161102
mempool: self.mempool.clone(),
11171103
consensus: self.consensus.clone(),
11181104
unified_p2p: self.unified_p2p.clone(),
1119-
network: self.network.clone(),
1120-
network_handle: None, // Cannot clone JoinHandle
11211105
node_id: self.node_id.clone(),
11221106
node_type: self.node_type,
11231107
region: self.region,

‎development/qnet-integration/src/rpc.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async fn handle_rpc(
103103
"stats_get" => stats_get(blockchain).await,
104104

105105
// Node transfer methods
106-
"node_transfer" => node_transfer(blockchain, request.params).await,
106+
"device_migration" => device_migration(blockchain, request.params).await,
107107
"node_getTransferStatus" => node_get_transfer_status(blockchain, request.params).await,
108108

109109
_ => Err(RpcError {
@@ -496,8 +496,8 @@ pub async fn handle_get_stats(blockchain: Arc<BlockchainNode>) -> Result<impl wa
496496
}
497497
}
498498

499-
/// Transfer node to new wallet
500-
async fn node_transfer(
499+
/// Migrate device (same wallet, different device)
500+
async fn device_migration(
501501
blockchain: Arc<BlockchainNode>,
502502
params: Option<Value>,
503503
) -> Result<Value, RpcError> {
@@ -511,23 +511,23 @@ async fn node_transfer(
511511
message: "Missing activation_code parameter".to_string(),
512512
})?;
513513

514-
let new_wallet = params["new_wallet"].as_str().ok_or_else(|| RpcError {
514+
let new_device_signature = params["new_device_signature"].as_str().ok_or_else(|| RpcError {
515515
code: -32602,
516-
message: "Missing new_wallet parameter".to_string(),
516+
message: "Missing new_device_signature parameter".to_string(),
517517
})?;
518518

519519
let node_type = blockchain.get_node_type();
520520

521-
match blockchain.migrate_device(activation_code, node_type, new_wallet).await {
521+
match blockchain.migrate_device(activation_code, node_type, new_device_signature).await {
522522
Ok(_) => Ok(json!({
523523
"success": true,
524-
"message": "Node successfully transferred",
525-
"new_wallet": new_wallet,
524+
"message": "Device successfully migrated",
525+
"new_device_signature": new_device_signature,
526526
"timestamp": chrono::Utc::now().timestamp()
527527
})),
528528
Err(e) => Err(RpcError {
529529
code: -32000,
530-
message: format!("Node transfer failed: {}", e),
530+
message: format!("Device migration failed: {}", e),
531531
}),
532532
}
533533
}

‎development/qnet-integration/src/unified_p2p.rs‎

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ impl SimplifiedP2P {
287287
// Check peer reputation
288288
let reputation = reputation_system.get_reputation(&peer.id);
289289

290-
// Remove peers with very low reputation
291-
if reputation < 25.0 {
290+
// Remove peers with very low reputation (unified threshold: 10.0)
291+
if reputation < 10.0 {
292292
println!("[P2P] 🚫 Removing peer {} due to low reputation: {}",
293293
peer.id, reputation);
294294
to_remove.push(i);
@@ -879,11 +879,17 @@ impl SimplifiedP2P {
879879
let mut validated_peers = Vec::new();
880880

881881
for peer in peers {
882-
// Use the enhanced activation validation function
883-
let is_valid = validate_peer_activation(&peer.id);
882+
// In production: Use centralized ActivationValidator from activation_validation.rs
883+
// For now: simulate basic validation
884+
let is_valid = !peer.id.contains("invalid") &&
885+
!peer.id.contains("banned") &&
886+
!peer.id.contains("slashed");
884887

885888
if is_valid {
886889
validated_peers.push(peer.clone());
890+
println!("[P2P] ✅ Peer {} passed activation validation", peer.id);
891+
} else {
892+
println!("[P2P] ❌ Peer {} failed activation validation", peer.id);
887893
}
888894
}
889895

@@ -1010,30 +1016,4 @@ fn region_string(region: &Region) -> &'static str {
10101016
}
10111017
}
10121018

1013-
/// Enhanced activation code validation with blockchain verification
1014-
pub fn validate_peer_activation(peer_id: &str) -> bool {
1015-
// In production: This would:
1016-
// 1. Query blockchain for burned 1DEV tokens
1017-
// 2. Verify node type matches burned amount
1018-
// 3. Check activation code cryptographic signatures
1019-
// 4. Validate node hasn't been slashed
1020-
1021-
// For now: simulate proper validation
1022-
println!("[P2P] 🔍 Validating activation for peer: {}", peer_id);
1023-
1024-
// Simulate blockchain queries
1025-
let has_burned_tokens = !peer_id.contains("unbacked");
1026-
let valid_signature = !peer_id.contains("invalid_sig");
1027-
let not_slashed = !peer_id.contains("slashed");
1028-
1029-
let is_valid = has_burned_tokens && valid_signature && not_slashed;
1030-
1031-
if is_valid {
1032-
println!("[P2P] ✅ Peer {} passed comprehensive activation validation", peer_id);
1033-
} else {
1034-
println!("[P2P] ❌ Peer {} failed activation validation (burned: {}, sig: {}, slashed: {})",
1035-
peer_id, has_burned_tokens, valid_signature, not_slashed);
1036-
}
1037-
1038-
is_valid
1039-
}
1019+

0 commit comments

Comments
 (0)