Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Remove look ahead (#442)
Browse files Browse the repository at this point in the history
* remove look ahead in query topdown

* use three pointers

* up crate

* fix error

* Update fendermint/vm/topdown/src/sync/syncer.rs

Co-authored-by: Akosh Farkash <[email protected]>

* fix from integration testing

* remove to_confirm pointer

* restrict memory size

* dont propose until interval reached

* update latest height

* split tendermint query to separete file

* Update fendermint/vm/topdown/src/sync/syncer.rs

Co-authored-by: adlrocha <[email protected]>

* fix test linting

* fix tests

* more tests

* check hash when executing

* sync

* sort by nonce

* fmt

* more unit tests

* New proposal logic (#447)

* new proposal logic

* fmt

* fix typo

* minor changes

* adding check

* ignore proposal height

* Fix type

* expose config params

---------

Co-authored-by: Alfonso de la Rocha <[email protected]>

---------

Signed-off-by: Alfonso de la Rocha <[email protected]>
Co-authored-by: Akosh Farkash <[email protected]>
Co-authored-by: adlrocha <[email protected]>
Co-authored-by: Alfonso de la Rocha <[email protected]>
  • Loading branch information
4 people authored Nov 29, 2023
1 parent 7aa9443 commit dca666c
Show file tree
Hide file tree
Showing 18 changed files with 1,445 additions and 875 deletions.
6 changes: 6 additions & 0 deletions fendermint/app/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ pub struct TopDownConfig {
/// conservative and avoid other from rejecting the proposal because they don't see the
/// height as final yet.
pub chain_head_delay: BlockHeight,
/// The number of blocks on top of `chain_head_delay` to wait before proposing a height
/// as final on the parent chain, to avoid slight disagreements between validators whether
/// a block is final, or not just yet.
pub proposal_delay: BlockHeight,
/// The max number of blocks one should make the topdown proposal
pub max_proposal_range: BlockHeight,
/// Parent syncing cron period, in seconds
#[serde_as(as = "DurationSeconds<u64>")]
pub polling_interval: Duration,
Expand Down
14 changes: 8 additions & 6 deletions fendermint/app/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ async fn run(settings: Settings) -> anyhow::Result<()> {
let (parent_finality_provider, ipc_tuple) = if settings.ipc.is_topdown_enabled() {
info!("topdown finality enabled");
let topdown_config = settings.ipc.topdown_config()?;
let config = fendermint_vm_topdown::Config {
chain_head_delay: topdown_config.chain_head_delay,
polling_interval: topdown_config.polling_interval,
exponential_back_off: topdown_config.exponential_back_off,
exponential_retry_limit: topdown_config.exponential_retry_limit,
};
let 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);
let ipc_provider = Arc::new(create_ipc_provider_proxy(&settings)?);
let finality_provider =
CachedFinalityProvider::uninitialized(config.clone(), ipc_provider.clone()).await?;
Expand Down
19 changes: 13 additions & 6 deletions fendermint/vm/interpreter/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,21 @@ where
"chain interpreter committed topdown finality",
);

// The commitment of the finality for block `N` triggers
// the execution of all side-effects up till `N-1`, as for
// deferred execution chains, this is the latest state that
// we know for sure that we have available.
let execution_fr = prev_height;
let execution_to = finality.height - 1;

// error happens if we cannot get the validator set from ipc agent after retries
let validator_changes = provider
.validator_changes_from(prev_height + 1, finality.height)
.validator_changes_from(execution_fr, execution_to)
.await
.context("failed to fetch validator changes")?;
tracing::debug!(
from = prev_height + 1,
to = finality.height,
from = execution_fr,
to = execution_to,
msgs = validator_changes.len(),
"chain interpreter received total validator changes"
);
Expand All @@ -282,13 +289,13 @@ where

// error happens if we cannot get the cross messages from ipc agent after retries
let msgs = provider
.top_down_msgs_from(prev_height + 1, p.height as u64, &finality.block_hash)
.top_down_msgs_from(execution_fr, execution_to)
.await
.context("failed to fetch top down messages")?;
tracing::debug!(
number_of_messages = msgs.len(),
start = prev_height + 1,
end = p.height,
start = execution_fr,
end = execution_to,
"chain interpreter received topdown msgs",
);

Expand Down
4 changes: 4 additions & 0 deletions fendermint/vm/topdown/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<K: PrimInt + Debug, V> SequentialKeyCache<K, V> {
self.increment
}

pub fn size(&self) -> usize {
self.data.len()
}

pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
Expand Down
4 changes: 0 additions & 4 deletions fendermint/vm/topdown/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ pub enum Error {
ParentChainReorgDetected,
#[error("Cannot query parent at height {1}: {0}")]
CannotQueryParent(String, BlockHeight),
/// This error happens when querying top down messages, the block ahead are all null rounds.
/// See `parent_views_at_height` for detailed explanation
#[error("Look ahead limit reached from {0}: {1}")]
LookAheadLimitReached(BlockHeight, BlockHeight),
}
Loading

0 comments on commit dca666c

Please sign in to comment.