Skip to content

Commit

Permalink
feat: add fc-storage (#1005)
Browse files Browse the repository at this point in the history
* feat: add fc-storage

move storage overrides of `fc-rpc` into a new crate `fc-storage`

* move onchain_storage_schema function into fc-storage

* remove useless trait bound

* move overrides_handle function into fc-storage

* ignore some explicit generic
  • Loading branch information
koushiro authored Feb 28, 2023
1 parent 5588121 commit b984ff1
Show file tree
Hide file tree
Showing 23 changed files with 188 additions and 185 deletions.
20 changes: 19 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"client/rpc-core",
"client/rpc",
"client/db",
"client/storage",
"client/mapping-sync",
"primitives/consensus",
"primitives/dynamic-fee",
Expand Down Expand Up @@ -121,6 +122,7 @@ fc-db = { version = "2.0.0-dev", path = "client/db" }
fc-mapping-sync = { version = "2.0.0-dev", path = "client/mapping-sync" }
fc-rpc = { version = "2.0.0-dev", path = "client/rpc" }
fc-rpc-core = { version = "1.1.0-dev", path = "client/rpc-core" }
fc-storage = { version = "1.0.0-dev", path = "client/storage" }
# Frontier Primitive
fp-consensus = { version = "2.0.0-dev", path = "primitives/consensus", default-features = false }
fp-dynamic-fee = { version = "1.0.0", path = "primitives/dynamic-fee", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sp-storage = { workspace = true }
# Frontier
fc-db = { workspace = true }
fc-rpc-core = { workspace = true }
fc-storage = { workspace = true }
fp-ethereum = { workspace = true, features = ["std"] }
fp-rpc = { workspace = true, features = ["std"] }
fp-storage = { workspace = true, features = ["std"] }
Expand Down
20 changes: 4 additions & 16 deletions client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ where
_ => return Ok(None),
};

let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;
let statuses = block_data_cache
Expand Down Expand Up @@ -113,10 +110,7 @@ where
.expect_block_hash_from_id(&id)
.map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?;

let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;
let statuses = block_data_cache
Expand Down Expand Up @@ -152,10 +146,7 @@ where
Some(hash) => hash,
_ => return Ok(None),
};
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
self.client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash);
let block = self
.overrides
.schemas
Expand Down Expand Up @@ -189,10 +180,7 @@ where
.client
.expect_block_hash_from_id(&id)
.map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?;
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
self.client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash);
let block = self
.overrides
.schemas
Expand Down
10 changes: 3 additions & 7 deletions client/rpc/src/eth/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ use sp_runtime::{
};
// Frontier
use fc_rpc_core::types::*;
use fc_storage::{OverrideHandle, StorageOverride};
use fp_rpc::{EthereumRuntimeRPCApi, TransactionStatus};
use fp_storage::EthereumStorageSchema;

use self::lru_cache::LRUCacheByteLimited;
use crate::{
frontier_backend_client,
overrides::{OverrideHandle, StorageOverride},
};

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

Expand Down Expand Up @@ -198,7 +195,7 @@ impl<B: BlockT> EthBlockDataCacheTask<B> {
handler_call: F,
) where
T: Clone + scale_codec::Encode,
F: FnOnce(&Box<dyn StorageOverride<B> + Send + Sync>) -> EthBlockDataCacheMessage<B>,
F: FnOnce(&Box<dyn StorageOverride<B>>) -> EthBlockDataCacheMessage<B>,
F: Send + 'static,
{
// Data is cached, we respond immediately.
Expand Down Expand Up @@ -318,8 +315,7 @@ where
FeeHistoryCacheItem,
Option<u64>
) {
let schema =
frontier_backend_client::onchain_storage_schema::<B, C, BE>(client.as_ref(), hash);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), hash);
let handler = overrides
.schemas
.get(&schema)
Expand Down
5 changes: 2 additions & 3 deletions client/rpc/src/eth/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use sp_runtime::{
use fc_rpc_core::types::*;
use fp_rpc::EthereumRuntimeRPCApi;

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

impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi, EGA> Eth<B, C, P, CT, BE, H, A, EGA>
where
Expand Down Expand Up @@ -70,8 +70,7 @@ where

pub fn author(&self) -> Result<H160> {
let hash = self.client.info().best_hash;
let schema =
frontier_backend_client::onchain_storage_schema::<B, C, BE>(self.client.as_ref(), hash);
let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), hash);

