Skip to content

Conversation

arvidn
Copy link
Contributor

@arvidn arvidn commented Aug 14, 2025

Purpose:

Make some of the RPCs a bit cheaper.

  • make GeneratorBlockInfo include block height. This makes it possible to run the block generator just from this information.
  • change a few calls to get_full_block() -> get_block_info() in the RPCs that run blocks (which is cheaper).
  • run get_puzzle_and_solution_for_coin() in the thread pool for RPCs.
  • get_additions_and_removals is really just a coin store lookup. We currently get the full block just to map the header hash to a height. Change this to parse out the block height with get_height_and_tx_status_from_block() instead of constructing a full block.

Current Behavior:

python tools/validate_rpcs.py -ar -r 100 -s 6758739

2025-08-15 10:12:15,313 INFO     block header hashes loaded from height-to-hash file.
2025-08-15 10:12:20,360 INFO     Processed 887 RPCs in 5.05s, 0.0057s per RPC (985 Blocks completed out of 713016)
2025-08-15 10:12:25,362 INFO     Processed 1249 RPCs in 5.00s, 0.0040s per RPC (2234 Blocks completed out of 713016)
2025-08-15 10:12:30,514 INFO     Processed 1078 RPCs in 5.15s, 0.0048s per RPC (3312 Blocks completed out of 713016)
2025-08-15 10:12:35,546 INFO     Processed 972 RPCs in 5.03s, 0.0052s per RPC (4284 Blocks completed out of 713016)
2025-08-15 10:12:40,563 INFO     Processed 803 RPCs in 5.02s, 0.0062s per RPC (5087 Blocks completed out of 713016)
2025-08-15 10:12:45,566 INFO     Processed 931 RPCs in 5.00s, 0.0054s per RPC (6018 Blocks completed out of 713016)
2025-08-15 10:12:50,569 INFO     Processed 885 RPCs in 5.00s, 0.0057s per RPC (6903 Blocks completed out of 713016)
chia-hotspot-88-123

New Behavior:

python tools/validate_rpcs.py -ar -r 100 -s 6758739

2025-08-15 10:16:21,376 INFO     block header hashes loaded from height-to-hash file.
2025-08-15 10:16:26,602 INFO     Processed 1210 RPCs in 5.23s, 0.0043s per RPC (1308 Blocks completed out of 713021)
2025-08-15 10:16:31,720 INFO     Processed 605 RPCs in 5.12s, 0.0085s per RPC (1913 Blocks completed out of 713021)
2025-08-15 10:16:36,727 INFO     Processed 1483 RPCs in 5.01s, 0.0034s per RPC (3396 Blocks completed out of 713021)
2025-08-15 10:16:41,735 INFO     Processed 1494 RPCs in 5.01s, 0.0034s per RPC (4890 Blocks completed out of 713021)
2025-08-15 10:16:46,735 INFO     Processed 1366 RPCs in 5.00s, 0.0037s per RPC (6256 Blocks completed out of 713021)
2025-08-15 10:16:51,778 INFO     Processed 1250 RPCs in 5.04s, 0.0040s per RPC (7506 Blocks completed out of 713021)
2025-08-15 10:16:56,778 INFO     Processed 538 RPCs in 5.00s, 0.0093s per RPC (8044 Blocks completed out of 713021)
chia-hotspot-64-111

@arvidn arvidn added the Changed Required label for PR that categorizes merge commit message as "Changed" for changelog label Aug 14, 2025
@arvidn arvidn force-pushed the rpc-optimizations branch from dd017b3 to b7967d3 Compare August 15, 2025 06:30
@arvidn arvidn marked this pull request as ready for review August 15, 2025 08:18
@arvidn arvidn requested a review from a team as a code owner August 15, 2025 08:18
@arvidn arvidn requested a review from AmineKhaldi August 20, 2025 09:18
Comment on lines -810 to +819

block: Optional[FullBlock] = await self.service.block_store.get_full_block(header_hash)
if block is None:
block_bytes: Optional[bytes] = await self.service.block_store.get_full_block_bytes(header_hash)
if block_bytes is None:
raise ValueError(f"Block {header_hash.hex()} not found")

block_view = memoryview(block_bytes)
height, _is_tx_block = get_height_and_tx_status_from_block(block_view)

Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to avoid this extra complexity by simply augmenting get_full_block_bytes to return the height as well. We have it in the full_blocks table it already queries.

Comment on lines -237 to +258
buf = skip_reward_chain_block(buf) # reward_chain_block
buf, height = height_from_reward_chain_block(buf) # reward_chain_block
Copy link
Contributor

Choose a reason for hiding this comment

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

We can avoid this added complexity by receiving height in block_info_from_block if we must (to keep returning this augmented GeneratorBlockInfo) instead of computing it. The caller has it already.

Copy link
Contributor

github-actions bot commented Oct 4, 2025

This PR has been flagged as stale due to no activity for over 60 days. It will not be automatically closed, but it has been given a stale-pr label and should be manually reviewed by the relevant parties.

@github-actions github-actions bot added the stale-pr Flagged as stale and in need of manual review label Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changed Required label for PR that categorizes merge commit message as "Changed" for changelog stale-pr Flagged as stale and in need of manual review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants