feat: update backfill sync state to pending when we request it (#9865)

This commit is contained in:
Matthias Seitz
2024-07-29 15:13:23 +02:00
committed by GitHub
parent 223f8ae0f7
commit 067dad79d2
2 changed files with 23 additions and 4 deletions

View File

@ -216,6 +216,13 @@ pub enum EngineApiEvent {
Download(DownloadRequest),
}
impl EngineApiEvent {
/// Returns `true` if the event is a backfill action.
pub const fn is_backfill_action(&self) -> bool {
matches!(self, Self::BackfillAction(_))
}
}
impl From<BeaconConsensusEngineEvent> for EngineApiEvent {
fn from(event: BeaconConsensusEngineEvent) -> Self {
Self::BeaconConsensus(event)

View File

@ -635,14 +635,14 @@ where
}
/// Convenience function to handle an optional tree event.
fn on_maybe_tree_event(&self, event: Option<TreeEvent>) {
fn on_maybe_tree_event(&mut self, event: Option<TreeEvent>) {
if let Some(event) = event {
self.on_tree_event(event);
}
}
/// Handles a tree event.
fn on_tree_event(&self, event: TreeEvent) {
fn on_tree_event(&mut self, event: TreeEvent) {
match event {
TreeEvent::TreeAction(action) => match action {
TreeAction::MakeCanonical(target) => {
@ -659,10 +659,22 @@ where
}
/// Emits an outgoing event to the engine.
fn emit_event(&self, event: impl Into<EngineApiEvent>) {
fn emit_event(&mut self, event: impl Into<EngineApiEvent>) {
let event = event.into();
if event.is_backfill_action() {
debug_assert_eq!(
self.backfill_sync_state,
BackfillSyncState::Idle,
"backfill action should only be emitted when backfill is idle"
);
self.backfill_sync_state = BackfillSyncState::Pending;
debug!(target: "engine", "emitting backfill action event");
}
let _ = self
.outgoing
.send(event.into())
.send(event)
.inspect_err(|err| error!("Failed to send internal event: {err:?}"));
}