Skip to content

Commit

Permalink
Expose max_cache_block parameter for parent syncing (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoAtwill authored Apr 3, 2024
1 parent 832ce37 commit 2d3c76d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions fendermint/app/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ pub struct TopDownSettings {
pub proposal_delay: BlockHeight,
/// The max number of blocks one should make the topdown proposal
pub max_proposal_range: BlockHeight,
/// The max number of blocks to hold in memory for parent syncer
pub max_cache_blocks: Option<BlockHeight>,
/// Parent syncing cron period, in seconds
#[serde_as(as = "DurationSeconds<u64>")]
pub polling_interval: Duration,
Expand Down
8 changes: 7 additions & 1 deletion fendermint/app/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,20 @@ async fn run(settings: Settings) -> anyhow::Result<()> {
let (parent_finality_provider, ipc_tuple) = if topdown_enabled {
info!("topdown finality enabled");
let topdown_config = settings.ipc.topdown_config()?;
let config = fendermint_vm_topdown::Config::new(
let mut config = fendermint_vm_topdown::Config::new(
topdown_config.chain_head_delay,
topdown_config.polling_interval,
topdown_config.exponential_back_off,
topdown_config.exponential_retry_limit,
)
.with_proposal_delay(topdown_config.proposal_delay)
.with_max_proposal_range(topdown_config.max_proposal_range);

if let Some(v) = topdown_config.max_cache_blocks {
info!(value = v, "setting max cache blocks");
config = config.with_max_cache_blocks(v);
}

let ipc_provider = Arc::new(make_ipc_provider_proxy(&settings)?);
let finality_provider =
CachedFinalityProvider::uninitialized(config.clone(), ipc_provider.clone()).await?;
Expand Down
12 changes: 10 additions & 2 deletions fendermint/vm/topdown/src/finality/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,21 @@ impl FinalityWithNull {

if let Some(latest_height) = self.latest_height_in_cache()? {
let r = latest_height >= proposal.height;
tracing::debug!(is_true = r, "incoming proposal height seen?");
tracing::debug!(
is_true = r,
latest_height,
proposal = proposal.height.to_string(),
"incoming proposal height seen?"
);
// requires the incoming height cannot be more advanced than our trusted parent node
Ok(r)
} else {
// latest height is not found, meaning we dont have any prefetched cache, we just be
// strict and vote no simply because we don't know.
tracing::debug!("reject proposal, no data in cache");
tracing::debug!(
proposal = proposal.height.to_string(),
"reject proposal, no data in cache"
);
Ok(false)
}
}
Expand Down
5 changes: 5 additions & 0 deletions fendermint/vm/topdown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl Config {
self
}

pub fn with_max_cache_blocks(mut self, max_cache_blocks: BlockHeight) -> Self {
self.max_cache_blocks = Some(max_cache_blocks);
self
}

pub fn max_proposal_range(&self) -> BlockHeight {
self.max_proposal_range
.unwrap_or(DEFAULT_MAX_PROPOSAL_RANGE)
Expand Down

0 comments on commit 2d3c76d

Please sign in to comment.