Skip to content

Implement mempool RPC commands (GetMempoolInfo, GetRawMempool, GetRawMempoolShard)#66

Open
alchemistkay wants to merge 2 commits intopurpleprotocol:mainfrom
alchemistkay:implement-mempool-rpc-commands
Open

Implement mempool RPC commands (GetMempoolInfo, GetRawMempool, GetRawMempoolShard)#66
alchemistkay wants to merge 2 commits intopurpleprotocol:mainfrom
alchemistkay:implement-mempool-rpc-commands

Conversation

@alchemistkay
Copy link
Contributor

Summary

This PR implements three previously stubbed mempool RPC commands and includes necessary API compatibility fixes to ensure the code builds and all tests pass.

New RPC Implementations

GetMempoolInfo

Returns mempool statistics including:

  • Total number of transactions in mempool
  • Total size of mempool in bytes

Returns MempoolSummary struct (already defined, now properly used).

GetRawMempool

Returns all transaction hashes from the entire mempool across all shards.

GetRawMempoolShard

Returns transaction hashes filtered by specific shard/chain_id.

Both raw mempool commands return a new RawMempool struct containing:

  • transaction_hashes: Vector of transaction hash strings
  • total_transactions: Count of transactions

API Compatibility Fixes

This PR also includes the same API compatibility fixes from PR #65, as this branch is based on main which still has the old API usage:

  • Update mempool access to use tx_map and current_size_bytes fields
  • Update shard method calls to use backend accessor
  • Handle BlockHeader.hash() now returning Option<&Hash256>
  • Update BlockData field access (transactions renamed to txs)
  • Update BlockHeader field access (pos renamed to height)
  • Remove timestamp field usage (removed from BlockHeader in protocol update)
  • Remove transaction fee field usage (no longer stored in blocks)

Testing

  • Build succeeds: ✅ (36 seconds)
  • All 722 tests pass: ✅

Related

This commit implements three previously stubbed mempool RPC commands and
includes API compatibility fixes similar to PR purpleprotocol#65.

New RPC implementations:
- GetMempoolInfo: Returns mempool statistics (transaction count, total size)
- GetRawMempool: Returns all transaction hashes from the entire mempool
- GetRawMempoolShard: Returns transaction hashes filtered by chain_id/shard

API compatibility fixes:
- Update mempool access to use tx_map and current_size_bytes fields
- Update shard method calls to use backend accessor
- Handle BlockHeader.hash() now returning Option<&Hash256>
- Update BlockData field access (transactions renamed to txs)
- Update BlockHeader field access (pos renamed to height)
- Remove timestamp field usage (removed from BlockHeader in protocol update)
- Remove transaction fee field usage (no longer stored in blocks)

New struct added:
- RawMempool: Contains transaction_hashes vector and total_transactions count
@alchemistkay alchemistkay force-pushed the implement-mempool-rpc-commands branch from d6f8ec3 to afffc68 Compare October 30, 2025 14:20
Address review feedback from Octavian:

1. Timestamp retrieval: Query PoW block header at same height
   - Calculate sector_id from shard_id (shard_id / 16)
   - Retrieve timestamp from PowBlockHeader.timestamp
   - Fallback to 0 if PoW block not available

2. Fee calculation: Document approach with TODO for caching
   - Fees should be computed as inputs - outputs
   - Added TODO to implement fee caching in storage
   - Return 0 for now as placeholder until caching implemented
   - Maintainer suggested caching vs runtime computation

The timestamp is now correctly sourced from the PoW chain which
maintains block timestamps. Fee calculation will be properly
implemented via storage caching in a follow-up.
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