Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize a simple module for testing store_block_header and relay_receipt #122

Merged
merged 3 commits into from
Nov 28, 2019
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions core/sr-eth-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
rstd = { package = "sr-std", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
#substrate-primitives = {git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
sr-primitives = {git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
rlp = { package = "rlp", git = "https://github.com/darwinia-network/parity-common.git", default-features = false}
rlp_derive = { git = "https://github.com/darwinia-network/parity-common.git" }
primitive-types = { git = "https://github.com/darwinia-network/parity-common.git", default-features = false, features = ["codec", "rlp"] }
Expand All @@ -33,7 +33,7 @@ std = [
"serde/std",
"codec/std",
"rstd/std",
# "substrate-primitives/std",
"sr-primitives/std",
"rlp/std",
"keccak-hash/std",
"primitive-types/std",
Expand Down
5 changes: 3 additions & 2 deletions core/sr-eth-primitives/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ use super::*;
use ethbloom::Bloom;
use pow::EthashSeal;
use rlp::RlpStream;
use sr_primitives::RuntimeDebug;

#[derive(PartialEq, Eq, Clone, Encode, Decode, Copy)]
#[derive(PartialEq, Eq, Clone, Encode, Decode, Copy, RuntimeDebug)]
enum Seal {
/// The seal/signature is included.
With,
/// The seal/signature is not included.
Without,
}

#[derive(Default, PartialEq, Eq, Clone, Encode, Decode)]
#[derive(Default, PartialEq, Eq, Clone, Encode, Decode, RlpEncodable, RlpDecodable, RuntimeDebug)]
pub struct EthHeader {
parent_hash: H256,
timestamp: u64,
Expand Down
1 change: 0 additions & 1 deletion core/sr-eth-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use rstd::vec::Vec;

pub mod encoded;
pub mod error;
//pub mod keccak;
pub mod header;
pub mod pow;
pub mod receipt;
Expand Down
5 changes: 2 additions & 3 deletions core/sr-eth-primitives/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use keccak_hash::KECCAK_EMPTY_LIST_RLP;
use primitive_types::{H160, H256, U128, U256, U512};
use rlp::*;
use rstd::{collections::btree_map::BTreeMap, mem, result};

//use substrate_primitives::RuntimeDebug;
use sr_primitives::RuntimeDebug;

#[derive(Default, PartialEq, Eq, Clone, Encode, Decode)]
pub struct EthashPartial {
Expand Down Expand Up @@ -178,7 +177,7 @@ impl EthashPartial {
}
}

#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct EthashSeal {
/// Ethash seal mix_hash
pub mix_hash: H256,
Expand Down
3 changes: 1 addition & 2 deletions core/sr-eth-primitives/src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::*;
use ethbloom::{Bloom, Input as BloomInput};
use rlp::*;
use rstd::ops::Deref;
use rstd::prelude::*;
//use substrate_primitives::RuntimeDebug;

use codec::{Decode, Encode};
use primitive_types::{H160, H256, U128, U256, U512};
use primitive_types::{H256, U256};

#[derive(PartialEq, Eq, Clone, Encode, Decode)]
pub enum TransactionOutcome {
Expand Down
2 changes: 1 addition & 1 deletion node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl staking::Trait for Runtime {
impl ethereum_bridge::Trait for Runtime {
type Event = Event;
// type Ring = Balances;
type Hash = Hash;
// type Hash = Hash;
}

construct_runtime!(
Expand Down
13 changes: 5 additions & 8 deletions srml/ethereum-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
#blake2 = { version = "0.8.1", default-features = false }
serde = { version = "1.0.101", optional = true }

codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
rstd = { package = "sr-std", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
system = { package = "srml-system", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
#sr-primitives = { git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
sr-primitives = { git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
support = { package = "srml-support", git = "https://github.com/darwinia-network/substrate.git", branch = "darwinia-develop", default-features = false }
sr-eth-primitives = { path = "../../core/sr-eth-primitives", default-features = false }
#merkle-mountain-range = { path = "../../core/merkle-mountain-range", default-features = false }

#web3 = {git = "https://github.com/ABMatrix/rust-web3.git", branch = "develop", default-features = false }
rlp = { package = "rlp", git = "https://github.com/darwinia-network/parity-common.git", default-features = false}

[features]
default = ["std"]
std = [
# "blake2/std",
"serde/std",
"codec/std",
"rstd/std",
# "sr-primitives/std",
"sr-primitives/std",
"support/std",
"system/std",
"sr-eth-primitives/std"
"sr-eth-primitives/std",
"rlp/std",
]
112 changes: 59 additions & 53 deletions srml/ethereum-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,26 @@ use sr_eth_primitives::{
use support::{decl_event, decl_module, decl_storage, dispatch::Result, traits::Currency};
use system::ensure_signed;

//use sr_primitives::RuntimeDebug;
use sr_primitives::RuntimeDebug;

//use web3::types::{
// Address, Block, BlockId, BlockNumber, Bytes, CallRequest, Filter, Index, Log, RawHeader, RawReceipt, SyncState,
// Transaction, TransactionId, TransactionReceipt, TransactionRequest, Work, H256, H520, H64, U128, U256,
//};

//use merkle_mountain_range::{Hash, MerkleMountainRange};
use rlp::{decode, encode};

pub trait Trait: system::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
type Hash: rstd::hash::Hash;
// type Hash: {};
// type Hash: rstd::hash::Hash;
}

//#[derive(PartialEq, Eq, Clone, Encode, Decode)]
//pub struct Proof {
// pub nodes: Vec<Vec<u8>>,
//}
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct Proof {
pub nodes: Vec<Vec<u8>>,
}

//#[derive(PartialEq, Eq, Clone, Encode, Decode)]
//pub struct ActionRecord {
// pub index: u64,
// pub proof: Vec<u8>,
// pub header_hash: H256,
//}
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct ActionRecord {
pub index: u64,
pub proof: Vec<u8>,
pub header_hash: H256,
}

decl_storage! {
trait Store for Module<T: Trait> as EthBridge {
Expand All @@ -48,32 +42,30 @@ decl_storage! {
///
pub BlockList get(block_list): map EthBlockNumber => EthHeader;


// pub HeaderOf get(header_of): map H256 => Option<EthHeader>;
pub HeaderOf get(header_of): map H256 => Option<EthHeader>;

// pub BestHashOf get(best_hash_of): map u64 => Option<H256>;
// pub HashsOf get(hashs_of): map u64 => Vec<H256>;

// Block delay for verify transaction
// pub FinalizeNumber get(finalize_number): Option<u64>;
/// Block delay for verify transaction
pub FinalizeNumber get(finalize_number): Option<u64>;

// pub ActionOf get(action_of): map T::Hash => Option<ActionRecord>;
pub ActionOf get(action_of): map T::Hash => Option<ActionRecord>;

// pub HeaderForIndex get(header_for_index): map H256 => Vec<(u64, T::Hash)>;

// add_extra_genesis {
// config(header): Option<Vec<u8>>;
// config(number): u64;z
// build(|config| {
// if let Some(h) = &config.header {
// BeginNumber::put(header.number);
//
// <Module<T>>::::genesis_header(header);
// } else {
pub HeaderForIndex get(header_for_index): map H256 => Vec<(u64, T::Hash)>;
}
add_extra_genesis {
config(header): Option<Vec<u8>>;
build(|config| {
if let Some(h) = &config.header {
let header: EthHeader = rlp::decode(&h).expect("can't deserialize the header");
BeginHeader::put(header.clone());

<Module<T>>::genesis_header(header);
} else {
// BeginNumber::put(config.number);
// }
// });
// }
}
});
}
}

Expand All @@ -82,21 +74,29 @@ decl_module! {
where
origin: T::Origin
{
// pub fn store_block_header(origin, header: EthHeader) {
// let _relayer = ensure_signed(origin)?;
// let _ = Self::verify(&header)?;
// }
//
// pub fn relay_receipt(origin, proof: ActionRecord) {
// // confirm that the block hash is right
// // get the MPT from the block header
// // Using MPT to verify the proof and index etc.
// }
//
// pub fn submit_header(origin, header: EthHeader) {
// // if header confirmed then return
// // if header in unverified header then challenge
// }
fn deposit_event() = default;

pub fn store_block_header(origin, header: EthHeader) {
let _relayer = ensure_signed(origin)?;
let _ = Self::verify(&header)?;

<Module<T>>::deposit_event(RawEvent::NewHeader(header));
}

pub fn relay_receipt(origin, proof: ActionRecord) {
// confirm that the block hash is right
// get the receipt MPT trie root from the block header
// Using receipt MPT trie root to verify the proof and index etc.

let _relayer = ensure_signed(origin)?;

<Module<T>>::deposit_event(RawEvent::RelayProof(proof));
}

pub fn submit_header(origin, header: EthHeader) {
// if header confirmed then return
// if header in unverified header then challenge
}
}
}

Expand All @@ -105,11 +105,17 @@ decl_event! {
where
<T as system::Trait>::AccountId
{
NewHeader(EthHeader),
RelayProof(ActionRecord),
TODO(AccountId),
}
}

impl<T: Trait> Module<T> {
pub fn genesis_header(header: EthHeader) {
unimplemented!()
}

pub fn adjust_deposit_value() {
unimplemented!()
}
Expand Down