Skip to content

Commit

Permalink
feat: Add flag to quit when reaching tip (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe authored Oct 22, 2024
1 parent ee04124 commit 79b8412
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/bin/dolos/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub async fn run(config: super::Config, _args: &Args) -> miette::Result<()> {
shelley,
mempool.clone(),
&config.retries,
false,
)
.into_diagnostic()
.context("bootstrapping sync pipeline")?;
Expand Down
9 changes: 7 additions & 2 deletions src/bin/dolos/sync.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use miette::{Context, IntoDiagnostic};

#[derive(Debug, clap::Args)]
pub struct Args {}
pub struct Args {
/// Skip the bootstrap if there's already data in the stores
#[arg(long, action)]
quit_on_tip: bool,
}

pub fn run(config: &super::Config, _args: &Args) -> miette::Result<()> {
pub fn run(config: &super::Config, args: &Args) -> miette::Result<()> {
crate::common::setup_tracing(&config.logging)?;

let (wal, ledger) = crate::common::open_data_stores(config)?;
Expand All @@ -21,6 +25,7 @@ pub fn run(config: &super::Config, _args: &Args) -> miette::Result<()> {
shelley,
mempool,
&config.retries,
args.quit_on_tip,
)
.into_diagnostic()
.context("bootstrapping sync pipeline")?;
Expand Down
2 changes: 2 additions & 0 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ pub fn pipeline(
shelley: shelley::GenesisFile,
mempool: Mempool,
retries: &Option<gasket::retries::Policy>,
quit_on_tip: bool,
) -> Result<Vec<gasket::runtime::Tether>, Error> {
let mut pull = pull::Stage::new(
upstream.peer_address.clone(),
upstream.network_magic,
config.pull_batch_size.unwrap_or(50),
wal.clone(),
quit_on_tip,
);

let mut roll = roll::Stage::new(wal.clone());
Expand Down
18 changes: 15 additions & 3 deletions src/sync/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum WorkUnit {

pub struct Worker {
peer_session: PeerClient,
quit_on_tip: bool,
}

impl Worker {
Expand Down Expand Up @@ -110,7 +111,10 @@ impl gasket::framework::Worker<Stage> for Worker {

info!(?intersection, "found intersection");

let worker = Self { peer_session };
let worker = Self {
peer_session,
quit_on_tip: stage.quit_on_tip,
};

Ok(worker)
}
Expand All @@ -125,8 +129,13 @@ impl gasket::framework::Worker<Stage> for Worker {
debug!("should request next batch of blocks");
Ok(WorkSchedule::Unit(WorkUnit::Pull))
} else {

Check failure on line 131 in src/sync/pull.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

this `else { if .. }` block can be collapsed
debug!("should await next block");
Ok(WorkSchedule::Unit(WorkUnit::Await))
if self.quit_on_tip {
debug!("reached tip, exiting");
Ok(WorkSchedule::Done)
} else {
debug!("should await next block");
Ok(WorkSchedule::Unit(WorkUnit::Await))
}
}
}

Expand Down Expand Up @@ -204,6 +213,7 @@ pub struct Stage {
network_magic: u64,
block_fetch_batch_size: usize,
wal: WalStore,
quit_on_tip: bool,

pub downstream: DownstreamPort,

Expand All @@ -220,11 +230,13 @@ impl Stage {
network_magic: u64,
block_fetch_batch_size: usize,
wal: WalStore,
quit_on_tip: bool,
) -> Self {
Self {
peer_address,
network_magic,
wal,
quit_on_tip,
block_fetch_batch_size,
downstream: Default::default(),
block_count: Default::default(),
Expand Down

0 comments on commit 79b8412

Please sign in to comment.