Skip to content

feat(p2p): add tx_count and subtree_count to node_status message#24

Merged
oskarszoon merged 16 commits into
bsv-blockchain:mainfrom
ordishs:add-tx-subtree-count-to-node-status
Oct 20, 2025
Merged

feat(p2p): add tx_count and subtree_count to node_status message#24
oskarszoon merged 16 commits into
bsv-blockchain:mainfrom
ordishs:add-tx-subtree-count-to-node-status

Conversation

@ordishs

@ordishs ordishs commented Oct 17, 2025

Copy link
Copy Markdown
Collaborator

Summary

  • Complete the implementation from PR refactor: remove BlockAssemblyDetails and improve UI components #8 by adding tx_count and subtree_count fields to node status messages
  • Retrieve block assembly state (transaction count and subtree count) and include in node status broadcasts
  • Provide visibility into block assembly state across the P2P network

Changes

  • services/p2p/Server.go:

    • Added TxCount and SubtreeCount fields to NodeStatusMessage struct
    • Implemented fetching of block assembly state via GetBlockAssemblyState() API in getNodeStatusMessage()
    • Included counts in P2P broadcast message construction in handleNodeStatusNotification()
  • services/p2p/HandleWebsocket.go:

    • Updated SubtreeCount comment to clarify it's for block assembly
    • Existing TxCount field is reused for both block notifications and block assembly count

Context

PR #8 removed BlockAssemblyDetails from node status but didn't add the intended replacement fields. This PR completes that work by adding simple count fields instead of the full state object.

Test plan

  • Verify linting passes (make lint)
  • Verify node status WebSocket messages include tx_count and subtree_count fields
  • Verify P2P broadcasts include these fields and are properly received by peers
  • Verify values correctly reflect block assembly state
  • Test graceful handling when block assembly service is unavailable

ordishs and others added 16 commits October 15, 2025 11:51
… support

- Fix capacity calculation in BlockHeaderMeta.Bytes() to include all fields
- Add ProcessedAt field to BlockHeaderMeta struct for tracking block processing time
- Update serialization/deserialization to handle ProcessedAt timestamp (8 bytes)
- Add ProcessedAt to protobuf GetBlockHeaderResponse with proper timestamp type conversion
- Update HTTP API responses to include Invalid and ProcessedAt fields
- Fix frontend date parsing to handle RFC 3339 timestamp format from JSON API
- Add hasCoinbaseColumn parameter to processBlockHeadersRows
- Fix GetBlockHeadersFromOldest to include processed_at column
- Remove dynamic column detection to improve performance
- Fix variable shadowing with err declaration
Add transaction count and subtree count fields to node status messages
to provide visibility into block assembly state across the P2P network.

Changes:
- Add TxCount and SubtreeCount fields to NodeStatusMessage struct
- Fetch block assembly state via GetBlockAssemblyState() API
- Include counts in both WebSocket notifications and P2P broadcasts
- Reuse existing TxCount field in notificationMsg for block assembly count
Update the dashboard UI to use the new top-level tx_count and subtree_count
fields instead of the old block_assembly_details structure.

Changes:
- Update p2pStore.ts to handle new field structure from backend
- Add subtree_count column to network nodes table
- Update network page comparison logic for new fields
- Add i18n translation for subtree_assembly column
- Fix baseUrl reference in block message handling
@oskarszoon

Copy link
Copy Markdown
Contributor

/claude-review

@claude

claude Bot commented Oct 18, 2025

Copy link
Copy Markdown
Contributor

Claude finished @oskarszoon's task —— View job


Code Review Complete ✅

  • Read changed files and analyze implementation
  • Check for bugs, security issues, and logic errors
  • Verify consistency between backend and frontend
  • Submit review feedback

Review Summary

The implementation correctly adds tx_count and subtree_count fields to node status messages. The changes are well-structured and consistent across backend and frontend.

Backend (Go):

  • ✅ Properly fetches block assembly state via GetBlockAssemblyState() in services/p2p/Server.go:1209
  • ✅ Gracefully handles when block assembly client is unavailable (defaults to 0)
  • ✅ Fields added to both NodeStatusMessage struct (lines 864-865) and P2P broadcast (lines 1261-1262)
  • ✅ Fields properly included in WebSocket notifications (lines 1227-1228)

Frontend (TypeScript/Svelte):

  • ✅ Store properly tracks tx_count and subtree_count in change detection (p2pStore.ts:215-216)
  • ✅ Table columns correctly configured with i18n keys (data.ts:109-123)
  • ✅ Cell renderers properly handle display and formatting (data.ts:286-308)
  • ✅ Translation keys added for new columns (en.json:375-376)

Good practices observed:

  • Error logging when block assembly state fetch fails
  • Nullish coalescing for safe default values
  • Consistent field naming across all layers (snake_case in JSON/DB, camelCase in TypeScript)

Minor Observations

  1. Comment accuracy (services/p2p/HandleWebsocket.go:41): The comment update correctly clarifies that SubtreeCount is for block assembly, which aligns with the PR objective.

  2. Type consistency: The fields use appropriate types (uint64 for tx_count, uint32 for subtree_count), matching the block assembly state API.

  3. UI Integration: The dashboard properly integrates these fields into the connected nodes table with appropriate formatting via formatNum().

No blocking issues found. The implementation is clean and follows existing patterns.


Job Run | Branch: add-tx-subtree-count-to-node-status

@claude claude Bot left a comment

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.

LGTM - Implementation correctly adds tx_count and subtree_count to node status messages with proper error handling and UI integration.

@oskarszoon oskarszoon merged commit 17d3c1e into bsv-blockchain:main Oct 20, 2025
5 checks passed
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.

3 participants