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

Commit

Permalink
add: relay authorities genesis (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier authored Dec 11, 2020
1 parent 4eaeedc commit ef46248
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

15 changes: 13 additions & 2 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ fn pangolin_build_spec_genesis() -> GenesisConfig {
const GENESIS_VALIDATOR_STASH: &'static str = "Alice//stash";
const GENESIS_VALIDATOR_BOND: Balance = COIN;
const GENESIS_EVM_ACCOUNT: &'static str = "0x68898db1012808808c903f390909c52d9f706749";
const GENESIS_ETHEREUM_RELAY_AUTHORITY_SIGNER: &'static str =
"0x6aA70f55E5D770898Dd45aa1b7078b8A80AAbD6C";

const TOKEN_REDEEM_ADDRESS: &'static str = "0x49262B932E439271d05634c32978294C7Ea15d0C";
const DEPOSIT_REDEEM_ADDRESS: &'static str = "0x6EF538314829EfA8386Fc43386cB13B4e0A67D1e";
Expand Down Expand Up @@ -177,7 +179,7 @@ fn pangolin_build_spec_genesis() -> GenesisConfig {
pallet_membership_Instance0: Some(Default::default()),
darwinia_claims: Some(Default::default()),
darwinia_vesting: Some(Default::default()),
pallet_sudo: Some(SudoConfig { key: root }),
pallet_sudo: Some(SudoConfig { key: root.clone() }),
darwinia_crab_issuing: Some(CrabIssuingConfig {
total_mapped_ring: 1 << 56
}),
Expand Down Expand Up @@ -211,6 +213,9 @@ fn pangolin_build_spec_genesis() -> GenesisConfig {
accounts: evm_accounts,
}),
dvm_ethereum: Some(Default::default()),
darwinia_relay_authorities_Instance0: Some(EthereumRelayAuthoritiesConfig {
authorities: vec![(root, fixed_hex_bytes_unchecked!(GENESIS_ETHEREUM_RELAY_AUTHORITY_SIGNER, 20), 1)]
}),
}
}

Expand Down Expand Up @@ -271,6 +276,9 @@ fn pangolin_development_genesis(
endowed_accounts: Vec<AccountId>,
evm_accounts: BTreeMap<H160, GenesisAccount>,
) -> GenesisConfig {
const GENESIS_ETHEREUM_RELAY_AUTHORITY_SIGNER: &'static str =
"0x6aA70f55E5D770898Dd45aa1b7078b8A80AAbD6C";

const TOKEN_REDEEM_ADDRESS: &'static str = "0x49262B932E439271d05634c32978294C7Ea15d0C";
const DEPOSIT_REDEEM_ADDRESS: &'static str = "0x6EF538314829EfA8386Fc43386cB13B4e0A67D1e";
const RING_TOKEN_ADDRESS: &'static str = "0xb52FBE2B925ab79a821b261C82c5Ba0814AAA5e0";
Expand Down Expand Up @@ -332,7 +340,7 @@ fn pangolin_development_genesis(
),
}),
darwinia_vesting: Some(Default::default()),
pallet_sudo: Some(SudoConfig { key: root_key }),
pallet_sudo: Some(SudoConfig { key: root_key.clone() }),
darwinia_crab_issuing: Some(CrabIssuingConfig {
total_mapped_ring: 1 << 56
}),
Expand Down Expand Up @@ -366,5 +374,8 @@ fn pangolin_development_genesis(
accounts: evm_accounts,
}),
dvm_ethereum: Some(Default::default()),
darwinia_relay_authorities_Instance0: Some(EthereumRelayAuthoritiesConfig {
authorities: vec![(root_key, fixed_hex_bytes_unchecked!(GENESIS_ETHEREUM_RELAY_AUTHORITY_SIGNER, 20), 1)]
}),
}
}
2 changes: 2 additions & 0 deletions bin/node/runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde = { version = "1.0.118", optional = true }
smallvec = { version = "1.5.1" }
static_assertions = { version = "1.1.0" }
# darwinia
array-bytes = { default-features = false, path = "../../../../primitives/array-bytes" }
darwinia-balances = { default-features = false, path = "../../../../frame/balances" }
darwinia-balances-rpc-runtime-api = { default-features = false, path = "../../../../frame/balances/rpc/runtime-api" }
darwinia-claims = { default-features = false, path = "../../../../frame/claims" }
Expand Down Expand Up @@ -88,6 +89,7 @@ default = ["std"]
std = [
"codec/std",
"serde",
"array-bytes/std",
"darwinia-balances/std",
"darwinia-balances-rpc-runtime-api/std",
"darwinia-claims/std",
Expand Down
45 changes: 43 additions & 2 deletions bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllModules,
// CustomOnRuntimeUpgrade,
CustomOnRuntimeUpgrade,
>;
/// The payload being signed in transactions.
type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
Expand Down Expand Up @@ -1184,7 +1184,7 @@ construct_runtime!(
EVM: darwinia_evm::{Module, Config, Call, Storage, Event<T>},
Ethereum: dvm_ethereum::{Module, Call, Storage, Event, Config, ValidateUnsigned},

EthereumRelayAuthorities: darwinia_relay_authorities::<Instance0>::{Module, Call, Storage, Event<T>},
EthereumRelayAuthorities: darwinia_relay_authorities::<Instance0>::{Module, Call, Storage, Config<T>, Event<T>},
}
);

