-
Notifications
You must be signed in to change notification settings - Fork 1.2k
revive/rpc: add ethereum-substrate block hash mapping infrastructure #9616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
be6bc17
322267c
38fa8a8
10878e1
b871ce5
93220bc
a0c0c76
7a98998
f17a0fd
162684e
de8524e
a11f36e
c335bc8
3d93b0f
765ed31
3adba58
904822c
2f23734
d5c48f8
e5fa0a1
cf2671e
a4555fc
72ca6da
0340c5b
0f1f09e
812314d
6d67931
6836c6b
6ae4350
a66e7f5
07e6df6
8e08f71
df52649
a196516
794f29c
efabca6
0765c4e
3feef3f
0b25e82
cfa979d
576bc2b
6e16fd0
10c8fbe
e6e4fa8
1e057f5
6ba63cd
7cfd1a5
8db0b2a
76b3ae1
e18c1a1
fde452e
16b61f4
e1ca942
be058ef
e72a519
a400f7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| CREATE TABLE IF NOT EXISTS eth_to_substrate_blocks ( | ||
| ethereum_block_hash BLOB NOT NULL PRIMARY KEY, | ||
| substrate_block_hash BLOB NOT NULL, | ||
| block_number INTEGER NOT NULL | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_substrate_block_hash ON eth_to_substrate_blocks ( | ||
| substrate_block_hash | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_block_number ON eth_to_substrate_blocks ( | ||
| block_number | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,14 @@ | |
| // limitations under the License. | ||
|
|
||
| use crate::{ | ||
| subxt_client::{self, runtime_types::pallet_revive::storage::ContractInfo, SrcChainConfig}, | ||
| subxt_client::{ | ||
| self, | ||
| runtime_types::pallet_revive::storage::{AccountType, ContractInfo}, | ||
| SrcChainConfig, | ||
| }, | ||
| ClientError, H160, | ||
| }; | ||
| use sp_core::H256; | ||
| use sp_core::{H256, U256}; | ||
| use subxt::{storage::Storage, OnlineClient}; | ||
|
|
||
| use pallet_revive::evm::{block_hash::ReceiptGasInfo, Block}; | ||
|
|
@@ -42,12 +46,15 @@ impl StorageApi { | |
| // TODO: remove once subxt is updated | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dq: @pgherveou do we know to which version subxt should be updated to? Was this caused by substitute-derive of the API codegen? |
||
| let contract_address: subxt::utils::H160 = contract_address.0.into(); | ||
|
|
||
| let query = subxt_client::storage().revive().contract_info_of(contract_address); | ||
| let Some(info) = self.0.fetch(&query).await? else { | ||
| return Err(ClientError::ContractNotFound); | ||
| }; | ||
|
|
||
| Ok(info) | ||
| let query = subxt_client::storage().revive().account_info_of(contract_address); | ||
| self.0 | ||
| .fetch(&query) | ||
| .await? | ||
| .and_then(|info| match info.account_type { | ||
| AccountType::Contract(contract_info) => Some(contract_info), | ||
| _ => None, | ||
| }) | ||
| .ok_or(ClientError::ContractNotFound) | ||
| } | ||
|
|
||
| /// Get the contract trie id for the given contract address. | ||
|
|
@@ -79,13 +86,15 @@ impl StorageApi { | |
| } | ||
|
|
||
| pub async fn get_ethereum_block_hash(&self, number: u64) -> Result<H256, ClientError> { | ||
| let key: subxt::dynamic::Value = number.into(); | ||
| let query = subxt::dynamic::storage("Revive", "BlockHash", vec![key]); | ||
| // Convert u64 to the wrapped U256 type that subxt expects | ||
| let number = subxt::utils::Static(U256::from(number)); | ||
|
|
||
| let Some(info) = self.0.fetch(&query).await? else { | ||
| let query = subxt_client::storage().revive().block_hash(number); | ||
|
||
|
|
||
| let Some(hash) = self.0.fetch(&query).await? else { | ||
| return Err(ClientError::EthereumBlockNotFound); | ||
| }; | ||
| let bytes = info.into_encoded(); | ||
| codec::Decode::decode(&mut &bytes[..]).map_err(|err| err.into()) | ||
|
|
||
| Ok(hash) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gut feeling tells me that fallback is not really needed.
@pgherveou please confirm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I would remove the fallback after the @pgherveou confirms