diff --git a/Cargo.lock b/Cargo.lock index a4e15c1acb..f4b65fa415 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7448,6 +7448,7 @@ dependencies = [ "pallet-evm", "pallet-parachain-staking", "pallet-score-staking", + "pallet-teebag", "pallet-timestamp", "parity-scale-codec", "precompile-utils", @@ -7941,6 +7942,8 @@ dependencies = [ "num-integer", "pallet-balances", "pallet-parachain-staking", + "pallet-teebag", + "pallet-timestamp", "parity-scale-codec", "scale-info", "serde", diff --git a/pallets/score-staking/Cargo.toml b/pallets/score-staking/Cargo.toml index a4869ecd19..f6c91f9a8d 100644 --- a/pallets/score-staking/Cargo.toml +++ b/pallets/score-staking/Cargo.toml @@ -13,12 +13,14 @@ serde = { workspace = true } frame-benchmarking = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } +pallet-timestamp = { workspace = true } sp-core = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } core-primitives = { workspace = true } pallet-parachain-staking = { workspace = true } +pallet-teebag = { workspace = true } [dev-dependencies] sp-io = { workspace = true } @@ -42,12 +44,15 @@ std = [ "pallet-balances/std", "core-primitives/std", "pallet-parachain-staking/std", + "pallet-teebag/std", + "pallet-timestamp/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", ] try-runtime = [ "frame-support/try-runtime", diff --git a/pallets/score-staking/src/lib.rs b/pallets/score-staking/src/lib.rs index 9d8b09aa7b..16d947f403 100644 --- a/pallets/score-staking/src/lib.rs +++ b/pallets/score-staking/src/lib.rs @@ -114,6 +114,8 @@ pub mod pallet { type AdminOrigin: EnsureOrigin; /// AccountId converter type AccountIdConvert: AccountIdConvert; + // For extrinsics that should only be called by origins from TEE + type TEECallOrigin: EnsureOrigin; } #[pallet::error] @@ -150,20 +152,45 @@ pub mod pallet { ScoreUserCountUnderflow, // when the score user count would exceed `MaxScoreUserCount` MaxScoreUserCountReached, + // the token staking amount has been updated already for the round + TokenStakingAmountAlreadyUpdated, } #[pallet::event] #[pallet::generate_deposit(pub (crate) fn deposit_event)] pub enum Event { - PoolStarted { start_block: BlockNumberFor }, + PoolStarted { + start_block: BlockNumberFor, + }, PoolStopped {}, - ScoreFeederSet { new_score_feeder: Option }, - RoundConfigSet { new_config: RoundSetting }, - ScoreUpdated { who: Identity, new_score: Score }, - ScoreRemoved { who: Identity }, + ScoreFeederSet { + new_score_feeder: Option, + }, + RoundConfigSet { + new_config: RoundSetting, + }, + ScoreUpdated { + who: Identity, + new_score: Score, + }, + ScoreRemoved { + who: Identity, + }, ScoreCleared {}, - RewardCalculated { total: BalanceOf, distributed: BalanceOf }, - RewardClaimed { who: T::AccountId, amount: BalanceOf }, + TokenStakingAmountUpdated { + account: T::AccountId, + amount: BalanceOf, + }, + RewardDistributionStarted { + total: BalanceOf, + distributed: BalanceOf, + round_index: RoundIndex, + }, + RewardDistributionCompleted {}, + RewardClaimed { + who: T::AccountId, + amount: BalanceOf, + }, } #[pallet::storage] @@ -242,7 +269,8 @@ pub mod pallet { // We are about to start a new round // 1. update round info - r.index = r.index.saturating_add(1); + let round_index = r.index.saturating_add(1); + r.index = round_index; r.start_block = now; Round::::put(r); weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); @@ -279,9 +307,10 @@ pub mod pallet { weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1)); } - Self::deposit_event(Event::::RewardCalculated { + Self::deposit_event(Event::::RewardDistributionStarted { total: round_reward, distributed: all_user_reward, + round_index, }); weight @@ -445,6 +474,47 @@ pub mod pallet { let payment = Scores::::get(&account).ok_or(Error::::UserNotExist)?; Self::claim(origin, payment.unpaid_reward) } + + #[pallet::call_index(9)] + #[pallet::weight((195_000_000, DispatchClass::Normal))] + pub fn update_token_staking_amount( + origin: OriginFor, + account: T::AccountId, + amount: BalanceOf, + round_index: RoundIndex, + ) -> DispatchResultWithPostInfo { + let _ = T::TEECallOrigin::ensure_origin(origin)?; + + match Scores::::get(&account) { + Some(mut s) => { + if round_index <= s.last_token_distributed_round { + return Err(Error::::TokenStakingAmountAlreadyUpdated.into()); + } + let last_round = Round::::get(); + s.last_round_reward += amount; + s.total_reward += amount; + s.unpaid_reward += amount; + s.last_token_distributed_round = last_round.index; + Scores::::insert(account.clone(), s); + Self::deposit_event(Event::TokenStakingAmountUpdated { + account: account.clone(), + amount, + }); + Ok(Pays::No.into()) + }, + None => Err(Error::::UserNotExist.into()), + } + } + + #[pallet::call_index(10)] + #[pallet::weight((195_000_000, DispatchClass::Normal))] + pub fn complete_reward_distribution(origin: OriginFor) -> DispatchResultWithPostInfo { + let _ = T::TEECallOrigin::ensure_origin(origin)?; + + Self::deposit_event(Event::RewardDistributionCompleted {}); + + Ok(Pays::No.into()) + } } } diff --git a/pallets/score-staking/src/mock.rs b/pallets/score-staking/src/mock.rs index 2463ac0540..d50d8acff3 100644 --- a/pallets/score-staking/src/mock.rs +++ b/pallets/score-staking/src/mock.rs @@ -18,8 +18,11 @@ use crate::{ self as pallet_score_staking, AccountIdConvert, Config, Perbill, PoolState, RoundSetting, }; +use core::marker::PhantomData; use frame_support::{ - assert_ok, construct_runtime, ord_parameter_types, parameter_types, + assert_ok, construct_runtime, ord_parameter_types, + pallet_prelude::EnsureOrigin, + parameter_types, traits::{OnFinalize, OnInitialize}, }; use frame_system::{EnsureRoot, EnsureSignedBy}; @@ -51,6 +54,7 @@ construct_runtime!( Balances: pallet_balances, ParachainStaking: pallet_parachain_staking, ScoreStaking: pallet_score_staking, + Teebag: pallet_teebag, } ); @@ -166,6 +170,66 @@ impl pallet_score_staking::Config for Test { type YearlyIssuance = ConstU128<{ 100_000_000 * UNIT }>; type YearlyInflation = DefaultYearlyInflation; type MaxScoreUserCount = ConstU32<2>; + type TEECallOrigin = EnsureEnclaveSigner; +} + +parameter_types! { + pub const MinimumPeriod: u64 = 6000 / 2; +} + +pub type Moment = u64; + +impl pallet_timestamp::Config for Test { + type Moment = Moment; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +parameter_types! { + pub const MomentsPerDay: u64 = 86_400_000; // [ms/d] +} + +impl pallet_teebag::Config for Test { + type RuntimeEvent = RuntimeEvent; + type MomentsPerDay = MomentsPerDay; + type SetAdminOrigin = EnsureRoot; + type MaxEnclaveIdentifier = ConstU32<1>; + type MaxAuthorizedEnclave = ConstU32<2>; + type WeightInfo = (); +} + +pub struct EnsureEnclaveSigner(PhantomData); +impl EnsureOrigin for EnsureEnclaveSigner +where + T: frame_system::Config + pallet_teebag::Config + pallet_timestamp::Config, + ::AccountId: From<[u8; 32]>, + ::Hash: From<[u8; 32]>, +{ + type Success = T::AccountId; + fn try_origin(o: T::RuntimeOrigin) -> Result { + o.into().and_then(|o| match o { + frame_system::RawOrigin::Signed(who) + if pallet_teebag::EnclaveRegistry::::contains_key(&who) => + { + Ok(who) + }, + r => Err(T::RuntimeOrigin::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + use pallet_teebag::test_util::{get_signer, TEST8_MRENCLAVE, TEST8_SIGNER_PUB}; + let signer: ::AccountId = get_signer(TEST8_SIGNER_PUB); + if !pallet_teebag::EnclaveRegistry::::contains_key(signer.clone()) { + assert_ok!(pallet_teebag::Pallet::::add_enclave( + &signer, + &pallet_teebag::Enclave::default().with_mrenclave(TEST8_MRENCLAVE), + )); + } + Ok(frame_system::RawOrigin::Signed(signer).into()) + } } pub fn alice() -> AccountId { @@ -186,6 +250,14 @@ pub fn new_test_ext(fast_round: bool) -> sp_io::TestExternalities { .assimilate_storage(&mut t) .unwrap(); + pallet_teebag::GenesisConfig:: { + allow_sgx_debug_mode: true, + admin: Some(AccountKeyring::Alice.to_account_id()), + mode: pallet_teebag::OperationalMode::Production, + } + .assimilate_storage(&mut t) + .unwrap(); + pallet_score_staking::GenesisConfig:: { state: PoolState::Stopped, marker: Default::default(), diff --git a/pallets/score-staking/src/tests.rs b/pallets/score-staking/src/tests.rs index 77b87b4dcc..3075fd5400 100644 --- a/pallets/score-staking/src/tests.rs +++ b/pallets/score-staking/src/tests.rs @@ -18,8 +18,9 @@ use crate::{mock::*, Error, Event, PoolState, RoundInfo, RoundSetting, ScorePayment, Scores}; use core_primitives::{Identity, DAYS, YEARS}; -use frame_support::{assert_err, assert_ok}; +use frame_support::{assert_err, assert_noop, assert_ok}; use pallet_parachain_staking::{Delegator, OnAllDelegationRemoved}; +use pallet_teebag::{Enclave, WorkerType}; use sp_runtime::Perbill; fn round_reward() -> Balance { @@ -127,10 +128,13 @@ fn default_mint_works() { // run to next reward distribution round run_to_block(7); - System::assert_last_event(RuntimeEvent::ScoreStaking(Event::::RewardCalculated { - total: round_reward(), - distributed: 0, - })); + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionStarted { + total: round_reward(), + distributed: 0, + round_index: 2, + }, + )); }); } @@ -165,7 +169,13 @@ fn score_staking_works() { assert_ok!(ScoreStaking::update_score(RuntimeOrigin::signed(alice()), alice().into(), 500)); assert_eq!( ScoreStaking::scores(alice()).unwrap(), - ScorePayment { score: 500, total_reward: 0, last_round_reward: 0, unpaid_reward: 0 } + ScorePayment { + score: 500, + total_reward: 0, + last_round_reward: 0, + unpaid_reward: 0, + last_token_distributed_round: 0 + } ); assert_eq!(ScoreStaking::total_score(), 500); assert_eq!(ScoreStaking::score_user_count(), 1); @@ -181,11 +191,14 @@ fn score_staking_works() { // run to next reward distribution round, alice should win all rewards run_to_block(7); - System::assert_last_event(RuntimeEvent::ScoreStaking(Event::::RewardCalculated { - total: round_reward(), - distributed: round_reward(), - })); - // total reward round 1 + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionStarted { + total: round_reward(), + distributed: round_reward(), + round_index: 2, + }, + )); + // total reward first distribution let mut alice_total_reward = round_reward(); assert_eq!( ScoreStaking::scores(alice()).unwrap(), @@ -194,18 +207,22 @@ fn score_staking_works() { total_reward: alice_total_reward, last_round_reward: alice_total_reward, unpaid_reward: alice_total_reward, + last_token_distributed_round: 0, } ); // alice's winning should accumulate run_to_block(12); - // total reward round 2 + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionStarted { + total: round_reward(), + distributed: round_reward(), + round_index: 3, + }, + )); + // total reward second distribution alice_total_reward += round_reward(); - System::assert_last_event(RuntimeEvent::ScoreStaking(Event::::RewardCalculated { - total: round_reward(), - distributed: round_reward(), - })); assert_eq!( ScoreStaking::scores(alice()).unwrap(), ScorePayment { @@ -213,6 +230,7 @@ fn score_staking_works() { total_reward: alice_total_reward, last_round_reward: round_reward(), unpaid_reward: alice_total_reward, + last_token_distributed_round: 0, } ); @@ -221,13 +239,16 @@ fn score_staking_works() { pallet_parachain_staking::Total::::put(1600); run_to_block(17); - // total reward round 3 + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionStarted { + total: round_reward(), + distributed: calculate_round_reward(2000, 2000, 900, 1600), + round_index: 4, + }, + )); + // total reward third distribution alice_total_reward += calculate_round_reward(2000, 2000, 900, 1600); - System::assert_last_event(RuntimeEvent::ScoreStaking(Event::::RewardCalculated { - total: round_reward(), - distributed: calculate_round_reward(2000, 2000, 900, 1600), - })); assert_eq!( ScoreStaking::scores(alice()).unwrap(), ScorePayment { @@ -235,6 +256,7 @@ fn score_staking_works() { total_reward: alice_total_reward, last_round_reward: calculate_round_reward(2000, 2000, 900, 1600), unpaid_reward: alice_total_reward, + last_token_distributed_round: 0, } ); @@ -247,7 +269,7 @@ fn score_staking_works() { assert_eq!(ScoreStaking::score_user_count(), 2); run_to_block(22); - // total rewards round 4 + // total rewards fourth distribution alice_total_reward += calculate_round_reward(2000, 3000, 900, 3200); let mut bob_total_reward = calculate_round_reward(1000, 3000, 1600, 3200); @@ -258,6 +280,7 @@ fn score_staking_works() { total_reward: alice_total_reward, last_round_reward: calculate_round_reward(2000, 3000, 900, 3200), unpaid_reward: alice_total_reward, + last_token_distributed_round: 0, } ); assert_eq!( @@ -267,6 +290,7 @@ fn score_staking_works() { total_reward: bob_total_reward, last_round_reward: bob_total_reward, unpaid_reward: bob_total_reward, + last_token_distributed_round: 0, } ); @@ -288,7 +312,7 @@ fn score_staking_works() { )); run_to_block(25); - // total rewards round 5 + // total rewards fifth distribution alice_total_reward += calculate_round_reward(2000, 3000, 900, 3200); bob_total_reward += calculate_round_reward(1000, 3000, 1600, 3200); @@ -300,7 +324,7 @@ fn score_staking_works() { )); run_to_block(31); - // total reward round 6 + // total reward sixth distribution alice_total_reward += calculate_round_reward(2000, 2000, 900, 900); // remove increased stake (keep only alice's stake) @@ -316,6 +340,7 @@ fn score_staking_works() { total_reward: alice_total_reward, last_round_reward: round_reward(), unpaid_reward: alice_total_reward, + last_token_distributed_round: 0, } ); @@ -327,6 +352,7 @@ fn score_staking_works() { total_reward: bob_total_reward, last_round_reward: 0, unpaid_reward: bob_total_reward, + last_token_distributed_round: 0, } ); assert_eq!(ScoreStaking::total_score(), 2000); @@ -360,10 +386,13 @@ fn claim_works() { // run to next reward distribution round, alice should win all rewards run_to_block(7); - System::assert_last_event(RuntimeEvent::ScoreStaking(Event::::RewardCalculated { - total: round_reward(), - distributed: round_reward(), - })); + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionStarted { + total: round_reward(), + distributed: round_reward(), + round_index: 2, + }, + )); assert_eq!( ScoreStaking::scores(alice()).unwrap(), ScorePayment { @@ -371,6 +400,7 @@ fn claim_works() { total_reward: round_reward(), last_round_reward: round_reward(), unpaid_reward: round_reward(), + last_token_distributed_round: 0, } ); @@ -386,6 +416,7 @@ fn claim_works() { total_reward: round_reward(), last_round_reward: round_reward(), unpaid_reward: round_reward() - 200, + last_token_distributed_round: 0, } ); @@ -401,6 +432,7 @@ fn claim_works() { total_reward: round_reward(), last_round_reward: round_reward(), unpaid_reward: 0, + last_token_distributed_round: 0, } ); @@ -412,6 +444,152 @@ fn claim_works() { }); } +#[test] +fn update_token_staking_amount_works() { + new_test_ext_with_parachain_staking().execute_with(|| { + let enclave = Enclave::new(WorkerType::Identity); + pallet_teebag::EnclaveRegistry::::insert(alice(), enclave); + + run_to_block(2); + assert_ok!(ScoreStaking::start_pool(RuntimeOrigin::root())); + + run_to_block(3); + pallet_parachain_staking::DelegatorState::::insert( + alice(), + Delegator::new(bob(), bob(), 900), + ); + pallet_parachain_staking::Total::::put(900); + assert_ok!(ScoreStaking::update_score(RuntimeOrigin::signed(alice()), alice().into(), 500)); + + // run to next reward distribution round, alice should win all rewards + run_to_block(7); + let mut total_reward = round_reward(); + + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionStarted { + total: total_reward, + distributed: total_reward, + round_index: 2, + }, + )); + + assert_ok!(ScoreStaking::update_token_staking_amount( + RuntimeOrigin::signed(alice()), + alice(), + 1000, + 2, + )); + + total_reward += 1000; + + assert_eq!( + ScoreStaking::scores(alice()).unwrap(), + ScorePayment { + score: 500, + total_reward, + last_round_reward: total_reward, + unpaid_reward: total_reward, + last_token_distributed_round: 2, + } + ); + + run_to_block(12); + + total_reward += round_reward(); + + assert_noop!( + ScoreStaking::update_token_staking_amount( + RuntimeOrigin::signed(alice()), + alice(), + 1000, + 2, + ), + Error::::TokenStakingAmountAlreadyUpdated + ); + + assert_ok!(ScoreStaking::update_token_staking_amount( + RuntimeOrigin::signed(alice()), + alice(), + 1200, + 3, + )); + + total_reward += 1200; + + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::TokenStakingAmountUpdated { account: alice(), amount: 1200 }, + )); + + assert_eq!( + ScoreStaking::scores(alice()).unwrap(), + ScorePayment { + score: 500, + total_reward, + last_round_reward: round_reward() + 1200, + unpaid_reward: total_reward, + last_token_distributed_round: 3, + } + ); + }) +} + +#[test] +fn update_token_staking_amount_origin_check_works() { + new_test_ext(false).execute_with(|| { + assert_noop!( + ScoreStaking::update_token_staking_amount( + RuntimeOrigin::signed(alice()), + alice(), + 1000, + 1 + ), + sp_runtime::DispatchError::BadOrigin + ); + }) +} + +#[test] +fn update_token_staking_amount_existing_user_check_works() { + new_test_ext(false).execute_with(|| { + let enclave = Enclave::new(WorkerType::Identity); + pallet_teebag::EnclaveRegistry::::insert(alice(), enclave); + + assert_noop!( + ScoreStaking::update_token_staking_amount( + RuntimeOrigin::signed(alice()), + alice(), + 1000, + 1 + ), + Error::::UserNotExist + ); + }) +} + +#[test] +fn complete_reward_distribution_works() { + new_test_ext(false).execute_with(|| { + let enclave = Enclave::new(WorkerType::Identity); + pallet_teebag::EnclaveRegistry::::insert(alice(), enclave); + + assert_ok!(ScoreStaking::complete_reward_distribution(RuntimeOrigin::signed(alice()))); + + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionCompleted {}, + )); + }); +} + +#[test] +fn complete_reward_distribution_origin_check_works() { + new_test_ext(false).execute_with(|| { + assert_noop!( + ScoreStaking::complete_reward_distribution(RuntimeOrigin::signed(alice())), + sp_runtime::DispatchError::BadOrigin + ); + }); +} + #[test] fn on_all_delegation_removed_works() { new_test_ext(true).execute_with(|| { diff --git a/pallets/score-staking/src/types.rs b/pallets/score-staking/src/types.rs index 1456f4e67d..5b6edda153 100644 --- a/pallets/score-staking/src/types.rs +++ b/pallets/score-staking/src/types.rs @@ -83,4 +83,5 @@ pub struct ScorePayment { pub total_reward: Balance, pub last_round_reward: Balance, pub unpaid_reward: Balance, + pub last_token_distributed_round: RoundIndex, } diff --git a/precompiles/score-staking/Cargo.toml b/precompiles/score-staking/Cargo.toml index e9bc95f33d..0913f0877b 100644 --- a/precompiles/score-staking/Cargo.toml +++ b/precompiles/score-staking/Cargo.toml @@ -6,6 +6,7 @@ version = '0.1.0' [dependencies] pallet-score-staking = { workspace = true } +pallet-teebag = { workspace = true } precompile-utils = { workspace = true } fp-evm = { workspace = true } @@ -38,9 +39,11 @@ std = [ "frame-system/std", "pallet-evm/std", "pallet-score-staking/std", + "pallet-teebag/std", "precompile-utils/std", "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-std/std", ] +runtime-benchmarks = [] diff --git a/precompiles/score-staking/src/mock.rs b/precompiles/score-staking/src/mock.rs index 6c5cbb288c..c127b263d8 100644 --- a/precompiles/score-staking/src/mock.rs +++ b/precompiles/score-staking/src/mock.rs @@ -15,8 +15,11 @@ // along with Litentry. If not, see . use super::*; +use core::marker::PhantomData; use frame_support::{ - assert_ok, construct_runtime, parameter_types, + assert_ok, construct_runtime, + pallet_prelude::EnsureOrigin, + parameter_types, traits::{OnFinalize, OnInitialize}, weights::Weight, }; @@ -43,6 +46,7 @@ construct_runtime!( Evm: pallet_evm, ParachainStaking: pallet_parachain_staking, ScoreStaking: pallet_score_staking, + Teebag: pallet_teebag, } ); @@ -164,6 +168,7 @@ impl pallet_score_staking::Config for Test { type YearlyIssuance = ConstU128<{ 100_000_000 * UNIT }>; type YearlyInflation = DefaultYearlyInflation; type MaxScoreUserCount = ConstU32<2>; + type TEECallOrigin = EnsureEnclaveSigner; } pub fn precompile_address() -> H160 { @@ -245,6 +250,52 @@ impl pallet_timestamp::Config for Test { type WeightInfo = (); } +parameter_types! { + pub const MomentsPerDay: u64 = 86_400_000; // [ms/d] +} + +impl pallet_teebag::Config for Test { + type RuntimeEvent = RuntimeEvent; + type MomentsPerDay = MomentsPerDay; + type SetAdminOrigin = EnsureRoot; + type MaxEnclaveIdentifier = ConstU32<1>; + type MaxAuthorizedEnclave = ConstU32<2>; + type WeightInfo = (); +} + +pub struct EnsureEnclaveSigner(PhantomData); +impl EnsureOrigin for EnsureEnclaveSigner +where + T: frame_system::Config + pallet_teebag::Config + pallet_timestamp::Config, + ::AccountId: From<[u8; 32]>, + ::Hash: From<[u8; 32]>, +{ + type Success = T::AccountId; + fn try_origin(o: T::RuntimeOrigin) -> Result { + o.into().and_then(|o| match o { + frame_system::RawOrigin::Signed(who) + if pallet_teebag::EnclaveRegistry::::contains_key(&who) => + { + Ok(who) + }, + r => Err(T::RuntimeOrigin::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + use pallet_teebag::test_util::{get_signer, TEST8_MRENCLAVE, TEST8_SIGNER_PUB}; + let signer: ::AccountId = get_signer(TEST8_SIGNER_PUB); + if !pallet_teebag::EnclaveRegistry::::contains_key(signer.clone()) { + assert_ok!(pallet_teebag::Pallet::::add_enclave( + &signer, + &pallet_teebag::Enclave::default().with_mrenclave(TEST8_MRENCLAVE), + )); + } + Ok(frame_system::RawOrigin::Signed(signer).into()) + } +} + pub fn alice() -> AccountId { U8Wrapper(1u8).into() } @@ -259,6 +310,14 @@ pub fn new_test_ext(fast_round: bool) -> sp_io::TestExternalities { .assimilate_storage(&mut t) .unwrap(); + pallet_teebag::GenesisConfig:: { + allow_sgx_debug_mode: true, + admin: Some(alice()), + mode: pallet_teebag::OperationalMode::Production, + } + .assimilate_storage(&mut t) + .unwrap(); + pallet_score_staking::GenesisConfig:: { state: PoolState::Stopped, marker: Default::default(), diff --git a/precompiles/score-staking/src/tests.rs b/precompiles/score-staking/src/tests.rs index b3e61b6e0e..c096c09a73 100644 --- a/precompiles/score-staking/src/tests.rs +++ b/precompiles/score-staking/src/tests.rs @@ -52,10 +52,13 @@ fn claim_is_ok() { // run to next reward distribution round, alice should win all rewards run_to_block(7); - System::assert_last_event(RuntimeEvent::ScoreStaking(Event::::RewardCalculated { - total: round_reward(), - distributed: round_reward(), - })); + System::assert_last_event(RuntimeEvent::ScoreStaking( + Event::::RewardDistributionStarted { + total: round_reward(), + distributed: round_reward(), + round_index: 2, + }, + )); assert_eq!( ScoreStaking::scores(alice()).unwrap(), ScorePayment { @@ -63,6 +66,7 @@ fn claim_is_ok() { total_reward: round_reward(), last_round_reward: round_reward(), unpaid_reward: round_reward(), + last_token_distributed_round: 0, } ); @@ -86,6 +90,7 @@ fn claim_is_ok() { total_reward: round_reward(), last_round_reward: round_reward(), unpaid_reward: round_reward() - 200, + last_token_distributed_round: 0, } ); @@ -109,6 +114,7 @@ fn claim_is_ok() { total_reward: round_reward(), last_round_reward: round_reward(), unpaid_reward: 0, + last_token_distributed_round: 0, } ); diff --git a/runtime/litentry/src/lib.rs b/runtime/litentry/src/lib.rs index 4815a5fc21..29171d88d9 100644 --- a/runtime/litentry/src/lib.rs +++ b/runtime/litentry/src/lib.rs @@ -1127,6 +1127,7 @@ impl pallet_score_staking::Config for Runtime { type YearlyIssuance = ConstU128<{ 100_000_000 * UNIT }>; type YearlyInflation = DefaultYearlyInflation; type MaxScoreUserCount = ConstU32<1_000_000>; + type TEECallOrigin = EnsureEnclaveSigner; } impl runtime_common::BaseRuntimeRequirements for Runtime {} diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index c875ce5e53..25ed6b2bf7 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1168,6 +1168,7 @@ impl pallet_score_staking::Config for Runtime { type YearlyIssuance = ConstU128<{ 100_000_000 * UNIT }>; type YearlyInflation = DefaultYearlyInflation; type MaxScoreUserCount = ConstU32<1_000_000>; + type TEECallOrigin = EnsureEnclaveSigner; } impl runtime_common::BaseRuntimeRequirements for Runtime {} diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index 0a9fd4f4ea..82188da3ed 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -384,7 +384,7 @@ dependencies = [ [[package]] name = "binary-merkle-tree" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", "log 0.4.20", @@ -886,7 +886,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", "strum 0.26.1", @@ -1837,7 +1837,7 @@ dependencies = [ "scale-info", "serde 1.0.204", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", ] @@ -1855,7 +1855,7 @@ dependencies = [ "scale-info", "serde 1.0.204", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-runtime-interface", "sp-std 5.0.0", @@ -1900,7 +1900,7 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-support-procedural", @@ -1914,7 +1914,7 @@ dependencies = [ "sp-api", "sp-application-crypto", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-runtime-interface", "sp-std 5.0.0", @@ -1925,14 +1925,14 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", "parity-scale-codec", "scale-info", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", "sp-tracing", @@ -1953,7 +1953,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bitflags 1.3.2", "environmental 1.1.4", @@ -1973,7 +1973,7 @@ dependencies = [ "sp-core", "sp-core-hashing-proc-macro", "sp-inherents", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-staking", "sp-state-machine", @@ -1986,7 +1986,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "cfg-expr", @@ -2002,7 +2002,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2014,7 +2014,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -2024,7 +2024,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "log 0.4.20", @@ -2032,7 +2032,7 @@ dependencies = [ "scale-info", "serde 1.0.204", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", "sp-version", @@ -2944,6 +2944,7 @@ name = "ita-parentchain-interface" version = "0.1.0" dependencies = [ "env_logger 0.9.3", + "frame-support", "ita-sgx-runtime", "ita-stf", "itc-parentchain-indirect-calls-executor", @@ -2953,15 +2954,21 @@ dependencies = [ "itp-node-api", "itp-ocall-api", "itp-sgx-crypto", + "itp-sgx-externalities", "itp-stf-executor", "itp-stf-primitives", + "itp-stf-state-handler", + "itp-storage", "itp-test", "itp-top-pool-author", "itp-types", "lc-dynamic-assertion", "lc-evm-dynamic-assertions", + "lc-parachain-extrinsic-task-sender", + "litentry-hex-utils 0.1.0", "litentry-primitives", "log 0.4.20", + "pallet-identity-management-tee", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -5011,7 +5018,9 @@ dependencies = [ "core-primitives", "hex", "itp-sgx-crypto", + "itp-utils", "log 0.4.20", + "pallet-parachain-staking", "pallet-teebag", "parity-scale-codec", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5022,7 +5031,7 @@ dependencies = [ "serde 1.0.204", "sgx_tstd", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", ] @@ -5905,7 +5914,7 @@ checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" [[package]] name = "pallet-assets" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5920,7 +5929,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -5934,7 +5943,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -5965,7 +5974,7 @@ dependencies = [ "rlp", "scale-info", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", ] @@ -5990,7 +5999,7 @@ dependencies = [ "rlp", "scale-info", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", ] @@ -6008,7 +6017,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", ] @@ -6042,14 +6051,14 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", ] [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -6059,7 +6068,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-session", "sp-staking", @@ -6069,13 +6078,13 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", ] @@ -6102,7 +6111,7 @@ dependencies = [ "serde 1.0.204", "serde_json 1.0.103", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", "x509-cert", @@ -6111,7 +6120,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-benchmarking", "frame-support", @@ -6120,7 +6129,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-inherents", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", "sp-timestamp", @@ -6129,7 +6138,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", "frame-system", @@ -6137,7 +6146,7 @@ dependencies = [ "scale-info", "serde 1.0.204", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-runtime", "sp-std 5.0.0", ] @@ -7311,7 +7320,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "array-bytes 4.2.0", "async-trait", @@ -8074,7 +8083,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", "log 0.4.20", @@ -8094,7 +8103,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "blake2", @@ -8108,20 +8117,20 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", "serde 1.0.204", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-std 5.0.0", ] [[package]] name = "sp-arithmetic" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "integer-sqrt", "num-traits 0.2.16", @@ -8135,7 +8144,7 @@ dependencies = [ [[package]] name = "sp-consensus-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "finality-grandpa", "log 0.4.20", @@ -8153,7 +8162,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -8165,7 +8174,7 @@ dependencies = [ [[package]] name = "sp-core" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "array-bytes 4.2.0", "bitflags 1.3.2", @@ -8209,7 +8218,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "blake2b_simd", "byteorder 1.4.3", @@ -8238,7 +8247,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -8249,7 +8258,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "proc-macro2", "quote", @@ -8259,7 +8268,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "environmental 1.1.4", "parity-scale-codec", @@ -8270,7 +8279,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -8297,7 +8306,7 @@ dependencies = [ [[package]] name = "sp-io" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bytes 1.4.0", "ed25519", @@ -8323,7 +8332,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "lazy_static", "sp-core", @@ -8334,7 +8343,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "futures 0.3.28", "parity-scale-codec", @@ -8348,7 +8357,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.1.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-metadata", "parity-scale-codec", @@ -8359,7 +8368,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "backtrace", "lazy_static", @@ -8369,7 +8378,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "either", "hash256-std-hasher", @@ -8383,7 +8392,7 @@ dependencies = [ "sp-application-crypto", "sp-arithmetic", "sp-core", - "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42)", "sp-std 5.0.0", "sp-weights", ] @@ -8391,7 +8400,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "bytes 1.4.0", "impl-trait-for-tuples", @@ -8409,7 +8418,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "Inflector", "proc-macro-crate", @@ -8421,7 +8430,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -8434,7 +8443,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", @@ -8447,7 +8456,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "hash-db 0.16.0", "log 0.4.20", @@ -8467,7 +8476,7 @@ dependencies = [ [[package]] name = "sp-std" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" [[package]] name = "sp-std" @@ -8478,7 +8487,7 @@ checksum = "af0ee286f98455272f64ac5bb1384ff21ac029fbb669afbaf48477faff12760e" [[package]] name = "sp-storage" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8491,7 +8500,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "async-trait", "futures-timer", @@ -8506,7 +8515,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "sp-std 5.0.0", @@ -8518,7 +8527,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "ahash 0.8.3", "hash-db 0.16.0", @@ -8541,7 +8550,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "impl-serde", "parity-scale-codec", @@ -8558,7 +8567,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -8569,7 +8578,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -8583,7 +8592,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "parity-scale-codec", "scale-info", diff --git a/tee-worker/app-libs/parentchain-interface/Cargo.toml b/tee-worker/app-libs/parentchain-interface/Cargo.toml index 46cd6d9f6d..f1ab5fc840 100644 --- a/tee-worker/app-libs/parentchain-interface/Cargo.toml +++ b/tee-worker/app-libs/parentchain-interface/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] # sgx dependencies +pallet-identity-management-tee = { path = "../../litentry/pallets/identity-management", default-features = false } sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true } # local dependencies @@ -16,9 +17,12 @@ itp-api-client-types = { path = "../../core-primitives/node-api/api-client-types itp-enclave-metrics = { path = "../../core-primitives/enclave-metrics", default-features = false } itp-node-api = { path = "../../core-primitives/node-api", default-features = false } itp-ocall-api = { path = "../../core-primitives/ocall-api", default-features = false } +itp-sgx-externalities = { path = "../../core-primitives/substrate-sgx/externalities", default-features = false } itp-stf-primitives = { path = "../../core-primitives/stf-primitives", default-features = false } +itp-stf-state-handler = { path = "../../core-primitives/stf-state-handler", default-features = false } +itp-storage = { path = "../../core-primitives/storage", default-features = false } itp-types = { path = "../../core-primitives/types", default-features = false } - +lc-parachain-extrinsic-task-sender = { path = "../../litentry/core/parachain-extrinsic-task/sender", default-features = false } # no-std compatible libraries codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } log = { version = "0.4", default-features = false } @@ -26,12 +30,14 @@ log = { version = "0.4", default-features = false } substrate-api-client = { optional = true, default-features = false, features = ["std", "sync-api"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.14.0" } # substrate dep +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false } sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } # litentry lc-dynamic-assertion = { path = "../../litentry/core/dynamic-assertion", default-features = false } lc-evm-dynamic-assertions = { path = "../../litentry/core/evm-dynamic-assertions", default-features = false } +litentry-hex-utils = { path = "../../../primitives/hex", default-features = false } litentry-primitives = { path = "../../litentry/primitives", default-features = false } sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } @@ -45,7 +51,6 @@ itp-test = { path = "../../core-primitives/test" } itp-top-pool-author = { path = "../../core-primitives/top-pool-author", features = ["mocks"] } itc-parentchain-test = { path = "../../core/parentchain/test" } - [features] default = ["std"] std = [ @@ -59,6 +64,7 @@ std = [ "itp-stf-executor/std", "itp-stf-primitives/std", "itp-top-pool-author/std", + "itp-sgx-externalities/std", "itp-types/std", "log/std", "sp-core/std", @@ -67,6 +73,7 @@ std = [ "litentry-primitives/std", "lc-dynamic-assertion/std", "lc-evm-dynamic-assertions/std", + "lc-parachain-extrinsic-task-sender/std", "sp-std/std", ] sgx = [ @@ -76,8 +83,10 @@ sgx = [ "itp-node-api/sgx", "itp-sgx-crypto/sgx", "itp-stf-executor/sgx", + "itp-sgx-externalities/sgx", "itp-top-pool-author/sgx", "litentry-primitives/sgx", "lc-dynamic-assertion/sgx", "lc-evm-dynamic-assertions/sgx", + "lc-parachain-extrinsic-task-sender/sgx", ] diff --git a/tee-worker/app-libs/parentchain-interface/src/integritee/event_filter.rs b/tee-worker/app-libs/parentchain-interface/src/integritee/event_filter.rs index 456cebe639..0c15bbdfcc 100644 --- a/tee-worker/app-libs/parentchain-interface/src/integritee/event_filter.rs +++ b/tee-worker/app-libs/parentchain-interface/src/integritee/event_filter.rs @@ -25,7 +25,7 @@ use itp_types::{ events::{ ActivateIdentityRequested, AssertionCreated, DeactivateIdentityRequested, EnclaveUnauthorized, LinkIdentityRequested, OpaqueTaskPosted, - ParentchainBlockProcessed, VCRequested, + ParentchainBlockProcessed, RewardDistributionStarted, VCRequested, }, FilterEvents, }, @@ -104,4 +104,10 @@ impl FilterEvents for FilterableEvents { ) -> Result, Self::Error> { self.filter() } + + fn get_reward_distribution_started_events( + &self, + ) -> Result, Self::Error> { + self.filter() + } } diff --git a/tee-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs b/tee-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs index 015cdaee70..c8eb71eb6f 100644 --- a/tee-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs +++ b/tee-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs @@ -16,39 +16,52 @@ */ use codec::{Decode, Encode}; -pub use ita_sgx_runtime::{Balance, Index}; +use frame_support::storage::storage_prefix; +pub use ita_sgx_runtime::{Balance, Index, Runtime}; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::error::Error; use itp_api_client_types::StaticEvent; use itp_enclave_metrics::EnclaveMetric; -use itp_ocall_api::EnclaveMetricsOCallApi; +use itp_node_api::metadata::{ + pallet_score_staking::ScoreStakingCallIndexes, provider::AccessNodeMetadata, NodeMetadataTrait, +}; +use itp_ocall_api::{EnclaveMetricsOCallApi, EnclaveOnChainOCallApi}; +use itp_sgx_externalities::{SgxExternalities, SgxExternalitiesTrait}; use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation}; +use itp_stf_state_handler::handle_state::HandleState; +use itp_storage::{key_to_account_id, storage_map_key, StorageHasher}; use itp_types::{ parentchain::{ events::ParentchainBlockProcessed, AccountId, FilterEvents, HandleParentchainEvents, - ParentchainEventProcessingError, ProcessedEventsArtifacts, + ParentchainEventProcessingError, ParentchainId, ProcessedEventsArtifacts, }, - RsaRequest, H256, + Delegator, OpaqueCall, RsaRequest, H256, }; use lc_dynamic_assertion::AssertionLogicRepository; use lc_evm_dynamic_assertions::repository::EvmAssertionRepository; +use lc_parachain_extrinsic_task_sender::{ParachainExtrinsicSender, SendParachainExtrinsic}; +use litentry_hex_utils::decode_hex; use litentry_primitives::{Assertion, Identity, ValidationData, Web3Network}; use log::*; +use pallet_identity_management_tee::IdentityContext; use sp_core::{blake2_256, H160}; +use sp_runtime::traits::Header; use sp_std::vec::Vec; -use std::{format, string::String, sync::Arc, time::Instant}; +use std::{collections::BTreeMap, format, println, string::String, sync::Arc, time::Instant}; -pub struct ParentchainEventHandler -where - MetricsApi: EnclaveMetricsOCallApi, -{ +pub struct ParentchainEventHandler { pub assertion_repository: Arc, - pub metrics_api: Arc, + pub ocall_api: Arc, + pub state_handler: Arc, + pub node_metadata_repository: Arc, } -impl ParentchainEventHandler +impl ParentchainEventHandler where - MetricsApi: EnclaveMetricsOCallApi, + OCallApi: EnclaveOnChainOCallApi + EnclaveMetricsOCallApi, + HS: HandleState, + NMR: AccessNodeMetadata, + NMR::MetadataType: NodeMetadataTrait, { fn link_identity>( executor: &Executor, @@ -210,27 +223,169 @@ where .save(id, (byte_code, decrypted_secrets)) .map_err(Error::AssertionCreatedHandling)?; let duration = start_time.elapsed(); - if let Err(e) = self - .metrics_api - .update_metric(EnclaveMetric::DynamicAssertionSaveTime(duration)) + if let Err(e) = + self.ocall_api.update_metric(EnclaveMetric::DynamicAssertionSaveTime(duration)) { warn!("Failed to update DynamicAssertionSaveTime metric with error: {:?}", e); } Ok(()) } + + fn update_staking_scores>( + &self, + executor: &Executor, + block_header: impl Header, + round_index: u32, + ) -> Result<(), Error> { + let scores_key_prefix = storage_prefix(b"ScoreStaking", b"Scores"); + let scores_storage_keys_response = self + .ocall_api + .get_storage_keys(scores_key_prefix.into()) + .map_err(|_| Error::Other("Failed to get storage keys".into()))?; + let scores_storage_keys: Vec> = scores_storage_keys_response + .into_iter() + .filter_map(decode_storage_key) + .collect(); + let account_ids: Vec = + scores_storage_keys.iter().filter_map(key_to_account_id).collect(); + + let delegator_state_storage_keys: Vec> = account_ids + .iter() + .map(|account_id| { + storage_map_key( + "ParachainStaking", + "DelegatorState", + account_id, + &StorageHasher::Blake2_128Concat, + ) + }) + .collect(); + let delegator_states: BTreeMap> = self + .ocall_api + .get_multiple_storages_verified( + delegator_state_storage_keys, + &block_header, + &ParentchainId::Litentry, + ) + .map_err(|_| Error::Other("Failed to get multiple storages".into()))? + .into_iter() + .filter_map(|entry| { + let storage_key = decode_storage_key(entry.key)?; + let account_id = key_to_account_id(&storage_key)?; + let delegator = entry.value?; + Some((account_id, delegator)) + }) + .collect(); + + let id_graphs_storage_keys: Vec> = account_ids + .iter() + .map(|account_id| { + storage_map_key( + "IdentityManagement", + "IDGraphs", + &Identity::from(account_id.clone()), + &StorageHasher::Blake2_128Concat, + ) + }) + .collect(); + + let shard = executor.get_default_shard(); + + let accounts_graphs = self + .state_handler + .execute_on_current(&shard, |state, _| { + let mut id_graphs_accounts: BTreeMap> = BTreeMap::new(); + for id_graph_storage_key in id_graphs_storage_keys.iter() { + let id_graph: Vec<(Identity, IdentityContext)> = state + .iter_prefix::>(id_graph_storage_key) + .unwrap_or_default(); + let graph_accounts: Vec = id_graph + .iter() + .filter_map(|(identity, _)| identity.to_account_id()) + .collect(); + if let Some(account_id) = key_to_account_id(id_graph_storage_key) { + id_graphs_accounts.insert(account_id, graph_accounts); + } + } + + id_graphs_accounts + }) + .map_err(|_| Error::Other("Failed to get id graphs".into()))?; + + let extrinsic_sender = ParachainExtrinsicSender::new(); + + let update_token_staking_amount_call_index = self + .node_metadata_repository + .get_from_metadata(|m| m.update_token_staking_amount_call_indexes()) + .map_err(|_| { + Error::Other( + "Metadata retrieval for update_token_staking_amount_call_indexes failed".into(), + ) + })? + .map_err(|_| Error::Other("Invalid metadata".into()))?; + + for account_id in account_ids.iter() { + let default_id_graph = Vec::new(); + let id_graph = accounts_graphs.get(account_id).unwrap_or(&default_id_graph); + let staking_amount: Balance = id_graph + .iter() + .filter_map(|identity| { + let delegator = delegator_states.get(identity)?; + Some(delegator.total) + }) + .sum(); + let call = OpaqueCall::from_tuple(&( + update_token_staking_amount_call_index, + account_id, + staking_amount, + round_index, + )); + extrinsic_sender + .send(call) + .map_err(|_| Error::Other("Failed to send extrinsic".into()))?; + } + + let complete_reward_distribution_call_index = self + .node_metadata_repository + .get_from_metadata(|m| m.complete_reward_distribution_call_indexes()) + .map_err(|_| { + Error::Other( + "Metadata retrieval for complete_reward_distribution_call_indexes failed" + .into(), + ) + })? + .map_err(|_| Error::Other("Invalid metadata".into()))?; + + let complete_reward_distribution_call = + OpaqueCall::from_tuple(&(complete_reward_distribution_call_index.clone())); + extrinsic_sender.send(complete_reward_distribution_call).map_err(|_| { + Error::Other("Failed to send complete_reward_distribution_call extrinsic".into()) + })?; + + Ok(()) + } +} + +fn decode_storage_key(raw_key: Vec) -> Option> { + let hex_key = String::decode(&mut raw_key.as_slice()).unwrap_or_default(); + decode_hex(hex_key).ok() } -impl HandleParentchainEvents - for ParentchainEventHandler +impl HandleParentchainEvents + for ParentchainEventHandler where Executor: IndirectExecutor, - MetricsApi: EnclaveMetricsOCallApi, + OCallApi: EnclaveOnChainOCallApi + EnclaveMetricsOCallApi, + HS: HandleState, + NMR: AccessNodeMetadata, + NMR::MetadataType: NodeMetadataTrait, { fn handle_events( &self, executor: &Executor, events: impl FilterEvents, + block_header: impl Header, ) -> Result { let mut handled_events: Vec = Vec::new(); let mut successful_assertion_ids: Vec = Vec::new(); @@ -349,6 +504,24 @@ where }); } + if let Ok(events) = events.get_reward_distribution_started_events() { + println!("Handling RewardDistributionStarted events"); + events + .iter() + .try_for_each(|event| { + let event_hash = hash_of(&event); + let result = self.update_staking_scores( + executor, + block_header.clone(), + event.round_index, + ); + handled_events.push(event_hash); + + result + }) + .map_err(|_| ParentchainEventProcessingError::RewardDistributionStartedFailure)?; + } + Ok((handled_events, successful_assertion_ids, failed_assertion_ids)) } } diff --git a/tee-worker/app-libs/parentchain-interface/src/target_a/event_filter.rs b/tee-worker/app-libs/parentchain-interface/src/target_a/event_filter.rs index 2490b2e1d9..8209b16a18 100644 --- a/tee-worker/app-libs/parentchain-interface/src/target_a/event_filter.rs +++ b/tee-worker/app-libs/parentchain-interface/src/target_a/event_filter.rs @@ -105,4 +105,10 @@ impl FilterEvents for FilterableEvents { ) -> Result, Self::Error> { Ok(Vec::new()) } + + fn get_reward_distribution_started_events( + &self, + ) -> Result, Self::Error> { + Ok(Vec::new()) + } } diff --git a/tee-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs b/tee-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs index af091e98f8..a73312c63e 100644 --- a/tee-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs +++ b/tee-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs @@ -22,6 +22,7 @@ use itc_parentchain_indirect_calls_executor::error::Error; use itp_stf_primitives::traits::IndirectExecutor; use itp_types::parentchain::{FilterEvents, HandleParentchainEvents, ProcessedEventsArtifacts}; use log::*; +use sp_runtime::traits::Header; use sp_std::vec::Vec; pub struct ParentchainEventHandler {} @@ -35,6 +36,7 @@ where &self, _executor: &Executor, _events: impl FilterEvents, + _block_header: impl Header, ) -> Result { debug!("not handling any events for target a"); Ok((Vec::new(), Vec::new(), Vec::new())) diff --git a/tee-worker/app-libs/parentchain-interface/src/target_b/event_filter.rs b/tee-worker/app-libs/parentchain-interface/src/target_b/event_filter.rs index 2490b2e1d9..8209b16a18 100644 --- a/tee-worker/app-libs/parentchain-interface/src/target_b/event_filter.rs +++ b/tee-worker/app-libs/parentchain-interface/src/target_b/event_filter.rs @@ -105,4 +105,10 @@ impl FilterEvents for FilterableEvents { ) -> Result, Self::Error> { Ok(Vec::new()) } + + fn get_reward_distribution_started_events( + &self, + ) -> Result, Self::Error> { + Ok(Vec::new()) + } } diff --git a/tee-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs b/tee-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs index 56151a9ccc..ce279228bf 100644 --- a/tee-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs +++ b/tee-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs @@ -22,6 +22,7 @@ use itc_parentchain_indirect_calls_executor::error::Error; use itp_stf_primitives::traits::IndirectExecutor; use itp_types::parentchain::{FilterEvents, HandleParentchainEvents, ProcessedEventsArtifacts}; use log::*; +use sp_runtime::traits::Header; use sp_std::vec::Vec; pub struct ParentchainEventHandler {} @@ -35,6 +36,7 @@ where &self, _executor: &Executor, _events: impl FilterEvents, + _block_header: impl Header, ) -> Result { debug!("not handling any events for target B"); Ok((Vec::new(), Vec::new(), Vec::new())) diff --git a/tee-worker/core-primitives/extrinsics-factory/src/lib.rs b/tee-worker/core-primitives/extrinsics-factory/src/lib.rs index ab58d65853..f869917b27 100644 --- a/tee-worker/core-primitives/extrinsics-factory/src/lib.rs +++ b/tee-worker/core-primitives/extrinsics-factory/src/lib.rs @@ -35,7 +35,7 @@ use itp_node_api::{ api_client::{ ExtrinsicParams, ParentchainAdditionalParams, ParentchainExtrinsicParams, SignExtrinsic, }, - metadata::{provider::AccessNodeMetadata, NodeMetadata}, + metadata::{provider::AccessNodeMetadata, NodeMetadata, NodeMetadataProvider}, }; use itp_nonce_cache::{MutateNonce, Nonce}; use itp_types::{parentchain::AccountId, OpaqueCall}; diff --git a/tee-worker/core-primitives/node-api/metadata/src/lib.rs b/tee-worker/core-primitives/node-api/metadata/src/lib.rs index 1705582b90..5625e77ed1 100644 --- a/tee-worker/core-primitives/node-api/metadata/src/lib.rs +++ b/tee-worker/core-primitives/node-api/metadata/src/lib.rs @@ -22,9 +22,10 @@ use crate::{ error::Result, pallet_balances::BalancesCallIndexes, pallet_evm_assertion::EvmAssertionsCallIndexes, pallet_imp::IMPCallIndexes, - pallet_proxy::ProxyCallIndexes, pallet_system::SystemConstants, - pallet_teebag::TeebagCallIndexes, pallet_timestamp::TimestampCallIndexes, - pallet_utility::UtilityCallIndexes, pallet_vcmp::VCMPCallIndexes, + pallet_proxy::ProxyCallIndexes, pallet_score_staking::ScoreStakingCallIndexes, + pallet_system::SystemConstants, pallet_teebag::TeebagCallIndexes, + pallet_timestamp::TimestampCallIndexes, pallet_utility::UtilityCallIndexes, + pallet_vcmp::VCMPCallIndexes, }; use codec::{Decode, Encode}; use sp_core::storage::StorageKey; @@ -37,6 +38,7 @@ pub mod pallet_balances; pub mod pallet_evm_assertion; pub mod pallet_imp; pub mod pallet_proxy; +pub mod pallet_score_staking; pub mod pallet_system; pub mod pallet_teebag; pub mod pallet_utility; @@ -48,6 +50,10 @@ pub mod pallet_timestamp; #[cfg(feature = "mocks")] pub mod metadata_mocks; +pub trait NodeMetadataProvider { + fn get_metadata(&self) -> Option<&Metadata>; +} + pub trait NodeMetadataTrait: TeebagCallIndexes + IMPCallIndexes @@ -58,6 +64,8 @@ pub trait NodeMetadataTrait: + BalancesCallIndexes + TimestampCallIndexes + EvmAssertionsCallIndexes + + ScoreStakingCallIndexes + + NodeMetadataProvider { } @@ -70,7 +78,9 @@ impl< + ProxyCallIndexes + BalancesCallIndexes + TimestampCallIndexes - + EvmAssertionsCallIndexes, + + EvmAssertionsCallIndexes + + ScoreStakingCallIndexes + + NodeMetadataProvider, > NodeMetadataTrait for T { } @@ -103,10 +113,6 @@ impl NodeMetadata { } } - pub fn get_metadata(&self) -> Option<&Metadata> { - self.node_metadata.as_ref() - } - /// Return the substrate chain runtime version. pub fn get_runtime_version(&self) -> u32 { self.runtime_spec_version @@ -181,3 +187,9 @@ impl NodeMetadata { } } } + +impl NodeMetadataProvider for NodeMetadata { + fn get_metadata(&self) -> Option<&Metadata> { + self.node_metadata.as_ref() + } +} diff --git a/tee-worker/core-primitives/node-api/metadata/src/metadata_mocks.rs b/tee-worker/core-primitives/node-api/metadata/src/metadata_mocks.rs index adf13c8cf8..a4461eb72a 100644 --- a/tee-worker/core-primitives/node-api/metadata/src/metadata_mocks.rs +++ b/tee-worker/core-primitives/node-api/metadata/src/metadata_mocks.rs @@ -18,9 +18,10 @@ use crate::{ error::Result, pallet_balances::BalancesCallIndexes, pallet_evm_assertion::EvmAssertionsCallIndexes, pallet_imp::IMPCallIndexes, - pallet_proxy::ProxyCallIndexes, pallet_system::SystemConstants, - pallet_teebag::TeebagCallIndexes, pallet_timestamp::TimestampCallIndexes, - pallet_utility::UtilityCallIndexes, pallet_vcmp::VCMPCallIndexes, runtime_call::RuntimeCall, + pallet_proxy::ProxyCallIndexes, pallet_score_staking::ScoreStakingCallIndexes, + pallet_system::SystemConstants, pallet_teebag::TeebagCallIndexes, + pallet_timestamp::TimestampCallIndexes, pallet_utility::UtilityCallIndexes, + pallet_vcmp::VCMPCallIndexes, runtime_call::RuntimeCall, NodeMetadataProvider, }; use codec::{Decode, Encode}; @@ -88,6 +89,11 @@ pub struct NodeMetadataMock { timestamp_set: u8, runtime_spec_version: u32, runtime_transaction_version: u32, + + //ScoreStaking + score_staking_module: u8, + update_token_staking_amount: u8, + complete_reward_distribution: u8, } impl NodeMetadataMock { @@ -143,6 +149,10 @@ impl NodeMetadataMock { timestamp_set: 0, runtime_spec_version: 25, runtime_transaction_version: 4, + + score_staking_module: 100u8, + update_token_staking_amount: 0u8, + complete_reward_distribution: 1u8, } } } @@ -177,6 +187,16 @@ impl TeebagCallIndexes for NodeMetadataMock { } } +impl ScoreStakingCallIndexes for NodeMetadataMock { + fn update_token_staking_amount_call_indexes(&self) -> Result<[u8; 2]> { + Ok([self.score_staking_module, self.update_token_staking_amount]) + } + + fn complete_reward_distribution_call_indexes(&self) -> Result<[u8; 2]> { + Ok([self.score_staking_module, self.complete_reward_distribution]) + } +} + impl IMPCallIndexes for NodeMetadataMock { fn link_identity_call_indexes(&self) -> Result<[u8; 2]> { Ok([self.imp_module, self.imp_link_identity]) @@ -310,3 +330,9 @@ impl EvmAssertionsCallIndexes for NodeMetadataMock { Ok([self.evm_assertions_module, self.evm_assertions_void_assertion]) } } + +impl NodeMetadataProvider for NodeMetadataMock { + fn get_metadata(&self) -> Option<&Metadata> { + None + } +} diff --git a/tee-worker/core-primitives/node-api/metadata/src/pallet_score_staking.rs b/tee-worker/core-primitives/node-api/metadata/src/pallet_score_staking.rs new file mode 100644 index 0000000000..9450e36c01 --- /dev/null +++ b/tee-worker/core-primitives/node-api/metadata/src/pallet_score_staking.rs @@ -0,0 +1,36 @@ +/* + Copyright 2021 Integritee AG and Supercomputing Systems AG + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ +use crate::{error::Result, NodeMetadata}; + +/// Pallet' name: +pub const SCORE_STAKING: &str = "ScoreStaking"; + +// we only list the extrinsics that we care +pub trait ScoreStakingCallIndexes { + fn update_token_staking_amount_call_indexes(&self) -> Result<[u8; 2]>; + + fn complete_reward_distribution_call_indexes(&self) -> Result<[u8; 2]>; +} + +impl ScoreStakingCallIndexes for NodeMetadata { + fn update_token_staking_amount_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(SCORE_STAKING, "update_token_staking_amount") + } + fn complete_reward_distribution_call_indexes(&self) -> Result<[u8; 2]> { + self.call_indexes(SCORE_STAKING, "complete_reward_distribution") + } +} diff --git a/tee-worker/core-primitives/storage/src/keys.rs b/tee-worker/core-primitives/storage/src/keys.rs index 43de4f667e..c4767097d7 100644 --- a/tee-worker/core-primitives/storage/src/keys.rs +++ b/tee-worker/core-primitives/storage/src/keys.rs @@ -17,6 +17,7 @@ use codec::Encode; use frame_metadata::v14::StorageHasher; +use sp_core::crypto::AccountId32 as AccountId; use sp_std::vec::Vec; pub fn storage_value_key(module_prefix: &str, storage_prefix: &str) -> Vec { @@ -69,3 +70,16 @@ fn key_hash(key: &K, hasher: &StorageHasher) -> Vec { StorageHasher::Twox64Concat => sp_core::twox_64(&encoded_key).to_vec(), } } + +/// Extracts the AccountId from a storage key +pub fn key_to_account_id(key: &Vec) -> Option { + if key.len() >= 32 { + let account_id_bytes = &key[key.len() - 32..]; + let mut account_id_32_bytes = [0; 32]; + account_id_32_bytes.copy_from_slice(account_id_bytes); + + Some(AccountId::new(account_id_32_bytes)) + } else { + None + } +} diff --git a/tee-worker/core-primitives/types/src/lib.rs b/tee-worker/core-primitives/types/src/lib.rs index a4d58a2969..35c31f1f18 100644 --- a/tee-worker/core-primitives/types/src/lib.rs +++ b/tee-worker/core-primitives/types/src/lib.rs @@ -29,8 +29,8 @@ pub mod storage; pub use itp_sgx_runtime_primitives::types::*; pub use litentry_primitives::{ - Assertion, AttestationType, DcapProvider, DecryptableRequest, Enclave, EnclaveFingerprint, - MrEnclave, SidechainBlockNumber, WorkerType, + Assertion, AttestationType, DcapProvider, DecryptableRequest, Delegator, Enclave, + EnclaveFingerprint, MrEnclave, SidechainBlockNumber, WorkerType, }; pub use sp_core::{crypto::AccountId32 as AccountId, H256}; diff --git a/tee-worker/core-primitives/types/src/parentchain/events.rs b/tee-worker/core-primitives/types/src/parentchain/events.rs index f6b40d1339..3cce6e2e10 100644 --- a/tee-worker/core-primitives/types/src/parentchain/events.rs +++ b/tee-worker/core-primitives/types/src/parentchain/events.rs @@ -244,3 +244,28 @@ impl StaticEvent for AssertionCreated { const PALLET: &'static str = "EvmAssertions"; const EVENT: &'static str = "AssertionCreated"; } + +#[derive(Encode, Decode, Debug)] +pub struct RewardDistributionStarted { + pub total: Balance, + pub distributed: Balance, + pub round_index: u32, +} + +impl core::fmt::Display for RewardDistributionStarted { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + let message = format!( + "{:?} :: total: {}, distributed: {}, round_index: {}", + RewardDistributionStarted::EVENT, + self.total, + self.distributed, + self.round_index + ); + write!(f, "{}", message) + } +} + +impl StaticEvent for RewardDistributionStarted { + const PALLET: &'static str = "ScoreStaking"; + const EVENT: &'static str = "RewardDistributionStarted"; +} diff --git a/tee-worker/core-primitives/types/src/parentchain/mod.rs b/tee-worker/core-primitives/types/src/parentchain/mod.rs index 723127eafa..34bd9f24fa 100644 --- a/tee-worker/core-primitives/types/src/parentchain/mod.rs +++ b/tee-worker/core-primitives/types/src/parentchain/mod.rs @@ -23,13 +23,17 @@ use codec::{Decode, Encode}; use core::fmt::Debug; use events::{ ActivateIdentityRequested, DeactivateIdentityRequested, EnclaveUnauthorized, - LinkIdentityRequested, OpaqueTaskPosted, VCRequested, + LinkIdentityRequested, OpaqueTaskPosted, RewardDistributionStarted, VCRequested, }; use itp_stf_primitives::traits::{IndirectExecutor, TrustedCallVerification}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; use sp_core::{bounded::alloc, H160, H256}; -use sp_runtime::{generic::Header as HeaderG, traits::BlakeTwo256, MultiAddress, MultiSignature}; +use sp_runtime::{ + generic::Header as HeaderG, + traits::{BlakeTwo256, Header as HeaderT}, + MultiAddress, MultiSignature, +}; use self::events::ParentchainBlockProcessed; @@ -116,6 +120,10 @@ pub trait FilterEvents { fn get_parentchain_block_proccessed_events( &self, ) -> Result, Self::Error>; + + fn get_reward_distribution_started_events( + &self, + ) -> Result, Self::Error>; } #[derive(Debug)] @@ -135,6 +143,7 @@ where &self, executor: &Executor, events: impl FilterEvents, + block_header: impl HeaderT, ) -> Result; } @@ -149,6 +158,7 @@ pub enum ParentchainEventProcessingError { OpaqueTaskPostedFailure, AssertionCreatedFailure, ParentchainBlockProcessedFailure, + RewardDistributionStartedFailure, } impl core::fmt::Display for ParentchainEventProcessingError { @@ -172,6 +182,8 @@ impl core::fmt::Display for ParentchainEventProcessingError { "Parentchain Event Processing Error: AssertionCreatedFailure", ParentchainEventProcessingError::ParentchainBlockProcessedFailure => "Parentchain Event Processing Error: ParentchainBlockProcessedFailure", + ParentchainEventProcessingError::RewardDistributionStartedFailure => + "Parentchain Event Processing Error: RewardDistributionStartedFailure", }; write!(f, "{}", message) } diff --git a/tee-worker/core/parentchain/indirect-calls-executor/src/executor.rs b/tee-worker/core/parentchain/indirect-calls-executor/src/executor.rs index 61ced37b8a..14815c880a 100644 --- a/tee-worker/core/parentchain/indirect-calls-executor/src/executor.rs +++ b/tee-worker/core/parentchain/indirect-calls-executor/src/executor.rs @@ -167,8 +167,9 @@ impl< })? .ok_or_else(|| Error::Other("Could not create events from metadata".into()))?; - let (processed_events, successful_assertion_ids, failed_assertion_ids) = - self.parentchain_event_handler.handle_events(self, events)?; + let (processed_events, successful_assertion_ids, failed_assertion_ids) = self + .parentchain_event_handler + .handle_events(self, events, block.header().clone())?; let mut calls: Vec = Vec::new(); if !successful_assertion_ids.is_empty() { calls.extend(self.create_assertion_stored_call(successful_assertion_ids)?); diff --git a/tee-worker/core/parentchain/indirect-calls-executor/src/mock.rs b/tee-worker/core/parentchain/indirect-calls-executor/src/mock.rs index bc63f95317..ad621adef6 100644 --- a/tee-worker/core/parentchain/indirect-calls-executor/src/mock.rs +++ b/tee-worker/core/parentchain/indirect-calls-executor/src/mock.rs @@ -12,6 +12,7 @@ use itp_types::{ RsaRequest, H256, }; use sp_core::H160; +use sp_runtime::traits::Header; use std::vec::Vec; pub struct TestEventCreator; @@ -70,6 +71,12 @@ impl FilterEvents for MockEvents { ) -> Result, Self::Error> { Ok(Vec::new()) } + + fn get_reward_distribution_started_events( + &self, + ) -> Result, Self::Error> { + Ok(Vec::new()) + } } pub struct MockParentchainEventHandler {} @@ -83,6 +90,7 @@ where &self, _: &Executor, _: impl FilterEvents, + _: impl Header, ) -> Result { Ok(( Vec::from([H256::default()]), diff --git a/tee-worker/enclave-runtime/Cargo.lock b/tee-worker/enclave-runtime/Cargo.lock index 3cb495b83b..836b581de0 100644 --- a/tee-worker/enclave-runtime/Cargo.lock +++ b/tee-worker/enclave-runtime/Cargo.lock @@ -1966,6 +1966,7 @@ dependencies = [ name = "ita-parentchain-interface" version = "0.1.0" dependencies = [ + "frame-support", "ita-sgx-runtime", "ita-stf", "itc-parentchain-indirect-calls-executor", @@ -1973,12 +1974,18 @@ dependencies = [ "itp-enclave-metrics", "itp-node-api", "itp-ocall-api", + "itp-sgx-externalities", "itp-stf-primitives", + "itp-stf-state-handler", + "itp-storage", "itp-types", "lc-dynamic-assertion", "lc-evm-dynamic-assertions", + "lc-parachain-extrinsic-task-sender", + "litentry-hex-utils 0.1.0", "litentry-primitives", "log", + "pallet-identity-management-tee", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -3380,7 +3387,9 @@ dependencies = [ "core-primitives", "hex", "itp-sgx-crypto", + "itp-utils", "log", + "pallet-parachain-staking", "pallet-teebag", "parity-scale-codec", "rand 0.7.3", diff --git a/tee-worker/enclave-runtime/src/initialization/global_components.rs b/tee-worker/enclave-runtime/src/initialization/global_components.rs index 5255d5303e..939d69fe18 100644 --- a/tee-worker/enclave-runtime/src/initialization/global_components.rs +++ b/tee-worker/enclave-runtime/src/initialization/global_components.rs @@ -177,7 +177,11 @@ pub type IntegriteeParentchainIndirectCallsExecutor = IndirectCallsExecutor< EnclaveTopPoolAuthor, EnclaveNodeMetadataRepository, EventCreator, - integritee::ParentchainEventHandler, + integritee::ParentchainEventHandler< + EnclaveOCallApi, + EnclaveStateHandler, + EnclaveNodeMetadataRepository, + >, EnclaveTrustedCallSigned, EnclaveGetter, >; diff --git a/tee-worker/enclave-runtime/src/initialization/parentchain/common.rs b/tee-worker/enclave-runtime/src/initialization/parentchain/common.rs index 52b345d75a..40fa90d6c7 100644 --- a/tee-worker/enclave-runtime/src/initialization/parentchain/common.rs +++ b/tee-worker/enclave-runtime/src/initialization/parentchain/common.rs @@ -69,10 +69,13 @@ pub(crate) fn create_integritee_parentchain_block_importer( let shielding_key_repository = GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT.get()?; let ocall_api = GLOBAL_OCALL_API_COMPONENT.get()?; let repository = GLOBAL_ASSERTION_REPOSITORY.get()?; + let state_handler = GLOBAL_STATE_HANDLER_COMPONENT.get()?; let parentchain_event_handler = LitentryParentchainEventHandler { assertion_repository: repository, - metrics_api: ocall_api.clone(), + ocall_api: ocall_api.clone(), + state_handler, + node_metadata_repository: node_metadata_repository.clone(), }; let stf_enclave_signer = Arc::new(EnclaveStfEnclaveSigner::new( diff --git a/tee-worker/litentry/primitives/Cargo.toml b/tee-worker/litentry/primitives/Cargo.toml index 9f3a4e6cfa..adbc8da826 100644 --- a/tee-worker/litentry/primitives/Cargo.toml +++ b/tee-worker/litentry/primitives/Cargo.toml @@ -25,6 +25,8 @@ sgx_tstd = { git = "https://github.com/apache/teaclave-sgx-sdk.git", branch = "m # internal dependencies itp-sgx-crypto = { path = "../../core-primitives/sgx/crypto", default-features = false } +itp-utils = { path = "../../core-primitives/utils", default-features = false } +pallet-parachain-staking = { git = "https://github.com/litentry/litentry-parachain", branch = "release-v0.9.19", default-features = false } pallet-teebag = { git = "https://github.com/litentry/litentry-parachain", branch = "release-v0.9.19", default-features = false } parentchain-primitives = { package = "core-primitives", git = "https://github.com/litentry/litentry-parachain", branch = "release-v0.9.19", default-features = false } diff --git a/tee-worker/litentry/primitives/src/lib.rs b/tee-worker/litentry/primitives/src/lib.rs index da8d5e8e94..1f05bb0afc 100644 --- a/tee-worker/litentry/primitives/src/lib.rs +++ b/tee-worker/litentry/primitives/src/lib.rs @@ -42,6 +42,7 @@ use bitcoin::sign_message::{signed_msg_hash, MessageSignature}; use codec::{Decode, Encode, MaxEncodedLen}; use itp_sgx_crypto::ShieldingCryptoDecrypt; use log::error; +pub use pallet_parachain_staking::Delegator; pub use pallet_teebag::{ decl_rsa_request, extract_tcb_info_from_raw_dcap_quote, AttestationType, DcapProvider, Enclave, EnclaveFingerprint, MrEnclave, ShardIdentifier, SidechainBlockNumber, WorkerMode, WorkerType,