Expand Down Expand Up @@ -1568,3 +1568,44 @@ impl dvm_rpc_runtime_api::ConvertTransaction<OpaqueExtrinsic> for TransactionCon
OpaqueExtrinsic::decode(&mut &encoded[..]).expect("Encoded extrinsic is always valid")
}
}

pub struct CustomOnRuntimeUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
// --- substrate ---
use frame_support::migration::*;
// --- darwinia ---
use array_bytes::fixed_hex_bytes_unchecked;
use darwinia_relay_primitives::relay_authorities::RelayAuthority;
use darwinia_support::balance::lock::{LockFor, LockableCurrency, WithdrawReasons};

let account_id = fixed_hex_bytes_unchecked!(
"0x72819fbc1b93196fa230243947c1726cbea7e33044c7eb6f736ff345561f9e4c",
32
)
.into();
let signer = fixed_hex_bytes_unchecked!("0x6aA70f55E5D770898Dd45aa1b7078b8A80AAbD6C", 20);
let stake = 1;

Ring::set_lock(
EthereumRelayAuthoritiesLockId::get(),
&account_id,
LockFor::Common { amount: stake },
WithdrawReasons::all(),
);

put_storage_value(
b"Instance0DarwiniaRelayAuthorities",
b"Authorities",
&[],
vec![RelayAuthority {
account_id,
signer,
stake,
term: System::block_number() + EthereumRelayAuthoritiesTermDuration::get(),
}],
);

<Runtime as frame_system::Trait>::MaximumBlockWeight::get()
}
}
24 changes: 24 additions & 0 deletions frame/bridge/relay-authorities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@ decl_storage! {
/// The mmr root signature submit duration, will be delayed if on authorities change
pub SubmitDuration get(fn submit_duration): BlockNumber<T> = T::SubmitDuration::get();
}
add_extra_genesis {
config(authorities): Vec<(AccountId<T>, Signer<T, I>, RingBalance<T, I>)>;
build(|config| {
let mut authorities = vec![];

for (account_id, signer, stake) in config.authorities.iter() {
T::RingCurrency::set_lock(
T::LockId::get(),
account_id,
LockFor::Common { amount: *stake },
WithdrawReasons::all(),
);

authorities.push(RelayAuthority {
account_id: account_id.to_owned(),
signer: signer.to_owned(),
stake: *stake,
term: <frame_system::Module<T>>::block_number() + T::TermDuration::get()
});
}

<Authorities<T, I>>::put(authorities);
});
}
}

decl_module! {
Expand Down

0 comments on commit ef46248

Please sign in to comment.