Overview
Comprehensive code cleanup based on Linus Torvalds-style security audit. Focus areas: dead code removal, logging migration, hardcoded values, and P2P bug fixes.
Priority: P0 (Blocker for mainnet)
Estimated Time: 4-6 hours
Audit Summary
Critical (P0) - Must Fix Before Mainnet
| Issue |
File |
Severity |
| P2P connection bug |
Issue #72 |
Critical |
| #[allow(dead_code)] modules |
vardiff.rs, pool_template.rs, block_submit.rs, chainstate.rs, metrics.rs, miner.rs |
High |
| expect() in production |
metrics.rs |
Medium |
| println!/eprintln! |
commands/.rs, network/.rs |
Medium |
| Hardcoded credentials |
rpc/src/jwt/secret.rs |
Critical |
High Priority (P1)
| Issue |
Description |
| Hardcoded RPC URL |
127.0.0.1:29443 hardcoded |
| Dependency PRs |
#71, #40, #41, #17 (breaking changes) |
Implementation Plan
Phase 1: Dead Code Removal (30 min)
Objective: Remove or feature-gate all #[allow(dead_code)] modules
Files to audit:
crates/node/src/vardiff.rs # Pool mining vardiff
crates/node/src/pool_template.rs # Stratum pool templates
crates/node/src/block_submit.rs # Pool block submission
crates/node/src/chainstate.rs # Chainstate queries
crates/node/src/metrics.rs # Mining metrics stub
crates/node/src/miner.rs # Various unused methods
Action Items:
Verification:
cargo build --all-features # Must pass
cargo build # Must pass (no pool code)
rg "allow\(dead_code\)" --type rust # Should be minimal
Phase 2: Logging Migration (45 min)
Objective: Replace all println!/eprintln! with tracing crate
Target files:
crates/node/src/commands/rpc.rs
crates/node/src/commands/p2p.rs
crates/node/src/ws_dashboard.rs
crates/network/src/sync.rs
Pattern:
// BEFORE
println!("Connected to {} peers", count);
eprintln!("Error: {}", err);
// AFTER
use tracing::{info, error, instrument};
#[instrument]
fn connect_peers(count: usize) {
info!(peer_count = count, "Connected to peers");
}
error!(error = ?err, "Connection failed");
Verification:
rg "println!|eprintln!" --type rust -g '!*test*' -g '!*bench*'
# Expected: 0 results in production code
Phase 3: Remove Hardcoded Values (20 min)
Objective: Remove hardcoded credentials and URLs
Actions:
- Remove test credentials from
rpc/src/jwt/secret.rs
- Move RPC URL to config struct
- Add config validation
Verification:
rg -i "admin.*password|secret.*=" --type rust -g '!*test*'
# Expected: 0 results
Phase 4: Fix P2P Bootstrap (45 min)
Objective: Add timeout and better error handling to peer bootstrap (fixes #72)
Changes:
// crates/network/src/bootstrap.rs
use tokio::time::{timeout, Duration};
use tracing::{info, warn, error};
pub async fn bootstrap_peers(&self, seeds: &[String]) -> Result<usize, NetworkError> {
let mut connected = 0;
for seed in seeds {
info!(seed = %seed, "Attempting to connect to seed peer");
match timeout(Duration::from_secs(30), self.connect_peer(seed)).await {
Ok(Ok(_)) => {
info!(seed = %seed, "Successfully connected to seed");
connected += 1;
}
Ok(Err(e)) => {
warn!(seed = %seed, error = ?e, "Failed to connect to seed");
}
Err(_) => {
warn!(seed = %seed, "Connection timeout after 30s");
}
}
}
if connected == 0 {
error!("Failed to connect to any seed peers!");
return Err(NetworkError::NoSeedPeersAvailable);
}
Ok(connected)
}
Verification:
- Manual P2P connection test
- Node can bootstrap from empty peer list
Phase 5: Dependency Updates (60 min)
Objective: Review and merge dependency PRs (carefully - breaking changes)
PRs to review:
Action:
# Test each PR carefully
gh pr checkout 41
cargo build --all-features
cargo test --all
# Verify crypto signatures still work
cargo test -p bq-crypto
Acceptance Criteria
Related Issues
Created: 2026-01-21
Priority: P0 (Blocker)
Status: Planning
Overview
Comprehensive code cleanup based on Linus Torvalds-style security audit. Focus areas: dead code removal, logging migration, hardcoded values, and P2P bug fixes.
Priority: P0 (Blocker for mainnet)
Estimated Time: 4-6 hours
Audit Summary
Critical (P0) - Must Fix Before Mainnet
High Priority (P1)
Implementation Plan
Phase 1: Dead Code Removal (30 min)
Objective: Remove or feature-gate all
#[allow(dead_code)]modulesFiles to audit:
Action Items:
poolfeature flag to Cargo.toml#[cfg(feature = "pool")]Verification:
Phase 2: Logging Migration (45 min)
Objective: Replace all
println!/eprintln!withtracingcrateTarget files:
Pattern:
Verification:
Phase 3: Remove Hardcoded Values (20 min)
Objective: Remove hardcoded credentials and URLs
Actions:
rpc/src/jwt/secret.rsVerification:
Phase 4: Fix P2P Bootstrap (45 min)
Objective: Add timeout and better error handling to peer bootstrap (fixes #72)
Changes:
Verification:
Phase 5: Dependency Updates (60 min)
Objective: Review and merge dependency PRs (carefully - breaking changes)
PRs to review:
Action:
Acceptance Criteria
#[allow(dead_code)]in production (except feature-gated)println!/eprintln!in production codeRelated Issues
Created: 2026-01-21
Priority: P0 (Blocker)
Status: Planning