Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 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
49 changes: 38 additions & 11 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ dependencies = [
"bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"indexmap 1.9.2",
"once_cell 1.17.0",
"strsim 0.10.0",
"termcolor",
Expand Down Expand Up @@ -1529,6 +1529,14 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"

[[package]]
name = "fork-tree"
version = "3.0.0"
dependencies = [
"parity-scale-codec",
"sgx_tstd",
]

[[package]]
name = "form_urlencoded"
version = "1.1.0"
Expand Down Expand Up @@ -2065,7 +2073,7 @@ dependencies = [
"futures-sink 0.3.25",
"futures-util 0.3.25",
"http 0.2.8",
"indexmap",
"indexmap 1.9.2",
"slab 0.4.7",
"tokio",
"tokio-util 0.7.4",
Expand Down Expand Up @@ -2093,6 +2101,12 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29fba9abe4742d586dfd0c06ae4f7e73a1c2d86b856933509b269d82cdf06e18"

[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"

[[package]]
name = "hashbrown"
version = "0.12.3"
Expand Down Expand Up @@ -2473,6 +2487,16 @@ dependencies = [
"syn",
]

[[package]]
name = "indexmap"
version = "1.6.1"
source = "git+https://github.com/mesalock-linux/indexmap-sgx#19f52458ba64dd7349a5d3a62227619a17e4db85"
dependencies = [
"autocfg 1.1.0",
"hashbrown 0.9.1",
"sgx_tstd",
]

[[package]]
name = "indexmap"
version = "1.9.2"
Expand Down Expand Up @@ -3718,6 +3742,7 @@ dependencies = [
name = "its-consensus-common"
version = "0.9.0"
dependencies = [
"fork-tree",
"itc-parentchain-light-client",
"itc-parentchain-test",
"itp-block-import-queue",
Expand Down Expand Up @@ -4923,7 +4948,7 @@ checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
dependencies = [
"crc32fast",
"hashbrown 0.12.3",
"indexmap",
"indexmap 1.9.2",
"memchr 2.5.0",
]

Expand Down Expand Up @@ -5437,9 +5462,9 @@ dependencies = [

[[package]]
name = "parity-scale-codec"
version = "3.2.1"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a"
checksum = "c3840933452adf7b3b9145e27086a5a3376c619dca1a21b1e5a5af0d54979bed"
dependencies = [
"arrayvec 0.7.2",
"bitvec",
Expand All @@ -5452,9 +5477,9 @@ dependencies = [

[[package]]
name = "parity-scale-codec-derive"
version = "3.1.3"
version = "3.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9299338969a3d2f491d65f140b00ddec470858402f888af98e8642fb5e8965cd"
checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b"
dependencies = [
"proc-macro-crate",
"proc-macro2",
Expand Down Expand Up @@ -6682,6 +6707,7 @@ name = "serde_json"
version = "1.0.60"
source = "git+https://github.com/mesalock-linux/serde-json-sgx?tag=sgx_1.1.3#380893814ad2a057758d825bab798aa117f7362a"
dependencies = [
"indexmap 1.6.1",
"itoa 0.4.5",
"ryu",
"serde 1.0.118 (git+https://github.com/mesalock-linux/serde-sgx)",
Expand All @@ -6705,6 +6731,7 @@ version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
dependencies = [
"indexmap 1.9.2",
"itoa 1.0.5",
"ryu",
"serde 1.0.152",
Expand Down Expand Up @@ -8844,7 +8871,7 @@ version = "0.89.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5d3e08b13876f96dd55608d03cd4883a0545884932d5adf11925876c96daef"
dependencies = [
"indexmap",
"indexmap 1.9.2",
]

[[package]]
Expand All @@ -8856,7 +8883,7 @@ dependencies = [
"anyhow",
"bincode",
"cfg-if 1.0.0",
"indexmap",
"indexmap 1.9.2",
"libc",
"log 0.4.17",
"object 0.29.0",
Expand Down Expand Up @@ -8890,7 +8917,7 @@ dependencies = [
"anyhow",
"cranelift-entity",
"gimli 0.26.2",
"indexmap",
"indexmap 1.9.2",
"log 0.4.17",
"object 0.29.0",
"serde 1.0.152",
Expand Down Expand Up @@ -8942,7 +8969,7 @@ dependencies = [
"anyhow",
"cc",
"cfg-if 1.0.0",
"indexmap",
"indexmap 1.9.2",
"libc",
"log 0.4.17",
"mach",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ members = [
"sidechain/consensus/aura",
"sidechain/consensus/common",
"sidechain/consensus/slots",
"sidechain/fork-tree",
"sidechain/peer-fetch",
"sidechain/primitives",
"sidechain/rpc-handler",
Expand Down
18 changes: 14 additions & 4 deletions enclave-runtime/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ dependencies = [
"cid",
"derive_more",
"env_logger",
"fork-tree",
"frame-support",
"frame-system",
"hex",
Expand Down Expand Up @@ -887,6 +888,14 @@ dependencies = [
"hashbrown 0.3.1",
]

[[package]]
name = "fork-tree"
version = "3.0.0"
dependencies = [
"parity-scale-codec",
"sgx_tstd",
]

[[package]]
name = "fp-evm"
version = "3.0.0-dev"
Expand Down Expand Up @@ -2242,6 +2251,7 @@ dependencies = [
name = "its-consensus-common"
version = "0.9.0"
dependencies = [
"fork-tree",
"itc-parentchain-light-client",
"itp-block-import-queue",
"itp-extrinsics-factory",
Expand Down Expand Up @@ -2910,9 +2920,9 @@ dependencies = [

[[package]]
name = "parity-scale-codec"
version = "3.2.1"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a"
checksum = "c3840933452adf7b3b9145e27086a5a3376c619dca1a21b1e5a5af0d54979bed"
dependencies = [
"arrayvec 0.7.2",
"bitvec",
Expand All @@ -2925,9 +2935,9 @@ dependencies = [

[[package]]
name = "parity-scale-codec-derive"
version = "3.1.3"
version = "3.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9299338969a3d2f491d65f140b00ddec470858402f888af98e8642fb5e8965cd"
checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b"
dependencies = [
"proc-macro-crate",
"proc-macro2",
Expand Down
1 change: 1 addition & 0 deletions enclave-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ cid = { default-features = false, git = "https://github.com/whalelephant/rust-ci
multibase = { default-features = false, git = "https://github.com/whalelephant/rust-multibase", branch = "nstd" }

# local deps
fork-tree = { path = "../sidechain/fork-tree", default-features = false, features = ["sgx"] }
ita-oracle = { path = "../app-libs/oracle", default-features = false, optional = true, features = ["sgx"] }
ita-sgx-runtime = { path = "../app-libs/sgx-runtime", default-features = false }
ita-stf = { path = "../app-libs/stf", default-features = false, features = ["sgx"] }
Expand Down
1 change: 1 addition & 0 deletions enclave-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use log::*;
use sgx_types::sgx_status_t;
use sp_core::crypto::Pair;
use std::{boxed::Box, slice, vec::Vec};
use fork_tree;

mod attestation;
mod empty_impls;
Expand Down
3 changes: 3 additions & 0 deletions sidechain/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ log = { version = "0.4", default-features = false }
thiserror = { version = "1.0.26", optional = true }

# local deps
fork-tree = { path = "../../fork-tree", default-features = false }
itc-parentchain-light-client = { path = "../../../core/parentchain/light-client", default-features = false }
itp-block-import-queue = { path = "../../../core-primitives/block-import-queue", default-features = false }
itp-extrinsics-factory = { path = "../../../core-primitives/extrinsics-factory", default-features = false }
Expand Down Expand Up @@ -60,6 +61,7 @@ std = [
"its-primitives/std",
"its-block-verification/std",
"its-state/std",
"fork-tree/std",
# substrate
"sp-runtime/std",
# scs
Expand All @@ -76,6 +78,7 @@ sgx = [
"itp-sgx-crypto/sgx",
"itp-sgx-externalities/sgx",
"its-state/sgx",
"fork-tree/sgx",
# scs
"its-block-verification/sgx",
]
9 changes: 8 additions & 1 deletion sidechain/consensus/common/src/block_import_queue_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::{Error, Result, SyncBlockFromPeer};
use core::marker::PhantomData;
use itp_block_import_queue::PopFromBlockQueue;
use its_primitives::traits::{Block as BlockTrait, SignedBlock as SignedSidechainBlockTrait};
use its_primitives::traits::{Block as BlockTrait, SignedBlock as SignedSidechainBlockTrait, Header};
use log::debug;
use sp_runtime::traits::Block as ParentchainBlockTrait;
use std::{sync::Arc, time::Instant};
Expand Down Expand Up @@ -74,6 +74,11 @@ where
}
}

fn get_hashes<SignedSidechainBlock: SignedSidechainBlockTrait>(block: SignedSidechainBlock) {
let block_hash = block.hash();
let parent_hash = block.block().header().parent_hash();
}

impl<ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer>
ProcessBlockImportQueue<ParentchainBlock::Header>
for BlockImportQueueWorker<
Expand All @@ -98,6 +103,8 @@ impl<ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer>

loop {
match self.block_import_queue.pop_front() {
// TODO: Add to fork-tree here
// Decide if block should be imported
Ok(maybe_block) => match maybe_block {
Some(block) => {
latest_imported_parentchain_header = self
Expand Down
35 changes: 35 additions & 0 deletions sidechain/consensus/common/src/is_descendent_of_builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use fork_tree::ForkTree;
use std::marker::PhantomData;

// TODO: Pass in Block as Generic param?
struct IsDescendentOfBuilder<Hash>(PhantomData<Hash>);
impl<Hash: PartialEq> IsDescendentOfBuilder<Hash> {
fn build_is_descendent_of(
current: Option<(&Hash, &Hash)>
) -> impl Fn(&Hash, &Hash) -> Result<bool, ()> {
move |base, head| {
// TODO: Add body here
// Need to make call to find_lowest_common_ancestor
Ok(true)
}
}
}

struct LowestCommonAncestorFinder<Hash>(PhantomData<Hash>);
impl <Hash: PartialEq + Default> LowestCommonAncestorFinder<Hash> {
fn find_lowest_common_ancestor(a: Hash, b: Hash) -> Hash {
// TODO: Implement lowest common ancestor algorithm
/*
** Need to access blocks and their headers for BlockHash and BlockNumber perhaps a cache?
** (BlockHash -> BlockHeader)
*/
Default::default()
}
}

#[test]
fn test_build_is_descendent_of_works() {
let is_descendent_of = <IsDescendentOfBuilder<u64>>::build_is_descendent_of(None);
let my_result = is_descendent_of(&42u64, &42u64);
assert_eq!(my_result, Ok(true));
}
1 change: 1 addition & 0 deletions sidechain/consensus/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod block_import_confirmation_handler;
mod block_import_queue_worker;
mod error;
mod peer_block_sync;
mod is_descendent_of_builder;

#[cfg(test)]
mod test;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::{
test::mocks::verifier_mock::VerifierMock,
BlockImport,
Error,
Result,
BlockImportQueueWorker,
SyncBlockFromPeer,
};
use core::marker::PhantomData;
use itp_sgx_crypto::aes::Aes;
use itp_sgx_externalities::SgxExternalities;
use itp_test::mock::onchain_mock::OnchainMock;
use itp_types::H256;
use its_primitives::traits::{ShardIdentifierFor, SignedBlock as SignedSidechainBlockTrait};
use sp_core::Pair;
use itp_block_import_queue::PopFromBlockQueue;
use its_primitives::traits::{Block as BlockTrait, Header};
use sp_runtime::traits::Block as ParentchainBlockTrait;
use std::{collections::VecDeque, sync::RwLock};

pub struct BlockImportQueueWorkerMock<ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer>
where
ParentchainBlock: ParentchainBlockTrait<Hash = H256>,
SignedSidechainBlock:
SignedSidechainBlockTrait<Public = <sp_core::ed25519::Pair as Pair>::Public> + 'static,
{
_phantom: PhantomData<(ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer)>,
}

impl<ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer>
BlockImportQueueWorkerMock<ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer>
where
ParentchainBlock: ParentchainBlockTrait<Hash = H256>,
SignedSidechainBlock:
SignedSidechainBlockTrait<Public = <sp_core::ed25519::Pair as Pair>::Public> + 'static,
SignedSidechainBlock::Block: BlockTrait,
BlockImportQueue: PopFromBlockQueue<BlockType = SignedSidechainBlock>,
PeerBlockSyncer: SyncBlockFromPeer<ParentchainBlock::Header, SignedSidechainBlock>,
{
pub fn new(
) -> Self {
BlockImportQueueWorkerMock {
_phantom: Default::default(),
}
}
}

impl<ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer> Default
for BlockImportQueueWorkerMock<ParentchainBlock, SignedSidechainBlock, BlockImportQueue, PeerBlockSyncer>
where
ParentchainBlock: ParentchainBlockTrait<Hash = H256>,
SignedSidechainBlock:
SignedSidechainBlockTrait<Public = <sp_core::ed25519::Pair as Pair>::Public> + 'static,
{
fn default() -> Self {
BlockImportQueueWorkerMock {
_phantom: Default::default(),
}
}
}

#[test]
fn queue_worker() {
println!("Hello!!!!!!");
}
Loading