Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize parachain events handling #3216

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tee-worker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ use sp_runtime::{
MultiAddress, MultiSignature,
};

use self::events::ParentchainBlockProcessed;

pub type StorageProof = Vec<Vec<u8>>;

// Basic Types.
Expand Down Expand Up @@ -114,10 +112,6 @@ pub trait FilterEvents {

fn get_assertion_created_events(&self) -> Result<Vec<AssertionCreated>, Self::Error>;

fn get_parentchain_block_proccessed_events(
&self,
) -> Result<Vec<ParentchainBlockProcessed>, Self::Error>;

fn get_enclave_added_events(&self) -> Result<Vec<EnclaveAdded>, Self::Error>;

fn get_enclave_removed_events(&self) -> Result<Vec<EnclaveRemoved>, Self::Error>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,56 @@
*/
//! Various way to filter Parentchain events

use itc_parentchain_indirect_calls_executor::event_filter::ToEvents;
use itp_api_client_types::Events;

use itp_api_client_types::{EventDetails, Events};
use itp_node_api::api_client::StaticEvent;
use itp_types::{
parentchain::{events::*, FilterEvents},
H256,
};
use std::vec::Vec;
use std::{vec, vec::Vec};

#[derive(Clone)]
pub struct FilterableEvents(pub Events<H256>);
pub struct FilterableEvents {
events: Vec<EventDetails<H256>>,
}

impl FilterableEvents {
pub fn new(events: Events<H256>) -> Self {
let mut interesting_events = vec![];
events.iter().flatten().for_each(|ev| {
// lets keep only events worker is interested in
if ev.pallet_name() == LinkIdentityRequested::PALLET
&& ev.variant_name() == LinkIdentityRequested::EVENT
|| ev.pallet_name() == VCRequested::PALLET
&& ev.variant_name() == VCRequested::EVENT
|| ev.pallet_name() == DeactivateIdentityRequested::PALLET
&& ev.variant_name() == DeactivateIdentityRequested::EVENT
|| ev.pallet_name() == ActivateIdentityRequested::PALLET
&& ev.variant_name() == ActivateIdentityRequested::EVENT
|| ev.pallet_name() == EnclaveUnauthorized::PALLET
&& ev.variant_name() == EnclaveUnauthorized::EVENT
|| ev.pallet_name() == OpaqueTaskPosted::PALLET
&& ev.variant_name() == OpaqueTaskPosted::EVENT
|| ev.pallet_name() == AssertionCreated::PALLET
&& ev.variant_name() == AssertionCreated::EVENT
|| ev.pallet_name() == EnclaveAdded::PALLET
&& ev.variant_name() == EnclaveAdded::EVENT
|| ev.pallet_name() == EnclaveRemoved::PALLET
&& ev.variant_name() == EnclaveRemoved::EVENT
|| ev.pallet_name() == AccountStoreUpdated::PALLET
&& ev.variant_name() == AccountStoreUpdated::EVENT
{
interesting_events.push(ev)
}
});

Self { events: interesting_events }
}

fn filter<T: StaticEvent, E>(&self) -> Result<Vec<T>, E> {
Ok(self
.to_events()
.events
.iter()
.flatten()
.filter_map(|ev| match ev.as_event::<T>() {
Ok(maybe_event) => maybe_event,
Err(e) => {
Expand All @@ -46,16 +77,9 @@ impl FilterableEvents {
}
}

// todo: improve: https://github.com/integritee-network/worker/pull/1378#discussion_r1393933766
impl ToEvents<Events<H256>> for FilterableEvents {
fn to_events(&self) -> &Events<H256> {
&self.0
}
}

impl From<Events<H256>> for FilterableEvents {
fn from(ev: Events<H256>) -> Self {
Self(ev)
Self::new(ev)
}
}

Expand Down Expand Up @@ -92,12 +116,6 @@ impl FilterEvents for FilterableEvents {
self.filter()
}

fn get_parentchain_block_proccessed_events(
&self,
) -> Result<Vec<ParentchainBlockProcessed>, Self::Error> {
self.filter()
}

fn get_enclave_added_events(&self) -> Result<Vec<EnclaveAdded>, Self::Error> {
self.filter()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,6 @@ where
.map_err(|_| ParentchainEventProcessingError::AssertionCreatedFailure)?;
}

if let Ok(events) = events.get_parentchain_block_proccessed_events() {
debug!("Handling ParentchainBlockProcessed events");
events.iter().for_each(|event| {
debug!("found ParentchainBlockProcessed event: {:?}", event);
// This is for monitoring purposes
handled_events.push(hash_of(&event));
});
}

if let Ok(events) = events.get_account_store_updated_events() {
debug!("Handling AccountStoreUpdated events");
events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ impl FilterEvents for FilterableEvents {
self.filter()
}

fn get_parentchain_block_proccessed_events(
&self,
) -> Result<Vec<ParentchainBlockProcessed>, Self::Error> {
Ok(Vec::new())
}

fn get_enclave_added_events(&self) -> Result<Vec<EnclaveAdded>, Self::Error> {
self.filter()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ impl FilterEvents for FilterableEvents {
self.filter()
}

fn get_parentchain_block_proccessed_events(
&self,
) -> Result<Vec<ParentchainBlockProcessed>, Self::Error> {
Ok(Vec::new())
}

fn get_enclave_added_events(&self) -> Result<Vec<EnclaveAdded>, Self::Error> {
self.filter()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ impl FilterEvents for MockEvents {
Ok(Vec::new())
}

fn get_parentchain_block_proccessed_events(
&self,
) -> Result<Vec<ParentchainBlockProcessed>, Self::Error> {
Ok(Vec::new())
}

fn get_enclave_added_events(&self) -> Result<Vec<EnclaveAdded>, Self::Error> {
Ok(Vec::new())
}
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/identity/enclave-runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading