pub struct EventGraph {Show 17 fields
p2p: P2pPtr,
dag_store: RwLock<DAGStore>,
static_dag: Tree,
datastore: PathBuf,
replay_mode: bool,
broadcasted_ids: RwLock<HashSet<Hash>>,
pub prune_task: OnceCell<StoppableTaskPtr>,
pub event_pub: PublisherPtr<Event>,
pub static_pub: PublisherPtr<Event>,
pub current_genesis: RwLock<Event>,
hours_rotation: u64,
pub synced: RwLock<bool>,
pub deg_enabled: RwLock<bool>,
deg_publisher: PublisherPtr<DegEvent>,
fast_mode: bool,
sled_db: Db,
pub rln_identity_tree: RwLock<SmtMemoryFp>,
}Expand description
An Event Graph instance
Fields§
§p2p: P2pPtrPointer to the P2P network instance
dag_store: RwLock<DAGStore>Sled tree containing the headers
static_dag: TreeStatic DAG
datastore: PathBufReplay logs path.
replay_mode: boolRun in replay_mode where if set we log Sled DB instructions
into datastore, useful to reacreate a faulty DAG to debug.
broadcasted_ids: RwLock<HashSet<Hash>>A HashSet containg event IDs and their 1-level parents.
These come from the events we’ve sent out using EventPut.
They are used with EventReq to decide if we should reply
or not. Additionally it is also used when we broadcast the
TipRep message telling peers about our unreferenced tips.
prune_task: OnceCell<StoppableTaskPtr>DAG Pruning Task
event_pub: PublisherPtr<Event>Event publisher, this notifies whenever an event is inserted into the DAG
static_pub: PublisherPtr<Event>Static Event publisher, this notifies whenever a static event is inserted into the static DAG
current_genesis: RwLock<Event>Current genesis event
hours_rotation: u64Currently configured DAG rotation, in hours
synced: RwLock<bool>Flag signalling DAG has finished initial sync
deg_enabled: RwLock<bool>Enable graph debugging
deg_publisher: PublisherPtr<DegEvent>The publisher for which we can give deg info over
fast_mode: boolRun in fast mode where if set we sync only headers.
sled_db: Dbsled DB
rln_identity_tree: RwLock<SmtMemoryFp>RLN identity storage
Implementations§
Source§impl EventGraph
impl EventGraph
Sourcepub async fn new(
p2p: P2pPtr,
sled_db: Db,
datastore: PathBuf,
replay_mode: bool,
fast_mode: bool,
hours_rotation: u64,
ex: Arc<Executor<'_>>,
) -> Result<EventGraphPtr>
pub async fn new( p2p: P2pPtr, sled_db: Db, datastore: PathBuf, replay_mode: bool, fast_mode: bool, hours_rotation: u64, ex: Arc<Executor<'_>>, ) -> Result<EventGraphPtr>
Create a new EventGraph instance, creates a new Genesis
event and checks if it
is containd in DAG, if not prunes DAG, may also start a pruning
task based on hours_rotation, and return an atomic instance of
Self
p2patomic pointer to p2p.sled_dbsled DB instance.datastorepath where we should log db instrucion if run in replay mode.replay_modeset the flag to keep a log of db instructions.hours_rotationmarks the lifetime of the DAG before it’s pruned.
pub fn hours_rotation(&self) -> u64
Sourcepub async fn dag_sync(&self, dag: Tree, fast_mode: bool) -> Result<()>
pub async fn dag_sync(&self, dag: Tree, fast_mode: bool) -> Result<()>
Sync the DAG from connected peers
Sourcepub async fn sync_selected(&self, count: usize, fast_mode: bool) -> Result<()>
pub async fn sync_selected(&self, count: usize, fast_mode: bool) -> Result<()>
Choose how many dags to sync
Sourceasync fn dag_prune(&self, genesis_event: Event) -> Result<()>
async fn dag_prune(&self, genesis_event: Event) -> Result<()>
Atomically prune the DAG and insert the given event as genesis.
Sourceasync fn dag_prune_task(self: Arc<Self>, hours_rotation: u64) -> Result<()>
async fn dag_prune_task(self: Arc<Self>, hours_rotation: u64) -> Result<()>
Background task periodically pruning the DAG.
Sourcepub async fn dag_insert(
&self,
events: &[Event],
dag_name: &str,
) -> Result<Vec<Hash>>
pub async fn dag_insert( &self, events: &[Event], dag_name: &str, ) -> Result<Vec<Hash>>
Atomically insert given events into the DAG and return the event IDs.
All provided events must be valid. An overlay is used over the DAG tree,
temporary writting each event in order. After all events have been
validated and inserted successfully, we write the overlay to sled.
This will append the new events into the unreferenced tips set, and
remove the events’ parents from it. It will also append the events’
level-1 parents to the broadcasted_ids set, so the P2P protocol
knows that any requests for them are actually legitimate.
TODO: The broadcasted_ids set should periodically be pruned, when
some sensible time has passed after broadcasting the event.
pub async fn header_dag_insert( &self, headers: Vec<Header>, dag_name: &str, ) -> Result<()>
Sourcepub async fn fetch_event_from_dags(
&self,
event_id: &Hash,
) -> Result<Option<Event>>
pub async fn fetch_event_from_dags( &self, event_id: &Hash, ) -> Result<Option<Event>>
Search and fetch an event through all DAGs
Sourceasync fn get_next_layer_with_parents(&self, dag_name: &u64) -> (u64, [Hash; 5])
async fn get_next_layer_with_parents(&self, dag_name: &u64) -> (u64, [Hash; 5])
Get next layer along with its N_EVENT_PARENTS from the unreferenced tips of the DAG. Since tips are mapped by their layer, we go backwards until we fill the vector, ensuring we always use latest layers tips as parents.
Sourceasync fn find_unreferenced_tips_static(&self, dag: &Tree) -> LayerUTips
async fn find_unreferenced_tips_static(&self, dag: &Tree) -> LayerUTips
Find the unreferenced tips in the current DAG state, mapped by their layers.
async fn get_next_layer_with_parents_static(&self) -> (u64, [Hash; 5])
Sourceasync fn get_unreferenced_tips_sorted(&self) -> Vec<[Hash; 5]>
async fn get_unreferenced_tips_sorted(&self) -> Vec<[Hash; 5]>
Internal function used for DAG sorting.
Sourcepub async fn order_events(&self) -> Vec<Event>
pub async fn order_events(&self) -> Vec<Event>
Perform a topological sort of the DAG.
Sourceasync fn dfs_topological_sort(
&self,
event: Event,
visited: &mut HashSet<Hash>,
) -> VecDeque<(u64, Event)>
async fn dfs_topological_sort( &self, event: Event, visited: &mut HashSet<Hash>, ) -> VecDeque<(u64, Event)>
We do a non-recursive DFS (https://en.wikipedia.org/wiki/Depth-first_search), and additionally we consider the timestamps.
Sourcepub async fn deg_enable(&self)
pub async fn deg_enable(&self)
Enable graph debugging
Sourcepub async fn deg_disable(&self)
pub async fn deg_disable(&self)
Disable graph debugging
Sourcepub async fn deg_subscribe(&self) -> Subscription<DegEvent>
pub async fn deg_subscribe(&self) -> Subscription<DegEvent>
Subscribe to deg events
Sourcepub async fn deg_notify(&self, event: DegEvent)
pub async fn deg_notify(&self, event: DegEvent)
Send a deg notification over the publisher
pub async fn eventgraph_info(&self, id: u16, _params: JsonValue) -> JsonResult
Sourcepub async fn fetch_headers_with_tips(
&self,
dag_name: &str,
tips: &LayerUTips,
) -> Result<Vec<Header>>
pub async fn fetch_headers_with_tips( &self, dag_name: &str, tips: &LayerUTips, ) -> Result<Vec<Header>>
Fetch all events that are not ancestors of the tips
Sourceasync fn get_ancestors(
&self,
visited: &mut HashSet<Hash>,
header: Header,
tree: &Tree,
) -> Result<()>
async fn get_ancestors( &self, visited: &mut HashSet<Hash>, header: Header, tree: &Tree, ) -> Result<()>
Finds all the ancestors of an event
Sourcepub async fn fetch_successors_of(&self, tips: LayerUTips) -> Result<Vec<Event>>
pub async fn fetch_successors_of(&self, tips: LayerUTips) -> Result<Vec<Event>>
Fetch all the events that are on a higher layers than the provided ones.
pub async fn static_new(sled_db: &Db) -> Result<Tree>
pub async fn static_sync(&self) -> Result<()>
pub async fn static_broadcast(&self, event: Event, blob: Vec<u8>) -> Result<()>
pub async fn static_insert(&self, event: &Event) -> Result<()>
pub async fn static_fetch(&self, event_id: &Hash) -> Result<Option<Event>>
pub async fn static_fetch_all(&self) -> Result<Vec<Event>>
pub async fn static_unreferenced_tips(&self) -> LayerUTips
Auto Trait Implementations§
impl !Freeze for EventGraph
impl !RefUnwindSafe for EventGraph
impl Send for EventGraph
impl Sync for EventGraph
impl Unpin for EventGraph
impl !UnwindSafe for EventGraph
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.