pub struct EventGraph {Show 13 fields
p2p: P2pPtr,
dag: Tree,
datastore: PathBuf,
replay_mode: bool,
unreferenced_tips: RwLock<BTreeMap<u64, HashSet<Hash>>>,
broadcasted_ids: RwLock<HashSet<Hash>>,
pub prune_task: OnceCell<StoppableTaskPtr>,
pub event_pub: PublisherPtr<Event>,
current_genesis: RwLock<Event>,
days_rotation: u64,
pub synced: RwLock<bool>,
pub deg_enabled: RwLock<bool>,
deg_publisher: PublisherPtr<DegEvent>,
}
Expand description
An Event Graph instance
Fields§
§p2p: P2pPtr
Pointer to the P2P network instance
dag: Tree
Sled tree containing the DAG
datastore: PathBuf
Replay logs path.
replay_mode: bool
Run in replay_mode where if set we log Sled DB instructions
into datastore
, useful to reacreate a faulty DAG to debug.
unreferenced_tips: RwLock<BTreeMap<u64, HashSet<Hash>>>
The set of unreferenced DAG tips
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
current_genesis: RwLock<Event>
Current genesis event
days_rotation: u64
Currently configured DAG rotation, in days
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
Implementations§
Source§impl EventGraph
impl EventGraph
Sourcepub async fn new(
p2p: P2pPtr,
sled_db: Db,
datastore: PathBuf,
replay_mode: bool,
dag_tree_name: &str,
days_rotation: u64,
ex: Arc<Executor<'_>>,
) -> Result<EventGraphPtr>
pub async fn new( p2p: P2pPtr, sled_db: Db, datastore: PathBuf, replay_mode: bool, dag_tree_name: &str, days_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 days_rotation
, and return an atomic instance of
Self
p2p
atomic pointer to p2p.sled_db
sled DB instance.datastore
path where we should log db instrucion if run in replay mode.replay_mode
set the flag to keep a log of db instructions.dag_tree_name
the name of disk-backed tree (or DAG name).days_rotation
marks the lifetime of the DAG before it’s pruned.
pub fn days_rotation(&self) -> u64
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>, days_rotation: u64) -> Result<()>
async fn dag_prune_task(self: Arc<Self>, days_rotation: u64) -> Result<()>
Background task periodically pruning the DAG.
Sourcepub async fn dag_insert(&self, events: &[Event]) -> Result<Vec<Hash>>
pub async fn dag_insert(&self, events: &[Event]) -> 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.
Sourcepub async fn dag_get(&self, event_id: &Hash) -> Result<Option<Event>>
pub async fn dag_get(&self, event_id: &Hash) -> Result<Option<Event>>
Fetch an event from the DAG
Sourceasync fn get_next_layer_with_parents(&self) -> (u64, [Hash; 5])
async fn get_next_layer_with_parents(&self) -> (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(&self) -> BTreeMap<u64, HashSet<Hash>>
async fn find_unreferenced_tips(&self) -> BTreeMap<u64, HashSet<Hash>>
Find the unreferenced tips in the current DAG state, mapped by their layers.
Sourceasync fn get_unreferenced_tips_sorted(&self) -> [Hash; 5]
async fn get_unreferenced_tips_sorted(&self) -> [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
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<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§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>
. Box<dyn Any>
can
then be further downcast
into Box<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>
. Rc<Any>
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> 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> 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> 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.