Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 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 @@ -16,6 +16,7 @@ members = [
"frame/evm/precompile/bls12377",
"frame/evm/precompile/dispatch",
"frame/evm/precompile/curve25519",
"client/api",
"client/consensus",
"client/rpc-core",
"client/rpc",
Expand Down Expand Up @@ -134,6 +135,7 @@ substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/
substrate-test-runtime-client = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
# Frontier Client
fc-api = { version = "1.0.0-dev", path = "client/api" }
fc-cli = { version = "1.0.0-dev", path = "client/cli", default-features = false }
fc-consensus = { version = "2.0.0-dev", path = "client/consensus" }
fc-db = { version = "2.0.0-dev", path = "client/db", default-features = false }
Expand Down
20 changes: 20 additions & 0 deletions client/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "fc-api"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think we name it fc-db-api instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this crate may not only contain db-related APIs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain more what you plan to add in the future? It's currently rather confusing for me though as another important "API" we have are the runtime APIs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's named fc-api, so it should be a crate that includes client side API.
Currently we only have db-related API, if I want to split the implementation of db into different crates, then the mapping-sync crate is likely to be refactored, and maybe related apis will be put into this crate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorpaas wdyt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway let's go with this now. We can change the name later.

version = "1.0.0-dev"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
description = "Frontier client interfaces"
authors = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
# Substrate
sp-core = { workspace = true, features = ["default"] }
sp-runtime = { workspace = true, features = ["default"] }
# Frontier
fp-storage = { workspace = true, features = ["default"] }
81 changes: 81 additions & 0 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Frontier.
//
// Copyright (c) 2023 Parity Technologies (UK) Ltd.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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 scale_codec::{Decode, Encode};
// Substrate
use sp_core::{H160, H256};
use sp_runtime::traits::Block as BlockT;
// Frontier
use fp_storage::EthereumStorageSchema;

#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)]
pub struct TransactionMetadata<Block: BlockT> {
pub substrate_block_hash: Block::Hash,
pub ethereum_block_hash: H256,
pub ethereum_index: u32,
}

/// The frontier backend interface.
#[async_trait::async_trait]
pub trait Backend<Block: BlockT>: Send + Sync {
/// Get the substrate hash with the given ethereum block hash.
async fn block_hash(
&self,
ethereum_block_hash: &H256,
) -> Result<Option<Vec<Block::Hash>>, String>;

/// Get the transaction metadata with the given ethereum block hash.
async fn transaction_metadata(
&self,
ethereum_transaction_hash: &H256,
) -> Result<Vec<TransactionMetadata<Block>>, String>;

/// Returns reference to log indexer backend.
fn log_indexer(&self) -> &dyn LogIndexerBackend<Block>;

/// Indicate whether the log indexing feature is supported.
fn is_indexed(&self) -> bool {
self.log_indexer().is_indexed()
}
}

#[derive(Debug, Eq, PartialEq)]
pub struct FilteredLog<Block: BlockT> {
pub substrate_block_hash: Block::Hash,
pub ethereum_block_hash: H256,
pub block_number: u32,
pub ethereum_storage_schema: EthereumStorageSchema,
pub transaction_index: u32,
pub log_index: u32,
}

/// The log indexer backend interface.
#[async_trait::async_trait]
pub trait LogIndexerBackend<Block: BlockT>: Send + Sync {
/// Indicate whether the log indexing feature is supported.
fn is_indexed(&self) -> bool;

/// Filter the logs by the parameters.
async fn filter_logs(
&self,
from_block: u64,
to_block: u64,
addresses: Vec<H160>,
topics: Vec<Vec<Option<H256>>>,
) -> Result<Vec<FilteredLog<Block>>, String>;
}
23 changes: 23 additions & 0 deletions client/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Frontier.
//
// Copyright (c) 2023 Parity Technologies (UK) Ltd.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![deny(unused_crate_dependencies)]

pub mod backend;

pub use self::backend::*;
1 change: 1 addition & 0 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sp-consensus = { workspace = true }
sp-io = { workspace = true }
substrate-test-runtime-client = { workspace = true }
# Frontier
fc-api = { workspace = true }
fc-db = { workspace = true, features = ["rocksdb"] }
frontier-template-runtime = { workspace = true, features = ["default"] }

Expand Down
16 changes: 8 additions & 8 deletions client/cli/src/frontier_db_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ fn commitment_create() {
);

// Expect the offchain-stored transaction metadata to match the one we stored in the runtime.
let expected_transaction_metadata = fc_db::TransactionMetadata {
block_hash,
let expected_transaction_metadata = fc_api::TransactionMetadata {
substrate_block_hash: block_hash,
ethereum_block_hash,
ethereum_index: 0,
};
Expand Down Expand Up @@ -660,8 +660,8 @@ fn commitment_update() {
);

// Expect the offchain-stored transaction metadata to match the one we stored in the runtime.
let expected_transaction_metadata_a1_t1 = fc_db::TransactionMetadata {
block_hash: block_a1_hash,
let expected_transaction_metadata_a1_t1 = fc_api::TransactionMetadata {
substrate_block_hash: block_a1_hash,
ethereum_block_hash,
ethereum_index: 0,
};
Expand Down Expand Up @@ -706,13 +706,13 @@ fn commitment_update() {
);

// Expect the offchain-stored transaction metadata to have data for both blocks.
let expected_transaction_metadata_a2_t1 = fc_db::TransactionMetadata {
block_hash: block_a2_hash,
let expected_transaction_metadata_a2_t1 = fc_api::TransactionMetadata {
substrate_block_hash: block_a2_hash,
ethereum_block_hash,
ethereum_index: 0,
};
let expected_transaction_metadata_a2_t2 = fc_db::TransactionMetadata {
block_hash: block_a2_hash,
let expected_transaction_metadata_a2_t2 = fc_api::TransactionMetadata {
substrate_block_hash: block_a2_hash,
ethereum_block_hash,
ethereum_index: 1,
};
Expand Down
1 change: 1 addition & 0 deletions client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sp-database = { workspace = true }
sp-runtime = { workspace = true }
sp-storage = { workspace = true, optional = true }
# Frontier
fc-api = { workspace = true }
fc-storage = { workspace = true, optional = true }
fp-consensus = { workspace = true, features = ["default"], optional = true }
fp-rpc = { workspace = true, features = ["default"], optional = true }
Expand Down
Loading