Skip to content

Commit 3c8212c

Browse files
sistemdlrubaszegithub-actions[bot]pgherveou
committed
revive/rpc: Adjust the RPC to utilize the ETH block from storage (#9512)
This PR adjusts the RPC layer of pallet-revive to use Ethereum blocks from storage via runtime APIs and establishes proper Ethereum ↔ Substrate block hash mappings. ## Key Changes ### Block Hash Mapping Infrastructure - **New database table**: `eth_to_substrate_blocks` maps Ethereum block hashes to Substrate block hashes and block numbers - **Bidirectional lookups**: Support for both ETH→Substrate and Substrate→ETH hash resolution with backward compatibility fallbacks - **Block pruning**: Updated to remove stale mappings alongside transaction and log data ### Pallet Changes - **Genesis block initialization**: Added `block_storage::on_finalize_build_eth_block()` call in `BuildGenesisConfig` to properly build and store block 0 ## Testing - Added comprehensive tests for block hash mapping operations - Ethereum vs Substrate hash resolution tests - Fork handling in block pruning tests - Log filtering with Ethereum block hash tests - TransactionInfo deserialization from JSON Value tests ## Implementation Details The implementation uses a **runtime API approach** where the RPC layer queries the runtime for Ethereum blocks and hashes, which are then mapped to Substrate block hashes in the local SQLite database. This provides: 1. **Backward compatibility**: Falls back to treating hashes as Substrate hashes when no mapping exists 2. **Efficient lookups**: Database indices on both Ethereum and Substrate block hashes 3. **Automatic cleanup**: Block mappings are pruned alongside transaction and log data 4. **Genesis block handling**: Block 0 is built during genesis using the block storage infrastructure Builds upon: #9418 Part of: paritytech/contract-issues#139 --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Lukasz Rubaszewski <[email protected]> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: PG Herveou <[email protected]>
1 parent 2543325 commit 3c8212c

28 files changed

Lines changed: 1603 additions & 366 deletions

prdoc/pr_9512.prdoc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
title: 'frame/revive: ETH block storage'
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
This PR adjusts the RPC layer of pallet-revive to use Ethereum blocks from storage via runtime APIs and establishes proper Ethereum ↔ Substrate block hash mappings.
6+
7+
## Key Changes
8+
9+
### Block Hash Mapping Infrastructure
10+
- **New database table**: `eth_to_substrate_blocks` maps Ethereum block hashes to Substrate block hashes and block numbers
11+
- **Bidirectional lookups**: Support for both ETH→Substrate and Substrate→ETH hash resolution with backward compatibility fallbacks
12+
- **Block pruning**: Updated to remove stale mappings alongside transaction and log data
13+
14+
### Pallet Changes
15+
16+
- **Genesis block initialization**: Added `block_storage::on_finalize_build_eth_block()` call in `BuildGenesisConfig` to properly build and store block 0
17+
18+
## Testing
19+
20+
- Added comprehensive tests for block hash mapping operations
21+
- Ethereum vs Substrate hash resolution tests
22+
- Fork handling in block pruning tests
23+
- Log filtering with Ethereum block hash tests
24+
- TransactionInfo deserialization from JSON Value tests
25+
26+
## Implementation Details
27+
28+
The implementation uses a **runtime API approach** where the RPC layer queries the runtime for Ethereum blocks and hashes, which are then mapped to Substrate block hashes in the local SQLite database. This provides:
29+
30+
1. **Backward compatibility**: Falls back to treating hashes as Substrate hashes when no mapping exists
31+
2. **Efficient lookups**: Database indices on both Ethereum and Substrate block hashes
32+
3. **Automatic cleanup**: Block mappings are pruned alongside transaction and log data
33+
4. **Genesis block handling**: Block 0 is built during genesis using the block storage infrastructure
34+
35+
Builds upon: https://github.com/paritytech/polkadot-sdk/pull/9418
36+
Part of: https://github.com/paritytech/contract-issues/issues/139
37+
crates:
38+
- name: pallet-revive
39+
bump: minor
40+
- name: pallet-revive-eth-rpc
41+
bump: major

substrate/frame/revive/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ rand_pcg = { workspace = true, optional = true }
4141
revm = { workspace = true }
4242
rlp = { workspace = true }
4343
scale-info = { features = ["derive"], workspace = true }
44-
serde = { features = ["alloc", "derive"], workspace = true, default-features = false }
44+
serde = { features = ["alloc", "derive"], workspace = true }
45+
serde_json = { features = ["alloc"], workspace = true }
4546

4647
# Polkadot SDK Dependencies
4748
bn = { workspace = true }

substrate/frame/revive/rpc/.sqlx/query-3de332f45edf5ee4592bd0061956305983861ccaea79eec44518e1bca5233920.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/frame/revive/rpc/.sqlx/query-47b830cef6768ed5b119c74037482baef86a7c3d3469873a205805ef342ba031.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/frame/revive/rpc/.sqlx/query-5c0ea8efbd2591e3ede3833acfcadf2d552140a20d84edbf90583da4619bcf2a.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/frame/revive/rpc/.sqlx/query-65a9c520f2fbc1ced140b3c946e53c5b5f22584c291703964bb24e5374fbc74f.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/frame/revive/rpc/.sqlx/query-76dd0f2460cfc0ffa93dda7a42893cbf05b3451cb8e4c4cb6cf86ec70930a11e.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

substrate/frame/revive/rpc/.sqlx/query-7e5be81ad6f5d96bc6dbf62098cbd61d257d1ffad222317634327e12be403ab2.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/frame/revive/rpc/.sqlx/query-de639fe0ac0c3cfdfbbfa07e81a61dae3a284ad4f7979dacb0ccff32cdc39051.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

substrate/frame/revive/rpc/.sqlx/query-e3d7860041663651866032e8fb054cff3e1707381845f47f693177dbce110448.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)