Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Mar 30, 2023
2 parents ffc21be + d13668c commit 07fdcfd
Show file tree
Hide file tree
Showing 84 changed files with 2,887 additions and 4,943 deletions.
6,578 changes: 2,008 additions & 4,570 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"client/db",
"client/storage",
"client/mapping-sync",
"primitives/account",
"primitives/consensus",
"primitives/dynamic-fee",
"primitives/evm",
Expand All @@ -41,9 +42,11 @@ environmental = { version = "1.1.3", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.37.0", default-features = false }
impl-serde = { version = "0.4.0", default-features = false }
jsonrpsee = "0.16.2"
kvdb-rocksdb = "0.17.0"
libsecp256k1 = "0.7.1"
libsecp256k1 = { version = "0.7.1", default-features = false }
log = { version = "0.4.17", default-features = false }
parity-db = "0.4.2"
rlp = { version = "0.5", default-features = false }
scale-codec = { package = "parity-scale-codec", version = "3.2.1", default-features = false, features = ["derive"] }
Expand All @@ -53,6 +56,7 @@ serde_json = "1.0"
# Substrate Client
sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down Expand Up @@ -124,6 +128,7 @@ 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-account = { version = "1.0.0-dev", path = "primitives/account", default-features = false }
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 }
fp-ethereum = { version = "1.0.0-dev", path = "primitives/ethereum", default-features = false }
Expand Down
8 changes: 3 additions & 5 deletions client/cli/src/frontier_db_cmd/mapping_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use serde::Deserialize;
// Substrate
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use sp_runtime::traits::Block as BlockT;
// Frontier
use fp_rpc::EthereumRuntimeRPCApi;

