Skip to content
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
7 changes: 4 additions & 3 deletions components/controller/src/known_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use keri_core::{
query::reply_event::{ReplyEvent, ReplyRoute, SignedReply},
};
use teliox::database::escrow::EscrowDb;
use teliox::database::EventDatabase;
use teliox::database::sled_db::SledEventDatabase;
use teliox::database::TelEventDatabase;
use teliox::processor::escrow::default_escrow_bus as tel_escrow_bus;
use teliox::processor::storage::TelEventStorage;
use teliox::tel::Tel;
Expand All @@ -50,7 +51,7 @@ pub struct KnownEvents {
pub storage: Arc<EventStorage<RedbDatabase>>,
pub oobi_manager: OobiManager,
pub partially_witnessed_escrow: Arc<PartiallyWitnessedEscrow>,
pub tel: Arc<Tel>,
pub tel: Arc<Tel<SledEventDatabase>>,
}

impl KnownEvents {
Expand Down Expand Up @@ -81,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 = {
Expand Down
11 changes: 3 additions & 8 deletions components/watcher/src/watcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ 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::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},
Expand Down Expand Up @@ -148,7 +143,7 @@ impl Watcher {
teliox::event::Event::Vc(_) => todo!(),
};
let seal = &ev.seal;
TelEventValidator::check_kel_event(
TelEventValidator::<SledEventDatabase, RedbDatabase>::check_kel_event(
self.watcher_data.event_storage.clone(),
seal,
&issuer_id,
Expand Down
6 changes: 3 additions & 3 deletions components/witness/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -145,7 +145,7 @@ pub struct Witness {
pub oobi_manager: OobiManager,
pub signer: Arc<Signer>,
pub receipt_generator: Arc<WitnessReceiptGenerator>,
pub tel: Arc<Tel>,
pub tel: Arc<Tel<SledEventDatabase>>,
}

impl Witness {
Expand Down Expand Up @@ -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 = {
Expand Down
65 changes: 13 additions & 52 deletions support/teliox/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -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<sled::Db>,
// "iids" tree
identifiers: SledEventTree<IdentifierPrefix>,
// "tels" tree
tel_events: SledEventTreeVec<VerifiableEvent>,
// "man" tree
management_events: SledEventTreeVec<VerifiableEvent>,
}

impl EventDatabase {
pub fn new(path: impl AsRef<Path>) -> Result<Self, Error> {
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 TelEventDatabase {
fn new(path: impl AsRef<Path>) -> Result<Self, Error>
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<impl DoubleEndedIterator<Item = VerifiableEvent>> {
self.tel_events
.iter_values(self.identifiers.designated_key(id))
}
) -> Option<impl DoubleEndedIterator<Item = VerifiableEvent>>;

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<impl DoubleEndedIterator<Item = VerifiableEvent>> {
self.management_events
.iter_values(self.identifiers.designated_key(id))
}
) -> Option<impl DoubleEndedIterator<Item = VerifiableEvent>>;
}
63 changes: 63 additions & 0 deletions support/teliox/src/database/sled_db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use crate::{database::TelEventDatabase, 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<sled::Db>,
// "iids" tree
identifiers: SledEventTree<IdentifierPrefix>,
// "tels" tree
tel_events: SledEventTreeVec<VerifiableEvent>,
// "man" tree
management_events: SledEventTreeVec<VerifiableEvent>,
}

impl TelEventDatabase for SledEventDatabase {
fn new(path: impl AsRef<Path>) -> Result<Self, Error> {
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<impl DoubleEndedIterator<Item = VerifiableEvent>> {
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<impl DoubleEndedIterator<Item = VerifiableEvent>> {
self.management_events
.iter_values(self.identifiers.designated_key(id))
}
}
29 changes: 15 additions & 14 deletions support/teliox/src/processor/escrow/missing_issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use keri_core::{
};

use crate::{
database::escrow::{Escrow, EscrowDb},
database::{
escrow::{Escrow, EscrowDb},
TelEventDatabase,
},
error::Error,
event::{verifiable_event::VerifiableEvent, Event},
processor::{
Expand All @@ -20,16 +23,16 @@ use crate::{
},
};

pub struct MissingIssuerEscrow {
pub struct MissingIssuerEscrow<D: TelEventDatabase> {
kel_reference: Arc<EventStorage<RedbDatabase>>,
tel_reference: Arc<TelEventStorage>,
tel_reference: Arc<TelEventStorage<D>>,
publisher: TelNotificationBus,
escrowed_missing_issuer: Escrow<VerifiableEvent>,
}

impl MissingIssuerEscrow {
impl<D: TelEventDatabase> MissingIssuerEscrow<D> {
pub fn new(
db: Arc<TelEventStorage>,
db: Arc<TelEventStorage<D>>,
escrow_db: Arc<EscrowDb>,
duration: Duration,
kel_reference: Arc<EventStorage<RedbDatabase>>,
Expand All @@ -45,7 +48,7 @@ impl MissingIssuerEscrow {
}
}
}
impl Notifier for MissingIssuerEscrow {
impl<D: TelEventDatabase> Notifier for MissingIssuerEscrow<D> {
fn notify(
&self,
notification: &Notification,
Expand All @@ -69,7 +72,7 @@ impl Notifier for MissingIssuerEscrow {
}
}

impl TelNotifier for MissingIssuerEscrow {
impl<D: TelEventDatabase> TelNotifier for MissingIssuerEscrow<D> {
fn notify(
&self,
notification: &TelNotification,
Expand All @@ -88,15 +91,13 @@ impl TelNotifier for MissingIssuerEscrow {
}
}

impl MissingIssuerEscrow {
impl<D: TelEventDatabase> MissingIssuerEscrow<D> {
/// 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),
Expand Down Expand Up @@ -150,7 +151,7 @@ mod tests {
};

use crate::{
database::{escrow::EscrowDb, EventDatabase},
database::{escrow::EscrowDb, sled_db::SledEventDatabase, TelEventDatabase},
error::Error,
event::{manager_event, verifiable_event::VerifiableEvent},
processor::{
Expand Down Expand Up @@ -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());

Expand Down
27 changes: 14 additions & 13 deletions support/teliox/src/processor/escrow/missing_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use keri_core::{
};

use crate::{
database::escrow::{Escrow, EscrowDb},
database::{
escrow::{Escrow, EscrowDb},
TelEventDatabase,
},
error::Error,
event::verifiable_event::VerifiableEvent,
processor::{
Expand All @@ -15,15 +18,15 @@ use crate::{
},
};

pub struct MissingRegistryEscrow {
tel_reference: Arc<TelEventStorage>,
pub struct MissingRegistryEscrow<D: TelEventDatabase> {
tel_reference: Arc<TelEventStorage<D>>,
kel_reference: Arc<EventStorage<RedbDatabase>>,
escrowed_missing_registry: Escrow<VerifiableEvent>,
}

impl MissingRegistryEscrow {
impl<D: TelEventDatabase> MissingRegistryEscrow<D> {
pub fn new(
tel_reference: Arc<TelEventStorage>,
tel_reference: Arc<TelEventStorage<D>>,
kel_reference: Arc<EventStorage<RedbDatabase>>,
escrow_db: Arc<EscrowDb>,
duration: Duration,
Expand All @@ -37,7 +40,7 @@ impl MissingRegistryEscrow {
}
}

impl TelNotifier for MissingRegistryEscrow {
impl<D: TelEventDatabase> TelNotifier for MissingRegistryEscrow<D> {
fn notify(
&self,
notification: &TelNotification,
Expand All @@ -60,18 +63,16 @@ impl TelNotifier for MissingRegistryEscrow {
}
}

impl MissingRegistryEscrow {
impl<D: TelEventDatabase> MissingRegistryEscrow<D> {
pub fn process_missing_registry(
&self,
bus: &TelNotificationBus,
id: &IdentifierPrefix,
) -> 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
Expand Down Expand Up @@ -114,7 +115,7 @@ mod tests {
};

use crate::{
database::{escrow::EscrowDb, EventDatabase},
database::{escrow::EscrowDb, sled_db::SledEventDatabase, TelEventDatabase},
error::Error,
event::verifiable_event::VerifiableEvent,
processor::{
Expand Down Expand Up @@ -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());

Expand Down
Loading
Loading