Skip to content

Commit

Permalink
chore(client): remove useless trait bound (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
koushiro authored Mar 1, 2023
1 parent b984ff1 commit 340ff4e
Show file tree
Hide file tree
Showing 33 changed files with 259 additions and 307 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions client/cli/src/frontier_db_cmd/mapping_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use std::sync::Arc;
use ethereum_types::H256;
use serde::Deserialize;
// Substrate
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
// Frontier
use fp_rpc::EthereumRuntimeRPCApi;
Expand All @@ -46,9 +48,9 @@ pub struct MappingDb<'a, C, B: BlockT> {

impl<'a, C, B: BlockT> MappingDb<'a, C, B>
where
C: sp_api::ProvideRuntimeApi<B>,
C: ProvideRuntimeApi<B>,
C::Api: EthereumRuntimeRPCApi<B>,
C: sp_blockchain::HeaderBackend<B>,
C: HeaderBackend<B>,
{
pub fn new(cmd: &'a FrontierDbCmd, client: Arc<C>, backend: Arc<fc_db::Backend<B>>) -> Self {
Self {
Expand Down
6 changes: 4 additions & 2 deletions client/cli/src/frontier_db_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use ethereum_types::H256;
use serde::Deserialize;
// Substrate
use sc_cli::{PruningParams, SharedParams};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;

use self::{
Expand Down Expand Up @@ -102,9 +104,9 @@ impl FrontierDbCmd {
backend: Arc<fc_db::Backend<B>>,
) -> sc_cli::Result<()>
where
C: sp_api::ProvideRuntimeApi<B>,
C: ProvideRuntimeApi<B>,
C::Api: fp_rpc::EthereumRuntimeRPCApi<B>,
C: sp_blockchain::HeaderBackend<B>,
C: HeaderBackend<B>,
{
match self.column {
Column::Meta => {
Expand Down
70 changes: 34 additions & 36 deletions client/cli/src/frontier_db_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use tempfile::tempdir;
// Substrate
use sc_block_builder::BlockBuilderProvider;
use sc_cli::DatabasePruningMode;
use sp_blockchain::HeaderBackend;
use sp_consensus::BlockOrigin;
use sp_io::hashing::twox_128;
use sp_runtime::{
Expand All @@ -45,14 +46,11 @@ use crate::frontier_db_cmd::{Column, FrontierDbCmd, Operation};
type OpaqueBlock =
Block<Header<u64, BlakeTwo256>, substrate_test_runtime_client::runtime::Extrinsic>;

pub fn open_frontier_backend<C>(
pub fn open_frontier_backend<Block: BlockT, C: HeaderBackend<Block>>(
client: Arc<C>,
path: PathBuf,
) -> Result<Arc<fc_db::Backend<OpaqueBlock>>, String>
where
C: sp_blockchain::HeaderBackend<OpaqueBlock>,
{
Ok(Arc::new(fc_db::Backend::<OpaqueBlock>::new(
) -> Result<Arc<fc_db::Backend<Block>>, String> {
Ok(Arc::new(fc_db::Backend::<Block>::new(
client,
&fc_db::DatabaseSettings {
source: sc_client_db::DatabaseSource::RocksDb {
Expand Down Expand Up @@ -129,8 +127,8 @@ fn schema_create_success_if_value_is_empty() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

assert_eq!(backend.meta().ethereum_schema(), Ok(None));

Expand Down Expand Up @@ -160,8 +158,8 @@ fn schema_create_fails_if_value_is_not_empty() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

let data_before = vec![(EthereumStorageSchema::V2, H256::default())];

Expand Down Expand Up @@ -191,8 +189,8 @@ fn schema_read_works() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

assert_eq!(backend.meta().ethereum_schema(), Ok(None));

Expand Down Expand Up @@ -223,8 +221,8 @@ fn schema_update_works() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

assert_eq!(backend.meta().ethereum_schema(), Ok(None));
// Run the command
Expand All @@ -250,8 +248,8 @@ fn schema_delete_works() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

let data = vec![(EthereumStorageSchema::V2, H256::default())];

Expand Down Expand Up @@ -281,8 +279,8 @@ fn tips_create_success_if_value_is_empty() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

assert_eq!(backend.meta().current_syncing_tips(), Ok(vec![]));
// Run the command
Expand Down Expand Up @@ -310,8 +308,8 @@ fn tips_create_fails_if_value_is_not_empty() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

let data_before = vec![H256::default()];

Expand Down Expand Up @@ -340,8 +338,8 @@ fn tips_read_works() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

assert_eq!(backend.meta().current_syncing_tips(), Ok(vec![]));

Expand Down Expand Up @@ -371,8 +369,8 @@ fn tips_update_works() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

assert_eq!(backend.meta().current_syncing_tips(), Ok(vec![]));
// Run the command
Expand All @@ -398,8 +396,8 @@ fn tips_delete_works() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

let data = vec![H256::default()];

Expand Down Expand Up @@ -429,8 +427,8 @@ fn non_existent_meta_static_keys_are_no_op() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");
let client = client;

let data = vec![(EthereumStorageSchema::V1, H256::default())];
Expand Down Expand Up @@ -503,8 +501,8 @@ fn not_deserializable_input_value_is_no_op() {
let (client, _) = TestClientBuilder::new().build_with_native_executor::<RuntimeApi, _>(None);
let client = Arc::new(client);
// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");
let client = client;

// Run the Create command
Expand Down Expand Up @@ -560,8 +558,8 @@ fn commitment_create() {
let test_value_path = test_json_file(&tmp, &TestValue::Commitment(block_hash));

// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

// Run the command using some ethereum block hash as key.
let ethereum_block_hash = H256::default();
Expand Down Expand Up @@ -645,8 +643,8 @@ fn commitment_update() {
let test_value_path = test_json_file(&tmp, &TestValue::Commitment(block_a1_hash));

// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

// Run the command using some ethereum block hash as key.
let ethereum_block_hash = H256::default();
Expand Down Expand Up @@ -767,8 +765,8 @@ fn mapping_read_works() {
let test_value_path = test_json_file(&tmp, &TestValue::Commitment(block_hash));

// Create a temporary frontier secondary DB.
let backend =
open_frontier_backend(client.clone(), tmp.into_path()).expect("a temporary db was created");
let backend = open_frontier_backend::<OpaqueBlock, _>(client.clone(), tmp.into_path())
.expect("a temporary db was created");

// Create command using some ethereum block hash as key.
let ethereum_block_hash = H256::default();
Expand Down
1 change: 0 additions & 1 deletion client/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"]
async-trait = "0.1"
thiserror = "1.0"
# Substrate
sc-client-api = { workspace = true }
sc-consensus = { workspace = true }
sp-api = { workspace = true }
sp-block-builder = { workspace = true, features = ["std"] }
Expand Down
15 changes: 6 additions & 9 deletions client/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
use std::{collections::HashMap, marker::PhantomData, sync::Arc};

// Substrate
use sc_client_api::{backend::AuxStore, BlockOf};
use sc_consensus::{BlockCheckParams, BlockImport, BlockImportParams, ImportResult};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::{well_known_cache_keys::Id as CacheKeyId, HeaderBackend};
use sp_blockchain::well_known_cache_keys::Id as CacheKeyId;
use sp_consensus::Error as ConsensusError;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
// Frontier
Expand Down Expand Up @@ -82,11 +81,10 @@ impl<Block: BlockT, I: Clone + BlockImport<Block>, C> Clone for FrontierBlockImp
impl<B, I, C> FrontierBlockImport<B, I, C>
where
B: BlockT,
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync,
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>>,
I::Error: Into<ConsensusError>,
C: ProvideRuntimeApi<B> + Send + Sync + HeaderBackend<B> + AuxStore + BlockOf,
C::Api: EthereumRuntimeRPCApi<B>,
C::Api: BlockBuilderApi<B>,
C: ProvideRuntimeApi<B>,
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
{
pub fn new(inner: I, client: Arc<C>, backend: Arc<fc_db::Backend<B>>) -> Self {
Self {
Expand All @@ -104,9 +102,8 @@ where
B: BlockT,
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync,
I::Error: Into<ConsensusError>,
C: ProvideRuntimeApi<B> + Send + Sync + HeaderBackend<B> + AuxStore + BlockOf,
C::Api: EthereumRuntimeRPCApi<B>,
C::Api: BlockBuilderApi<B>,
C: ProvideRuntimeApi<B> + Send + Sync,
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
{
type Error = ConsensusError;
type Transaction = sp_api::TransactionFor<C, B>;
Expand Down
5 changes: 3 additions & 2 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use parking_lot::Mutex;
use scale_codec::{Decode, Encode};
// Substrate
pub use sc_client_db::DatabaseSource;
use sp_blockchain::HeaderBackend;
use sp_core::H256;
pub use sp_database::Database;
use sp_runtime::traits::Block as BlockT;
Expand Down Expand Up @@ -71,7 +72,7 @@ pub fn frontier_database_dir(db_config_dir: &Path, db_path: &str) -> PathBuf {
}

impl<Block: BlockT> Backend<Block> {
pub fn open<C: sp_blockchain::HeaderBackend<Block>>(
pub fn open<C: HeaderBackend<Block>>(
client: Arc<C>,
database: &DatabaseSource,
db_config_dir: &Path,
Expand Down Expand Up @@ -102,7 +103,7 @@ impl<Block: BlockT> Backend<Block> {
)
}

pub fn new<C: sp_blockchain::HeaderBackend<Block>>(
pub fn new<C: HeaderBackend<Block>>(
client: Arc<C>,
config: &DatabaseSettings,
) -> Result<Self, String> {
Expand Down
5 changes: 2 additions & 3 deletions client/db/src/parity_db_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use sp_database::{error::DatabaseError, Change, ColumnId, Transaction};

use crate::Database;
// Substrate
use sp_database::{error::DatabaseError, Change, ColumnId, Database, Transaction};

fn handle_err<T>(result: parity_db::Result<T>) -> T {
match result {
Expand Down
Loading

0 comments on commit 340ff4e

Please sign in to comment.