Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Polkadot SDK #1002

Closed
wants to merge 12 commits into from
Closed
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
3 changes: 3 additions & 0 deletions parachain/pallets/outbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sp-std = { path = "../../../polkadot-sdk/substrate/primitives/std", default-feat
sp-runtime = { path = "../../../polkadot-sdk/substrate/primitives/runtime", default-features = false }
sp-io = { path = "../../../polkadot-sdk/substrate/primitives/io", default-features = false }
sp-arithmetic = { path = "../../../polkadot-sdk/substrate/primitives/arithmetic", default-features = false }
bridge-hub-common = { path = "../../../polkadot-sdk/cumulus/parachains/runtimes/bridge-hubs/common", default-features = false }

snowbridge-core = { path = "../../primitives/core", features = ["serde"], default-features = false }
snowbridge-outbound-queue-merkle-tree = { path = "merkle-tree", default-features = false }
Expand Down Expand Up @@ -53,11 +54,13 @@ std = [
"snowbridge-outbound-queue-merkle-tree/std",
"ethabi/std",
"xcm/std",
"bridge-hub-common/std",
]
runtime-benchmarks = [
"snowbridge-core/runtime-benchmarks",
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"bridge-hub-common/runtime-benchmarks",
"hex-literal",
]
6 changes: 4 additions & 2 deletions parachain/pallets/outbound-queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use super::*;

use codec::Encode;
use frame_benchmarking::v2::*;
use snowbridge_core::outbound::{AggregateMessageOrigin, Command, ExportOrigin, Initializer};
use snowbridge_core::outbound::{
AggregateMessageOrigin, Command, Initializer, SnowbridgeMessageOrigin,
};
use sp_core::{H160, H256};

#[allow(unused_imports)]
Expand Down Expand Up @@ -32,7 +34,7 @@ mod benchmarks {
}),
},
};
let origin = AggregateMessageOrigin::Export(ExportOrigin::Here);
let origin = AggregateMessageOrigin::Snowbridge(SnowbridgeMessageOrigin::Here);
let encoded_enqueued_message = enqueued_message.encode();

#[block]
Expand Down
12 changes: 5 additions & 7 deletions parachain/pallets/outbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ mod mock;
#[cfg(test)]
mod test;

