Skip to content

Commit aeda9f6

Browse files
committed
refactor(chain): improve block production pipeline with sync status check
- Enhanced the block production pipeline by adding a check for the node's sync status before proceeding with block production. - Introduced a query to the SyncActor to determine if the node is currently syncing, allowing for better handling of block production requests. - Removed outdated sync check logic to streamline the process and improve clarity in the codebase.
1 parent ae01431 commit aeda9f6

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

app/src/actors_v2/chain/actor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use tokio::sync::RwLock;
1414
use tracing::{debug, error, info, warn};
1515
use uuid::Uuid;
1616

17-
use super::{messages::BlockSource, ChainConfig, ChainError, ChainMetrics, ChainState};
17+
use super::{
18+
messages::BlockSource, ChainConfig, ChainError, ChainMetrics, ChainState,
19+
};
1820

1921
use crate::actors_v2::{
2022
engine::EngineActor,

app/src/actors_v2/chain/handlers.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,14 @@ impl Handler<ChainMessage> for ChainActor {
6161
"Node is not configured as validator".to_string(),
6262
))
6363
})
64-
} else if !self.state.is_synced() {
65-
info!("Block production requested but node is not synced");
66-
Box::pin(async move { Err(ChainError::NotSynced) })
6764
} else {
68-
// Complete block production pipeline (Phase 2)
65+
// Complete block production pipeline
6966
let start_time = Instant::now();
7067
let correlation_id = Uuid::new_v4();
7168
let engine_actor = self.engine_actor.clone();
7269
let storage_actor = self.storage_actor.clone();
7370
let network_actor = self.network_actor.clone();
71+
let sync_actor = self.sync_actor.clone();
7472

7573
// Capture simple state data and clone for async
7674
let config_validator_address = self.config.validator_address;
@@ -85,6 +83,37 @@ impl Handler<ChainMessage> for ChainActor {
8583
);
8684

8785
Box::pin(async move {
86+
// Phase 3: Check sync status before producing blocks (query SyncActor)
87+
if let Some(ref sync_actor) = sync_actor {
88+
match sync_actor.send(crate::actors_v2::network::SyncMessage::GetSyncStatus).await {
89+
Ok(Ok(crate::actors_v2::network::SyncResponse::Status(status))) => {
90+
if status.is_syncing {
91+
info!(
92+
slot = slot,
93+
current_height = status.current_height,
94+
target_height = status.target_height,
95+
"Skipping block production - node is syncing"
96+
);
97+
return Err(ChainError::NotSynced);
98+
}
99+
debug!(
100+
slot = slot,
101+
current_height = status.current_height,
102+
"Node is synced - proceeding with block production"
103+
);
104+
}
105+
other => {
106+
error!(
107+
slot = slot,
108+
response = ?other,
109+
"Failed to get sync status from SyncActor - skipping block production"
110+
);
111+
return Err(ChainError::NotSynced);
112+
}
113+
}
114+
}
115+
116+
// Node is synced (or sync status unavailable) - proceed with block production
88117
// Step 2: Get parent block from storage
89118
// Capture both execution hash (for Geth) and consensus hash (for ConsensusBlock.parent_hash)
90119
let (parent_execution_hash, parent_consensus_hash) = if let Some(ref storage_actor) = storage_actor {

0 commit comments

Comments
 (0)