Skip to content

Commit

Permalink
Update from upstream (#1123)
Browse files Browse the repository at this point in the history
* upstream changes

* fix merge damage

* clippy

* fmt

* update test

* fmt

* update rust version

* remove invalid import

* fix simple errors

* fix test issues

* update polkadot-sdk

* fmt

* update polkadot-sdk

* update polkadot-sdk

* another update

* update polkadot-sdk

* fix merge damage

* update polkadot-sdk

* cleanup imports

* update polkadot-sdk

---------

Co-authored-by: claravanstaden <Cats 4 life!>
  • Loading branch information
claravanstaden authored Jan 23, 2024
1 parent c229119 commit d65afb4
Show file tree
Hide file tree
Showing 34 changed files with 1,803 additions and 6,409 deletions.
7,239 changes: 1,342 additions & 5,897 deletions parachain/Cargo.lock

Large diffs are not rendered by default.

40 changes: 29 additions & 11 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,32 @@ members = [
"runtime/test-common",
]

[patch.'https://github.com/snowfork/snowbridge']
snowbridge-beacon-primitives = { path = "./primitives/beacon" }
snowbridge-pallet-system = { path = "./pallets/system" }
snowbridge-system-runtime-api = { path = "./pallets/system/runtime-api" }
snowbridge-core = { path = "./primitives/core" }
snowbridge-pallet-ethereum-client = { path = "./pallets/ethereum-client" }
snowbridge-pallet-inbound-queue = { path = "./pallets/inbound-queue" }
snowbridge-pallet-outbound-queue = { path = "./pallets/outbound-queue" }
snowbridge-outbound-queue-runtime-api = { path = "./pallets/outbound-queue/runtime-api" }
snowbridge-router-primitives = { path = "./primitives/router" }
snowbridge-runtime-common = { path = "./runtime/runtime-common" }

[workspace.lints.rust]
suspicious_double_ref_op = { level = "allow", priority = 2 }

[workspace.lints.clippy]
all = { level = "allow", priority = 0 }
correctness = { level = "warn", priority = 1 }
complexity = { level = "warn", priority = 1 }
if-same-then-else = { level = "allow", priority = 2 }
zero-prefixed-literal = { level = "allow", priority = 2 } # 00_1000_000
type_complexity = { level = "allow", priority = 2 } # raison d'etre
nonminimal-bool = { level = "allow", priority = 2 } # maybe
borrowed-box = { level = "allow", priority = 2 } # Reasonable to fix this one
too-many-arguments = { level = "allow", priority = 2 } # (Turning this on would lead to)
needless-lifetimes = { level = "allow", priority = 2 } # generated code
unnecessary_cast = { level = "allow", priority = 2 } # Types may change
identity-op = { level = "allow", priority = 2 } # One case where we do 0 +
useless_conversion = { level = "allow", priority = 2 } # Types may change
unit_arg = { level = "allow", priority = 2 } # stylistic
option-map-unit-fn = { level = "allow", priority = 2 } # stylistic
bind_instead_of_map = { level = "allow", priority = 2 } # stylistic
erasing_op = { level = "allow", priority = 2 } # E.g. 0 * DOLLARS
eq_op = { level = "allow", priority = 2 } # In tests we test equality.
while_immutable_condition = { level = "allow", priority = 2 } # false positives
needless_option_as_deref = { level = "allow", priority = 2 } # false positives
derivable_impls = { level = "allow", priority = 2 } # false positives
stable_sort_primitive = { level = "allow", priority = 2 } # prefer stable sort
extra-unused-type-parameters = { level = "allow", priority = 2 } # stylistic
default_constructed_unit_structs = { level = "allow", priority = 2 } # stylistic
8 changes: 4 additions & 4 deletions parachain/pallets/ethereum-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.188", optional = true }
serde_json = { version = "1.0.96", optional = true }
serde = { version = "1.0.195", optional = true }
serde_json = { version = "1.0.111", optional = true }
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
ssz_rs = { version = "0.9.0", default-features = false }
Expand Down Expand Up @@ -44,11 +44,11 @@ pallet-timestamp = { path = "../../../polkadot-sdk/substrate/frame/timestamp", d
[dev-dependencies]
rand = "0.8.5"
sp-keyring = { path = "../../../polkadot-sdk/substrate/primitives/keyring" }
serde_json = "1.0.96"
serde_json = "1.0.111"
hex-literal = "0.4.1"
pallet-timestamp = { path = "../../../polkadot-sdk/substrate/frame/timestamp" }
sp-io = { path = "../../../polkadot-sdk/substrate/primitives/io" }
serde = "1.0.188"
serde = "1.0.195"

[features]
default = ["std"]
Expand Down
27 changes: 12 additions & 15 deletions parachain/pallets/ethereum-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,22 +629,19 @@ fn submit_update_with_skipped_sync_committee_period() {

#[test]
fn submit_update_execution_headers_too_far_behind() {
let checkpoint = load_checkpoint_update_fixture();
let finalized_header_update = load_finalized_header_update_fixture();
let execution_header_update = load_execution_header_update_fixture();
let next_update = load_next_sync_committee_update_fixture();
let checkpoint = Box::new(load_checkpoint_update_fixture());
let finalized_header_update = Box::new(load_finalized_header_update_fixture());
let execution_header_update = Box::new(load_execution_header_update_fixture());
let next_update = Box::new(load_next_sync_committee_update_fixture());

new_tester().execute_with(|| {
let far_ahead_finalized_header_slot = finalized_header_update.finalized_header.slot +
(EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH * 2) as u64;
assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint));
assert_ok!(EthereumBeaconClient::submit(
RuntimeOrigin::signed(1),
Box::new(finalized_header_update)
));
assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), finalized_header_update));
assert_ok!(EthereumBeaconClient::submit_execution_header(
RuntimeOrigin::signed(1),
Box::new(execution_header_update)
execution_header_update
));

let header_root: H256 = TEST_HASH.into();
Expand All @@ -658,7 +655,7 @@ fn submit_update_execution_headers_too_far_behind() {
LatestFinalizedBlockRoot::<Test>::set(header_root);

assert_err!(
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(next_update)),
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), next_update),
Error::<Test>::ExecutionHeaderTooFarBehind
);
});
Expand Down Expand Up @@ -699,14 +696,14 @@ fn submit_update_with_missing_bootstrap() {

#[test]
fn submit_update_with_invalid_sync_committee_update() {
let checkpoint = load_checkpoint_update_fixture();
let update = load_sync_committee_update_fixture();
let mut next_update = load_next_sync_committee_update_fixture();
let checkpoint = Box::new(load_checkpoint_update_fixture());
let update = Box::new(load_sync_committee_update_fixture());
let mut next_update = Box::new(load_next_sync_committee_update_fixture());

new_tester().execute_with(|| {
assert_ok!(EthereumBeaconClient::process_checkpoint_update(&checkpoint));

assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(update)));
assert_ok!(EthereumBeaconClient::submit(RuntimeOrigin::signed(1), update));

// makes update with invalid next_sync_committee
<FinalizedBeaconState<Test>>::mutate(<LatestFinalizedBlockRoot<Test>>::get(), |x| {
Expand All @@ -719,7 +716,7 @@ fn submit_update_with_invalid_sync_committee_update() {
next_update.next_sync_committee_update = Some(next_sync_committee);

assert_err!(
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), Box::new(next_update)),
EthereumBeaconClient::submit(RuntimeOrigin::signed(1), next_update),
Error::<Test>::InvalidSyncCommitteeUpdate
);
});
Expand Down
4 changes: 2 additions & 2 deletions parachain/pallets/inbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.188", optional = true }
serde = { version = "1.0.195", optional = true }
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
hex-literal = { version = "0.4.1", optional = true }
Expand Down Expand Up @@ -47,7 +47,7 @@ snowbridge-beacon-primitives = { path = "../../primitives/beacon", default-featu
frame-benchmarking = { path = "../../../polkadot-sdk/substrate/frame/benchmarking" }
sp-keyring = { path = "../../../polkadot-sdk/substrate/primitives/keyring" }
snowbridge-beacon-primitives = { path = "../../primitives/beacon" }
snowbridge-pallet-ethereum-client = { path = "../../pallets/ethereum-client" }
snowbridge-pallet-ethereum-client = { path = "../ethereum-client" }
hex-literal = { version = "0.4.1" }

[features]
Expand Down
10 changes: 5 additions & 5 deletions parachain/pallets/inbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ use scale_info::TypeInfo;
use sp_core::{H160, H256};
use sp_std::{convert::TryFrom, vec};
use xcm::prelude::{
send_xcm, Instruction::SetTopic, Junction::*, Junctions::*, MultiLocation,
SendError as XcmpSendError, SendXcm, Xcm, XcmContext, XcmHash,
send_xcm, Instruction::SetTopic, Junction::*, Location, SendError as XcmpSendError, SendXcm,
Xcm, XcmContext, XcmHash,
};
use xcm_executor::traits::TransactAsset;

Expand Down Expand Up @@ -324,7 +324,7 @@ pub mod pallet {
}

pub fn send_xcm(xcm: Xcm<()>, dest: ParaId) -> Result<XcmHash, Error<T>> {
let dest = MultiLocation { parents: 1, interior: X1(Parachain(dest.into())) };
let dest = Location::new(1, [Parachain(dest.into())]);
let (xcm_hash, _) = send_xcm::<T::XcmSender>(dest, xcm).map_err(Error::<T>::from)?;
Ok(xcm_hash)
}
Expand All @@ -341,8 +341,8 @@ pub mod pallet {
pub fn burn_fees(para_id: ParaId, fee: BalanceOf<T>) -> DispatchResult {
let dummy_context =
XcmContext { origin: None, message_id: Default::default(), topic: None };
let dest = MultiLocation { parents: 1, interior: X1(Parachain(para_id.into())) };
let fees = (MultiLocation::parent(), fee.saturated_into::<u128>()).into();
let dest = Location::new(1, [Parachain(para_id.into())]);
let fees = (Location::parent(), fee.saturated_into::<u128>()).into();
T::AssetTransactor::can_check_out(&dest, &fees, &dummy_context).map_err(|error| {
log::error!(
target: LOG_TARGET,
Expand Down
59 changes: 23 additions & 36 deletions parachain/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use sp_runtime::{
BuildStorage, FixedU128, MultiSignature,
};
use sp_std::convert::From;
use xcm::v3::{prelude::*, MultiAssets, SendXcm};
use xcm_executor::Assets;
use xcm::{latest::SendXcm, prelude::*};
use xcm_executor::AssetsInHolding;

use crate::{self as inbound_queue};

Expand Down Expand Up @@ -159,17 +159,16 @@ impl SendXcm for MockXcmSender {
type Ticket = Xcm<()>;

fn validate(
dest: &mut Option<MultiLocation>,
xcm: &mut Option<xcm::v3::Xcm<()>>,
dest: &mut Option<Location>,
xcm: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
match dest {
Some(MultiLocation { interior, .. }) => {
if let X1(Parachain(1001)) = interior {
return Err(XcmpSendError::NotApplicable)
}
Ok((xcm.clone().unwrap(), MultiAssets::default()))
},
_ => Ok((xcm.clone().unwrap(), MultiAssets::default())),
if let Some(location) = dest {
match location.unpack() {
(_, [Parachain(1001)]) => return Err(XcmpSendError::NotApplicable),
_ => Ok((xcm.clone().unwrap(), Assets::default())),
}
} else {
Ok((xcm.clone().unwrap(), Assets::default()))
}
}

Expand Down Expand Up @@ -207,45 +206,33 @@ impl StaticLookup for MockChannelLookup {

pub struct SuccessfulTransactor;
impl TransactAsset for SuccessfulTransactor {
fn can_check_in(
_origin: &MultiLocation,
_what: &MultiAsset,
_context: &XcmContext,
) -> XcmResult {
fn can_check_in(_origin: &Location, _what: &Asset, _context: &XcmContext) -> XcmResult {
Ok(())
}

fn can_check_out(
_dest: &MultiLocation,
_what: &MultiAsset,
_context: &XcmContext,
) -> XcmResult {
fn can_check_out(_dest: &Location, _what: &Asset, _context: &XcmContext) -> XcmResult {
Ok(())
}

fn deposit_asset(
_what: &MultiAsset,
_who: &MultiLocation,
_context: Option<&XcmContext>,
) -> XcmResult {
fn deposit_asset(_what: &Asset, _who: &Location, _context: Option<&XcmContext>) -> XcmResult {
Ok(())
}

fn withdraw_asset(
_what: &MultiAsset,
_who: &MultiLocation,
_what: &Asset,
_who: &Location,
_context: Option<&XcmContext>,
) -> Result<Assets, XcmError> {
Ok(Assets::default())
) -> Result<AssetsInHolding, XcmError> {
Ok(AssetsInHolding::default())
}

fn internal_transfer_asset(
_what: &MultiAsset,
_from: &MultiLocation,
_to: &MultiLocation,
_what: &Asset,
_from: &Location,
_to: &Location,
_context: &XcmContext,
) -> Result<Assets, XcmError> {
Ok(Assets::default())
) -> Result<AssetsInHolding, XcmError> {
Ok(AssetsInHolding::default())
}
}

Expand Down
4 changes: 2 additions & 2 deletions parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ fn test_submit_happy_path() {
.into(),
nonce: 1,
message_id: [
27, 217, 88, 127, 46, 143, 199, 70, 236, 66, 212, 244, 85, 221, 153, 104, 175, 37,
224, 20, 140, 95, 140, 7, 27, 74, 182, 199, 77, 12, 194, 236,
57, 61, 232, 3, 66, 61, 25, 190, 234, 188, 193, 174, 13, 186, 1, 64, 237, 94, 73,
83, 14, 18, 209, 213, 78, 121, 43, 108, 251, 245, 107, 67,
],
fee_burned: 110000000000,
}
Expand Down
4 changes: 2 additions & 2 deletions parachain/pallets/outbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.188", features = ["alloc", "derive"], default-features = false }
serde = { version = "1.0.195", features = ["alloc", "derive"], default-features = false }
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
hex-literal = { version = "0.4.1", optional = true }
Expand All @@ -31,7 +31,7 @@ sp-arithmetic = { path = "../../../polkadot-sdk/substrate/primitives/arithmetic"

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-core = { path = "../../primitives/core", default-features = false, features = ["serde"] }
snowbridge-outbound-queue-merkle-tree = { path = "merkle-tree", default-features = false }
ethabi = { git = "https://github.com/snowfork/ethabi-decode.git", package = "ethabi-decode", branch = "master", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions parachain/pallets/outbound-queue/merkle-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ hex-literal = { version = "0.4.1" }
env_logger = "0.9"
hex = "0.4"
array-bytes = "4.1"
sp-crypto-hashing = { path = "../../../../polkadot-sdk/substrate/primitives/crypto/hashing" }

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion parachain/pallets/outbound-queue/merkle-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ where
mod tests {
use super::*;
use hex_literal::hex;
use sp_core::keccak_256;
use sp_crypto_hashing::keccak_256;
use sp_runtime::traits::Keccak256;

fn make_leaves(count: u64) -> Vec<H256> {
Expand Down
4 changes: 2 additions & 2 deletions parachain/pallets/system/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#![cfg_attr(not(feature = "std"), no_std)]

use snowbridge_core::AgentId;
use xcm::VersionedMultiLocation;
use xcm::VersionedLocation;

sp_api::decl_runtime_apis! {
pub trait ControlApi
{
fn agent_id(location: VersionedMultiLocation) -> Option<AgentId>;
fn agent_id(location: VersionedLocation) -> Option<AgentId>;
}
}
6 changes: 3 additions & 3 deletions parachain/pallets/system/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
//! Helpers for implementing runtime api

use snowbridge_core::AgentId;
use xcm::{prelude::*, VersionedMultiLocation};
use xcm::{prelude::*, VersionedLocation};

use crate::{agent_id_of, Config};

pub fn agent_id<Runtime>(location: VersionedMultiLocation) -> Option<AgentId>
pub fn agent_id<Runtime>(location: VersionedLocation) -> Option<AgentId>
where
Runtime: Config,
{
let location: MultiLocation = location.try_into().ok()?;
let location: Location = location.try_into().ok()?;
agent_id_of::<Runtime>(&location).ok()
}
Loading

0 comments on commit d65afb4

Please sign in to comment.