massa_event_cache/lib.rs
1// Copyright (c) 2022 MASSA LABS <info@massa.net>
2
3//! # General description
4//!
5//! A database (build on top of rocksdb) to store final events emitted by:
6//! * The massa node during execution
7//! * A Smart contract during execution
8//!
9//! The database can also be queried with: get_filtered_sc_output_events
10//!
11//! # Architecture
12//!
13//! * controller.rs / worker.rs: db wrapper controller & worker
14//! * rocksdb_operator: a rocksdb operator to handle counter (as u64 counter)
15//! * ser_deser.rs: event serializer && deserializer (using nom)
16//! * event_cache: db over rocksdb code
17//!
18//! # DBKeyBuilder
19//!
20//! The db use the DbKeyBuilder structure to create the rocksdb keys required for its operations.
21//! There are 3 types of keys:
22//! * regular key: and the associated value is the event data serialized
23//! * prefix key: Key used to iterate in rocksdb
24//! * counter key: key used to query count info (example: number of event for operation id X)
25//!
26//! See `key_from_event` method for more information about the keys.
27//!
28//! # Db queries
29//!
30//! WHen inserting an event in the DB, counters are being updated. They are used later when we need
31//! to query the DB in order to query by ordering with counter values (to optimize the DB query plan).
32//!
33//! Let say you want to query events for a specific slot range && an emitter_address, the query method
34//! will first query the counts for each filter item then select the one with fewer rows then select the
35//! other.
36//!
37//! # Snip
38//!
39//! The method snip on the DB must be used to remove items and keep a reasonable DB size. It will remove
40//! the oldest (by slot) items (number is configurable) in the DB.
41//!
42//! # Tests
43//!
44//! * Check unit tests for info on how to use the DB directly.
45
46pub mod config;
47
48pub mod controller;
49mod event_cache;
50mod rocksdb_operator;
51mod ser_deser;
52pub mod worker;
53
54#[cfg(feature = "test-exports")]
55pub use controller::{MockEventCacheController, MockEventCacheControllerWrapper};