Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Refactor Relayer Game #250

Merged
merged 19 commits into from
Aug 28, 2020
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
14 changes: 13 additions & 1 deletion 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 @@ -24,6 +24,7 @@ members = [
"primitives/array-bytes",
"primitives/ethereum-primitives",
"primitives/merkle-patricia-trie",
"primitives/relay",
]

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
Expand Down
2 changes: 2 additions & 0 deletions bin/node-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ darwinia-ethereum-offchain = { default-features = false, path = "../../
darwinia-ethereum-relay = { default-features = false, path = "../../../frame/bridge/ethereum/relay" }
darwinia-header-mmr = { default-features = false, path = "../../../frame/header-mmr" }
darwinia-header-mmr-rpc-runtime-api = { default-features = false, path = "../../../frame/header-mmr/rpc/runtime-api" }
darwinia-relay-primitives = { default-features = false, path = "../../../primitives/relay" }
darwinia-relayer-game = { default-features = false, path = "../../../frame/bridge/relayer-game" }
darwinia-staking = { default-features = false, path = "../../../frame/staking" }
darwinia-staking-rpc-runtime-api = { default-features = false, path = "../../../frame/staking/rpc/runtime-api" }
Expand Down Expand Up @@ -87,6 +88,7 @@ std = [
"darwinia-ethereum-relay/std",
"darwinia-header-mmr/std",
"darwinia-header-mmr-rpc-runtime-api/std",
"darwinia-relay-primitives/std",
"darwinia-relayer-game/std",
"darwinia-staking/std",
"darwinia-staking-rpc-runtime-api/std",
Expand Down
51 changes: 22 additions & 29 deletions bin/node-template/runtime/darwinia_types.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"__[frame.system]__": {},
"Address": "AccountId",
"LookupSource": "AccountId",
"__[pallet.balances]__": {},
"BalanceInfo": null,
"BalanceLock": {
Expand Down Expand Up @@ -118,25 +119,29 @@
"kton_bond": "Balance"
},
"__[pallet.bridge.eth]__": {},
"EthTransactionIndex": "(H256, u64)",
"EthHeaderBrief": {
"EthereumTransactionIndex": "(H256, u64)",
"EthereumHeaderBrief": {
"total_difficulty": "U256",
"parent_hash": "H256",
"number": "EthBlockNumber",
"number": "EthereumBlockNumber",
"relayer": "AccountId"
},
"EthBlockNumber": "u64",
"EthHeaderThing": {
"eth_header": "EthHeader",
"EthereumBlockNumber": "u64",
"EthereumHeaderThingWithProof": {
"header": "EthereumHeader",
"ethash_proof": "Vec<EthashProof>",
"mmr_root": "MMRHash",
"mmr_proof": "Vec<MMRHash>"
"mmr_root": "H256",
"mmr_proof": "Vec<H256>"
},
"EthHeader": {
"EthereumHeaderThing": {
"header": "EthereumHeader",
"mmr_root": "H256"
},
"EthereumHeader": {
"parent_hash": "H256",
"timestamp": "u64",
"number": "EthBlockNumber",
"author": "EthAddress",
"number": "EthereumBlockNumber",
"author": "EthereumAddress",
"transactions_root": "H256",
"uncles_hash": "H256",
"extra_data": "Bytes",
Expand All @@ -149,14 +154,14 @@
"seal": "Vec<Bytes>",
"hash": "Option<H256>"
},
"EthAddress": "H160",
"EthereumAddress": "H160",
"Bloom": "[u8; 256; Bloom]",
"H128": "[u8; 16; H128]",
"EthashProof": {
"dag_nodes": "(H512, H512)",
"proof": "Vec<H128>"
},
"Receipt": {
"EthereumReceipt": {
"gas_used": "U256",
"log_bloom": "Bloom",
"logs": "Vec<LogEntry>",
Expand Down Expand Up @@ -203,26 +208,14 @@
},
"__[pallet.relayer-game]__": {},
"Round": "u64",
"TcHeaderThingWithProof": "Vec<u8>",
"TcHeaderThing": "Vec<u8>",
"TcBlockNumber": "Vec<u8>",
"TcHeaderHash": "Vec<u8>",
"TcHeaderMMR": "Vec<u8>",
"MMRHash": "Vec<u8>",
"GameId": "TcBlockNumber",
"RawHeaderThing": "Vec<u8>",
"TcHeaderBrief": {
"number": "TcBlockNumber",
"hash": "TcHeaderHash",
"parent_hash": "TcHeaderHash",
"mmr": "TcHeaderMMR",
"others": "Vec<u8>"
},
"BondedTcHeader": {
"header_brief": "TcHeaderBrief",
"bond": "Balance"
},
"RelayProposal": {
"RelayProposalT": {
"relayer": "AccountId",
"bonded_chain": "Vec<BondedTcHeader>",
"bonded_samples": "Vec<(Balance, TcHeaderThing)>",
"extend_from_header_hash": "Option<TcHeaderHash>"
},
"__[node.rpc]__": {},
Expand Down
45 changes: 25 additions & 20 deletions bin/node-template/runtime/polkadot_compatible_types.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"__[frame.system]__": {},
"Address": "AccountId",
"LookupSource": "AccountId",
"__[pallet.balances]__": {},
"BalanceInfo": null,
"BalanceLock": {
Expand Down Expand Up @@ -88,8 +89,6 @@
"own_power": "Power",
"total_power": "Power",
"others": "Vec<IndividualExposure>",
"total": "Compact<Balance>",
"own": "Compact<Balance>"
},
"IndividualExposure": {
"who": "AccountId",
Expand Down Expand Up @@ -126,29 +125,31 @@
"kton_value": "Balance",
"ring_bond": "Balance",
"kton_bond": "Balance",
"value": "Balance",
"bond": "Balance"
},
"__[pallet.bridge.eth]__": {},
"EthTransactionIndex": "(H256, u64)",
"EthHeaderBrief": {
"EthereumTransactionIndex": "(H256, u64)",
"EthereumHeaderBrief": {
"total_difficulty": "U256",
"parent_hash": "H256",
"number": "EthBlockNumber",
"number": "EthereumBlockNumber",
"relayer": "AccountId"
},
"EthBlockNumber": "u64",
"EthHeaderThing": {
"eth_header": "EthHeader",
"EthereumBlockNumber": "u64",
"EthereumHeaderThingWithProof": {
"header": "EthereumHeader",
"ethash_proof": "Vec<EthashProof>",
"mmr_root": "MMRHash",
"mmr_proof": "Vec<MMRHash>"
"mmr_root": "H256",
"mmr_proof": "Vec<H256>"
},
"EthereumHeaderThing": {
"header": "EthereumHeader",
"mmr_root": "H256"
},
"EthHeader": {
"EthereumHeader": {
"parent_hash": "H256",
"timestamp": "u64",
"number": "EthBlockNumber",
"author": "EthAddress",
"number": "EthereumBlockNumber",
"author": "EthereumAddress",
"transactions_root": "H256",
"uncles_hash": "H256",
"extra_data": "Bytes",
Expand All @@ -161,14 +162,14 @@
"seal": "Vec<Bytes>",
"hash": "Option<H256>"
},
"EthAddress": "H160",
"EthereumAddress": "H160",
"Bloom": "[u8; 256; Bloom]",
"H128": "[u8; 16; H128]",
"EthashProof": {
"dag_nodes": "(H512, H512)",
"proof": "Vec<H128>"
},
"Receipt": {
"EthereumReceipt": {
"gas_used": "U256",
"log_bloom": "Bloom",
"logs": "Vec<LogEntry>",
Expand Down Expand Up @@ -215,12 +216,16 @@
},
"__[pallet.relayer-game]__": {},
"Round": "u64",
"TcHeaderThingWithProof": "Vec<u8>",
"TcHeaderThing": "Vec<u8>",
"TcBlockNumber": "Vec<u8>",
"TcHeaderHash": "Vec<u8>",
"TcHeaderMMR": "Vec<u8>",
"MMRHash": "Vec<u8>",
"GameId": "TcBlockNumber",
"RawHeaderThing": "Vec<u8>",
"RelayProposalT": {
"relayer": "AccountId",
"bonded_samples": "Vec<(Balance, TcHeaderThing)>",
"extend_from_header_hash": "Option<TcHeaderHash>"
},
"__[node.rpc]__": {},
"BalancesRuntimeDispatchInfo": {
"usable_balance": "Balance"
Expand Down
11 changes: 5 additions & 6 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ pub mod impls {
pub mod relay {
// --- darwinia ---
use crate::{impls::*, *};
use darwinia_support::relay::*;
use darwinia_relay_primitives::*;

pub struct EthereumRelayerGameAdjustor;
impl AdjustableRelayerGame for EthereumRelayerGameAdjustor {
type Moment = BlockNumber;
type Balance = Balance;
type TcBlockNumber =
<EthereumRelay as darwinia_support::relay::Relayable>::TcBlockNumber;
type TcBlockNumber = <EthereumRelay as Relayable>::BlockNumber;

fn challenge_time(round: Round) -> Self::Moment {
match round {
Expand All @@ -54,11 +53,11 @@ pub mod impls {
}
}

fn round_from_chain_len(chain_len: u64) -> Round {
chain_len - 1
fn round_of_samples_count(samples_count: u64) -> Round {
samples_count - 1
}

fn chain_len_from_round(round: Round) -> u64 {
fn samples_count_of_round(round: Round) -> u64 {
round + 1
}

Expand Down
11 changes: 3 additions & 8 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,9 @@ use sp_runtime::{
},
DispatchError, DispatchResult,
};
use sp_std::{
borrow::{Borrow, ToOwned},
cmp,
convert::Infallible,
fmt::Debug,
mem,
prelude::*,
};
#[cfg(not(feature = "std"))]
use sp_std::borrow::ToOwned;
use sp_std::{borrow::Borrow, cmp, convert::Infallible, fmt::Debug, mem, prelude::*};
// --- darwinia ---
use darwinia_balances_rpc_runtime_api::RuntimeDispatchInfo;
use darwinia_support::{
Expand Down
33 changes: 18 additions & 15 deletions frame/bridge/ethereum/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ use sp_runtime::{
use sp_std::borrow::ToOwned;
use sp_std::{convert::TryFrom, marker::PhantomData, vec};
// --- darwinia ---
use darwinia_support::{balance::lock::*, relay::EthereumReceipt, traits::OnDepositRedeem};
use ethereum_primitives::{receipt::EthTransactionIndex, EthAddress, U256};
use darwinia_support::{
balance::lock::*,
traits::{EthereumReceipt, OnDepositRedeem},
};
use ethereum_primitives::{receipt::EthereumTransactionIndex, EthereumAddress, U256};
use types::*;

pub trait Trait: frame_system::Trait {
Expand Down Expand Up @@ -77,11 +80,11 @@ decl_event! {
KtonBalance = KtonBalance<T>,
{
/// Some one redeem some *RING*. [account, amount, transaction index]
RedeemRing(AccountId, RingBalance, EthTransactionIndex),
RedeemRing(AccountId, RingBalance, EthereumTransactionIndex),
/// Some one redeem some *KTON*. [account, amount, transaction index]
RedeemKton(AccountId, KtonBalance, EthTransactionIndex),
RedeemKton(AccountId, KtonBalance, EthereumTransactionIndex),
/// Some one redeem a deposit. [account, deposit id, amount, transaction index]
RedeemDeposit(AccountId, DepositId, RingBalance, EthTransactionIndex),
RedeemDeposit(AccountId, DepositId, RingBalance, EthereumTransactionIndex),
}
}

Expand All @@ -104,7 +107,7 @@ decl_error! {
/// *RING* - ALREADY REDEEMED
RingAR,

/// Receipt Proof - INVALID
/// EthereumReceipt Proof - INVALID
ReceiptProofI,

/// Eth Log - PARSING FAILED
Expand All @@ -127,18 +130,18 @@ decl_storage! {
trait Store for Module<T: Trait> as DarwiniaEthereumBacking {
pub RingProofVerified
get(fn ring_proof_verfied)
: map hasher(blake2_128_concat) EthTransactionIndex => Option<bool>;
pub RingRedeemAddress get(fn ring_redeem_address) config(): EthAddress;
: map hasher(blake2_128_concat) EthereumTransactionIndex => Option<bool>;
pub RingRedeemAddress get(fn ring_redeem_address) config(): EthereumAddress;

pub KtonProofVerified
get(fn kton_proof_verfied)
: map hasher(blake2_128_concat) EthTransactionIndex => Option<bool>;
pub KtonRedeemAddress get(fn kton_redeem_address) config(): EthAddress;
: map hasher(blake2_128_concat) EthereumTransactionIndex => Option<bool>;
pub KtonRedeemAddress get(fn kton_redeem_address) config(): EthereumAddress;

pub DepositProofVerified
get(fn deposit_proof_verfied)
: map hasher(blake2_128_concat) EthTransactionIndex => Option<bool>;
pub DepositRedeemAddress get(fn deposit_redeem_address) config(): EthAddress;
: map hasher(blake2_128_concat) EthereumTransactionIndex => Option<bool>;
pub DepositRedeemAddress get(fn deposit_redeem_address) config(): EthereumAddress;
}
add_extra_genesis {
config(ring_locked): RingBalance<T>;
Expand Down Expand Up @@ -200,7 +203,7 @@ decl_module! {
/// - `O(1)`.
/// # </weight>
#[weight = 10_000_000]
pub fn set_ring_redeem_address(origin, new: EthAddress) {
pub fn set_ring_redeem_address(origin, new: EthereumAddress) {
ensure_root(origin)?;
RingRedeemAddress::put(new);
}
Expand All @@ -215,7 +218,7 @@ decl_module! {
/// - `O(1)`.
/// # </weight>
#[weight = 10_000_000]
pub fn set_kton_redeem_address(origin, new: EthAddress) {
pub fn set_kton_redeem_address(origin, new: EthereumAddress) {
ensure_root(origin)?;
KtonRedeemAddress::put(new);
}
Expand All @@ -230,7 +233,7 @@ decl_module! {
/// - `O(1)`.
/// # </weight>
#[weight = 10_000_000]
pub fn set_deposit_redeem_address(origin, new: EthAddress) {
pub fn set_deposit_redeem_address(origin, new: EthereumAddress) {
ensure_root(origin)?;
DepositRedeemAddress::put(new);
}
Expand Down
Loading