Ok(self
.overrides
Expand Down
6 changes: 1 addition & 5 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,8 @@ where
};

let block_gas_limit = {
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
&client,
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);
let block = block_data_cache.current_block(schema, substrate_hash).await;

block
.ok_or_else(|| internal_err("block unavailable, cannot query gas limit"))?
.header
Expand Down
6 changes: 2 additions & 4 deletions client/rpc/src/eth/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ where
self.client.expect_block_hash_from_id(&id).map_err(|_| {
internal_err(format!("Expect block number from id: {}", id))
})?;
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
self.client.as_ref(),
substrate_hash,
);
let schema =
fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash);
let handler = self
.overrides
.schemas
Expand Down
14 changes: 4 additions & 10 deletions client/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,8 @@ where
internal_err(format!("Expect block number from id: {}", id))
})?;

let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema =
fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;
if let Some(block) = block {
Expand Down Expand Up @@ -376,10 +374,7 @@ where
Some(hash) => hash,
_ => return Ok(Vec::new()),
};
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;
let statuses = block_data_cache
Expand Down Expand Up @@ -460,8 +455,7 @@ where
.expect_block_hash_from_id(&id)
.map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?;

let schema =
frontier_backend_client::onchain_storage_schema::<B, C, BE>(client, substrate_hash);
let schema = fc_storage::onchain_storage_schema(client, substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;

Expand Down
3 changes: 2 additions & 1 deletion client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ use sp_runtime::{
};
// Frontier
use fc_rpc_core::{types::*, EthApiServer};
use fc_storage::OverrideHandle;
use fp_rpc::{ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi, TransactionStatus};

use crate::{internal_err, overrides::OverrideHandle, public_key, signer::EthSigner};
use crate::{internal_err, public_key, signer::EthSigner};

pub use self::{
cache::{EthBlockDataCacheTask, EthTask},
Expand Down
10 changes: 2 additions & 8 deletions client/rpc/src/eth/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ where
.client
.expect_block_hash_from_id(&id)
.map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?;
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
self.client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash);
Ok(self
.overrides
.schemas
Expand Down Expand Up @@ -173,10 +170,7 @@ where
.client
.expect_block_hash_from_id(&id)
.map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?;
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
self.client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(self.client.as_ref(), substrate_hash);

Ok(self
.overrides
Expand Down
20 changes: 4 additions & 16 deletions client/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ where
_ => return Ok(None),
};

let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;
let statuses = block_data_cache
Expand Down Expand Up @@ -185,10 +182,7 @@ where

let index = index.value();

let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;
let statuses = block_data_cache
Expand Down Expand Up @@ -241,10 +235,7 @@ where
.map_err(|_| internal_err(format!("Expect block number from id: {}", id)))?;

let index = index.value();
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);

let block = block_data_cache.current_block(schema, substrate_hash).await;
let statuses = block_data_cache
Expand Down Expand Up @@ -301,10 +292,7 @@ where
_ => return Ok(None),
};

let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
substrate_hash,
);
let schema = fc_storage::onchain_storage_schema(client.as_ref(), substrate_hash);
let handler = overrides
.schemas
.get(&schema)
Expand Down
21 changes: 9 additions & 12 deletions client/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ use fc_rpc_core::{
},
EthPubSubApiServer,
};
use fc_storage::OverrideHandle;
use fp_rpc::EthereumRuntimeRPCApi;

use crate::{frontier_backend_client, overrides::OverrideHandle};

#[derive(Debug)]
pub struct EthereumSubIdProvider;

Expand Down Expand Up @@ -231,11 +230,10 @@ where
if notification.is_new_best {
let substrate_hash = notification.hash;

let schema = frontier_backend_client::onchain_storage_schema::<
B,
C,
BE,
>(client.as_ref(), notification.hash);
let schema = fc_storage::onchain_storage_schema(
client.as_ref(),
substrate_hash,
);
let handler = overrides
.schemas
.get(&schema)
Expand Down Expand Up @@ -269,11 +267,10 @@ where
.import_notification_stream()
.filter_map(move |notification| {
if notification.is_new_best {
let schema = frontier_backend_client::onchain_storage_schema::<
B,
C,
BE,
>(client.as_ref(), notification.hash);
let schema = fc_storage::onchain_storage_schema(
client.as_ref(),
notification.hash,
);
let handler = overrides
.schemas
.get(&schema)
Expand Down
Loading

0 comments on commit b984ff1

Please sign in to comment.