Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

feat(marketplace) add as a new pallet extending acurast core #26

Merged
merged 1 commit into from
Nov 25, 2022
Merged
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
45 changes: 26 additions & 19 deletions pallets/acurast-xcm-sender/src/mock/runtime/receiver_parachain.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use sp_std::prelude::*;
use codec::{Decode, Encode};
use frame_support::traits::Get;
use frame_support::{
construct_runtime, parameter_types,
traits::{Everything, Nothing, ConstU32},
traits::{ConstU32, Everything, Nothing},
weights::Weight,
BoundedVec,
};
Expand All @@ -12,7 +12,7 @@ use sp_runtime::{
traits::{AccountIdLookup, Hash},
AccountId32,
};
use frame_support::traits::Get;
use sp_std::prelude::*;

use pallet_xcm::XcmPassthrough;
use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
Expand All @@ -21,10 +21,8 @@ use polkadot_parachain::primitives::{
};
use xcm::{latest::prelude::*, VersionedXcm};
use xcm_builder::{
AllowUnpaidExecutionFrom,
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, LocationInverter,
NativeAsset, SignedAccountId32AsNative,
SignedToAccountId32,
AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds,
LocationInverter, NativeAsset, SignedAccountId32AsNative, SignedToAccountId32,
};
use xcm_executor::{Config, XcmExecutor};
pub type AccountId = AccountId32;
Expand Down Expand Up @@ -170,10 +168,14 @@ pub mod mock_msg_queue {
let location = (1, Parachain(sender.into()));
match T::XcmExecutor::execute_xcm(location, xcm, max_weight.ref_time()) {
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
Outcome::Complete(w) => (Ok(Weight::from_ref_time(w)), Event::Success(Some(hash))),
Outcome::Complete(w) => {
(Ok(Weight::from_ref_time(w)), Event::Success(Some(hash)))
}
// As far as the caller is concerned, this was dispatched without error, so
// we just report the weight used.
Outcome::Incomplete(w, e) => (Ok(Weight::from_ref_time(w)), Event::Fail(Some(hash), e)),
Outcome::Incomplete(w, e) => {
(Ok(Weight::from_ref_time(w)), Event::Fail(Some(hash), e))
}
}
}
Err(()) => (
Expand All @@ -187,10 +189,7 @@ pub mod mock_msg_queue {
}

impl<T: Config> XcmpMessageHandler for Pallet<T> {
fn handle_xcmp_messages<
'a,
I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>,
>(
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
iter: I,
max_weight: Weight,
) -> Weight {
Expand Down Expand Up @@ -219,8 +218,8 @@ pub mod mock_msg_queue {
) -> Weight {
for (_i, (_sent_at, data)) in iter.enumerate() {
let id = sp_io::hashing::blake2_256(&data[..]);
let maybe_msg = VersionedXcm::<T::Call>::decode(&mut &data[..])
.map(Xcm::<T::Call>::try_from);
let maybe_msg =
VersionedXcm::<T::Call>::decode(&mut &data[..]).map(Xcm::<T::Call>::try_from);
match maybe_msg {
Err(_) => {
Self::deposit_event(Event::InvalidFormat(id));
Expand All @@ -229,7 +228,8 @@ pub mod mock_msg_queue {
Self::deposit_event(Event::UnsupportedVersion(id));
}
Ok(Ok(x)) => {
let outcome = T::XcmExecutor::execute_xcm(Parent, x.clone(), limit.ref_time());
let outcome =
T::XcmExecutor::execute_xcm(Parent, x.clone(), limit.ref_time());
<ReceivedDmp<T>>::append(x);
Self::deposit_event(Event::ExecutedDownward(id, outcome));
}
Expand Down Expand Up @@ -268,8 +268,12 @@ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>
type Block = frame_system::mocking::MockBlock<Runtime>;

pub struct AllowAcurastBarrier {}
impl<T: pallet_acurast_receiver::Config> pallet_acurast_receiver::traits::ParachainBarrier<T> for AllowAcurastBarrier {
fn ensure_xcm_origin(_: <T as frame_system::Config>::Origin) -> Result<(), sp_runtime::DispatchError> {
impl<T: pallet_acurast_receiver::Config> pallet_acurast_receiver::traits::ParachainBarrier<T>
for AllowAcurastBarrier
{
fn ensure_xcm_origin(
_: <T as frame_system::Config>::Origin,
) -> Result<(), sp_runtime::DispatchError> {
Ok(())
}
}
Expand All @@ -284,7 +288,10 @@ impl pallet_acurast_receiver::Config for Runtime {

pub struct OnFulfillment;
impl pallet_acurast_receiver::traits::OnFulfillment<Runtime> for OnFulfillment {
fn fulfill(_fulfillment: Vec<u8>, _parameters: Option<Vec<u8>>,) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fn fulfill(
_fulfillment: Vec<u8>,
_parameters: Option<Vec<u8>>,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
Ok(().into())
}
}
Expand Down
1 change: 0 additions & 1 deletion pallets/acurast-xcm-sender/src/mock/runtime/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl frame_system::Config for Runtime {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}


impl shared::Config for Runtime {}

impl configuration::Config for Runtime {
Expand Down
9 changes: 3 additions & 6 deletions pallets/acurast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ authors = ["Papers AG"]
description = "FRAME pallet template for defining custom runtime logic."
version = "0.0.1"
license = "Unlicense"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
homepage = "https://docs.acurast.com/"
repository = "https://github.com/acurast"
edition = "2021"

[package.metadata.docs.rs]
Expand Down Expand Up @@ -46,6 +46,7 @@ p384 = { package = "p384_vendored", path = "p384", default-features = false, fea
sha2 = { version = "0.10", default-features = false }
num-bigint = { version = "0.4.3", default-features = false }
ecdsa-vendored = { package = "ecdsa_vendored", path = "p384/ecdsa", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }

# benchmarks
hex-literal = { version = "0.3", optional = true }
Expand All @@ -67,9 +68,6 @@ pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-fe
parachain-info = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.29" }
parachains-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.29", default-features = false }

# Acurast
acurast-p256-crypto = { path = "../../p256-crypto" }

[features]
default = ["std"]
runtime-benchmarks = [
Expand All @@ -83,7 +81,6 @@ runtime-benchmarks = [
]

std = [
"acurast-p256-crypto/std",
"asn1/std",
"base64/std",
"codec/std",
Expand Down
6 changes: 1 addition & 5 deletions pallets/acurast/p384/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ impl VerifyPrimitive<NistP384> for AffinePoint {}

#[cfg(all(test, feature = "ecdsa"))]
mod tests {
use crate::{
ecdsa::{SigningKey},
SecretKey,
};
use crate::{ecdsa::SigningKey, SecretKey};

#[test]
fn signing_secret_key_equivalent() {
Expand All @@ -83,5 +80,4 @@ mod tests {
use crate::{test_vectors::ecdsa::ECDSA_TEST_VECTORS, NistP384};
ecdsa_vendored::new_verification_test!(NistP384, ECDSA_TEST_VECTORS);
}

}
2 changes: 1 addition & 1 deletion pallets/acurast/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub fn validate_certificate_chain<'a>(
}

/// The list of trusted root certificates, as decoded bytes arrays. [Source](https://developer.android.com/training/articles/security-key-attestation#root_certificate)
const TRUSTED_ROOT_CERTS: & [&[u8]] = &[
const TRUSTED_ROOT_CERTS: &[&[u8]] = &[
// base64 equivalent: r"MIIFYDCCA0igAwIBAgIJAOj6GWMU0voYMA0GCSqGSIb3DQEBCwUAMBsxGTAXBgNVBAUTEGY5MjAwOWU4NTNiNmIwNDUwHhcNMTYwNTI2MTYyODUyWhcNMjYwNTI0MTYyODUyWjAbMRkwFwYDVQQFExBmOTIwMDllODUzYjZiMDQ1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8DslVgfP097vju4KDlqN64xV1grw3ZLl4CiOe/A91oeLm2UHOq6wn3esB4r2EIQKb6jTVGu5sYCcdWpXr0AUVqcABPdgL+H7qJguBw09ojm6xNIrw2OocrDKsudk/okr/AwqEyPKw9WnMlQgLIKw1rODG2NvU9oR3GVGdMkUBZutL8VuFkERQGt6vQ2OCw0sV47VMkuYbacK/xyZFiRcrPJPb41zgbQj9XAEyLKCHex0SdDrx+tWUDqG8At2JHA=="
Expand Down
66 changes: 20 additions & 46 deletions pallets/acurast/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use super::*;
use crate::utils::validate_and_extract_attestation;
use crate::Pallet as Acurast;
use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_support::{
assert_ok,
Expand All @@ -10,8 +7,14 @@ use frame_support::{
use frame_system::RawOrigin;
use hex_literal::hex;
use sp_std::prelude::*;
use types::{AllowedSourcesUpdate, JobAssignmentUpdate};
use xcm::prelude::*;

pub use pallet::Config;
use types::{AttestationChain, JobRegistration, JobRegistrationFor, Script};

use crate::utils::validate_and_extract_attestation;
use crate::Pallet as Acurast;

use super::*;

pub type Balance = u128;

Expand All @@ -28,29 +31,15 @@ pub fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}

pub fn job_registration_n<T: Config>(extra: T::RegistrationExtra) -> JobRegistrationFor<T>
where
<<T as Config>::RewardManager as RewardManager<T>>::Reward: From<MultiAsset>,
{
pub fn job_registration<T: Config>(extra: T::RegistrationExtra) -> JobRegistrationFor<T> {
return JobRegistration {
script: script(),
allowed_sources: None,
extra,
reward: owned_asset().into(),
allow_only_verified_sources: false,
extra,
};
}

pub fn owned_asset() -> MultiAsset {
MultiAsset {
id: Concrete(MultiLocation {
parents: 1,
interior: X3(Parachain(1000), PalletInstance(50), GeneralIndex(22)),
}),
fun: Fungible(INITIAL_BALANCE / 2),
}
}

pub fn script() -> Script {
SCRIPT_BYTES.to_vec().try_into().unwrap()
}
Expand Down Expand Up @@ -84,7 +73,7 @@ where
use pallet_assets::Pallet as Assets;
let caller: T::AccountId = account("token_account", 0, SEED);
whitelist_account!(caller);
let pallet_account: T::AccountId = T::PalletId::get().into_account_truncating();
let pallet_account: T::AccountId = <T as Config>::PalletId::get().into_account_truncating();
let pallet_origin: T::Origin = RawOrigin::Signed(pallet_account.clone()).into();

T::Currency::make_free_balance_be(&caller, u32::MAX.into());
Expand All @@ -111,14 +100,14 @@ where
fn register_job<T: Config>(submit: bool) -> (T::AccountId, JobRegistrationFor<T>)
where
T: pallet_assets::Config,
<T as Config>::RegistrationExtra: Default,
<<T as Config>::RewardManager as RewardManager<T>>::Reward: From<MultiAsset>,
<T as pallet_assets::Config>::AssetId: From<u32>,
<T as pallet_assets::Config>::Balance: From<u128>,
<T as Config>::RegistrationExtra: Default,
{
let caller: T::AccountId = token_22_funded_account::<T>();
whitelist_account!(caller);
let job = job_registration_n::<T>(Default::default());

let job = job_registration::<T>(Default::default());

if submit {
let register_call =
Expand All @@ -145,7 +134,7 @@ where
job_id: (caller.clone(), job.script.clone()),
};

// create processor account by giving it over existential deposit
// create processor account by giving t over existential deposit
T::Currency::make_free_balance_be(&processor_account, u32::MAX.into());

if submit {
Expand All @@ -161,32 +150,28 @@ where

benchmarks! {
where_clause { where
T: pallet_assets::Config,
<T as Config>::RegistrationExtra: Default,
<<T as Config>::RewardManager as RewardManager<T>>::Reward: From<MultiAsset>,
T: pallet_assets::Config + pallet_timestamp::Config,
<T as pallet_assets::Config>::AssetId: From<u32>,
<T as pallet_assets::Config>::Balance: From<u128>,
<T as Config>::RegistrationExtra: Default,
<T as frame_system::Config>::AccountId: From<[u8; 32]>,
T: pallet_timestamp::Config,
<T as pallet_timestamp::Config>::Moment: From<u64>,
}

register {
let (caller, job) = register_job::<T>(false);

}: _(RawOrigin::Signed(caller.clone()), job.clone())
verify {
assert_last_event::<T>(Event::JobRegistrationStored(
assert_last_event::<T>(Event::<T>::JobRegistrationStored(
job, caller
).into());
}

deregister {
let (caller, job) = register_job::<T>(true);

}: _(RawOrigin::Signed(caller.clone()), job.script.clone())
verify {
assert_last_event::<T>(Event::JobRegistrationRemoved(
assert_last_event::<T>(Event::<T>::JobRegistrationRemoved(
job.script, caller
).into());
}
Expand All @@ -205,17 +190,6 @@ benchmarks! {
).into());
}

update_job_assignments {
let (caller, job) = register_job::<T>(true);
let job_assignment = assign_job::<T>(false, caller.clone(), job.clone());

}: _(RawOrigin::Signed(caller.clone()), vec![job_assignment.clone()])
verify {
assert_last_event::<T>(Event::JobAssignmentUpdate(
caller, vec![job_assignment]
).into());
}

fulfill {
let (caller, job) = register_job::<T>(true);
let job_assignment = assign_job::<T>(true, caller.clone(), job.clone());
Expand Down Expand Up @@ -265,5 +239,5 @@ benchmarks! {
).into());
}

impl_benchmark_test_suite!(Acurast, mock::ExtBuilder::default().build(), mock::Test)
impl_benchmark_test_suite!(Acurast, mock::ExtBuilder::default().build(), mock::Test);
}
Loading