use bridge_hub_common::{
AggregateMessageOrigin, AggregateMessageOrigin::Snowbridge, SnowbridgeMessageOrigin::Here,
};
use codec::Decode;
use frame_support::{
storage::StorageStreamIter,
traits::{tokens::Balance, EnqueueMessage, Get, ProcessMessageError},
weights::{Weight, WeightToFee},
};
use snowbridge_core::{
outbound::{
AggregateMessageOrigin, Command, ExportOrigin, Fee, GasMeter, QueuedMessage,
VersionedQueuedMessage, ETHER_DECIMALS,
},
outbound::{Command, Fee, GasMeter, QueuedMessage, VersionedQueuedMessage, ETHER_DECIMALS},
BasicOperatingMode, ParaId, GWEI, METH,
};
use snowbridge_outbound_queue_merkle_tree::merkle_root;
Expand Down Expand Up @@ -332,8 +332,6 @@ pub mod pallet {
origin: ProcessMessageOriginOf<T>,
mut message: &[u8],
) -> Result<bool, ProcessMessageError> {
use AggregateMessageOrigin::*;
use ExportOrigin::*;
use ProcessMessageError::*;

// Yield if the maximum number of messages has been processed this block.
Expand All @@ -345,7 +343,7 @@ pub mod pallet {
);

// If this is a high priority message, mark it as processed
if let Export(Here) = origin {
if let Snowbridge(Here) = origin {
PendingHighPriorityMessageCount::<T>::mutate(|count| {
*count = count.saturating_sub(1)
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Implementation for [`frame_support::traits::ProcessMessage`]
use super::*;
use crate::weights::WeightInfo;
use bridge_hub_common::AggregateMessageOrigin;
use frame_support::{
traits::{ProcessMessage, ProcessMessageError},
weights::WeightMeter,
};
use snowbridge_core::outbound::AggregateMessageOrigin;

impl<T: Config> ProcessMessage for Pallet<T> {
type Origin = AggregateMessageOrigin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
//! Implementation for [`frame_support::traits::QueuePausedQuery`]
use super::*;
use bridge_hub_common::{AggregateMessageOrigin, SnowbridgeMessageOrigin::Sibling};
use frame_support::traits::QueuePausedQuery;
use snowbridge_core::outbound::{AggregateMessageOrigin, ExportOrigin};

impl<T> QueuePausedQuery<AggregateMessageOrigin> for Pallet<T>
where
T: Config,
{
fn is_paused(origin: &AggregateMessageOrigin) -> bool {
use AggregateMessageOrigin::*;
use ExportOrigin::*;

// Queues for sibling parachains are paused when:
// 1. The pallet is halted
// 2. A higher-priority queue has pending messages
if let Export(Sibling(_)) = origin {
if let Snowbridge(Sibling(_)) = origin {
if Self::operating_mode().is_halted() {
return true
}
Expand Down
18 changes: 10 additions & 8 deletions parachain/pallets/outbound-queue/src/send_message_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! Implementation for [`snowbridge_core::outbound::SendMessage`]
use super::*;
use bridge_hub_common::{
AggregateMessageOrigin,
AggregateMessageOrigin::Snowbridge,
SnowbridgeMessageOrigin::{Here, Sibling},
};
use codec::Encode;
use frame_support::{
ensure,
Expand All @@ -8,8 +13,8 @@ use frame_support::{
};
use frame_system::unique;
use snowbridge_core::outbound::{
AggregateMessageOrigin, ExportOrigin, Fee, Message, QueuedMessage, SendError, SendMessage,
SendMessageFeeProvider, VersionedQueuedMessage,
Fee, Message, QueuedMessage, SendError, SendMessage, SendMessageFeeProvider,
VersionedQueuedMessage,
};
use sp_core::H256;
use sp_runtime::BoundedVec;
Expand Down Expand Up @@ -66,19 +71,16 @@ where
}

fn deliver(ticket: Self::Ticket) -> Result<H256, SendError> {
use AggregateMessageOrigin::*;
use ExportOrigin::*;

// Assign an `AggregateMessageOrigin` to track the message within the MessageQueue
// pallet. Governance commands are assigned origin `ExportOrigin::Here`. In other words
// emitted from BridgeHub itself.
let origin = if ticket.origin == T::OwnParaId::get() {
Export(Here)
Snowbridge(Here)
} else {
Export(Sibling(ticket.origin))
Snowbridge(Sibling(ticket.origin))
};

if let Export(Here) = origin {
if let Snowbridge(Here) = origin {
// Increase PendingHighPriorityMessageCount by one
PendingHighPriorityMessageCount::<T>::mutate(|count| *count = count.saturating_add(1));
} else {
Expand Down
38 changes: 21 additions & 17 deletions parachain/pallets/outbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ use frame_support::{
weights::WeightMeter,
};

use bridge_hub_common::{
AggregateMessageOrigin, AggregateMessageOrigin::Snowbridge, SnowbridgeMessageOrigin,
SnowbridgeMessageOrigin::Sibling,
};
use codec::Encode;
use snowbridge_core::outbound::{Command, ExportOrigin, SendError, SendMessage};
use snowbridge_core::outbound::{Command, SendError, SendMessage};
use sp_core::H256;
use sp_runtime::{AccountId32, DispatchError};

Expand Down Expand Up @@ -83,7 +87,8 @@ fn process_message_yields_on_max_messages_per_block() {
MessageLeaves::<Test>::append(H256::zero())
}

let origin = AggregateMessageOrigin::Export(ExportOrigin::Sibling(1000.into()));
let origin =
AggregateMessageOrigin::Snowbridge(SnowbridgeMessageOrigin::Sibling(1000.into()));
let message = QueuedMessage {
id: Default::default(),
origin: 1000.into(),
Expand All @@ -108,7 +113,8 @@ fn process_message_yields_on_max_messages_per_block() {
fn process_message_fails_on_overweight_message() {
new_tester().execute_with(|| {
let sibling_id = 1000;
let origin = AggregateMessageOrigin::Export(ExportOrigin::Sibling(sibling_id.into()));
let origin =
AggregateMessageOrigin::Snowbridge(SnowbridgeMessageOrigin::Sibling(sibling_id.into()));
let message = mock_message(sibling_id).encode();
let mut meter = WeightMeter::with_limit(Weight::from_parts(1, 1));
assert_noop!(
Expand Down Expand Up @@ -156,12 +162,10 @@ fn set_fee_config_invalid() {

#[test]
fn low_priority_messages_are_processed_last() {
use AggregateMessageOrigin::*;
use ExportOrigin::*;

let sibling_id = 1000;
let high_priority_queue = Export(Here);
let low_priority_queue = Export(Sibling(sibling_id.into()));
let high_priority_queue =
Snowbridge(bridge_hub_common::message_queue::SnowbridgeMessageOrigin::Here);
let low_priority_queue = Snowbridge(Sibling(sibling_id.into()));

new_tester().execute_with(|| {
// submit a lot of high priority messages from asset_hub which will need multiple blocks to
Expand All @@ -173,49 +177,49 @@ fn low_priority_messages_are_processed_last() {
OutboundQueue::deliver(ticket).unwrap();
}
let footprint = MessageQueue::footprint(high_priority_queue);
assert_eq!(footprint.count, (max_messages) as u64);
assert_eq!(footprint.storage.count, (max_messages) as u64);

// submit low priority message
let message = mock_message(sibling_id);
let (ticket, _) = OutboundQueue::validate(&message).unwrap();
OutboundQueue::deliver(ticket).unwrap();
let footprint = MessageQueue::footprint(low_priority_queue);
assert_eq!(footprint.count, 1);
assert_eq!(footprint.storage.count, 1);

// run to next block; only high priority messages should have been processed
ServiceWeight::set(Some(Weight::MAX));
run_to_end_of_next_block();
let footprint = MessageQueue::footprint(high_priority_queue);
assert_eq!(footprint.count, 40);
assert_eq!(footprint.storage.count, 40);

let footprint = MessageQueue::footprint(low_priority_queue);
assert_eq!(footprint.count, 1);
assert_eq!(footprint.storage.count, 1);

// move to the next block, some high priority messages get executed
ServiceWeight::set(Some(Weight::MAX));
run_to_end_of_next_block();
let footprint = MessageQueue::footprint(high_priority_queue);
assert_eq!(footprint.count, 20);
assert_eq!(footprint.storage.count, 20);

let footprint = MessageQueue::footprint(low_priority_queue);
assert_eq!(footprint.count, 1);
assert_eq!(footprint.storage.count, 1);

// move to the next block, some high priority messages get executed
ServiceWeight::set(Some(Weight::MAX));
run_to_end_of_next_block();
let footprint = MessageQueue::footprint(high_priority_queue);
assert_eq!(footprint.count, 0);
assert_eq!(footprint.storage.count, 0);

let footprint = MessageQueue::footprint(low_priority_queue);
assert_eq!(footprint.count, 1);
assert_eq!(footprint.storage.count, 1);

// move to the next block, the last remaining pending message,
// a lower priority one, is processed
ServiceWeight::set(Some(Weight::MAX));
run_to_end_of_next_block();

let footprint = MessageQueue::footprint(low_priority_queue);
assert_eq!(footprint.count, 0);
assert_eq!(footprint.storage.count, 0);
});
}

Expand Down
21 changes: 1 addition & 20 deletions parachain/primitives/core/src/outbound.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use codec::{Decode, Encode, MaxEncodedLen};
use codec::{Decode, Encode};
use frame_support::PalletError;
pub use polkadot_parachain_primitives::primitives::Id as ParaId;
use scale_info::TypeInfo;
Expand Down Expand Up @@ -381,23 +381,4 @@ impl GasMeter for () {
}
}

impl From<u32> for AggregateMessageOrigin {
fn from(value: u32) -> Self {
AggregateMessageOrigin::Export(ExportOrigin::Sibling(value.into()))
}
}

#[derive(Encode, Decode, Clone, Copy, MaxEncodedLen, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub enum ExportOrigin {
Here,
Sibling(ParaId),
}

/// Aggregate message origin for the `MessageQueue` pallet.
#[derive(Encode, Decode, Clone, Copy, MaxEncodedLen, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub enum AggregateMessageOrigin {
/// Message is to be exported via a bridge
Export(ExportOrigin),
}

pub const ETHER_DECIMALS: u8 = 18;
2 changes: 1 addition & 1 deletion polkadot-sdk
Submodule polkadot-sdk updated 967 files
2 changes: 1 addition & 1 deletion relayer/cmd/generate_beacon_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func generateBeaconCheckpoint(cmd *cobra.Command, _ []string) error {
}
checkPointBytes, _ := types.EncodeToBytes(checkPointScale)
// Call index for EthereumBeaconClient.force_checkpoint
checkPointCallIndex := "0x3200"
checkPointCallIndex := "0x3E00"
checkPointUpdateCall := checkPointCallIndex + hex.EncodeToString(checkPointBytes)
fmt.Println(checkPointUpdateCall)
return nil
Expand Down
Loading