Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

chore: adding storage context on startup #404

Merged
merged 2 commits into from
Dec 15, 2023
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
4 changes: 4 additions & 0 deletions crates/topos-tce-storage/src/fullnode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ impl WriteStore for FullNodeStore {
}

impl ReadStore for FullNodeStore {
fn count_certificates_delivered(&self) -> Result<usize, StorageError> {
Ok(self.perpetual_tables.certificates.iter()?.count())
}

fn get_source_head(&self, subnet_id: &SubnetId) -> Result<Option<SourceHead>, StorageError> {
Ok(self
.index_tables
Expand Down
3 changes: 3 additions & 0 deletions crates/topos-tce-storage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub trait WriteStore: Send {
/// [`ValidatorStore`](struct@super::validator::ValidatorStore) and
/// [`FullNodeStore`](struct@super::fullnode::FullNodeStore) to read data.
pub trait ReadStore: Send {
/// Returns the number of certificates delivered
fn count_certificates_delivered(&self) -> Result<usize, StorageError>;

/// Try to get a SourceHead of a subnet
///
/// Returns `Ok(None)` if the subnet is not found, meaning that no certificate are currently
Expand Down
9 changes: 9 additions & 0 deletions crates/topos-tce-storage/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ impl ValidatorStore {
Ok(self.pending_tables.pending_pool.iter()?.count())
}

/// Returns the number of certificates in the precedence pool
pub fn count_precedence_pool_certificates(&self) -> Result<usize, StorageError> {
Ok(self.pending_tables.precedence_pool.iter()?.count())
}

/// Try to return the [`PendingCertificateId`] for a [`CertificateId`]
///
/// Return `Ok(None)` if the `certificate_id` is not found.
Expand Down Expand Up @@ -375,6 +380,10 @@ impl ValidatorStore {
}
}
impl ReadStore for ValidatorStore {
fn count_certificates_delivered(&self) -> Result<usize, StorageError> {
self.fullnode_store.count_certificates_delivered()
}

fn get_source_head(&self, subnet_id: &SubnetId) -> Result<Option<SourceHead>, StorageError> {
self.fullnode_store.get_source_head(subnet_id)
}
Expand Down
25 changes: 24 additions & 1 deletion crates/topos-tce/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use futures::StreamExt;
use opentelemetry::global;
use std::{
future::IntoFuture,
panic::UnwindSafe,
sync::{atomic::AtomicBool, Arc},
};
use tokio::{
Expand All @@ -22,11 +23,12 @@ use topos_tce_storage::{
epoch::{EpochValidatorsStore, ValidatorPerEpochStore},
fullnode::FullNodeStore,
index::IndexTables,
store::ReadStore,
validator::{ValidatorPerpetualTables, ValidatorStore},
StorageClient,
};
use topos_tce_synchronizer::SynchronizerService;
use tracing::{debug, warn};
use tracing::{debug, info, warn};

mod app_context;
pub mod config;
Expand Down Expand Up @@ -117,6 +119,27 @@ pub async fn run(
),
);

let certificates_synced = fullnode_store
.count_certificates_delivered()
.map_err(|error| format!("Unable to count certificates delivered: {error}"))
.unwrap();

let pending_certificates = validator_store
.count_pending_certificates()
.map_err(|error| format!("Unable to count pending certificates: {error}"))
.unwrap();

let precedence_pool_certificates = validator_store
.count_precedence_pool_certificates()
.map_err(|error| format!("Unable to count precedence pool certificates: {error}"))
.unwrap();

info!(
"Storage initialized with {} certificates delivered, {} pending certificates and {} \
certificates in the precedence pool",
certificates_synced, pending_certificates, precedence_pool_certificates
);

let (network_client, event_stream, unbootstrapped_runtime) = topos_p2p::network::builder()
.peer_key(key)
.listen_addr(addr)
Expand Down
Loading