Skip to content

Commit

Permalink
add: eth offchain workder
Browse files Browse the repository at this point in the history
- get current eth block hight for current time stamp
- get total difficulty, parent hash
- retry in request
- build eth header
- verify eth header
- poc version: pass api key when build
  • Loading branch information
yanganto committed Mar 20, 2020
1 parent 78c06fd commit 0f2d751
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ jobs:
env: RUST_TOOLCHAIN=nightly-2020-02-07 TARGET=native ETHBACKING
script: .maintain/ci/darwinia_test_script.sh eth-backing

- stage: Darwinia Test
env: RUST_TOOLCHAIN=nightly-2020-02-07 TARGET=native ETHOFFCHAIN
script: .maintain/ci/darwinia_test_script.sh eth-offchain

# TODO: remove this when overall test case ready
allow_failures:
- stage: Overall Test
Expand Down
34 changes: 34 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"frame/claims",
"frame/chainrelay/eth/backing",
"frame/chainrelay/eth/relay",
"frame/chainrelay/eth/offchain",
"frame/elections-phragmen",
"frame/staking",
"frame/support",
Expand Down
2 changes: 2 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pallet-claims = { package = "darwinia-claims", default-features = false, path =
pallet-elections-phragmen = { package = "darwinia-elections-phragmen", default-features = false, path = "../../../frame/elections-phragmen" }
pallet-eth-backing = { package = "darwinia-eth-backing", default-features = false, path = "../../../frame/chainrelay/eth/backing" }
pallet-eth-relay = { package = "darwinia-eth-relay", default-features = false, path = "../../../frame/chainrelay/eth/relay" }
pallet-eth-offchain = { package = "darwinia-eth-offchain", default-features = false, path = "../../../frame/chainrelay/eth/offchain" }
pallet-kton = { package = "darwinia-kton", default-features = false, path = "../../../frame/balances/kton" }
pallet-ring = { package = "darwinia-ring", default-features = false, path = "../../../frame/balances/ring" }
pallet-staking = { package = "darwinia-staking", default-features = false, features = ["migrate"], path = "../../../frame/staking" }
Expand Down Expand Up @@ -122,6 +123,7 @@ std = [
"pallet-elections-phragmen/std",
"pallet-eth-backing/std",
"pallet-eth-relay/std",
"pallet-eth-offchain/std",
"pallet-kton/std",
"pallet-ring/std",
"pallet-staking/std",
Expand Down
23 changes: 23 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;

use pallet_eth_offchain;
pub use pallet_ring::Call as RingCall;
pub use pallet_staking::StakerStatus;

Expand Down Expand Up @@ -99,6 +100,27 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
}
}

type SubmitPFTransaction =
frame_system::offchain::TransactionSubmitter<pallet_eth_offchain::crypto::Public, Runtime, UncheckedExtrinsic>;

parameter_types! {
pub const BlockFetchDur: BlockNumber = 3;
// TODO: pass this from command line
// this a poc versiona, build with following command to launch the poc binary
// `APIKEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX cargo build`
pub const EthScanAPIKey: Option<Vec<u8>> = match option_env!("APIKEY"){
Some(s) => Some(s.as_bytes().to_vec()),
None => None,
};
}

impl pallet_eth_offchain::Trait for Runtime {
type Event = Event;
type Call = Call;
type SubmitSignedTransaction = SubmitPFTransaction;
type BlockFetchDur = BlockFetchDur;
type APIKey = EthScanAPIKey;
}
parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1_000_000_000;
Expand Down Expand Up @@ -666,6 +688,7 @@ construct_runtime!(
Elections: pallet_elections_phragmen::{Module, Call, Storage, Event<T>},
EthBacking: pallet_eth_backing::{Module, Call, Storage, Config<T>, Event<T>},
EthRelay: pallet_eth_relay::{Module, Call, Storage, Config<T>, Event<T>},
EthOffchain: pallet_eth_offchain::{Module, Call, Storage, Event<T>},
Kton: pallet_kton::{Module, Call, Storage, Config<T>, Event<T>},
Balances: pallet_ring::{Module, Call, Storage, Config<T>, Event<T>},
Staking: pallet_staking::{Module, Call, Storage, Config<T>, Event<T>},
Expand Down
57 changes: 57 additions & 0 deletions frame/chainrelay/eth/offchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[package]
name = "darwinia-eth-offchain"
version = "0.1.0"
authors = ["yanganto <yanganto@gmail.com>"]
edition = "2018"

[dependencies]
num-traits = { default-features = false, version = "0.2.8" }

sp-std = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1" }
sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1" }
sp-io = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1" }
sp-session = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1" }

frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1" }
frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1" }

pallet-timestamp = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1" }
pallet-eth-relay = { default-features = false, package = "darwinia-eth-relay", path = "../relay" }

parity-scale-codec = { version = "1.0.0", default-features = false, features = ["derive"] }
simple-json = { git = 'https://github.com/jimmychu0807/simple-json', version = '0.1.5', default_features = false }
primitive-types = { default-features = false, features = ["codec", "rlp"], git = "https://github.com/darwinia-network/parity-common.git" }
hex = { default-features = false, version = "0.4.2" }
eth-primitives = { default-features = false, path = "../../../../primitives/eth-primitives" }
ethereum-types = { default-features = false, git = "https://github.com/darwinia-network/parity-common.git" }
ethbloom = { default-features = false, git ="https://github.com/darwinia-network/parity-common.git" }
rlp = { default-features = false, git = "https://github.com/darwinia-network/parity-common.git" }

[build-dependencies]
wasm-builder-runner = { git = "https://github.com/darwinia-network/substrate.git", tag = "v2.0.0-alpha.darwinia.1", package = "substrate-wasm-builder-runner", version = "1.0.4" }

[features]
default = ["std"]
std = [
"num-traits/std",

"sp-std/std",
"sp-io/std",
"sp-runtime/std",
"sp-session/std",

"frame-support/std",
"frame-system/std",

"pallet-timestamp/std",
"pallet-eth-relay/std",

"parity-scale-codec/std",
"simple-json/std",
"primitive-types/std",
"hex/std",
"eth-primitives/std",
"ethereum-types/std",
"ethbloom/std",
"rlp/std",
]
Loading

0 comments on commit 0f2d751

Please sign in to comment.