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

feat: update to polkadot v1.0.0 #50

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = [ "crates/*", 'client', "integration-test", 'pallets/portal', 'pallets/asset-registry' ]
#members = [ "crates/*", 'pallets/portal', 'pallets/asset-registry', "integration-test" ] # FIXME: put this back "client"
members = [ "crates/*", 'pallets/portal', 'pallets/asset-registry'] # FIXME: put this back "client"
12 changes: 6 additions & 6 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ clap = { version = "4.0.9", features = [ "derive" ] }
config = "0.13.2"

# Codec
codec = { package = "parity-scale-codec", version = "3.1.5", features = [ 'derive' ] }
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ 'derive' ] }
hex = { version = "0.4.3", features = [ "serde" ] }
scale-info = { version = "2.1.2", features = [ "derive" ] }
serde = { version = "1.0.136", features = [ "derive" ] }
serde_json = { version = "1.0.79" }

# Substrate
sp-core = { version = "6.0.0", features = [ "full_crypto" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" }
sp-keyring = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.27" }
sp-core = { features = [ "full_crypto" ], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27", version = "0" }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0" }

# Transport
actix-web = { version = "4", optional = true }
futures = "0.3.24"
signal-hook = "0.3.14"
signal-hook-tokio = { version = "0.3.1", features = [ "futures-v0_3" ] }
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.27", features = [ "std" ], version = "0.6.0" }
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.27", features = [ "std" ] }
tokio = { version = "1", features = [ "full" ] }

# XBI
Expand Down
12 changes: 6 additions & 6 deletions crates/channel-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ repository = "https://github.com/t3rn/xbi"
version = "0.3.7"

[dependencies]
codec = { package = "parity-scale-codec", version = "3", default-features = false }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = [ "derive" ] }

sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "6.0.0" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "4.0.0" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }

xp-format = { path = "../format", default-features = false, version = "0.3.7" }
xp-format = { path = "../format", default-features = false }

# Optional frame specific deps
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, optional = true, version = "4.0.0-dev" }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.27", default-features = false, optional = true, version = "0" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false, optional = true }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0", default-features = false, optional = true }

