Skip to content

Commit

Permalink
Proxy contracts (#55)
Browse files Browse the repository at this point in the history
* Fix cumulus builds

* Update cumulus (#46)

* Create Agent (#47)

* add hashed description

* use existing account

* add call filter

* Create Agent (#48)

* initial

* update cargo lock

* handle local accounts and pallets

* Add set_gateway to safe call filter (#49)

* Fix cumulus bridgehub runtime for proxy contracts. (#50)

Co-authored-by: claravanstaden <Cats 4 life!>

* Update inbound queue benchmarks. (#51)

* Update inbound queue benchmarks.

* Update inbound queue benchmarks.

---------

Co-authored-by: claravanstaden <Cats 4 life!>

* Asset transfer (#52)

* update registry to gateway

* added agent config

* ws

* increase message size

---------

Co-authored-by: David Dunn <26876072+doubledup@users.noreply.github.com>
Co-authored-by: Ron <yrong1997@gmail.com>
Co-authored-by: Alistair Singh <alistair.singh7@gmail.com>
Co-authored-by: Clara van Staden <claravanstaden64@gmail.com>
  • Loading branch information
5 people authored Jul 30, 2023
1 parent 9b83c73 commit bc52d55
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 42 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion parachains/runtimes/assets/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
(
FromSiblingParachain<parachain_info::Pallet<Runtime>>,
snowbridge_router_primitives::inbound::FromEthereumGlobalConsensus<
crate::bridging::EthereumRegistryLocation,
crate::bridging::EthereumGatewayLocation,
>,
),
ForeignCreatorsSovereignAccountOf,
Expand Down
10 changes: 5 additions & 5 deletions parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,11 @@ pub mod bridging {
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

// The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets.
pub EthereumRegistryLocation: MultiLocation = EthereumLocation::get()
pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get()
.pushed_with_interior(
AccountKey20 {
network: None,
key: hex_literal::hex!("D184c103F7acc340847eEE82a0B909E3358bc28d"),
key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"),
}
).unwrap();

Expand Down Expand Up @@ -604,14 +604,14 @@ pub mod bridging {
EthereumLocation::get(),
AssetFilter::ByMultiLocation(
MultiLocationFilter::default()
.add_starts_with(EthereumRegistryLocation::get())
.add_starts_with(EthereumGatewayLocation::get())
)
),
(
EthereumRegistryLocation::get(),
EthereumGatewayLocation::get(),
AssetFilter::ByMultiLocation(
MultiLocationFilter::default()
.add_starts_with(EthereumRegistryLocation::get())
.add_starts_with(EthereumGatewayLocation::get())
)
),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ runtime-benchmarks = [
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"snowbridge-control/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"snowbridge-inbound-queue/runtime-benchmarks",
"snowbridge-outbound-queue/runtime-benchmarks",
Expand Down
26 changes: 17 additions & 9 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod xcm_config;
use constants::currency::*;
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_router_primitives::outbound::AgentHashedDescription;
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
Expand Down Expand Up @@ -67,18 +68,20 @@ use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot,
};

use pallet_xcm::EnsureXcm;

pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};
use xcm::v3::NetworkId::{self, Rococo};
use xcm_config::{RelayLocation, UniversalLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};

use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_runtime::HeaderId;

#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;

pub use snowbridge_core::MessageId;

use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};

Expand Down Expand Up @@ -589,18 +592,17 @@ impl<T: snowbridge_ethereum_beacon_client::Config> BenchmarkHelper<T> for Runtim

impl snowbridge_inbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Verifier = snowbridge_ethereum_beacon_client::Pallet<Runtime>;
type Token = Balances;
type Reward = Reward;
type Verifier = snowbridge_ethereum_beacon_client::Pallet<Runtime>;
type XcmSender = XcmRouter;
type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo<Runtime>;
type AllowListLength = ConstU32<8>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
}

parameter_types! {
pub const MaxMessagePayloadSize: u32 = 256;
pub const MaxMessagePayloadSize: u32 = 512;
pub const MaxMessagesPerBlock: u32 = 32;
}

Expand Down Expand Up @@ -667,16 +669,22 @@ impl snowbridge_ethereum_beacon_client::Config for Runtime {
}

parameter_types! {
pub const GovernanceProxyContract: snowbridge_core::ContractId = snowbridge_core::ContractId::new(hex_literal::hex!("44bef07c29162ad04096f5cbe78ca2df62dffe97cea85825f08d13319e13f34a"));
// TODO: placeholder value - choose a real one
pub const MaxUpgradeDataSize: u32 = 1024;
pub const RelayNetwork: NetworkId = Rococo;
}

impl snowbridge_control::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OwnParaId = ParachainInfo;
type OutboundQueue = EthereumOutboundQueue;
type GovernanceProxyContract = GovernanceProxyContract;
type MessageHasher = BlakeTwo256;
type WeightInfo = ();
type MaxUpgradeDataSize = MaxUpgradeDataSize;
type CreateAgentOrigin = EnsureXcm<Everything>;
type AgentHashedDescription = AgentHashedDescription;
type UniversalLocation = UniversalLocation;
type RelayLocation = RelayLocation;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down Expand Up @@ -732,7 +740,7 @@ construct_runtime!(
BridgeRelayers: pallet_bridge_relayers::{Pallet, Call, Storage, Event<T>} = 47,

// Ethereum Bridge
EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Config<T>, Storage, Event<T>} = 48,
EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Config, Storage, Event<T>} = 48,
EthereumOutboundQueue: snowbridge_outbound_queue::{Pallet, Call, Storage, Event<T>} = 49,
EthereumBeaconClient: snowbridge_ethereum_beacon_client::{Pallet, Call, Storage, Event<T>} = 50,
EthereumControl: snowbridge_control::{Pallet, Call, Storage, Event<T>} = 51,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Autogenerated weights for `snowbridge_inbound_queue`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-07-14, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-07-25, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Claras-MacBook-Pro-2.local`, CPU: `<UNKNOWN>`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bridge-hub-rococo-dev"), DB CACHE: 1024
Expand Down Expand Up @@ -34,10 +34,12 @@ use core::marker::PhantomData;
/// Weight functions for `snowbridge_inbound_queue`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> snowbridge_inbound_queue::WeightInfo for WeightInfo<T> {
/// Storage: EthereumInboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumInboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: EthereumBeaconClient ExecutionHeaders (r:1 w:0)
/// Proof: EthereumBeaconClient ExecutionHeaders (max_values: None, max_size: Some(136), added: 2611, mode: MaxEncodedLen)
/// Storage: EthereumInboundQueue AllowList (r:1 w:0)
/// Proof: EthereumInboundQueue AllowList (max_values: Some(1), max_size: Some(161), added: 656, mode: MaxEncodedLen)
/// Storage: EthereumInboundQueue Gateway (r:1 w:0)
/// Proof: EthereumInboundQueue Gateway (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen)
/// Storage: EthereumInboundQueue Nonce (r:1 w:1)
/// Proof: EthereumInboundQueue Nonce (max_values: None, max_size: Some(20), added: 2495, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
Expand All @@ -54,12 +56,12 @@ impl<T: frame_system::Config> snowbridge_inbound_queue::WeightInfo for WeightInf
/// Proof Skipped: ParachainSystem RelevantMessagingState (max_values: Some(1), max_size: None, mode: Measured)
fn submit() -> Weight {
// Proof Size summary in bytes:
// Measured: `577`
// Estimated: `4042`
// Minimum execution time: 118_000_000 picoseconds.
Weight::from_parts(125_000_000, 0)
.saturating_add(Weight::from_parts(0, 4042))
.saturating_add(T::DbWeight::get().reads(9))
// Measured: `575`
// Estimated: `4040`
// Minimum execution time: 98_000_000 picoseconds.
Weight::from_parts(107_000_000, 0)
.saturating_add(Weight::from_parts(0, 4040))
.saturating_add(T::DbWeight::get().reads(10))
.saturating_add(T::DbWeight::get().writes(4))
}
}
38 changes: 22 additions & 16 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom};
use polkadot_parachain::primitives::Sibling;
use snowbridge_outbound_queue;
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use snowbridge_router_primitives::outbound::{AgentHashedDescription, EthereumBlobExporter};
use sp_core::Get;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete,
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
IsConcrete, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
Expand All @@ -57,17 +57,17 @@ parameter_types! {
X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into()));
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;

// Network and location for the local Ethereum testnet.
pub const EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

// The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets.
pub EthereumRegistryLocation: MultiLocation = EthereumLocation::get()
pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get()
.pushed_with_interior(
AccountKey20 {
network: None,
key: hex_literal::hex!("D184c103F7acc340847eEE82a0B909E3358bc28d"),
AccountKey20 {
network: None,
key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"),
}
).unwrap();
}
Expand Down Expand Up @@ -213,14 +213,16 @@ impl Contains<RuntimeCall> for SafeCallFilter {
| snowbridge_ethereum_beacon_client::Call::set_owner { .. }
| snowbridge_ethereum_beacon_client::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumInboundQueue(
snowbridge_inbound_queue::Call::add_allow_list { .. }
| snowbridge_inbound_queue::Call::remove_allow_list { .. }
| snowbridge_inbound_queue::Call::set_owner { .. }
snowbridge_inbound_queue::Call::set_owner { .. }
| snowbridge_inbound_queue::Call::set_gateway { .. }
| snowbridge_inbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumOutboundQueue(
snowbridge_outbound_queue::Call::set_owner { .. }
| snowbridge_outbound_queue::Call::set_operating_mode { .. },
) | RuntimeCall::EthereumControl(snowbridge_control::Call::upgrade { .. },)
) | RuntimeCall::EthereumControl(
snowbridge_control::Call::upgrade { .. }
| snowbridge_control::Call::create_agent { .. },
)
)
}
}
Expand Down Expand Up @@ -345,8 +347,12 @@ impl cumulus_pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
}

pub type SnowbridgeExporter =
EthereumBlobExporter<UniversalLocation, EthereumRegistryLocation, snowbridge_outbound_queue::Pallet<Runtime>>;
pub type SnowbridgeExporter = EthereumBlobExporter<
UniversalLocation,
EthereumGatewayLocation,
snowbridge_outbound_queue::Pallet<Runtime>,
AgentHashedDescription
>;

/// Hacky switch implementation, because we have just one runtime for Rococo and Wococo BridgeHub, so it means we have just one XcmConfig
pub struct BridgeHubRococoOrBridgeHubWococoSwitchExporter;
Expand Down Expand Up @@ -386,7 +392,7 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter {
destination,
message,
)
.map(|result| ((EthereumNetwork::get(), result.0), result.1))
.map(|result| ((EthereumNetwork::get(), (result.0, XcmHash::default())), result.1))
},
_ => unimplemented!("Unsupported network: {:?}", network),
}
Expand All @@ -399,7 +405,7 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter {
Rococo => ToBridgeHubRococoHaulBlobExporter::deliver(ticket),
Wococo => ToBridgeHubWococoHaulBlobExporter::deliver(ticket),
location if location == EthereumNetwork::get() && relay == NetworkId::Rococo => {
SnowbridgeExporter::deliver(ticket)
SnowbridgeExporter::deliver(ticket.0)
},
_ => unimplemented!("Unsupported network: {:?}", network),
}
Expand Down
3 changes: 1 addition & 2 deletions polkadot-parachain/src/chain_spec/bridge_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ pub mod rococo {
},
// Ethereum Bridge
ethereum_inbound_queue: bridge_hub_rococo_runtime::EthereumInboundQueueConfig {
allowlist: Default::default(),
owner: bridges_pallet_owner,
gateway: Default::default(),
..Default::default()
},
}
Expand Down

0 comments on commit bc52d55

Please sign in to comment.