Skip to content

Commit

Permalink
migrate lost topdown commits
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoAtwill committed Feb 22, 2024
1 parent 4d3f890 commit b61bcc8
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 277 deletions.
4 changes: 4 additions & 0 deletions fendermint/vm/topdown/src/finality/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ impl<T> CachedFinalityProvider<T> {
pub fn cached_blocks(&self) -> Stm<BlockHeight> {
self.inner.cached_blocks()
}

pub fn first_non_null_block(&self, height: BlockHeight) -> Stm<Option<BlockHeight>> {
self.inner.first_non_null_block(height)
}
}

#[cfg(test)]
Expand Down
27 changes: 13 additions & 14 deletions fendermint/vm/topdown/src/finality/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,23 @@ impl FinalityWithNull {
};
Ok(Some(h))
}
}

/// All the private functions
impl FinalityWithNull {
/// Get the first non-null block in the range [start, end].
fn first_non_null_block_before(&self, height: BlockHeight) -> Stm<Option<BlockHeight>> {
/// Get the first non-null block in the range of earliest cache block till the height specified, inclusive.
pub(crate) fn first_non_null_block(&self, height: BlockHeight) -> Stm<Option<BlockHeight>> {
let cache = self.cached_data.read()?;
Ok(cache.lower_bound().and_then(|lower_bound| {
for h in (lower_bound..height).rev() {
for h in (lower_bound..=height).rev() {
if let Some(Some(_)) = cache.get_value(h) {
return Some(h);
}
}
None
}))
}
}

/// All the private functions
impl FinalityWithNull {
fn propose_next_height(&self) -> Stm<Option<BlockHeight>> {
let latest_height = if let Some(h) = self.latest_height_in_cache()? {
h
Expand All @@ -207,18 +207,17 @@ impl FinalityWithNull {
let candidate_height = min(max_proposal_height, latest_height);
tracing::debug!(max_proposal_height, candidate_height, "propose heights");

let first_non_null_height =
if let Some(h) = self.first_non_null_block_before(candidate_height)? {
h
} else {
tracing::debug!(height = candidate_height, "no non-null block found before");
return Ok(None);
};
let first_non_null_height = if let Some(h) = self.first_non_null_block(candidate_height)? {
h
} else {
tracing::debug!(height = candidate_height, "no non-null block found before");
return Ok(None);
};

tracing::debug!(first_non_null_height, candidate_height);
// an extra layer of delay
let maybe_proposal_height =
self.first_non_null_block_before(first_non_null_height - self.config.proposal_delay())?;
self.first_non_null_block(first_non_null_height - self.config.proposal_delay())?;
tracing::debug!(
delayed_height = maybe_proposal_height,
delay = self.config.proposal_delay()
Expand Down
2 changes: 0 additions & 2 deletions fendermint/vm/topdown/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0, MIT
//! A constant running process that fetch or listener to parent state

mod pointers;
mod syncer;
mod tendermint;

Expand Down Expand Up @@ -178,7 +177,6 @@ fn start_syncing<T, C, P>(
tokio::spawn(async move {
let lotus_syncer =
LotusParentSyncer::new(config, parent_proxy, view_provider, vote_tally, query)
.await
.expect("");

let mut tendermint_syncer = TendermintAwareSyncer::new(lotus_syncer, tendermint_client);
Expand Down
50 changes: 0 additions & 50 deletions fendermint/vm/topdown/src/sync/pointers.rs

This file was deleted.

Loading

0 comments on commit b61bcc8

Please sign in to comment.