[dev-dependencies]
lazy_static = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/channel-primitives/src/queue/ringbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ where
/// Will remove the item, but will not update the bounds in storage.
fn pop(&mut self) -> Option<Item> {
if self.is_empty() {
return None;
return None
}
let item = M::take(self.start);
self.start = self.start.wrapping_add(1.into());
Expand Down
32 changes: 22 additions & 10 deletions crates/channel-primitives/src/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use codec::{Decode, Encode, FullCodec};
use frame_support::traits::{fungibles::Inspect, Get};
use frame_support::traits::{fungibles::Inspect, tokens::Preservation, Get};
use sp_runtime::DispatchResult;
use sp_std::prelude::*;
use xp_format::Fees;
Expand All @@ -17,7 +17,7 @@ pub mod shims;
/// Which might be relevant to the user.
///
/// This also adds information about weight used by the instruction handler.
#[derive(Encode, Decode, Default, Debug)]
#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, Eq)]
pub struct HandlerInfo<Weight: core::fmt::Debug> {
// TODO[Optimisation]: We can bound the size, but ideally this should be configured by the user who sends the message.
// We have ideas on how to specify this in future releases.
Expand All @@ -39,13 +39,13 @@ impl<Weight: core::fmt::Debug> From<(Vec<u8>, Weight)> for HandlerInfo<Weight> {
// Justification: no need for from here
#[allow(clippy::from_over_into)]
#[cfg(feature = "frame")]
impl Into<frame_support::weights::PostDispatchInfo>
impl Into<frame_support::dispatch::PostDispatchInfo>
for HandlerInfo<frame_support::weights::Weight>
{
fn into(self) -> frame_support::weights::PostDispatchInfo {
frame_support::weights::PostDispatchInfo {
fn into(self) -> frame_support::dispatch::PostDispatchInfo {
frame_support::dispatch::PostDispatchInfo {
actual_weight: Some(self.weight),
pays_fee: frame_support::weights::Pays::Yes,
pays_fee: frame_support::dispatch::Pays::Yes,
}
}
}
Expand Down Expand Up @@ -90,11 +90,17 @@ where
Decode::decode(&mut &fees.get_aggregated_limit().encode()[..])
.map_err(|_| "Failed to decode balance from fees")?;

if let Err(x) = Assets::can_withdraw(asset, origin, balance).into_result() {
if let Err(x) = Assets::can_withdraw(asset.clone(), origin, balance).into_result(true) {
log::warn!(target: "xp-channel", "Insufficient funds to pay fees, {:?}", x);
return Err(x);
return Err(x)
}
Assets::teleport(asset, origin, &Custodian::get(), balance)?;
Assets::transfer(
asset.clone(),
origin,
&Custodian::get(),
balance,
Preservation::Preserve,
)?;

log::debug!(target: "xp-channel", "Charged Asset({:?}, {:?}) for XBI metadata fees {:?}", asset, balance, fees);
} else {
Expand Down Expand Up @@ -136,7 +142,13 @@ where
Decode::decode(&mut &(reserved - cost).encode()[..])
.map_err(|_| "Failed to decode balance from aggregation")?;

Assets::teleport(asset, &Custodian::get(), origin, to_unreserve)?;
Assets::transfer(
asset,
&Custodian::get(),
origin,
to_unreserve,
Preservation::Preserve,
)?;
} else {
log::warn!(target: "xp-channel", "Tried refunding more than was reserved for XBI metadata fees {:?} {:?}", cost, reserved);
}
Expand Down
20 changes: 10 additions & 10 deletions crates/channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ repository = "https://github.com/t3rn/xbi"
version = "0.3.7"

[dependencies]
codec = { package = "parity-scale-codec", version = "3", default-features = false }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
log = { version = "0.4", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = [ "derive" ] }

sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "6.0.0" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "6.0.0" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "6.0.0" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "4.0.0" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }

xp-channel = { path = "../../crates/channel-primitives", default-features = false, version = "0.3" }
xp-format = { path = "../../crates/format", default-features = false, version = "0.3" }
xp-xcm = { path = "../xcm-primitives", default-features = false, version = "0.3" }
xp-channel = { path = "../../crates/channel-primitives", default-features = false }
xp-format = { path = "../../crates/format", default-features = false }
xp-xcm = { path = "../xcm-primitives", default-features = false }

# Enabled by frame
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "4.0.0-dev", optional = true }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27", default-features = false, version = "4.0.0-dev", optional = true }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false, optional = true }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false, optional = true }

[dev-dependencies]
lazy_static = "1.4.0"
Expand Down
1 change: 0 additions & 1 deletion crates/channel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(box_syntax)]
#![feature(result_option_inspect)]
#![cfg_attr(not(feature = "std"), no_std)]

Expand Down
13 changes: 8 additions & 5 deletions crates/channel/src/receiver/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn handler_to_xbi_result<Emitter: ChannelProgressionEmitter>(
info: &HandlerInfo<frame_support::weights::Weight>,
msg: &mut XbiFormat,
) -> XbiResult {
Emitter::emit_instruction_handled(msg, &info.weight);
Emitter::emit_instruction_handled(msg, &info.weight.ref_time());

let status: Status = Status::from(&msg.metadata.fees);

Expand Down Expand Up @@ -67,7 +67,10 @@ mod tests {
use super::{handler_to_xbi_result, invert_destination_from_message};

use codec::Encode;
use frame_support::{dispatch::DispatchErrorWithPostInfo, weights::PostDispatchInfo};
use frame_support::{
dispatch::DispatchErrorWithPostInfo,
weights::{PostDispatchInfo, Weight},
};
use xp_channel::{traits::HandlerInfo, XbiFormat, XbiMetadata};
use xp_format::{Fees, Status};

Expand All @@ -92,7 +95,7 @@ mod tests {
#[test]
fn xbi_handler_maps_to_result_correctly_when_exceeded_gas() {
let info = HandlerInfo {
weight: 100,
weight: Weight::from_parts(100, 0u64),
output: b"world".to_vec(),
};

Expand Down Expand Up @@ -120,7 +123,7 @@ mod tests {
#[test]
fn xbi_handler_maps_to_result_correctly() {
let info = HandlerInfo {
weight: 100,
weight: Weight::from_parts(100, 0u64),
output: b"world".to_vec(),
};

Expand Down Expand Up @@ -149,7 +152,7 @@ mod tests {
fn xbi_handler_error_maps_to_result_correctly() {
let err = DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(1000),
actual_weight: Some(1000.into()),
..Default::default()
},
error: sp_runtime::DispatchError::Other("Fail"),
Expand Down
8 changes: 3 additions & 5 deletions crates/channel/src/receiver/frame/queue_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use crate::receiver::Receiver as ReceiverExt;
use frame_support::pallet_prelude::DispatchResultWithPostInfo;
use frame_system::{ensure_signed_or_root, Config};
use sp_runtime::{traits::UniqueSaturatedInto, Either};
use sp_std::borrow::ToOwned;
use sp_std::marker::PhantomData;
use sp_std::{borrow::ToOwned, marker::PhantomData};
use xp_channel::{
queue::{QueueSignal, Queueable},
ChannelProgressionEmitter, Message,
};
use xp_format::Timestamp::*;
use xp_format::{XbiFormat, XbiMetadata, XbiResult};
use xp_format::{Timestamp::*, XbiFormat, XbiMetadata, XbiResult};

/// This is an asynchronous queue backed frame receiver, which expects some queue handler to transport the messages back via the transport layer,
/// detaching the message handling part with the transport of the message.
Expand All @@ -23,7 +21,7 @@ where
Queue: Queueable<(Message, QueueSignal)>,
Emitter: ChannelProgressionEmitter,
{
type Origin = T::Origin;
type Origin = T::RuntimeOrigin;
type Outcome = DispatchResultWithPostInfo;

/// Request should always run the instruction, and produce some info containing meters for the execution
Expand Down
10 changes: 5 additions & 5 deletions crates/channel/src/receiver/frame/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use xp_channel::{
traits::{HandlerInfo, Writable, XbiInstructionHandler},
ChannelProgressionEmitter, Message,
};
use xp_format::Timestamp::*;
use xp_format::{XbiFormat, XbiMetadata, XbiResult};
use xp_format::{Timestamp::*, XbiFormat, XbiMetadata, XbiResult};

use super::handle_instruction_result;

Expand Down Expand Up @@ -78,15 +77,15 @@ where
Sender: SenderExt<Message>,
Emitter: ChannelProgressionEmitter,
Queue: Queueable<(Message, QueueSignal)>,
InstructionHandler: XbiInstructionHandler<T::Origin>,
InstructionHandler: XbiInstructionHandler<T::RuntimeOrigin>,
ResultStore: Writable<(sp_core::H256, XbiResult)>,
Currency: ReservableCurrency<T::AccountId>,
Assets: Mutate<T::AccountId>,
ChargeForMessage:
xp_channel::traits::RefundForMessage<T::AccountId, Currency, Assets, AssetReserveCustodian>,
AssetReserveCustodian: Get<T::AccountId>,
{
type Origin = T::Origin;
type Origin = T::RuntimeOrigin;
type Outcome = DispatchResultWithPostInfo;

/// Request should always run the instruction, and product some dispatch info containing meters for the execution
Expand Down Expand Up @@ -116,7 +115,8 @@ where
Ok(info) => Some(info.weight),
Err(e) => e.post_info.actual_weight,
}
.unwrap_or_default(),
.unwrap_or_default()
.ref_time(),
);

Sender::send(Message::Response(xbi_result, msg.metadata.clone()));
Expand Down
7 changes: 3 additions & 4 deletions crates/channel/src/sender/frame/queue_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::sender::Sender as SenderExt;
use frame_support::traits::{fungibles::Mutate, Get, ReservableCurrency};
use frame_system::Config;
use sp_runtime::{traits::UniqueSaturatedInto, DispatchResult};
use sp_std::borrow::ToOwned;
use sp_std::marker::PhantomData;
use sp_std::{borrow::ToOwned, marker::PhantomData};
use xp_channel::{
queue::{QueueSignal, Queueable},
Message,
Expand Down Expand Up @@ -59,7 +58,7 @@ where
Message::Request(format.to_owned()),
QueueSignal::PendingRequest,
));
}
},
Message::Response(result, metadata) => {
let o: T::AccountId = crate::xbi_origin(metadata)?;

Expand All @@ -73,7 +72,7 @@ where
Message::Response(result.to_owned(), metadata.to_owned()),
QueueSignal::PendingResponse,
));
}
},
}
Ok(())
}
Expand Down
Loading
Loading