Skip to content

Commit

Permalink
Prepare nexus runtime upgrade (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Oct 17, 2024
1 parent 8028e84 commit e00c6fd
Show file tree
Hide file tree
Showing 15 changed files with 856 additions and 62 deletions.
7 changes: 6 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ frame-try-runtime = { version = "0.43.0", default-features = false }
pallet-aura = { version = "36.0.0", default-features = false }
pallet-authorship = { version = "37.0.0", default-features = false }
pallet-balances = { version = "38.0.0", default-features = false }
pallet-multisig = { version = "37.0.0", default-features = false }
pallet-proxy = { version = "37.0.0", default-features = false }
pallet-session = { version = "37.0.0", default-features = false }
pallet-sudo = { version = "37.0.0", default-features = false }
pallet-utility = { version = "37.0.0", default-features = false }
Expand Down
6 changes: 5 additions & 1 deletion modules/ismp/pallets/asset-gateway/src/xcm_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ where
let pallet_account = Pallet::<T>::account_id();
let protocol_percentage = Pallet::<T>::protocol_fee_percentage();

let protocol_fees = protocol_percentage * u128::from(amount);
// If destination is ETH mainnet charge a base fee of 2 DOT to cover expensive consensus
// messages
let base_fee =
if who.dest_state_machine == StateMachine::Evm(1) { 20_000_000_000u128 } else { 0 };
let protocol_fees = protocol_percentage * u128::from(amount) + base_fee;
let remainder = amount - protocol_fees.into();
// Mint protocol fees
T::Assets::mint_into(asset_id.clone(), &protocol_account, protocol_fees.into())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn should_dispatch_ismp_request_when_assets_are_received_from_relay_chain() {
let beneficiary: Location = Junctions::X3(Arc::new([
Junction::AccountId32 { network: None, id: ALICE.into() },
Junction::AccountKey20 {
network: Some(NetworkId::Ethereum { chain_id: 1 }),
network: Some(NetworkId::Ethereum { chain_id: 97 }),
key: [1u8; 20],
},
Junction::GeneralIndex(60 * 60),
Expand Down Expand Up @@ -89,7 +89,7 @@ fn should_process_on_accept_module_callback_correctly() {
let beneficiary: Location = Junctions::X3(Arc::new([
Junction::AccountId32 { network: None, id: ALICE.into() },
Junction::AccountKey20 {
network: Some(NetworkId::Ethereum { chain_id: 1 }),
network: Some(NetworkId::Ethereum { chain_id: 97 }),
key: [1u8; 20],
},
Junction::GeneralIndex(60 * 60),
Expand Down Expand Up @@ -197,7 +197,7 @@ fn should_process_on_timeout_module_callback_correctly() {
let beneficiary: Location = Junctions::X3(Arc::new([
Junction::AccountId32 { network: None, id: ALICE.into() },
Junction::AccountKey20 {
network: Some(NetworkId::Ethereum { chain_id: 1 }),
network: Some(NetworkId::Ethereum { chain_id: 97 }),
key: [0u8; 20],
},
Junction::GeneralIndex(60 * 60),
Expand Down Expand Up @@ -266,7 +266,7 @@ fn should_process_on_timeout_module_callback_correctly() {
};
let post = PostRequest {
source: StateMachine::Kusama(100),
dest: StateMachine::Evm(1),
dest: StateMachine::Evm(97),
nonce: 0,
from: H160::zero().0.to_vec(),
to: H160::zero().0.to_vec(),
Expand Down
4 changes: 3 additions & 1 deletion parachain/chainspec/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"/dns4/boot.helikon.io/tcp/8610/p2p/12D3KooWNvVYuuHtV9KSpUXy7puERNvoNyAcRGizp3s2QpHQuuhq",
"/dns4/boot.helikon.io/tcp/8612/wss/p2p/12D3KooWNvVYuuHtV9KSpUXy7puERNvoNyAcRGizp3s2QpHQuuhq",
"/dns/hyperbridge-nexus-boot-ng.dwellir.com/tcp/30367/p2p/12D3KooWSQsd5E7SyPX184B7vPBWAiF5Wjn4DvhSt8TrRB6FQeDk",
"/dns/hyperbridge-nexus-boot-ng.dwellir.com/tcp/443/wss/p2p/12D3KooWSQsd5E7SyPX184B7vPBWAiF5Wjn4DvhSt8TrRB6FQeDk"
"/dns/hyperbridge-nexus-boot-ng.dwellir.com/tcp/443/wss/p2p/12D3KooWSQsd5E7SyPX184B7vPBWAiF5Wjn4DvhSt8TrRB6FQeDk",
"/dns/nexus-bootnode.radiumblock.com/tcp/30333/p2p/12D3KooWJ9J1a3ktfko2UBr8jyx2pQVYYyubfCcMqo3SSsQKQ81o",
"/dns/nexus-bootnode.radiumblock.com/tcp/30336/wss/p2p/12D3KooWJ9J1a3ktfko2UBr8jyx2pQVYYyubfCcMqo3SSsQKQ81o"
],
"telemetryEndpoints": [
[
Expand Down
2 changes: 0 additions & 2 deletions parachain/runtimes/gargantua/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ sp-mmr-primitives = { workspace = true }
simnode-runtime-api = { workspace = true }
hyperbridge-client-machine = { workspace = true }
pallet-token-gateway-inspector = { workspace = true }
pallet-token-gateway = { workspace = true }

[features]
default = [
Expand Down Expand Up @@ -179,7 +178,6 @@ std = [
"pallet-state-coprocessor/std",
"pallet-xcm-gateway/std",
"pallet-token-gateway-inspector/std",
"pallet-token-gateway/std",
"pallet-token-governor/std",
"pallet-assets/std",
"pallet-mmr/std",
Expand Down
25 changes: 12 additions & 13 deletions parachain/runtimes/gargantua/src/ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use crate::{
alloc::{boxed::Box, string::ToString},
weights, AccountId, Assets, Balance, Balances, Ismp, IsmpParachain, Mmr, ParachainInfo,
Runtime, RuntimeEvent, Timestamp, TokenGatewayInspector, TokenGovernor, XcmGateway,
EXISTENTIAL_DEPOSIT,
Runtime, RuntimeEvent, Timestamp, TokenGatewayInspector, TokenGovernor, TreasuryPalletId,
XcmGateway, EXISTENTIAL_DEPOSIT,
};
use anyhow::anyhow;
use frame_support::{
Expand Down Expand Up @@ -106,7 +106,7 @@ impl ismp_grandpa::Config for Runtime {
impl pallet_token_governor::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Dispatcher = Ismp;
type TreasuryAccount = ProtocolAccount;
type TreasuryAccount = TreasuryPalletId;
}

impl pallet_ismp_demo::Config for Runtime {
Expand Down Expand Up @@ -140,10 +140,8 @@ impl pallet_fishermen::Config for Runtime {
type IsmpHost = Ismp;
}

// todo: set corrrect parameters
parameter_types! {
pub const AssetPalletId: PalletId = PalletId(*b"asset-tx");
pub const ProtocolAccount: PalletId = PalletId(*b"protocol");
pub const TransferParams: AssetGatewayParams = AssetGatewayParams::from_parts(Permill::from_parts(1_000)); // 0.1%
}

Expand Down Expand Up @@ -216,13 +214,13 @@ impl IsmpModule for ProxyModule {
let pallet_id =
ModuleId::from_bytes(&request.to).map_err(|err| Error::Custom(err.to_string()))?;

let token_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(&request.source));
let xcm_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(&request.source));
let token_governor = ModuleId::Pallet(PalletId(pallet_token_governor::PALLET_ID));

match pallet_id {
pallet_ismp_demo::PALLET_ID =>
pallet_ismp_demo::IsmpModuleCallback::<Runtime>::default().on_accept(request),
id if id == token_gateway =>
id if id == xcm_gateway =>
pallet_xcm_gateway::Module::<Runtime>::default().on_accept(request),
id if id == token_governor => TokenGovernor::default().on_accept(request),
_ => Err(anyhow!("Destination module not found")),
Expand Down Expand Up @@ -254,23 +252,24 @@ impl IsmpModule for ProxyModule {
}

fn on_timeout(&self, timeout: Timeout) -> Result<(), anyhow::Error> {
let (from, source) = match &timeout {
let (from, _source, dest) = match &timeout {
Timeout::Request(Request::Post(post)) => {
if post.source != HostStateMachine::get() {
TokenGatewayInspector::handle_timeout(post)?;
}
(&post.from, &post.source)
(&post.from, post.source.clone(), post.dest.clone())
},
Timeout::Request(Request::Get(get)) => (&get.from, &get.source),
Timeout::Response(res) => (&res.post.to, &res.post.dest),
Timeout::Request(Request::Get(get)) =>
(&get.from, get.source.clone(), get.dest.clone()),
Timeout::Response(res) => (&res.post.to, res.source_chain(), res.dest_chain()),
};

let pallet_id = ModuleId::from_bytes(from).map_err(|err| Error::Custom(err.to_string()))?;
let token_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(source));
let xcm_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(&dest));
match pallet_id {
pallet_ismp_demo::PALLET_ID =>
pallet_ismp_demo::IsmpModuleCallback::<Runtime>::default().on_timeout(timeout),
id if id == token_gateway =>
id if id == xcm_gateway =>
pallet_xcm_gateway::Module::<Runtime>::default().on_timeout(timeout),
// instead of returning an error, do nothing. The timeout is for a connected chain.
_ => Ok(()),
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/gargantua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("gargantua"),
impl_name: create_runtime_str!("gargantua"),
authoring_version: 1,
spec_version: 1140,
spec_version: 1150,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
19 changes: 16 additions & 3 deletions parachain/runtimes/nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pallet-utility = { workspace = true }
pallet-treasury = { workspace = true}
pallet-asset-rate = { workspace = true}
pallet-collective = { workspace = true}
pallet-multisig = { workspace = true}
pallet-proxy = { workspace = true}

sp-api = { workspace = true }
sp-io = { workspace = true }
Expand Down Expand Up @@ -96,12 +98,15 @@ ismp-parachain = { workspace = true }
ismp-parachain-runtime-api = { workspace = true }
ismp-sync-committee = { workspace = true }
ismp-bsc = { workspace = true }
ismp-grandpa = { workspace = true }
pallet-ismp-relayer = { workspace = true }
pallet-ismp-host-executive = { workspace = true }
pallet-call-decompressor = { workspace = true }
pallet-xcm-gateway = { workspace = true }
pallet-token-governor = { workspace = true }

pallet-fishermen = { workspace = true }
pallet-state-coprocessor = { workspace = true }
pallet-token-gateway-inspector = { workspace = true }

pallet-mmr = { workspace = true }
pallet-mmr-runtime-api = { workspace = true }
Expand Down Expand Up @@ -189,7 +194,13 @@ std = [
"simnode-runtime-api/std",
"hyperbridge-client-machine/std",
"frame-metadata-hash-extension/std",
"anyhow/std"
"anyhow/std",
"pallet-token-gateway-inspector/std",
"pallet-fishermen/std",
"pallet-state-coprocessor/std",
"ismp-grandpa/std",
"pallet-multisig/std",
"pallet-proxy/std"
]

runtime-benchmarks = [
Expand All @@ -214,7 +225,9 @@ runtime-benchmarks = [
"pallet-message-queue/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"parachains-common/runtime-benchmarks"
"parachains-common/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks"
]

try-runtime = [
Expand Down
58 changes: 41 additions & 17 deletions parachain/runtimes/nexus/src/ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
use crate::{
alloc::{boxed::Box, string::ToString},
weights, AccountId, Assets, Balance, Balances, Ismp, IsmpParachain, Mmr, ParachainInfo,
Runtime, RuntimeEvent, Timestamp, XcmGateway, EXISTENTIAL_DEPOSIT,
Runtime, RuntimeEvent, Timestamp, TokenGatewayInspector, TokenGovernor, TreasuryPalletId,
XcmGateway, EXISTENTIAL_DEPOSIT,
};
use frame_support::{
pallet_prelude::{ConstU32, Get},
Expand Down Expand Up @@ -62,6 +63,11 @@ impl ismp_sync_committee::pallet::Config for Runtime {
type IsmpHost = Ismp;
}

impl pallet_state_coprocessor::Config for Runtime {
type IsmpHost = Ismp;
type Mmr = Mmr;
}

pub struct Coprocessor;

impl Get<Option<StateMachine>> for Coprocessor {
Expand All @@ -88,11 +94,17 @@ impl pallet_ismp::Config for Runtime {
IsmpParachain,
HyperbridgeClientMachine<Runtime, Ismp>,
>,
ismp_grandpa::consensus::GrandpaConsensusClient<Runtime>,
);
type Mmr = Mmr;
type WeightProvider = ();
}

impl ismp_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = Ismp;
}

impl pallet_ismp_relayer::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = Ismp;
Expand All @@ -107,15 +119,18 @@ impl pallet_call_decompressor::Config for Runtime {
type MaxCallSize = ConstU32<3>;
}

impl pallet_fishermen::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = Ismp;
}

impl ismp_parachain::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type IsmpHost = Ismp;
}

// todo: set corrrect parameters
parameter_types! {
pub const AssetPalletId: PalletId = PalletId(*b"asset-tx");
pub const ProtocolAccount: PalletId = PalletId(*b"protocol");
pub const TransferParams: AssetGatewayParams = AssetGatewayParams::from_parts(Permill::from_parts(1_000)); // 0.1%
}

Expand All @@ -130,7 +145,7 @@ impl pallet_xcm_gateway::Config for Runtime {
impl pallet_token_governor::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Dispatcher = Ismp;
type TreasuryAccount = ProtocolAccount;
type TreasuryAccount = TreasuryPalletId;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -175,13 +190,14 @@ impl pallet_assets::Config for Runtime {
type BenchmarkHelper = XcmBenchmarkHelper;
}

impl pallet_token_gateway_inspector::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl IsmpModule for ProxyModule {
fn on_accept(&self, request: PostRequest) -> Result<(), anyhow::Error> {
if request.dest != HostStateMachine::get() {
let token_gateway = XcmGateway::token_gateway_address(&request.dest);
if request.source.is_substrate() && request.from == token_gateway.0.to_vec() {
Err(Error::Custom("Illegal request!".into()))?
}
TokenGatewayInspector::inspect_request(&request)?;

Ismp::dispatch_request(
Request::Post(request),
FeeMetadata::<Runtime> { payer: [0u8; 32].into(), fee: Default::default() },
Expand All @@ -192,10 +208,13 @@ impl IsmpModule for ProxyModule {
let pallet_id =
ModuleId::from_bytes(&request.to).map_err(|err| Error::Custom(err.to_string()))?;

let token_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(&request.source));
let xcm_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(&request.source));
let token_governor = ModuleId::Pallet(PalletId(pallet_token_governor::PALLET_ID));

match pallet_id {
id if id == token_gateway =>
id if id == xcm_gateway =>
pallet_xcm_gateway::Module::<Runtime>::default().on_accept(request),
id if id == token_governor => TokenGovernor::default().on_accept(request),
_ => Err(anyhow!("Destination module not found")),
}
}
Expand All @@ -213,18 +232,23 @@ impl IsmpModule for ProxyModule {
}

fn on_timeout(&self, timeout: Timeout) -> Result<(), anyhow::Error> {
let (from, source) = match &timeout {
Timeout::Request(Request::Post(post)) => (&post.from, &post.source),
Timeout::Request(Request::Get(get)) => (&get.from, &get.source),
Timeout::Response(res) => (&res.post.to, &res.post.dest),
let (from, _source, dest) = match &timeout {
Timeout::Request(Request::Post(post)) => {
if post.source != HostStateMachine::get() {
TokenGatewayInspector::handle_timeout(post)?;
}
(&post.from, &post.source, &post.dest)
},
Timeout::Request(Request::Get(get)) => (&get.from, &get.source, &get.dest),
Timeout::Response(res) => (&res.post.to, &res.post.dest, &res.post.dest),
};

let pallet_id = ModuleId::from_bytes(from).map_err(|err| Error::Custom(err.to_string()))?;
let token_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(source));
let xcm_gateway = ModuleId::Evm(XcmGateway::token_gateway_address(dest));
match pallet_id {
id if id == token_gateway =>
id if id == xcm_gateway =>
pallet_xcm_gateway::Module::<Runtime>::default().on_timeout(timeout),
// instead of returning an error, do nothing. The timeout is for a connected chain
// instead of returning an error, do nothing. The timeout is for a connected chain.
_ => Ok(()),
}
}
Expand Down
Loading

0 comments on commit e00c6fd

Please sign in to comment.