Expand Down Expand Up @@ -83,11 +83,10 @@ where
.block_hash(ethereum_block_hash)?
.is_none()
{
let id = BlockId::Hash(*substrate_block_hash);
let existing_transaction_hashes: Vec<H256> = if let Some(statuses) = self
.client
.runtime_api()
.current_transaction_statuses(&id)
.current_transaction_statuses(*substrate_block_hash)
.map_err(|e| format!("{:?}", e))?
{
statuses
Expand Down Expand Up @@ -142,11 +141,10 @@ where
.block_hash(ethereum_block_hash)?
.is_some()
{
let id = BlockId::Hash(*substrate_block_hash);
let existing_transaction_hashes: Vec<H256> = if let Some(statuses) = self
.client
.runtime_api()
.current_transaction_statuses(&id)
.current_transaction_statuses(*substrate_block_hash)
.map_err(|e| format!("{:?}", e))?
{
statuses
Expand Down
14 changes: 3 additions & 11 deletions client/cli/src/frontier_db_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_blockchain::HeaderBackend;
use sp_consensus::BlockOrigin;
use sp_io::hashing::twox_128;
use sp_runtime::{
generic::{Block, BlockId, Header},
generic::{Block, Header},
traits::{BlakeTwo256, Block as BlockT},
};
use substrate_test_runtime_client::{
Expand Down Expand Up @@ -626,11 +626,7 @@ fn commitment_update() {

// Build a block A1 and fill the pallet-ethereum status.
let mut builder = client
.new_block_at(
&BlockId::Hash(client.genesis_hash()),
Default::default(),
false,
)
.new_block_at(client.genesis_hash(), Default::default(), false)
.unwrap();
builder
.push_storage_change(key.clone(), Some(statuses_a1.encode()))
Expand Down Expand Up @@ -680,11 +676,7 @@ fn commitment_update() {
let tmp = tempdir().expect("create a temporary directory");

let mut builder = client
.new_block_at(
&BlockId::Hash(client.genesis_hash()),
Default::default(),
false,
)
.new_block_at(client.genesis_hash(), Default::default(), false)
.unwrap();
builder
.push_storage_change(key, Some(statuses_a2.encode()))
Expand Down
2 changes: 2 additions & 0 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +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/>.

#![deny(unused_crate_dependencies)]

mod frontier_db_cmd;

pub use self::frontier_db_cmd::FrontierDbCmd;
1 change: 0 additions & 1 deletion client/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ sp-blockchain = { workspace = true }
sp-consensus = { workspace = true }
sp-runtime = { workspace = true }
# Frontier
fc-db = { workspace = true }
fp-consensus = { workspace = true, features = ["default"] }
fp-rpc = { workspace = true, features = ["default"] }
2 changes: 2 additions & 0 deletions client/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +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/>.

#![deny(unused_crate_dependencies)]

use std::{collections::HashMap, marker::PhantomData, sync::Arc};

// Substrate
Expand Down
14 changes: 3 additions & 11 deletions client/db/src/kv/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ mod tests {
use sp_blockchain::HeaderBackend;
use sp_core::H256;
use sp_runtime::{
generic::{Block, BlockId, Header},
generic::{Block, Header},
traits::{BlakeTwo256, Block as BlockT},
};
use tempfile::tempdir;
Expand Down Expand Up @@ -406,23 +406,15 @@ mod tests {
// Keep track of the canon hash to later verify the migration replaced it.
// A1
let mut builder = client
.new_block_at(
&BlockId::Hash(previous_canon_block_hash),
Default::default(),
false,
)
.new_block_at(previous_canon_block_hash, Default::default(), false)
.unwrap();
builder.push_storage_change(vec![1], None).unwrap();
let block = builder.build().unwrap().block;
let next_canon_block_hash = block.header.hash();
executor::block_on(client.import(BlockOrigin::Own, block)).unwrap();
// A2
let mut builder = client
.new_block_at(
&BlockId::Hash(previous_canon_block_hash),
Default::default(),
false,
)
.new_block_at(previous_canon_block_hash, Default::default(), false)
.unwrap();
builder.push_storage_change(vec![2], None).unwrap();
let block = builder.build().unwrap().block;
Expand Down
2 changes: 2 additions & 0 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +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/>.

#![deny(unused_crate_dependencies)]

use scale_codec::{Decode, Encode};
// Substrate
pub use sc_client_db::DatabaseSource;
Expand Down
49 changes: 43 additions & 6 deletions client/db/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use fc_storage::OverrideHandle;
use fp_consensus::FindLogError;
use fp_consensus::{FindLogError, Hashes, Log as ConsensusLog, PostLog, PreLog};
use fp_rpc::EthereumRuntimeRPCApi;
use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA};
use futures::TryStreamExt;
Expand Down Expand Up @@ -223,7 +223,10 @@ where
{
let has_api = client
.runtime_api()
.has_api_with::<dyn EthereumRuntimeRPCApi<Block>, _>(&id, |version| version >= 1)
.has_api_with::<dyn EthereumRuntimeRPCApi<Block>, _>(
substrate_genesis_hash,
|version| version >= 1,
)
.expect("runtime api reachable");

log::debug!(
Expand All @@ -238,7 +241,7 @@ where
// Read from the runtime and store the block metadata.
let ethereum_block = client
.runtime_api()
.current_block(&id)
.current_block(substrate_genesis_hash)
.expect("runtime api reachable")
.expect("ethereum genesis block");

Expand Down Expand Up @@ -276,6 +279,7 @@ where
fn insert_block_metadata_inner<Client, BE>(
client: Arc<Client>,
hash: H256,
overrides: Arc<OverrideHandle<Block>>,
) -> Result<BlockMetadata, Error>
where
Client: StorageProvider<Block, BE> + HeaderBackend<Block> + Send + Sync + 'static,
Expand All @@ -290,6 +294,39 @@ where
if let Ok(Some(header)) = client.header(hash) {
match fp_consensus::find_log(header.digest()) {
Ok(log) => {
let schema = Self::onchain_storage_schema(client.as_ref(), hash);
let log_hashes = match log {
ConsensusLog::Post(PostLog::Hashes(post_hashes)) => post_hashes,
ConsensusLog::Post(PostLog::Block(block)) => Hashes::from_block(block),
ConsensusLog::Post(PostLog::BlockHash(expect_eth_block_hash)) => {
let ethereum_block = overrides
.schemas
.get(&schema)
.unwrap_or(&overrides.fallback)
.current_block(hash);
match ethereum_block {
Some(block) => {
let got_eth_block_hash = block.header.hash();
if got_eth_block_hash != expect_eth_block_hash {
return Err(Error::Protocol(format!(
"Ethereum block hash mismatch: \
frontier consensus digest ({expect_eth_block_hash:?}), \
db state ({got_eth_block_hash:?})"
)));
} else {
Hashes::from_block(block)
}
}
None => {
return Err(Error::Protocol(format!(
"Missing ethereum block for hash mismatch {expect_eth_block_hash:?}"
)))
}
}
}
ConsensusLog::Pre(PreLog::Block(block)) => Hashes::from_block(block),
};

let header_number = *header.number();
let block_number =
UniqueSaturatedInto::<u32>::unique_saturated_into(header_number) as i32;
Expand All @@ -313,7 +350,6 @@ where
}
};

let schema = Self::onchain_storage_schema(client.as_ref(), hash);
log::trace!(
target: "frontier-sql",
"[Metadata] Prepared block metadata for #{} ({:?}) canon={}",
Expand All @@ -324,7 +360,7 @@ where
return Ok(BlockMetadata {
substrate_block_hash: hash,
block_number,
post_hashes: log.into_hashes(),
post_hashes: log_hashes,
schema,
is_canon,
});
Expand Down Expand Up @@ -362,8 +398,9 @@ where
BE::State: StateBackend<BlakeTwo256>,
{
// Spawn a blocking task to get block metadata from substrate backend.
let overrides = self.overrides.clone();
let metadata = tokio::task::spawn_blocking(move || {
Self::insert_block_metadata_inner(client.clone(), hash)
Self::insert_block_metadata_inner(client.clone(), hash, overrides)
})
.await
.map_err(|_| Error::Protocol("tokio blocking metadata task failed".to_string()))??;
Expand Down
6 changes: 3 additions & 3 deletions client/mapping-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"]
futures = "0.3.25"
futures-timer = "3.0.2"
log = "0.4.17"
sqlx = { features = ["runtime-tokio-native-tls", "sqlite", "offline"], git = "https://github.com/PureStake/sqlx", branch = "v0.6.2-timeout" }
tokio = { version = "1.19", features = ["macros", "sync"] }

# Substrate
Expand All @@ -26,12 +25,14 @@ sp-runtime = { workspace = true }

# Frontier
fc-db = { workspace = true }
fc-storage = { workspace = true }
fp-consensus = { workspace = true, features = ["default"] }
fp-rpc = { workspace = true, features = ["default"] }

[dev-dependencies]
ethereum = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
sqlx = { features = ["runtime-tokio-native-tls", "sqlite", "offline"], git = "https://github.com/PureStake/sqlx", branch = "v0.6.2-timeout" }
tempfile = "3.3.0"
# Frontier
fp-consensus = { workspace = true, features = ["std"] }
Expand All @@ -41,7 +42,6 @@ ethereum-types = { workspace = true }
fc-rpc = { workspace = true }
frontier-template-runtime = { workspace = true }
sc-block-builder = { workspace = true }
sc-client-db = { workspace = true }
sp-consensus = { workspace = true }
sp-io = { workspace = true }
substrate-test-runtime-client = { workspace = true }
substrate-test-runtime-client = { workspace = true }

0 comments on commit 07fdcfd

Please sign in to comment.