Skip to content

Commit

Permalink
Enable TON bridge on stage (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
vovac12 authored Oct 22, 2024
1 parent 92d8f47 commit 58c51a4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
10 changes: 5 additions & 5 deletions node/chain_spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use framenode_runtime::multicollateral_bonding_curve_pool::{
DistributionAccount, DistributionAccountData, DistributionAccounts,
};
use framenode_runtime::opaque::SessionKeys;
#[cfg(feature = "wip")]
#[cfg(feature = "stage")] // EVM/TON bridge
use framenode_runtime::BridgeOutboundChannelConfig;
use framenode_runtime::{
assets, eth_bridge, frame_system, AccountId, AssetId, AssetName, AssetSymbol, AssetsConfig,
Expand Down Expand Up @@ -1211,7 +1211,7 @@ fn testnet_genesis(
TBCD.into(),
];
GenesisConfig {
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
jetton_app: Default::default(),
#[cfg(feature = "wip")] // EVM bridge
evm_fungible_app: Default::default(),
Expand All @@ -1221,7 +1221,7 @@ fn testnet_genesis(
#[cfg(feature = "wip")] // Trustless substrate bridge
beefy_light_client: Default::default(),

#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
bridge_outbound_channel: BridgeOutboundChannelConfig {
interval: 10,
..Default::default()
Expand Down Expand Up @@ -2251,7 +2251,7 @@ fn mainnet_genesis(
)
}));
GenesisConfig {
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
jetton_app: Default::default(),
#[cfg(feature = "wip")] // EVM bridge
evm_fungible_app: Default::default(),
Expand All @@ -2261,7 +2261,7 @@ fn mainnet_genesis(
#[cfg(feature = "wip")] // Trustless substrate bridge
beefy_light_client: Default::default(),

#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
bridge_outbound_channel: BridgeOutboundChannelConfig {
interval: 10,
},
Expand Down
10 changes: 6 additions & 4 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,18 @@ wip = [
"beefy-light-client",
"beefy-light-client-runtime-api",
"evm-fungible-app",
"jetton-app",
"bridge-channel",
"pallet-beefy",
"pallet-beefy-mmr",
"xor-fee/wip",
"soratopia",
"vested-rewards/wip",
]

stage = ["framenode-chain-spec/stage"]
stage = [
"framenode-chain-spec/stage",
"jetton-app",
"bridge-channel",
"soratopia",
]

runtime-benchmarks = [
"apollo-platform/runtime-benchmarks",
Expand Down
12 changes: 6 additions & 6 deletions runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ impl Dispatchable for DispatchableSubstrateBridgeCall {
post_info: Default::default(),
error: DispatchError::Other("Unavailable"),
}),
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
bridge_types::substrate::BridgeCall::JettonApp(msg) => {
let call: jetton_app::Call<crate::Runtime> = msg.into();
let call: crate::RuntimeCall = call.into();
call.dispatch(origin)
}
#[cfg(not(feature = "wip"))] // TON bridge
#[cfg(not(feature = "stage"))] // TON bridge
bridge_types::substrate::BridgeCall::JettonApp(_) => Err(DispatchErrorWithPostInfo {
post_info: Default::default(),
error: DispatchError::Other("Unavailable"),
Expand Down Expand Up @@ -354,12 +354,12 @@ impl GetDispatchInfo for DispatchableSubstrateBridgeCall {
}
#[cfg(not(feature = "wip"))] // EVM bridge
bridge_types::substrate::BridgeCall::FAApp(_) => Default::default(),
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
bridge_types::substrate::BridgeCall::JettonApp(msg) => {
let call: jetton_app::Call<crate::Runtime> = msg.clone().into();
call.get_dispatch_info()
}
#[cfg(not(feature = "wip"))] // TON bridge
#[cfg(not(feature = "stage"))] // TON bridge
bridge_types::substrate::BridgeCall::JettonApp(_) => Default::default(),
}
}
Expand Down Expand Up @@ -536,9 +536,9 @@ impl Contains<DispatchableSubstrateBridgeCall> for SubstrateBridgeCallFilter {
bridge_types::substrate::BridgeCall::FAApp(_) => true,
#[cfg(not(feature = "wip"))] // EVM bridge
bridge_types::substrate::BridgeCall::FAApp(_) => false,
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
bridge_types::substrate::BridgeCall::JettonApp(_) => true,
#[cfg(not(feature = "wip"))] // TON bridge
#[cfg(not(feature = "stage"))] // TON bridge
bridge_types::substrate::BridgeCall::JettonApp(_) => false,
}
}
Expand Down
77 changes: 46 additions & 31 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
extern crate alloc;
use alloc::string::String;
use bridge_types::traits::Verifier;
#[cfg(feature = "wip")] // EVM bridge
use bridge_types::types::GenericAdditionalInboundData;
use bridge_types::{GenericNetworkId, SubNetworkId, H256};
use sp_runtime::traits::Keccak256;

Expand Down Expand Up @@ -257,10 +255,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("sora-substrate"),
impl_name: create_runtime_str!("sora-substrate"),
authoring_version: 1,
spec_version: 100,
spec_version: 101,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 100,
transaction_version: 101,
state_version: 0,
};

Expand Down Expand Up @@ -992,7 +990,7 @@ parameter_types! {
pub const CheckInTransferAmount: Balance = balance!(1000);
}

#[cfg(feature = "wip")] // Soratopia
#[cfg(feature = "stage")] // Soratopia
impl soratopia::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AdminAccount = AdminAccount;
Expand Down Expand Up @@ -2155,11 +2153,14 @@ parameter_types! {

// Ethereum bridge pallets

#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
impl dispatch::Config<dispatch::Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
type OriginOutput =
bridge_types::types::CallOriginOutput<GenericNetworkId, H256, GenericAdditionalInboundData>;
type OriginOutput = bridge_types::types::CallOriginOutput<
GenericNetworkId,
H256,
bridge_types::types::GenericAdditionalInboundData,
>;
type Origin = RuntimeOrigin;
type MessageId = bridge_types::types::MessageId;
type Hashing = Keccak256;
Expand Down Expand Up @@ -2192,7 +2193,7 @@ parameter_types! {
pub const ThisNetworkId: GenericNetworkId = GenericNetworkId::Sub(bridge_types::SubNetworkId::Mainnet);
}

#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
impl bridge_channel::inbound::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Verifier = MultiVerifier;
Expand All @@ -2207,11 +2208,17 @@ impl bridge_channel::inbound::Config for Runtime {
type Balance = Balance;
type MessageStatusNotifier = BridgeProxy;
type OutboundChannel = BridgeOutboundChannel;
#[cfg(feature = "wip")] // EVM bridge
type EVMFeeHandler = EVMFungibleApp;
#[cfg(not(feature = "wip"))] // EVM bridge
type EVMFeeHandler = ();
#[cfg(feature = "wip")] // EVM bridge
type EVMPriorityFee = EVMBridgePriorityFee;
#[cfg(not(feature = "wip"))] // EVM bridge
type EVMPriorityFee = ();
}

#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
impl bridge_channel::outbound::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxMessagePayloadSize = BridgeMaxMessagePayloadSize;
Expand Down Expand Up @@ -2249,7 +2256,11 @@ impl evm_fungible_app::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OutboundChannel = BridgeOutboundChannel;
type CallOrigin = dispatch::EnsureAccount<
bridge_types::types::CallOriginOutput<GenericNetworkId, H256, GenericAdditionalInboundData>,
bridge_types::types::CallOriginOutput<
GenericNetworkId,
H256,
bridge_types::types::GenericAdditionalInboundData,
>,
>;
type AppRegistry = BridgeInboundChannel;
type MessageStatusNotifier = BridgeProxy;
Expand All @@ -2262,11 +2273,15 @@ impl evm_fungible_app::Config for Runtime {
type WeightInfo = ();
}

#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
impl jetton_app::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CallOrigin = dispatch::EnsureAccount<
bridge_types::types::CallOriginOutput<GenericNetworkId, H256, GenericAdditionalInboundData>,
bridge_types::types::CallOriginOutput<
GenericNetworkId,
H256,
bridge_types::types::GenericAdditionalInboundData,
>,
>;
type MessageStatusNotifier = BridgeProxy;
type AssetRegistry = BridgeProxy;
Expand Down Expand Up @@ -2343,7 +2358,7 @@ pub enum MultiProof {
Beefy(<BeefyLightClient as Verifier>::Proof),
#[codec(index = 1)]
Multisig(<MultisigVerifier as Verifier>::Proof),
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
#[codec(index = 2)]
EVMMultisig(<multisig_verifier::MultiEVMVerifier<Runtime> as Verifier>::Proof),
/// This proof is only used for benchmarking purposes
Expand All @@ -2364,7 +2379,7 @@ impl Verifier for MultiVerifier {
#[cfg(feature = "wip")] // Trustless substrate bridge
MultiProof::Beefy(proof) => BeefyLightClient::verify(network_id, message, proof),
MultiProof::Multisig(proof) => MultisigVerifier::verify(network_id, message, proof),
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
MultiProof::EVMMultisig(proof) => {
multisig_verifier::MultiEVMVerifier::<Runtime>::verify(network_id, message, proof)
}
Expand All @@ -2378,7 +2393,7 @@ impl Verifier for MultiVerifier {
#[cfg(feature = "wip")] // Trustless substrate bridge
MultiProof::Beefy(proof) => BeefyLightClient::verify_weight(proof),
MultiProof::Multisig(proof) => MultisigVerifier::verify_weight(proof),
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
MultiProof::EVMMultisig(proof) => {
multisig_verifier::MultiEVMVerifier::<Runtime>::verify_weight(proof)
}
Expand Down Expand Up @@ -2560,15 +2575,15 @@ construct_runtime! {
BridgeProxy: bridge_proxy::{Pallet, Call, Storage, Event} = 103,

// Trustless EVM bridge
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
BridgeInboundChannel: bridge_channel::inbound::{Pallet, Call, Storage, Event<T>, ValidateUnsigned} = 96,
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
BridgeOutboundChannel: bridge_channel::outbound::{Pallet, Config<T>, Storage, Event<T>} = 97,
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
Dispatch: dispatch::<Instance1>::{Pallet, Storage, Event<T>, Origin<T>} = 98,
#[cfg(feature = "wip")] // EVM bridge
EVMFungibleApp: evm_fungible_app::{Pallet, Call, Storage, Event<T>, Config<T>} = 100,
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
JettonApp: jetton_app::{Pallet, Call, Storage, Event<T>, Config<T>} = 101,

// Trustless substrate bridge
Expand Down Expand Up @@ -2607,7 +2622,7 @@ construct_runtime! {
ApolloPlatform: apollo_platform::{Pallet, Call, Storage, Event<T>, ValidateUnsigned} = 114,
ExtendedAssets: extended_assets::{Pallet, Call, Storage, Event<T>} = 115,

#[cfg(feature = "wip")]
#[cfg(feature = "stage")]
Soratopia: soratopia::{Pallet, Call, Storage, Event<T>} = 116,
}
}
Expand Down Expand Up @@ -3347,19 +3362,19 @@ impl_runtime_apis! {
list_benchmark!(list, extra, order_book, OrderBookBench::<Runtime>);

// Trustless bridge
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
list_benchmark!(list, extra, bridge_inbound_channel, BridgeInboundChannel);
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
list_benchmark!(list, extra, bridge_outbound_channel, BridgeOutboundChannel);
#[cfg(feature = "wip")] // EVM bridge
list_benchmark!(list, extra, evm_fungible_app, EVMFungibleApp);
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
list_benchmark!(list, extra, jetton_app, JettonApp);

list_benchmark!(list, extra, evm_bridge_proxy, BridgeProxy);
// Dispatch pallet benchmarks is strictly linked to EVM bridge params
// TODO: fix
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
list_benchmark!(list, extra, dispatch, Dispatch);
list_benchmark!(list, extra, substrate_bridge_channel::inbound, SubstrateBridgeInboundChannel);
list_benchmark!(list, extra, substrate_bridge_channel::outbound, SubstrateBridgeOutboundChannel);
Expand All @@ -3369,7 +3384,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, multisig_verifier, MultisigVerifier);
list_benchmark!(list, extra, extended_assets, ExtendedAssets);

#[cfg(feature = "wip")] // Soratopia
#[cfg(feature = "stage")] // Soratopia
list_benchmark!(list, extra, soratopia, Soratopia);

let storage_info = AllPalletsWithSystem::storage_info();
Expand Down Expand Up @@ -3448,19 +3463,19 @@ impl_runtime_apis! {
add_benchmark!(params, batches, order_book, OrderBookBench::<Runtime>);

// Trustless bridge
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
add_benchmark!(params, batches, bridge_inbound_channel, BridgeInboundChannel);
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
add_benchmark!(params, batches, bridge_outbound_channel, BridgeOutboundChannel);
#[cfg(feature = "wip")] // EVM bridge
add_benchmark!(params, batches, evm_fungible_app, EVMFungibleApp);
#[cfg(feature = "wip")] // TON bridge
#[cfg(feature = "stage")] // TON bridge
add_benchmark!(params, batches, jetton_app, JettonApp);

add_benchmark!(params, batches, evm_bridge_proxy, BridgeProxy);
// Dispatch pallet benchmarks is strictly linked to EVM bridge params
// TODO: fix
#[cfg(feature = "wip")] // EVM bridge
#[cfg(feature = "stage")] // EVM/TON bridge
add_benchmark!(params, batches, dispatch, Dispatch);
add_benchmark!(params, batches, substrate_bridge_channel::inbound, SubstrateBridgeInboundChannel);
add_benchmark!(params, batches, substrate_bridge_channel::outbound, SubstrateBridgeOutboundChannel);
Expand All @@ -3470,7 +3485,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, multisig_verifier, MultisigVerifier);
add_benchmark!(params, batches, extended_assets, ExtendedAssets);

#[cfg(feature = "wip")] // Soratopia
#[cfg(feature = "stage")] // Soratopia
add_benchmark!(params, batches, soratopia, Soratopia);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Expand Down

0 comments on commit 58c51a4

Please sign in to comment.