Skip to content

Commit

Permalink
docs: add a few explanatory docs
Browse files Browse the repository at this point in the history
Parsing the code, adding some helpful docs as I go.
  • Loading branch information
CjS77 committed Nov 14, 2023
1 parent ba59da4 commit 8c24a98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/sdm-launchpad/src/resources/images/l2_base_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl ManagedContainer for TariBaseNode {
}
}

/// A helper struct to track the progress of the initial block download.
struct Checker {
progress: SyncProgress,
identity_sent: bool,
Expand All @@ -155,6 +156,10 @@ impl Checker {

#[async_trait]
impl ContainerChecker<LaunchpadProtocol> for Checker {
/// The interval hook in the base node checker is used to query the base node via gRPC for the current sync progress.
/// The progress is then reported to the SDM via the `CheckerEvent::Progress` event.
/// The task is reported as complete (`READY`) once the `sync_state` value from the `get_sync_progress` RPC call
/// is `Done`.
async fn on_interval(&mut self, ctx: &mut CheckerContext<LaunchpadProtocol>) -> Result<(), Error> {
if self.ready {
return Ok(());
Expand Down
5 changes: 5 additions & 0 deletions libs/sdm/src/image/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ impl<P: ManagedProtocol> CheckerContext<P> {
}
}

/// Polls a container for the logs and stats, and executes the related hooks for the event. If no events are
/// received for 1 second, the `on_interval` hook is called. The default implementation of all of the hooks do nothing.
///
/// In each of the hooks, a mutable reference to a `CheckerContext` is provided, which can be used to access / update
/// the log and stats history, and update the progress of a task.
#[async_trait]
pub trait ContainerChecker<P: ManagedProtocol>: Send {
async fn entrypoint(mut self: Box<Self>, mut ctx: CheckerContext<P>) {
Expand Down
2 changes: 2 additions & 0 deletions libs/sdm/src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ pub(crate) use task::ImageTask;

use crate::config::ManagedProtocol;

/// A container that can be managed by SDM.
pub trait ManagedContainer: fmt::Debug + Send + 'static {
type Protocol: ManagedProtocol;


fn checker(&mut self) -> Box<dyn ContainerChecker<Self::Protocol>> {
Box::<ReadyIfStarted>::default()
}
Expand Down

0 comments on commit 8c24a98

Please sign in to comment.