Skip to content

Commit

Permalink
fix: header sync and lingering volumes (#317)
Browse files Browse the repository at this point in the history
* fix: header sync progress

* fix: remove lingering volumes
  • Loading branch information
brianp committed Feb 12, 2024
1 parent e47acf3 commit 64521a4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
6 changes: 6 additions & 0 deletions libs/protocol/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ impl TaskProgress {
}
}

impl fmt::Display for TaskProgress {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} 0 {}%", self.stage, self.pct)
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum TaskStatus {
Inactive,
Expand Down
28 changes: 16 additions & 12 deletions libs/sdm-launchpad/src/resources/images/l2_base_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use anyhow::Error;
use async_trait::async_trait;
use log::debug;
use minotari_node_grpc_client::{grpc, BaseNodeGrpcClient};
use tari_launchpad_protocol::{container::TaskProgress, settings::BaseNodeConfig};
use tari_launchpad_protocol::container::TaskProgress;
use tari_launchpad_protocol::settings::BaseNodeConfig;
use tari_sdm::{
ids::{ManagedTask, TaskId},
image::{
Expand All @@ -38,6 +39,7 @@ use super::{
sync_progress::SyncProgress, Tor, BLOCKCHAIN_PATH, BLOCKCHAIN_VOLUME, DEFAULT_REGISTRY, GENERAL_VOLUME,
VAR_TARI_PATH,
};
use crate::resources::images::sync_progress::SyncType;
use crate::resources::{
config::{ConnectionSettings, LaunchpadConfig, LaunchpadInnerEvent, LaunchpadProtocol},
networks::LocalNet,
Expand Down Expand Up @@ -175,18 +177,20 @@ impl ContainerChecker<LaunchpadProtocol> for Checker {

let response = client.get_sync_progress(grpc::Empty {}).await?.into_inner();
log::trace!("Sync progress: {:?}", response);
let done = matches!(response.state(), minotari_app_grpc::tari_rpc::SyncState::Done);
self.progress.update(response);
let info = self.progress.progress_info();
log::trace!("Progress updated !common::progress={}", info.block_progress);
let progress = TaskProgress {
pct: info.block_progress as u8,
stage: "Syncing blockchain...".into(),
};
ctx.report(CheckerEvent::Progress(progress)).ok();
if done {
self.ready = true;
ctx.report(CheckerEvent::Ready).ok();

let progress = TaskProgress::from(&self.progress);
log::trace!("Progress updated !common::progress={}", progress);

match self.progress.sync_type {
SyncType::Header | SyncType::Block => {
ctx.report(CheckerEvent::Progress(progress)).ok();
},
SyncType::Done => {
self.ready = true;
ctx.report(CheckerEvent::Ready).ok();
},
_ => {},
}
Ok(())
}
Expand Down
32 changes: 22 additions & 10 deletions libs/sdm-launchpad/src/resources/images/sync_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::time::{Duration, Instant};

use minotari_app_grpc::tari_rpc::{SyncProgressResponse, SyncState};
use serde::Serialize;
use tari_launchpad_protocol::container::TaskProgress;

pub const BLOCKS_SYNC_EXPECTED_TIME: Duration = Duration::from_secs(4 * 3600);
pub const HEADERS_SYNC_EXPECTED_TIME: Duration = Duration::from_secs(2 * 3600);
Expand All @@ -49,7 +50,7 @@ pub struct SyncProgressInfo {
}

pub struct SyncProgress {
sync_type: SyncType,
pub sync_type: SyncType,
header_sync: ItemCount,
blocks_sync: ItemCount,
}
Expand Down Expand Up @@ -201,16 +202,27 @@ impl SyncProgress {
pub fn total_sync_time(&self) -> Duration {
self.header_sync.total_sync_time() + self.blocks_sync.total_sync_time()
}
}

pub fn progress_info(&self) -> SyncProgressInfo {
SyncProgressInfo {
sync_type: self.sync_type.clone(),
header_progress: (self.header_sync.progress() * 100.0) as u64,
block_progress: (self.blocks_sync.progress() * 100.0) as u64,
total_blocks: self.blocks_sync.total_items,
estimated_time_sec: self.estimated_time_remaining().as_secs(),
done: self.is_done(),
sync_time_sec: self.total_sync_time().as_secs(),
impl From<&SyncProgress> for TaskProgress {
fn from(value: &SyncProgress) -> Self {
match value.sync_type {
SyncType::Startup => TaskProgress {
pct: 0,
stage: "Starting...".to_string(),
},
SyncType::Block => TaskProgress {
pct: (value.blocks_sync.progress() * 100.0) as u8,
stage: "Syncing blockchain...".to_string(),
},
SyncType::Header => TaskProgress {
pct: (value.header_sync.progress() * 100.0) as u8,
stage: "Syncing headers...".to_string(),
},
SyncType::Done => TaskProgress {
pct: 100,
stage: "Complete".to_string(),
},
}
}
}
1 change: 1 addition & 0 deletions libs/sdm/src/image/task/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl<C: ManagedProtocol> TaskContext<ImageTask<C>> {
volumes: Some(volumes),
cmd: Some(args.build()),
host_config: Some(HostConfig {
auto_remove: Some(true),
binds: Some(vec![]),
network_mode: Some("bridge".to_string()),
port_bindings: Some(ports_map(&ports)),
Expand Down

0 comments on commit 64521a4

Please sign in to comment.