Skip to content

Commit 566232c

Browse files
committed
extend ethereum api param
1 parent 3898ada commit 566232c

File tree

17 files changed

+132
-60
lines changed

17 files changed

+132
-60
lines changed

Cargo.lock

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

client/cli/src/frontier_db_cmd/mapping_db.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use serde::Deserialize;
2323
// Substrate
2424
use sp_api::ProvideRuntimeApi;
2525
use sp_blockchain::HeaderBackend;
26+
use sp_runtime::SaturatedConversion;
2627
use sp_runtime::traits::Block as BlockT;
2728
// Frontier
2829
use fp_rpc::EthereumRuntimeRPCApi;
@@ -83,10 +84,15 @@ where
8384
.block_hash(ethereum_block_hash)?
8485
.is_none()
8586
{
87+
let substrate_block_num = self
88+
.client
89+
.number(*substrate_block_hash)
90+
.map_err(|e| format!("{:?}", e))?
91+
.ok_or(format!("substrate block hash: {substrate_block_hash:?} query block number return none"))?;
8692
let existing_transaction_hashes: Vec<H256> = if let Some(statuses) = self
8793
.client
8894
.runtime_api()
89-
.current_transaction_statuses(*substrate_block_hash)
95+
.current_transaction_statuses(*substrate_block_hash, substrate_block_num.saturated_into::<u128>().into())
9096
.map_err(|e| format!("{:?}", e))?
9197
{
9298
statuses
@@ -141,10 +147,15 @@ where
141147
.block_hash(ethereum_block_hash)?
142148
.is_some()
143149
{
150+
let substrate_block_num = self
151+
.client
152+
.number(*substrate_block_hash)
153+
.map_err(|e| format!("{:?}", e))?
154+
.ok_or(format!("substrate block hash: {substrate_block_hash:?} query block number return none"))?;
144155
let existing_transaction_hashes: Vec<H256> = if let Some(statuses) = self
145156
.client
146157
.runtime_api()
147-
.current_transaction_statuses(*substrate_block_hash)
158+
.current_transaction_statuses(*substrate_block_hash, substrate_block_num.saturated_into::<u128>().into())
148159
.map_err(|e| format!("{:?}", e))?
149160
{
150161
statuses

client/db/src/sql/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ where
229229
// Read from the runtime and store the block metadata.
230230
let ethereum_block = client
231231
.runtime_api()
232-
.current_block(substrate_genesis_hash)
232+
.current_block(substrate_genesis_hash, Default::default())
233233
.expect("runtime api reachable")
234234
.expect("ethereum genesis block");
235235

client/mapping-sync/src/kv/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use sc_client_api::backend::{Backend, StorageProvider};
2929
use sp_api::{ApiExt, ProvideRuntimeApi};
3030
use sp_blockchain::{Backend as _, HeaderBackend};
3131
use sp_consensus::SyncOracle;
32+
use sp_runtime::SaturatedConversion;
3233
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Zero};
3334
// Frontier
3435
use fc_storage::OverrideHandle;
@@ -128,7 +129,7 @@ where
128129
let block = if api_version > 1 {
129130
client
130131
.runtime_api()
131-
.current_block(substrate_block_hash)
132+
.current_block(substrate_block_hash, (*header.number()).saturated_into::<u128>().into())
132133
.map_err(|e| format!("{:?}", e))?
133134
} else {
134135
#[allow(deprecated)]

client/rpc/src/eth/block.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ where
128128
let statuses = block_data_cache
129129
.current_transaction_statuses(schema, substrate_hash)
130130
.await;
131-
131+
log::warn!("block_by_number: substrate_hash: {substrate_hash:?}, block: {block:?}, statuses: {statuses:?}");
132132
let base_fee = client.runtime_api().gas_price(substrate_hash).ok();
133133

134134
match (block, statuses) {
@@ -187,6 +187,7 @@ where
187187
.map_err(|_| internal_err(format!("Runtime access error at {}", best_hash)))?;
188188

189189
let base_fee = api.gas_price(best_hash).ok();
190+
log::warn!("block_by_number: best_hash: {best_hash:?}, block: {block:?}, statuses: {statuses:?}");
190191

191192
match (block, statuses) {
192193
(Some(block), Some(statuses)) => Ok(Some(rich_block_build(
@@ -200,7 +201,10 @@ where
200201
_ => Ok(None),
201202
}
202203
}
203-
None => Ok(None),
204+
None => {
205+
log::warn!("block_by_number: none");
206+
Ok(None)
207+
},
204208
}
205209
}
206210

client/rpc/src/eth/cache/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use self::lru_cache::LRUCacheByteLimited;
4747

4848
type WaitList<Hash, T> = HashMap<Hash, Vec<oneshot::Sender<Option<T>>>>;
4949

50+
#[derive(Debug)]
5051
enum EthBlockDataCacheMessage<B: BlockT> {
5152
RequestCurrentBlock {
5253
block_hash: B::Hash,
@@ -201,13 +202,16 @@ impl<B: BlockT> EthBlockDataCacheTask<B> {
201202
return;
202203
}
203204

205+
log::warn!("request_current: not find in cache");
206+
204207
// Another request already triggered caching but the
205208
// response is not known yet, we add the sender to the waiting
206209
// list.
207210
if let Some(waiting) = wait_list.get_mut(&block_hash) {
208211
waiting.push(response_tx);
209212
return;
210213
}
214+
log::warn!("request_current: not find in wait_list");
211215

212216
// Data is neither cached nor already requested, so we start fetching
213217
// the data.
@@ -220,6 +224,8 @@ impl<B: BlockT> EthBlockDataCacheTask<B> {
220224
.unwrap_or(&overrides.fallback);
221225

222226
let message = handler_call(handler);
227+
log::warn!("request_current: send message: {message:?}");
228+
223229
let _ = task_tx.send(message).await;
224230
});
225231
}

client/rpc/src/eth/execute.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use scale_codec::{Decode, Encode};
2525
// Substrate
2626
use sc_client_api::backend::{Backend, StorageProvider};
2727
use sc_transaction_pool::{ChainApi, RCGroup};
28-
use sp_api::{ApiExt, CallApiAt, CallApiAtParams, ProvideRuntimeApi, StorageTransactionCache};
28+
use sp_api::{ApiExt, BlockId, CallApiAt, CallApiAtParams, ProvideRuntimeApi, StorageTransactionCache};
2929
use sp_block_builder::BlockBuilder as BlockBuilderApi;
3030
use sp_blockchain::HeaderBackend;
3131
use sp_core::ExecutionContext;
@@ -103,7 +103,7 @@ where
103103
)
104104
};
105105

106-
let (substrate_hash, api) = match frontier_backend_client::native_block_id::<B, C>(
106+
let (substrate_hash, substrate_block_num, api) = match frontier_backend_client::native_block_id::<B, C>(
107107
self.client.as_ref(),
108108
self.backend.as_ref(),
109109
number,
@@ -115,13 +115,21 @@ where
115115
.client
116116
.expect_block_hash_from_id(&id)
117117
.map_err(|_| crate::err(JSON_RPC_ERROR_DEFAULT, "header not found", None))?;
118-
(hash, self.client.runtime_api())
118+
let num = match id {
119+
BlockId::Hash(hash) => {
120+
self.client.number(hash).map_err(|e| crate::err(JSON_RPC_ERROR_DEFAULT, e.to_string(), None))?
121+
.ok_or(crate::err(JSON_RPC_ERROR_DEFAULT, "Block number not found", None))?
122+
},
123+
BlockId::Number(num) => num,
124+
};
125+
(hash, num, self.client.runtime_api())
119126
}
120127
None => {
121128
// Not mapped in the db, assume pending.
122129
let hash = self.client.info().best_hash;
130+
let num = self.client.info().best_number;
123131
let api = pending_runtime_api(self.client.as_ref(), self.graph.as_ref())?;
124-
(hash, api)
132+
(hash, num, api)
125133
}
126134
};
127135

@@ -134,7 +142,7 @@ where
134142
};
135143

136144
let block = if api_version > 1 {
137-
api.current_block(substrate_hash)
145+
api.current_block(substrate_hash, substrate_block_num.saturated_into::<u128>().into())
138146
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
139147
} else {
140148
#[allow(deprecated)]

client/rpc/src/eth/submit.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use sp_api::{ApiExt, ProvideRuntimeApi};
2727
use sp_block_builder::BlockBuilder as BlockBuilderApi;
2828
use sp_blockchain::HeaderBackend;
2929
use sp_runtime::{
30-
generic::BlockId, traits::Block as BlockT, transaction_validity::TransactionSource,
30+
generic::BlockId, traits::Block as BlockT, transaction_validity::TransactionSource, SaturatedConversion,
3131
};
3232
// Frontier
3333
use fc_rpc_core::types::*;
@@ -81,12 +81,13 @@ where
8181
};
8282

8383
let hash = self.client.info().best_hash;
84+
let number = self.client.info().best_number;
8485

8586
let gas_price = request.gas_price;
8687
let gas_limit = match request.gas {
8788
Some(gas_limit) => gas_limit,
8889
None => {
89-
let block = self.client.runtime_api().current_block(hash);
90+
let block = self.client.runtime_api().current_block(hash, number.saturated_into::<u128>().into());
9091
if let Ok(Some(block)) = block {
9192
block.header.gas_limit
9293
} else {

client/rpc/src/eth/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ where
376376
}
377377
}
378378
};
379-
379+
log::warn!("");
380380
let status = statuses[index].clone();
381381
let mut cumulative_receipts = receipts;
382382
cumulative_receipts.truncate((status.transaction_index + 1) as usize);

client/storage/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1414
ethereum = { workspace = true, features = ["with-codec"] }
1515
ethereum-types = { workspace = true }
1616
scale-codec = { package = "parity-scale-codec", workspace = true }
17+
log = { workspace = true }
1718

1819
# Substrate
1920
sc-client-api = { workspace = true }

0 commit comments

Comments
 (0)