From ad8b1dbc4971925e8a802c80161bc0d9ad4fa36a Mon Sep 17 00:00:00 2001 From: Edyta Pawlak Date: Mon, 30 Jun 2025 13:40:00 +0200 Subject: [PATCH 1/2] refactor: add database trait in teliox --- components/controller/src/known_events.rs | 3 +- components/watcher/src/watcher/mod.rs | 4 +- components/witness/src/witness.rs | 4 +- support/teliox/src/database/mod.rs | 65 ++++--------------- support/teliox/src/database/sled_db.rs | 63 ++++++++++++++++++ .../src/processor/escrow/missing_issuer.rs | 29 +++++---- .../src/processor/escrow/missing_registry.rs | 27 ++++---- support/teliox/src/processor/escrow/mod.rs | 13 ++-- .../src/processor/escrow/out_of_order.rs | 28 ++++---- support/teliox/src/processor/mod.rs | 11 ++-- support/teliox/src/processor/storage.rs | 8 +-- support/teliox/src/processor/validator.rs | 13 ++-- support/teliox/src/tel/mod.rs | 26 ++++---- 13 files changed, 165 insertions(+), 129 deletions(-) create mode 100644 support/teliox/src/database/sled_db.rs diff --git a/components/controller/src/known_events.rs b/components/controller/src/known_events.rs index 0f25893b..c9df39f8 100644 --- a/components/controller/src/known_events.rs +++ b/components/controller/src/known_events.rs @@ -29,6 +29,7 @@ use keri_core::{ query::reply_event::{ReplyEvent, ReplyRoute, SignedReply}, }; use teliox::database::escrow::EscrowDb; +use teliox::database::sled_db::SledEventDatabase; use teliox::database::EventDatabase; use teliox::processor::escrow::default_escrow_bus as tel_escrow_bus; use teliox::processor::storage::TelEventStorage; @@ -50,7 +51,7 @@ pub struct KnownEvents { pub storage: Arc>, pub oobi_manager: OobiManager, pub partially_witnessed_escrow: Arc, - pub tel: Arc, + pub tel: Arc>, } impl KnownEvents { diff --git a/components/watcher/src/watcher/mod.rs b/components/watcher/src/watcher/mod.rs index 0cd4eaf2..3d4ef75b 100644 --- a/components/watcher/src/watcher/mod.rs +++ b/components/watcher/src/watcher/mod.rs @@ -19,7 +19,7 @@ use keri_core::{ query::reply_event::{ReplyRoute, SignedReply}, }; use tel_providing::RegistryMapping; -use teliox::event::parse_tel_query_stream; +use teliox::{database::sled_db::SledEventDatabase, event::parse_tel_query_stream}; use teliox::{ event::verifiable_event::VerifiableEvent, processor::{validator::TelEventValidator, TelReplyType}, @@ -148,7 +148,7 @@ impl Watcher { teliox::event::Event::Vc(_) => todo!(), }; let seal = &ev.seal; - TelEventValidator::check_kel_event( + TelEventValidator::::check_kel_event( self.watcher_data.event_storage.clone(), seal, &issuer_id, diff --git a/components/witness/src/witness.rs b/components/witness/src/witness.rs index d4435eb7..7ceea958 100644 --- a/components/witness/src/witness.rs +++ b/components/witness/src/witness.rs @@ -35,7 +35,7 @@ use keri_core::{ }; use serde::{Deserialize, Serialize}; use teliox::{ - database::escrow::EscrowDb, + database::{escrow::EscrowDb, sled_db::SledEventDatabase}, event::{parse_tel_query_stream, verifiable_event::VerifiableEvent}, processor::{escrow::default_escrow_bus, storage::TelEventStorage, TelReplyType}, tel::Tel, @@ -145,7 +145,7 @@ pub struct Witness { pub oobi_manager: OobiManager, pub signer: Arc, pub receipt_generator: Arc, - pub tel: Arc, + pub tel: Arc>, } impl Witness { diff --git a/support/teliox/src/database/mod.rs b/support/teliox/src/database/mod.rs index 2331c851..6a10d9e2 100644 --- a/support/teliox/src/database/mod.rs +++ b/support/teliox/src/database/mod.rs @@ -1,68 +1,29 @@ use crate::{error::Error, event::verifiable_event::VerifiableEvent}; use keri_core::prefix::IdentifierPrefix; -use sled_tables::{ - self, - tables::{SledEventTree, SledEventTreeVec}, -}; -use std::{path::Path, sync::Arc}; +use std::path::Path; pub mod escrow; +pub mod sled_db; -pub struct EventDatabase { - db: Arc, - // "iids" tree - identifiers: SledEventTree, - // "tels" tree - tel_events: SledEventTreeVec, - // "man" tree - management_events: SledEventTreeVec, -} - -impl EventDatabase { - pub fn new(path: impl AsRef) -> Result { - let db = Arc::new(sled::open(path)?); - Ok(Self { - db: db.clone(), - identifiers: SledEventTree::new(db.open_tree(b"iids")?), - tel_events: SledEventTreeVec::new(db.open_tree(b"tels")?), - management_events: SledEventTreeVec::new(db.open_tree(b"mans")?), - }) - } +pub trait EventDatabase { + fn new(path: impl AsRef) -> Result + where + Self: Sized; - pub fn add_new_event( - &self, - event: VerifiableEvent, - id: &IdentifierPrefix, - ) -> Result<(), Error> { - self.tel_events - .push(self.identifiers.designated_key(id), event)?; - self.db.flush()?; - Ok(()) - } + fn add_new_event(&self, event: VerifiableEvent, id: &IdentifierPrefix) -> Result<(), Error>; - pub fn get_events( + fn get_events( &self, id: &IdentifierPrefix, - ) -> Option> { - self.tel_events - .iter_values(self.identifiers.designated_key(id)) - } + ) -> Option>; - pub fn add_new_management_event( + fn add_new_management_event( &self, event: VerifiableEvent, id: &IdentifierPrefix, - ) -> Result<(), Error> { - self.management_events - .push(self.identifiers.designated_key(id), event)?; - self.db.flush()?; - Ok(()) - } + ) -> Result<(), Error>; - pub fn get_management_events( + fn get_management_events( &self, id: &IdentifierPrefix, - ) -> Option> { - self.management_events - .iter_values(self.identifiers.designated_key(id)) - } + ) -> Option>; } diff --git a/support/teliox/src/database/sled_db.rs b/support/teliox/src/database/sled_db.rs new file mode 100644 index 00000000..03fe157a --- /dev/null +++ b/support/teliox/src/database/sled_db.rs @@ -0,0 +1,63 @@ +use crate::{database::EventDatabase, error::Error, event::verifiable_event::VerifiableEvent}; +use keri_core::prefix::IdentifierPrefix; +use sled_tables::{ + self, + tables::{SledEventTree, SledEventTreeVec}, +}; +use std::{path::Path, sync::Arc}; + +pub struct SledEventDatabase { + db: Arc, + // "iids" tree + identifiers: SledEventTree, + // "tels" tree + tel_events: SledEventTreeVec, + // "man" tree + management_events: SledEventTreeVec, +} + +impl EventDatabase for SledEventDatabase { + fn new(path: impl AsRef) -> Result { + let db = Arc::new(sled::open(path)?); + Ok(Self { + db: db.clone(), + identifiers: SledEventTree::new(db.open_tree(b"iids")?), + tel_events: SledEventTreeVec::new(db.open_tree(b"tels")?), + management_events: SledEventTreeVec::new(db.open_tree(b"mans")?), + }) + } + + fn add_new_event(&self, event: VerifiableEvent, id: &IdentifierPrefix) -> Result<(), Error> { + self.tel_events + .push(self.identifiers.designated_key(id), event)?; + self.db.flush()?; + Ok(()) + } + + fn get_events( + &self, + id: &IdentifierPrefix, + ) -> Option> { + self.tel_events + .iter_values(self.identifiers.designated_key(id)) + } + + fn add_new_management_event( + &self, + event: VerifiableEvent, + id: &IdentifierPrefix, + ) -> Result<(), Error> { + self.management_events + .push(self.identifiers.designated_key(id), event)?; + self.db.flush()?; + Ok(()) + } + + fn get_management_events( + &self, + id: &IdentifierPrefix, + ) -> Option> { + self.management_events + .iter_values(self.identifiers.designated_key(id)) + } +} diff --git a/support/teliox/src/processor/escrow/missing_issuer.rs b/support/teliox/src/processor/escrow/missing_issuer.rs index 5a530d43..6e38582d 100644 --- a/support/teliox/src/processor/escrow/missing_issuer.rs +++ b/support/teliox/src/processor/escrow/missing_issuer.rs @@ -10,7 +10,10 @@ use keri_core::{ }; use crate::{ - database::escrow::{Escrow, EscrowDb}, + database::{ + escrow::{Escrow, EscrowDb}, + EventDatabase, + }, error::Error, event::{verifiable_event::VerifiableEvent, Event}, processor::{ @@ -20,16 +23,16 @@ use crate::{ }, }; -pub struct MissingIssuerEscrow { +pub struct MissingIssuerEscrow { kel_reference: Arc>, - tel_reference: Arc, + tel_reference: Arc>, publisher: TelNotificationBus, escrowed_missing_issuer: Escrow, } -impl MissingIssuerEscrow { +impl MissingIssuerEscrow { pub fn new( - db: Arc, + db: Arc>, escrow_db: Arc, duration: Duration, kel_reference: Arc>, @@ -45,7 +48,7 @@ impl MissingIssuerEscrow { } } } -impl Notifier for MissingIssuerEscrow { +impl Notifier for MissingIssuerEscrow { fn notify( &self, notification: &Notification, @@ -69,7 +72,7 @@ impl Notifier for MissingIssuerEscrow { } } -impl TelNotifier for MissingIssuerEscrow { +impl TelNotifier for MissingIssuerEscrow { fn notify( &self, notification: &TelNotification, @@ -88,15 +91,13 @@ impl TelNotifier for MissingIssuerEscrow { } } -impl MissingIssuerEscrow { +impl MissingIssuerEscrow { /// Reprocess escrowed events that need issuer event of given digest for acceptance. pub fn process_missing_issuer_escrow(&self, id: &IdentifierPrefix) -> Result<(), Error> { if let Some(esc) = self.escrowed_missing_issuer.get(id) { for event in esc { - let validator = TelEventValidator::new( - self.tel_reference.db.clone(), - self.kel_reference.clone(), - ); + let validator = + TelEventValidator::new(self.tel_reference.clone(), self.kel_reference.clone()); let result = match &event.event { Event::Management(man) => validator.validate_management(&man, &event.seal), Event::Vc(vc) => validator.validate_vc(&vc, &event.seal), @@ -150,7 +151,7 @@ mod tests { }; use crate::{ - database::{escrow::EscrowDb, EventDatabase}, + database::{escrow::EscrowDb, sled_db::SledEventDatabase, EventDatabase}, error::Error, event::{manager_event, verifiable_event::VerifiableEvent}, processor::{ @@ -184,7 +185,7 @@ mod tests { // Initiate tel and it's escrows let tel_root = Builder::new().prefix("test-db").tempdir().unwrap(); let tel_escrow_root = Builder::new().prefix("test-db").tempdir().unwrap(); - let tel_events_db = Arc::new(EventDatabase::new(&tel_root.path()).unwrap()); + let tel_events_db = Arc::new(SledEventDatabase::new(&tel_root.path()).unwrap()); let tel_escrow_db = Arc::new(EscrowDb::new(&tel_escrow_root.path()).unwrap()); diff --git a/support/teliox/src/processor/escrow/missing_registry.rs b/support/teliox/src/processor/escrow/missing_registry.rs index 41baa32f..562471e7 100644 --- a/support/teliox/src/processor/escrow/missing_registry.rs +++ b/support/teliox/src/processor/escrow/missing_registry.rs @@ -5,7 +5,10 @@ use keri_core::{ }; use crate::{ - database::escrow::{Escrow, EscrowDb}, + database::{ + escrow::{Escrow, EscrowDb}, + EventDatabase, + }, error::Error, event::verifiable_event::VerifiableEvent, processor::{ @@ -15,15 +18,15 @@ use crate::{ }, }; -pub struct MissingRegistryEscrow { - tel_reference: Arc, +pub struct MissingRegistryEscrow { + tel_reference: Arc>, kel_reference: Arc>, escrowed_missing_registry: Escrow, } -impl MissingRegistryEscrow { +impl MissingRegistryEscrow { pub fn new( - tel_reference: Arc, + tel_reference: Arc>, kel_reference: Arc>, escrow_db: Arc, duration: Duration, @@ -37,7 +40,7 @@ impl MissingRegistryEscrow { } } -impl TelNotifier for MissingRegistryEscrow { +impl TelNotifier for MissingRegistryEscrow { fn notify( &self, notification: &TelNotification, @@ -60,7 +63,7 @@ impl TelNotifier for MissingRegistryEscrow { } } -impl MissingRegistryEscrow { +impl MissingRegistryEscrow { pub fn process_missing_registry( &self, bus: &TelNotificationBus, @@ -68,10 +71,8 @@ impl MissingRegistryEscrow { ) -> Result<(), Error> { if let Some(esc) = self.escrowed_missing_registry.get(id) { for event in esc { - let validator = TelEventValidator::new( - self.tel_reference.db.clone(), - self.kel_reference.clone(), - ); + let validator = + TelEventValidator::new(self.tel_reference.clone(), self.kel_reference.clone()); match validator.validate(&event) { Ok(_) => { // remove from escrow @@ -114,7 +115,7 @@ mod tests { }; use crate::{ - database::{escrow::EscrowDb, EventDatabase}, + database::{escrow::EscrowDb, sled_db::SledEventDatabase, EventDatabase}, error::Error, event::verifiable_event::VerifiableEvent, processor::{ @@ -145,7 +146,7 @@ mod tests { // Initiate tel and it's escrows let tel_root = Builder::new().prefix("test-db").tempdir().unwrap(); let tel_escrow_root = Builder::new().prefix("test-db").tempdir().unwrap(); - let tel_events_db = Arc::new(EventDatabase::new(&tel_root.path()).unwrap()); + let tel_events_db = Arc::new(SledEventDatabase::new(&tel_root.path()).unwrap()); let tel_escrow_db = Arc::new(EscrowDb::new(&tel_escrow_root.path()).unwrap()); diff --git a/support/teliox/src/processor/escrow/mod.rs b/support/teliox/src/processor/escrow/mod.rs index 1e15adb1..edc7cfab 100644 --- a/support/teliox/src/processor/escrow/mod.rs +++ b/support/teliox/src/processor/escrow/mod.rs @@ -2,7 +2,10 @@ use std::{sync::Arc, time::Duration}; use keri_core::{database::redb::RedbDatabase, processor::event_storage::EventStorage}; -use crate::{database::escrow::EscrowDb, error::Error}; +use crate::{ + database::{escrow::EscrowDb, sled_db::SledEventDatabase}, + error::Error, +}; use self::{ missing_issuer::MissingIssuerEscrow, missing_registry::MissingRegistryEscrow, @@ -16,15 +19,15 @@ pub mod missing_registry; pub mod out_of_order; pub fn default_escrow_bus( - tel_storage: Arc, + tel_storage: Arc>, kel_storage: Arc>, tel_escrow_db: Arc, ) -> Result< ( TelNotificationBus, - Arc, - Arc, - Arc, + Arc>, + Arc>, + Arc>, ), Error, > { diff --git a/support/teliox/src/processor/escrow/out_of_order.rs b/support/teliox/src/processor/escrow/out_of_order.rs index 30437e58..823c5337 100644 --- a/support/teliox/src/processor/escrow/out_of_order.rs +++ b/support/teliox/src/processor/escrow/out_of_order.rs @@ -5,7 +5,10 @@ use keri_core::{ }; use crate::{ - database::escrow::{Escrow, EscrowDb}, + database::{ + escrow::{Escrow, EscrowDb}, + EventDatabase, + }, error::Error, event::verifiable_event::VerifiableEvent, processor::{ @@ -15,15 +18,15 @@ use crate::{ }, }; -pub struct OutOfOrderEscrow { - tel_reference: Arc, +pub struct OutOfOrderEscrow { + tel_reference: Arc>, kel_reference: Arc>, escrowed_out_of_order: Escrow, } -impl OutOfOrderEscrow { +impl OutOfOrderEscrow { pub fn new( - tel_reference: Arc, + tel_reference: Arc>, kel_reference: Arc>, escrow_db: Arc, duration: Duration, @@ -37,7 +40,7 @@ impl OutOfOrderEscrow { } } -impl TelNotifier for OutOfOrderEscrow { +impl TelNotifier for OutOfOrderEscrow { fn notify( &self, notification: &TelNotification, @@ -59,7 +62,7 @@ impl TelNotifier for OutOfOrderEscrow { } } -impl OutOfOrderEscrow { +impl OutOfOrderEscrow { pub fn process_out_of_order_events( &self, bus: &TelNotificationBus, @@ -67,10 +70,8 @@ impl OutOfOrderEscrow { ) -> Result<(), Error> { if let Some(esc) = self.escrowed_out_of_order.get(id) { for event in esc { - let validator = TelEventValidator::new( - self.tel_reference.db.clone(), - self.kel_reference.clone(), - ); + let validator = + TelEventValidator::new(self.tel_reference.clone(), self.kel_reference.clone()); match validator.validate(&event) { Ok(_) => { // remove from escrow @@ -109,7 +110,7 @@ mod tests { }; use crate::{ - database::{escrow::EscrowDb, EventDatabase}, + database::{escrow::EscrowDb, sled_db::SledEventDatabase, EventDatabase}, error::Error, event::verifiable_event::VerifiableEvent, processor::{ @@ -127,7 +128,6 @@ mod tests { // Setup issuer key event log. Without ixn events tel event's can't be validated. let keri_root = Builder::new().prefix("test-db").tempfile().unwrap(); let keri_db = Arc::new(RedbDatabase::new(keri_root.path()).unwrap()); - let escrow_root = Builder::new().prefix("test-db").tempdir().unwrap(); let keri_processor = BasicProcessor::new(keri_db.clone(), None); let keri_storage = Arc::new(EventStorage::new(keri_db.clone())); @@ -141,7 +141,7 @@ mod tests { // Initiate tel and it's escrows let tel_root = Builder::new().prefix("test-db").tempdir().unwrap(); let tel_escrow_root = Builder::new().prefix("test-db").tempdir().unwrap(); - let tel_events_db = Arc::new(EventDatabase::new(&tel_root.path()).unwrap()); + let tel_events_db = Arc::new(SledEventDatabase::new(&tel_root.path()).unwrap()); let tel_escrow_db = Arc::new(EscrowDb::new(&tel_escrow_root.path()).unwrap()); diff --git a/support/teliox/src/processor/mod.rs b/support/teliox/src/processor/mod.rs index b3184338..b669e876 100644 --- a/support/teliox/src/processor/mod.rs +++ b/support/teliox/src/processor/mod.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use keri_core::{database::redb::RedbDatabase, processor::event_storage::EventStorage}; use crate::{ + database::EventDatabase, error::Error, event::{verifiable_event::VerifiableEvent, Event}, query::SignedTelQuery, @@ -19,16 +20,16 @@ pub mod notification; pub mod storage; pub mod validator; -pub struct TelEventProcessor { +pub struct TelEventProcessor { kel_reference: Arc>, - pub tel_reference: Arc, + pub tel_reference: Arc>, pub publisher: TelNotificationBus, } -impl TelEventProcessor { +impl TelEventProcessor { pub fn new( kel_reference: Arc>, - tel_reference: Arc, + tel_reference: Arc>, tel_publisher: Option, ) -> Self { Self { @@ -50,7 +51,7 @@ impl TelEventProcessor { // Checks verifiable event and adds it to database. pub fn process(&self, event: VerifiableEvent) -> Result<(), Error> { let validator = - TelEventValidator::new(self.tel_reference.db.clone(), self.kel_reference.clone()); + TelEventValidator::new(self.tel_reference.clone(), self.kel_reference.clone()); match &event.event.clone() { Event::Management(ref man) => match validator.validate_management(man, &event.seal) { Ok(_) => { diff --git a/support/teliox/src/processor/storage.rs b/support/teliox/src/processor/storage.rs index 6aac269b..c087b829 100644 --- a/support/teliox/src/processor/storage.rs +++ b/support/teliox/src/processor/storage.rs @@ -12,11 +12,11 @@ use crate::{ use super::TelReplyType; -pub struct TelEventStorage { - pub db: Arc, +pub struct TelEventStorage { + pub db: Arc, } -impl TelEventStorage { - pub fn new(db: Arc) -> Self { +impl TelEventStorage { + pub fn new(db: Arc) -> Self { Self { db } } diff --git a/support/teliox/src/processor/validator.rs b/support/teliox/src/processor/validator.rs index df01d811..bfc7b456 100644 --- a/support/teliox/src/processor/validator.rs +++ b/support/teliox/src/processor/validator.rs @@ -22,15 +22,18 @@ use crate::{ use super::TelEventStorage; -pub struct TelEventValidator { +pub struct TelEventValidator { kel_reference: Arc>, - db: TelEventStorage, + db: Arc>, } -impl TelEventValidator { - pub fn new(db: Arc, kel_reference: Arc>) -> Self { +impl TelEventValidator { + pub fn new( + db: Arc>, + kel_reference: Arc>, + ) -> Self { Self { - db: TelEventStorage::new(db), + db: db.clone(), kel_reference, } } diff --git a/support/teliox/src/tel/mod.rs b/support/teliox/src/tel/mod.rs index 8f17313c..9b18eff9 100644 --- a/support/teliox/src/tel/mod.rs +++ b/support/teliox/src/tel/mod.rs @@ -1,10 +1,9 @@ use std::sync::{Arc, RwLock}; use crate::{ + database::EventDatabase, error::Error, - event::manager_event::Config, - event::verifiable_event::VerifiableEvent, - event::Event, + event::{manager_event::Config, verifiable_event::VerifiableEvent, Event}, processor::{ notification::{TelNotification, TelNotificationBus, TelNotificationKind, TelNotifier}, storage::TelEventStorage, @@ -44,14 +43,14 @@ impl TelNotifier for RecentlyAddedEvents { } /// Transaction Event Log -pub struct Tel { - pub processor: TelEventProcessor, +pub struct Tel { + pub processor: TelEventProcessor, pub recently_added_events: Arc, } -impl Tel { +impl Tel { pub fn new( - tel_reference: Arc, + tel_reference: Arc>, kel_reference: Arc>, publisher: Option, ) -> Self { @@ -175,15 +174,18 @@ impl Tel { .collect::>()) } - pub fn get_management_tel( - &self, - registry_id: &IdentifierPrefix, - ) -> Result>, Error> { + pub fn get_management_tel<'a>( + &'a self, + registry_id: &'a IdentifierPrefix, + ) -> Result + 'a>>, Error> { Ok(self .processor .tel_reference .db - .get_management_events(®istry_id)) + .get_management_events(registry_id) + .map(|iter| { + Box::new(iter) as Box + 'a> + })) } pub fn get_management_tel_state( From 531af267e73dd30828a449e0d916bf51bd3c6aef Mon Sep 17 00:00:00 2001 From: Edyta Pawlak Date: Mon, 30 Jun 2025 13:59:01 +0200 Subject: [PATCH 2/2] refactor: parameterize kel database in teliox --- components/controller/src/known_events.rs | 4 ++-- components/watcher/src/watcher/mod.rs | 9 ++------- components/witness/src/witness.rs | 2 +- support/teliox/src/database/mod.rs | 2 +- support/teliox/src/database/sled_db.rs | 4 ++-- .../src/processor/escrow/missing_issuer.rs | 14 +++++++------- .../src/processor/escrow/missing_registry.rs | 12 ++++++------ .../teliox/src/processor/escrow/out_of_order.rs | 12 ++++++------ support/teliox/src/processor/mod.rs | 6 +++--- support/teliox/src/processor/storage.rs | 6 +++--- support/teliox/src/processor/validator.rs | 17 +++++++---------- support/teliox/src/tel/mod.rs | 6 +++--- 12 files changed, 43 insertions(+), 51 deletions(-) diff --git a/components/controller/src/known_events.rs b/components/controller/src/known_events.rs index c9df39f8..66fb1022 100644 --- a/components/controller/src/known_events.rs +++ b/components/controller/src/known_events.rs @@ -30,7 +30,7 @@ use keri_core::{ }; use teliox::database::escrow::EscrowDb; use teliox::database::sled_db::SledEventDatabase; -use teliox::database::EventDatabase; +use teliox::database::TelEventDatabase; use teliox::processor::escrow::default_escrow_bus as tel_escrow_bus; use teliox::processor::storage::TelEventStorage; use teliox::tel::Tel; @@ -82,7 +82,7 @@ impl KnownEvents { let mut path = db_path.clone(); path.push("tel"); path.push("events"); - Arc::new(EventDatabase::new(&path)?) + Arc::new(TelEventDatabase::new(&path)?) }; let tel_escrow_db = { diff --git a/components/watcher/src/watcher/mod.rs b/components/watcher/src/watcher/mod.rs index 3d4ef75b..2c491f87 100644 --- a/components/watcher/src/watcher/mod.rs +++ b/components/watcher/src/watcher/mod.rs @@ -11,12 +11,7 @@ use keri_core::{ actor::{ error::ActorError, parse_event_stream, parse_notice_stream, parse_query_stream, parse_reply_stream, possible_response::PossibleResponse, - }, - error::Error, - event_message::signed_event_message::Message, - oobi::{error::OobiError, EndRole, LocationScheme}, - prefix::{BasicPrefix, IdentifierPrefix}, - query::reply_event::{ReplyRoute, SignedReply}, + }, database::redb::RedbDatabase, error::Error, event_message::signed_event_message::Message, oobi::{error::OobiError, EndRole, LocationScheme}, prefix::{BasicPrefix, IdentifierPrefix}, query::reply_event::{ReplyRoute, SignedReply} }; use tel_providing::RegistryMapping; use teliox::{database::sled_db::SledEventDatabase, event::parse_tel_query_stream}; @@ -148,7 +143,7 @@ impl Watcher { teliox::event::Event::Vc(_) => todo!(), }; let seal = &ev.seal; - TelEventValidator::::check_kel_event( + TelEventValidator::::check_kel_event( self.watcher_data.event_storage.clone(), seal, &issuer_id, diff --git a/components/witness/src/witness.rs b/components/witness/src/witness.rs index 7ceea958..f706377e 100644 --- a/components/witness/src/witness.rs +++ b/components/witness/src/witness.rs @@ -191,7 +191,7 @@ impl Witness { let tel_events_db = { tel_path.push("tel"); tel_path.push("events"); - Arc::new(teliox::database::EventDatabase::new(&tel_path).unwrap()) + Arc::new(teliox::database::TelEventDatabase::new(&tel_path).unwrap()) }; let tel_escrow_db = { diff --git a/support/teliox/src/database/mod.rs b/support/teliox/src/database/mod.rs index 6a10d9e2..61c320d9 100644 --- a/support/teliox/src/database/mod.rs +++ b/support/teliox/src/database/mod.rs @@ -4,7 +4,7 @@ use std::path::Path; pub mod escrow; pub mod sled_db; -pub trait EventDatabase { +pub trait TelEventDatabase { fn new(path: impl AsRef) -> Result where Self: Sized; diff --git a/support/teliox/src/database/sled_db.rs b/support/teliox/src/database/sled_db.rs index 03fe157a..690262e2 100644 --- a/support/teliox/src/database/sled_db.rs +++ b/support/teliox/src/database/sled_db.rs @@ -1,4 +1,4 @@ -use crate::{database::EventDatabase, error::Error, event::verifiable_event::VerifiableEvent}; +use crate::{database::TelEventDatabase, error::Error, event::verifiable_event::VerifiableEvent}; use keri_core::prefix::IdentifierPrefix; use sled_tables::{ self, @@ -16,7 +16,7 @@ pub struct SledEventDatabase { management_events: SledEventTreeVec, } -impl EventDatabase for SledEventDatabase { +impl TelEventDatabase for SledEventDatabase { fn new(path: impl AsRef) -> Result { let db = Arc::new(sled::open(path)?); Ok(Self { diff --git a/support/teliox/src/processor/escrow/missing_issuer.rs b/support/teliox/src/processor/escrow/missing_issuer.rs index 6e38582d..13506964 100644 --- a/support/teliox/src/processor/escrow/missing_issuer.rs +++ b/support/teliox/src/processor/escrow/missing_issuer.rs @@ -12,7 +12,7 @@ use keri_core::{ use crate::{ database::{ escrow::{Escrow, EscrowDb}, - EventDatabase, + TelEventDatabase, }, error::Error, event::{verifiable_event::VerifiableEvent, Event}, @@ -23,14 +23,14 @@ use crate::{ }, }; -pub struct MissingIssuerEscrow { +pub struct MissingIssuerEscrow { kel_reference: Arc>, tel_reference: Arc>, publisher: TelNotificationBus, escrowed_missing_issuer: Escrow, } -impl MissingIssuerEscrow { +impl MissingIssuerEscrow { pub fn new( db: Arc>, escrow_db: Arc, @@ -48,7 +48,7 @@ impl MissingIssuerEscrow { } } } -impl Notifier for MissingIssuerEscrow { +impl Notifier for MissingIssuerEscrow { fn notify( &self, notification: &Notification, @@ -72,7 +72,7 @@ impl Notifier for MissingIssuerEscrow { } } -impl TelNotifier for MissingIssuerEscrow { +impl TelNotifier for MissingIssuerEscrow { fn notify( &self, notification: &TelNotification, @@ -91,7 +91,7 @@ impl TelNotifier for MissingIssuerEscrow { } } -impl MissingIssuerEscrow { +impl MissingIssuerEscrow { /// Reprocess escrowed events that need issuer event of given digest for acceptance. pub fn process_missing_issuer_escrow(&self, id: &IdentifierPrefix) -> Result<(), Error> { if let Some(esc) = self.escrowed_missing_issuer.get(id) { @@ -151,7 +151,7 @@ mod tests { }; use crate::{ - database::{escrow::EscrowDb, sled_db::SledEventDatabase, EventDatabase}, + database::{escrow::EscrowDb, sled_db::SledEventDatabase, TelEventDatabase}, error::Error, event::{manager_event, verifiable_event::VerifiableEvent}, processor::{ diff --git a/support/teliox/src/processor/escrow/missing_registry.rs b/support/teliox/src/processor/escrow/missing_registry.rs index 562471e7..cdab77a9 100644 --- a/support/teliox/src/processor/escrow/missing_registry.rs +++ b/support/teliox/src/processor/escrow/missing_registry.rs @@ -7,7 +7,7 @@ use keri_core::{ use crate::{ database::{ escrow::{Escrow, EscrowDb}, - EventDatabase, + TelEventDatabase, }, error::Error, event::verifiable_event::VerifiableEvent, @@ -18,13 +18,13 @@ use crate::{ }, }; -pub struct MissingRegistryEscrow { +pub struct MissingRegistryEscrow { tel_reference: Arc>, kel_reference: Arc>, escrowed_missing_registry: Escrow, } -impl MissingRegistryEscrow { +impl MissingRegistryEscrow { pub fn new( tel_reference: Arc>, kel_reference: Arc>, @@ -40,7 +40,7 @@ impl MissingRegistryEscrow { } } -impl TelNotifier for MissingRegistryEscrow { +impl TelNotifier for MissingRegistryEscrow { fn notify( &self, notification: &TelNotification, @@ -63,7 +63,7 @@ impl TelNotifier for MissingRegistryEscrow { } } -impl MissingRegistryEscrow { +impl MissingRegistryEscrow { pub fn process_missing_registry( &self, bus: &TelNotificationBus, @@ -115,7 +115,7 @@ mod tests { }; use crate::{ - database::{escrow::EscrowDb, sled_db::SledEventDatabase, EventDatabase}, + database::{escrow::EscrowDb, sled_db::SledEventDatabase, TelEventDatabase}, error::Error, event::verifiable_event::VerifiableEvent, processor::{ diff --git a/support/teliox/src/processor/escrow/out_of_order.rs b/support/teliox/src/processor/escrow/out_of_order.rs index 823c5337..7fc05c79 100644 --- a/support/teliox/src/processor/escrow/out_of_order.rs +++ b/support/teliox/src/processor/escrow/out_of_order.rs @@ -7,7 +7,7 @@ use keri_core::{ use crate::{ database::{ escrow::{Escrow, EscrowDb}, - EventDatabase, + TelEventDatabase, }, error::Error, event::verifiable_event::VerifiableEvent, @@ -18,13 +18,13 @@ use crate::{ }, }; -pub struct OutOfOrderEscrow { +pub struct OutOfOrderEscrow { tel_reference: Arc>, kel_reference: Arc>, escrowed_out_of_order: Escrow, } -impl OutOfOrderEscrow { +impl OutOfOrderEscrow { pub fn new( tel_reference: Arc>, kel_reference: Arc>, @@ -40,7 +40,7 @@ impl OutOfOrderEscrow { } } -impl TelNotifier for OutOfOrderEscrow { +impl TelNotifier for OutOfOrderEscrow { fn notify( &self, notification: &TelNotification, @@ -62,7 +62,7 @@ impl TelNotifier for OutOfOrderEscrow { } } -impl OutOfOrderEscrow { +impl OutOfOrderEscrow { pub fn process_out_of_order_events( &self, bus: &TelNotificationBus, @@ -110,7 +110,7 @@ mod tests { }; use crate::{ - database::{escrow::EscrowDb, sled_db::SledEventDatabase, EventDatabase}, + database::{escrow::EscrowDb, sled_db::SledEventDatabase, TelEventDatabase}, error::Error, event::verifiable_event::VerifiableEvent, processor::{ diff --git a/support/teliox/src/processor/mod.rs b/support/teliox/src/processor/mod.rs index b669e876..a152955e 100644 --- a/support/teliox/src/processor/mod.rs +++ b/support/teliox/src/processor/mod.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use keri_core::{database::redb::RedbDatabase, processor::event_storage::EventStorage}; use crate::{ - database::EventDatabase, + database::TelEventDatabase, error::Error, event::{verifiable_event::VerifiableEvent, Event}, query::SignedTelQuery, @@ -20,13 +20,13 @@ pub mod notification; pub mod storage; pub mod validator; -pub struct TelEventProcessor { +pub struct TelEventProcessor { kel_reference: Arc>, pub tel_reference: Arc>, pub publisher: TelNotificationBus, } -impl TelEventProcessor { +impl TelEventProcessor { pub fn new( kel_reference: Arc>, tel_reference: Arc>, diff --git a/support/teliox/src/processor/storage.rs b/support/teliox/src/processor/storage.rs index c087b829..1a41c120 100644 --- a/support/teliox/src/processor/storage.rs +++ b/support/teliox/src/processor/storage.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use keri_core::prefix::IdentifierPrefix; use crate::{ - database::EventDatabase, + database::TelEventDatabase, error::Error, event::{verifiable_event::VerifiableEvent, Event}, query::TelQueryRoute, @@ -12,10 +12,10 @@ use crate::{ use super::TelReplyType; -pub struct TelEventStorage { +pub struct TelEventStorage { pub db: Arc, } -impl TelEventStorage { +impl TelEventStorage { pub fn new(db: Arc) -> Self { Self { db } } diff --git a/support/teliox/src/processor/validator.rs b/support/teliox/src/processor/validator.rs index bfc7b456..7cc6086b 100644 --- a/support/teliox/src/processor/validator.rs +++ b/support/teliox/src/processor/validator.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use keri_core::{ - database::redb::RedbDatabase, + database::EventDatabase, event::{event_data::EventData, sections::seal::Seal}, prefix::IdentifierPrefix, processor::event_storage::EventStorage, @@ -9,7 +9,7 @@ use keri_core::{ use said::SelfAddressingIdentifier; use crate::{ - database::EventDatabase, + database::TelEventDatabase, error::Error, event::{ manager_event::{ManagerEventType, ManagerTelEventMessage}, @@ -22,16 +22,13 @@ use crate::{ use super::TelEventStorage; -pub struct TelEventValidator { - kel_reference: Arc>, +pub struct TelEventValidator { + kel_reference: Arc>, db: Arc>, } -impl TelEventValidator { - pub fn new( - db: Arc>, - kel_reference: Arc>, - ) -> Self { +impl TelEventValidator { + pub fn new(db: Arc>, kel_reference: Arc>) -> Self { Self { db: db.clone(), kel_reference, @@ -40,7 +37,7 @@ impl TelEventValidator { /// Checks if kel event pointed by seal has seal to tel event inside. pub fn check_kel_event( - kel_reference: Arc>, + kel_reference: Arc>, seal: &AttachedSourceSeal, issuer_id: &IdentifierPrefix, expected_digest: SelfAddressingIdentifier, diff --git a/support/teliox/src/tel/mod.rs b/support/teliox/src/tel/mod.rs index 9b18eff9..41e5a66a 100644 --- a/support/teliox/src/tel/mod.rs +++ b/support/teliox/src/tel/mod.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, RwLock}; use crate::{ - database::EventDatabase, + database::TelEventDatabase, error::Error, event::{manager_event::Config, verifiable_event::VerifiableEvent, Event}, processor::{ @@ -43,12 +43,12 @@ impl TelNotifier for RecentlyAddedEvents { } /// Transaction Event Log -pub struct Tel { +pub struct Tel { pub processor: TelEventProcessor, pub recently_added_events: Arc, } -impl Tel { +impl Tel { pub fn new( tel_reference: Arc>, kel_reference: Arc>,