Skip to content

Peer service: Announce and filter full vs pruned nodes for block catchup#49

Closed
freemans13 wants to merge 5 commits into
bsv-blockchain:mainfrom
freemans13:feature/full-or-pruned-node-peers
Closed

Peer service: Announce and filter full vs pruned nodes for block catchup#49
freemans13 wants to merge 5 commits into
bsv-blockchain:mainfrom
freemans13:feature/full-or-pruned-node-peers

Conversation

@freemans13

Copy link
Copy Markdown
Collaborator

Summary

Implement peer announcement and filtering for full vs pruned nodes to ensure reliable block catchup. Nodes now announce whether they have full block data (block persister running and caught up) or are pruned, and the sync-peer selection logic filters to only use full nodes for catchup by default.

Changes

Node Mode Determination

  • P2P service determines if node is "full" or "pruned" by querying blockchain state for BlockPersisterHeight
  • A node is "full" if block persister is within configurable lag threshold of chain tip (default: 10 blocks)
  • Node mode is announced in node_status messages (published every 10 seconds)

Peer Tracking

  • Added NodeMode field to PeerInfo struct to track peer capabilities
  • Added UpdateNodeMode() method to peer registry
  • Node status handler extracts and stores mode from received announcements

Sync-Peer Selection Filtering

  • Enhanced PeerSelector.isEligible() to filter based on node mode
  • Default behavior: Only sync from peers announcing as "full" nodes
  • Configurable backward compatibility for old peers

Configuration

Two new settings in P2PSettings:

FullNodeLagThreshold   uint32 // Default: 10 blocks
TreatUnknownNodeModeAs string // Default: "pruned" (strict), or "full" (permissive)

Modes:

  • "pruned" (default): Strict - only sync from confirmed full nodes
  • "full": Permissive - allow all peers (backward compatible)

Test plan

  • Build verification passed
  • All P2P unit tests pass (17.4s)
  • PeerSelector tests pass with node mode filtering
  • SyncCoordinator tests pass
  • Test mocks handle new GetState calls gracefully
  • Integration testing with mixed full/pruned node network
  • Verify catchup only selects full nodes in strict mode

Technical Details

Files modified:

  • services/p2p/Server.go - Node mode determination and announcement (services/p2p/Server.go:1261-1309)
  • services/p2p/HandleWebsocket.go - Added NodeMode to WebSocket notifications
  • services/p2p/peer_registry.go - Peer mode tracking
  • services/p2p/peer_selector.go - Node mode filtering in eligibility check (services/p2p/peer_selector.go:163-189)
  • services/p2p/*_test.go - Updated test mocks
  • settings/interface.go - Added configuration settings

🤖 Generated with Claude Code

freemans13 and others added 4 commits October 23, 2025 11:33
Decouple network block fetching from worker distribution using a two-goroutine
pipeline. This keeps the network connection saturated even when validation
is slower than fetch, improving overall catchup performance.

Changes:
- Add batchFetchWithPrefetch and distributeBatchesToWorkers functions
- Introduce FetchPrefetchDepth setting (default: 5 batches ahead)
- Add context cancellation check in subtree validation level processing

The fetcher can now run up to prefetchDepth batches ahead of distribution,
maximizing network throughput during block catchup operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@freemans13 freemans13 self-assigned this Oct 24, 2025
@github-actions

github-actions Bot commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

Status: Complete


Current Review:

  • Default value mismatch in get_blocks.go:76 - code uses 2 but settings default is 5 (inline comment)

Overall Assessment:
The PR implements peer node mode filtering (full vs pruned) with good architecture. The P2P changes are sound - node mode determination, peer tracking, and selection filtering all follow clean patterns. The block validation prefetch pipeline is a solid performance improvement.

The default value inconsistency should be fixed to avoid configuration confusion, but it's a minor issue that doesn't affect correctness when settings are properly configured.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
58.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

largeBatchSize := 100 // Large batches for maximum HTTP efficiency (peer limit)
numWorkers := 16 // Number of worker goroutines for parallel processing
bufferSize := 500 // Buffer size for channels
prefetchDepth := 2 // Number of batches to prefetch ahead (default: 2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The default value in the code (line 76) is 2, but the settings default (settings/settings.go) is 5. This inconsistency means the documented behavior does not match actual behavior when settings are not configured. Recommend changing line 76 to match the settings default of 5.

@freemans13

Copy link
Copy Markdown
Collaborator Author

Closing - branch had extra commits. Creating clean PR.

@freemans13 freemans13 closed this Oct 24, 2025
ordishs added a commit to ordishs/teranode that referenced this pull request Jan 12, 2026
- Update config parameter names to include validator_ prefix
- Reference validator_kafkaWorkers, validator_httpRateLimit, validator_verbose_debug
- Add note that these are advanced settings not in default settings.conf
- Link to comprehensive Validator Settings Reference documentation

Addresses issue bsv-blockchain#49 from teranode-review - settings exist in code but not in default config file, which is expected for advanced options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant