Skip to content

Commit

Permalink
report back intent execution result (#3132)
Browse files Browse the repository at this point in the history
* report back intention execution result
  • Loading branch information
kziemianek authored Oct 23, 2024
1 parent 628b66a commit 64136cb
Show file tree
Hide file tree
Showing 29 changed files with 589 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sp_runtime::{traits::ConstU32, BoundedVec};
pub const CALL_ETHEREUM_INPUT_LEN: u32 = 10 * 1024;

#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum Intention {
pub enum Intent {
#[codec(index = 0)]
TransferEthereum(TransferEthereum),
#[codec(index = 1)]
Expand Down
4 changes: 2 additions & 2 deletions common/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub use assertion::Assertion;
pub mod identity;
pub use identity::*;

pub mod intention;
pub use intention::*;
pub mod intent;
pub use intent::*;

pub mod omni_account;
pub use omni_account::*;
Expand Down
61 changes: 56 additions & 5 deletions parachain/pallets/omni-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod mock;
#[cfg(test)]
mod tests;

pub use core_primitives::{Identity, Intention, MemberAccount, OmniAccountConverter};
pub use core_primitives::{Identity, Intent, MemberAccount, OmniAccountConverter};
pub use frame_system::pallet_prelude::BlockNumberFor;
pub use pallet::*;

Expand Down Expand Up @@ -55,6 +55,13 @@ pub enum RawOrigin<AccountId> {
pub mod pallet {
use super::*;

#[derive(PartialEq, Eq, Clone, RuntimeDebug, Encode, Decode, TypeInfo)]
pub enum IntentExecutionResult {
Success,
Failure,
}

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

#[pallet::pallet]
Expand Down Expand Up @@ -97,6 +104,8 @@ pub mod pallet {

/// Convert an `Identity` to OmniAccount type
type OmniAccountConverter: OmniAccountConverter<OmniAccount = Self::AccountId>;

type SetOmniExecutorOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;
}

pub type MemberAccounts<T> = BoundedVec<MemberAccount, <T as Config>::MaxAccountStoreLength>;
Expand All @@ -115,6 +124,10 @@ pub mod pallet {
pub type MemberAccountHash<T: Config> =
StorageMap<Hasher = Blake2_128Concat, Key = H256, Value = T::AccountId>;

#[pallet::storage]
#[pallet::getter(fn omni_executor)]
pub type OmniExecutor<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand All @@ -132,8 +145,12 @@ pub mod pallet {
DispatchedAsOmniAccount { who: T::AccountId, result: DispatchResult },
/// Some call is dispatched as signed origin
DispatchedAsSigned { who: T::AccountId, result: DispatchResult },
/// Intention is requested
IntentionRequested { who: T::AccountId, intention: Intention },
/// Intent is requested
IntentRequested { who: T::AccountId, intent: Intent },
/// Intent is executed
IntentExecuted { who: T::AccountId, intent: Intent, result: IntentExecutionResult },
/// Omni executor is set
OmniExecutorSet { omni_executor: T::AccountId },
}

#[pallet::error]
Expand All @@ -144,6 +161,7 @@ pub mod pallet {
InvalidAccount,
UnknownAccountStore,
EmptyAccount,
RequireOmniExecutor,
}

#[pallet::call]
Expand Down Expand Up @@ -290,9 +308,9 @@ pub mod pallet {

#[pallet::call_index(6)]
#[pallet::weight((195_000_000, DispatchClass::Normal))]
pub fn request_intention(origin: OriginFor<T>, intention: Intention) -> DispatchResult {
pub fn request_intent(origin: OriginFor<T>, intent: Intent) -> DispatchResult {
let who = T::OmniAccountOrigin::ensure_origin(origin)?;
Self::deposit_event(Event::IntentionRequested { who, intention });
Self::deposit_event(Event::IntentRequested { who, intent });
Ok(())
}

Expand Down Expand Up @@ -325,6 +343,31 @@ pub mod pallet {

Ok(Pays::No.into())
}

#[pallet::call_index(8)]
#[pallet::weight((195_000_000, DispatchClass::Normal, Pays::No))]
pub fn intent_executed(
origin: OriginFor<T>,
who: T::AccountId,
intent: Intent,
result: IntentExecutionResult,
) -> DispatchResult {
Self::ensure_omni_executor(origin)?;
Self::deposit_event(Event::IntentExecuted { who, intent, result });
Ok(())
}

#[pallet::call_index(9)]
#[pallet::weight((195_000_000, DispatchClass::Normal, Pays::No))]
pub fn set_omni_executor(
origin: OriginFor<T>,
new_omni_executor: T::AccountId,
) -> DispatchResult {
T::SetOmniExecutorOrigin::ensure_origin(origin)?;
OmniExecutor::<T>::put(new_omni_executor.clone());
Self::deposit_event(Event::OmniExecutorSet { omni_executor: new_omni_executor });
Ok(())
}
}

impl<T: Config> Pallet<T> {
Expand All @@ -346,6 +389,14 @@ pub mod pallet {

Ok(member_accounts)
}

fn ensure_omni_executor(origin: OriginFor<T>) -> DispatchResult {
ensure!(
Some(ensure_signed(origin)?) == Self::omni_executor(),
Error::<T>::RequireOmniExecutor
);
Ok(())
}
}
}

Expand Down
1 change: 1 addition & 0 deletions parachain/pallets/omni-account/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl pallet_omni_account::Config for TestRuntime {
type MaxAccountStoreLength = ConstU32<3>;
type OmniAccountOrigin = EnsureOmniAccount<Self::AccountId>;
type OmniAccountConverter = DefaultOmniAccountConverter;
type SetOmniExecutorOrigin = EnsureRoot<Self::AccountId>;
}

pub fn get_tee_signer() -> SystemAccountId {
Expand Down
16 changes: 7 additions & 9 deletions parachain/pallets/omni-account/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ fn publicize_account_call(id: Identity) -> Box<RuntimeCall> {
Box::new(call)
}

fn request_intention_call(intention: Intention) -> Box<RuntimeCall> {
RuntimeCall::OmniAccount(crate::Call::request_intention { intention }).into()
fn request_intent_call(intent: Intent) -> Box<RuntimeCall> {
RuntimeCall::OmniAccount(crate::Call::request_intent { intent }).into()
}

fn make_balance_transfer_call(dest: AccountId, value: Balance) -> Box<RuntimeCall> {
Expand Down Expand Up @@ -498,7 +498,7 @@ fn publicize_account_identity_not_found_works() {
}

#[test]
fn request_intention_works() {
fn request_intent_works() {
new_test_ext().execute_with(|| {
let tee_signer = get_tee_signer();
let bob = private_member_account(bob());
Expand All @@ -515,12 +515,10 @@ fn request_intention_works() {
call
));

let intention = Intention::CallEthereum(CallEthereum {
address: H160::zero(),
input: BoundedVec::new(),
});
let intent =
Intent::CallEthereum(CallEthereum { address: H160::zero(), input: BoundedVec::new() });

let call = request_intention_call(intention.clone());
let call = request_intent_call(intent.clone());
assert_ok!(OmniAccount::dispatch_as_omni_account(
RuntimeOrigin::signed(tee_signer.clone()),
alice().identity.hash(),
Expand All @@ -536,7 +534,7 @@ fn request_intention_works() {
);

System::assert_has_event(
Event::IntentionRequested { who: alice().omni_account, intention }.into(),
Event::IntentRequested { who: alice().omni_account, intent }.into(),
);
});
}
Expand Down
1 change: 1 addition & 0 deletions parachain/runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ impl pallet_omni_account::Config for Runtime {
type MaxAccountStoreLength = ConstU32<64>;
type OmniAccountOrigin = EnsureOmniAccount;
type OmniAccountConverter = DefaultOmniAccountConverter;
type SetOmniExecutorOrigin = EnsureRootOrHalfCouncil;
}

impl pallet_bitacross::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions parachain/runtime/paseo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ impl pallet_omni_account::Config for Runtime {
type MaxAccountStoreLength = ConstU32<64>;
type OmniAccountOrigin = EnsureOmniAccount;
type OmniAccountConverter = DefaultOmniAccountConverter;
type SetOmniExecutorOrigin = EnsureRootOrAllCouncil;
}

impl pallet_bitacross::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions parachain/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ impl pallet_omni_account::Config for Runtime {
type MaxAccountStoreLength = ConstU32<64>;
type OmniAccountOrigin = EnsureOmniAccount;
type OmniAccountConverter = DefaultOmniAccountConverter;
type SetOmniExecutorOrigin = EnsureRootOrAllCouncil;
}

impl pallet_bitacross::Config for Runtime {
Expand Down
76 changes: 72 additions & 4 deletions tee-worker/omni-executor/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 tee-worker/omni-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [
"executor-core",
"executor-worker",
"parentchain/listener",
"ethereum/intention-executor",
"ethereum/intent-executor",
]

resolver = "2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "intention-executor"
name = "intent-executor"
version = "0.1.0"
authors = ['Trust Computing GmbH <[email protected]>']
edition.workspace = true
Expand Down
Loading

0 comments on commit 64136cb

Please sign in to comment.