Implement mempool RPC commands (GetMempoolInfo, GetRawMempool, GetRawMempoolShard)#66
Open
alchemistkay wants to merge 2 commits intopurpleprotocol:mainfrom
Open
Conversation
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
d6f8ec3 to
afffc68
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Returns
MempoolSummarystruct (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
RawMempoolstruct containing:transaction_hashes: Vector of transaction hash stringstotal_transactions: Count of transactionsAPI 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:
tx_mapandcurrent_size_bytesfieldsbackendaccessorBlockHeader.hash()now returningOption<&Hash256>BlockDatafield access (transactionsrenamed totxs)BlockHeaderfield access (posrenamed toheight)Testing
Related