Skip to content

Commit

Permalink
Replace the is_canon
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Apr 24, 2024
1 parent c5650bb commit 69ef658
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 60 deletions.
2 changes: 1 addition & 1 deletion client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use fp_rpc::EthereumRuntimeRPCApi;

use crate::{
eth::{rich_block_build, BlockInfo, Eth, EthConfig},
frontier_backend_client, internal_err,
internal_err,
};

impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use fp_storage::{EVM_ACCOUNT_CODES, PALLET_EVM};

use crate::{
eth::{Eth, EthConfig},
frontier_backend_client, internal_err,
internal_err,
};

/// Default JSONRPC error code return by geth
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/src/eth/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use fp_rpc::EthereumRuntimeRPCApi;

use crate::{
eth::{Eth, EthConfig},
frontier_backend_client, internal_err,
internal_err,
};

impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/src/eth/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use fp_rpc::EthereumRuntimeRPCApi;

use crate::{
eth::{Eth, EthConfig},
frontier_backend_client, internal_err,
internal_err,
};

impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
Expand Down
72 changes: 16 additions & 56 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,6 @@ pub mod frontier_backend_client {
}
}

// pub async fn native_block_id<B: BlockT, C>(
// client: &C,
// backend: &dyn fc_api::Backend<B>,
// number: Option<BlockNumberOrHash>,
// ) -> RpcResult<Option<BlockId<B>>>
// where
// B: BlockT,
// C: HeaderBackend<B> + 'static,
// {
// Ok(match number.unwrap_or(BlockNumberOrHash::Latest) {
// BlockNumberOrHash::Hash { hash, .. } => {
// if let Ok(Some(hash)) = load_hash::<B, C>(client, backend, hash).await {
// Some(BlockId::Hash(hash))
// } else {
// None
// }
// }
// BlockNumberOrHash::Num(number) => Some(BlockId::Number(number.unique_saturated_into())),
// BlockNumberOrHash::Latest => Some(BlockId::Hash(client.info().best_hash)),
// BlockNumberOrHash::Earliest => Some(BlockId::Number(Zero::zero())),
// BlockNumberOrHash::Pending => None,
// BlockNumberOrHash::Safe => Some(BlockId::Hash(client.info().finalized_hash)),
// BlockNumberOrHash::Finalized => Some(BlockId::Hash(client.info().finalized_hash)),
// })
// }

pub async fn load_hash<B: BlockT, C>(
client: &C,
backend: &dyn fc_api::Backend<B>,
Expand All @@ -230,27 +204,14 @@ pub mod frontier_backend_client {

if let Some(substrate_hashes) = substrate_hashes {
for substrate_hash in substrate_hashes {
if is_canon::<B, C>(client, substrate_hash) {
if backend.is_canon(substrate_hash).await {
return Ok(Some(substrate_hash));
}
}
}
Ok(None)
}

pub fn is_canon<B: BlockT, C>(client: &C, target_hash: B::Hash) -> bool
where
B: BlockT,
C: HeaderBackend<B> + 'static,
{
if let Ok(Some(number)) = client.number(target_hash) {
if let Ok(Some(hash)) = client.hash(number) {
return hash == target_hash;
}
}
false
}

pub async fn load_transactions<B: BlockT, C>(
client: &C,
backend: &dyn fc_api::Backend<B>,
Expand All @@ -266,22 +227,21 @@ pub mod frontier_backend_client {
.await
.map_err(|err| internal_err(format!("fetch aux store failed: {:?}", err)))?;

transaction_metadata
.iter()
.find(|meta| is_canon::<B, C>(client, meta.substrate_block_hash))
.map_or_else(
|| {
if !only_canonical && transaction_metadata.len() > 0 {
Ok(Some((
transaction_metadata[0].ethereum_block_hash,
transaction_metadata[0].ethereum_index,
)))
} else {
Ok(None)
}
},
|meta| Ok(Some((meta.ethereum_block_hash, meta.ethereum_index))),
)
for meta in &transaction_metadata {
if backend.is_canon(meta.substrate_block_hash).await {
return Ok(Some((meta.ethereum_block_hash, meta.ethereum_index)));
} else {
if !only_canonical && transaction_metadata.len() > 0 {
return Ok(Some((
transaction_metadata[0].ethereum_block_hash,
transaction_metadata[0].ethereum_index,
)));
} else {
return Ok(None);
}
}
}
Ok(None)
}
}

Expand Down

0 comments on commit 69ef658

Please sign in to comment.