-
Notifications
You must be signed in to change notification settings - Fork 76
Fix: Reset block production executor state after chain reorg #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
bfc0d89
503bb66
e73b49f
17a12e6
9ddce95
f51ab17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,8 @@ orchestrator/build/ | |
| orchestrator/node_modules/ | ||
| lib/ | ||
| s3/ | ||
|
|
||
| *.rs | ||
| *.toml | ||
| Cargo.toml | ||
| Cargo.lock | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,6 +281,45 @@ impl ExecutorThread { | |
| let _ = callback.send(Ok(())); | ||
| Default::default() | ||
| } | ||
| super::ExecutorCommand::ResetState(callback) => { | ||
| tracing::info!("🔄 Resetting executor state after reorg"); | ||
| // Reinitialize the state adapter from the current database state | ||
| let new_state_adaptor = match mc_exec::LayeredStateAdapter::new(self.backend.clone()) { | ||
|
||
| Ok(adaptor) => adaptor, | ||
| Err(e) => { | ||
| tracing::error!("Failed to reinitialize state adapter after reorg: {:#}", e); | ||
| let _ = callback.send(Err(super::ExecutorCommandError::ChannelClosed)); | ||
| return Err(e.into()); | ||
| } | ||
| }; | ||
|
|
||
| let latest_block_n = new_state_adaptor.previous_block_n(); | ||
| tracing::info!("✅ State adapter reinitialized to block_n={}", new_state_adaptor.block_n()); | ||
|
||
|
|
||
| // Reset the executor state to NewBlock with the fresh state adapter | ||
| state = ExecutorThreadState::NewBlock(ExecutorStateNewBlock { | ||
| state_adaptor: new_state_adaptor, | ||
| consumed_l1_to_l2_nonces: HashSet::new(), | ||
|
||
| }); | ||
|
|
||
| // Clear any pending transactions by clearing both fields | ||
| to_exec.txs.clear(); | ||
| to_exec.additional_info.clear(); | ||
|
|
||
| // Reset block state flags | ||
| block_empty = true; | ||
| force_close = false; | ||
| l2_gas_consumed_block = 0; | ||
|
|
||
| // Notify the main task that state was reset | ||
| if self.replies_sender.blocking_send(super::ExecutorMessage::StateReset { latest_block_n }).is_err() { | ||
| tracing::error!("Failed to send StateReset message to block production task"); | ||
| } | ||
|
|
||
| let _ = callback.send(Ok(())); | ||
| // Continue the loop to wait for new transactions - don't return a batch | ||
| continue; | ||
| } | ||
| }, | ||
| // Channel closed. Exit gracefully. | ||
| WaitTxBatchOutcome::Exit => return Ok(()), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ use mp_rpc::v0_9_0::{ | |
| ClassAndTxnHash, ContractAndTxnHash, | ||
| }; | ||
| use mp_transactions::{L1HandlerTransactionResult, L1HandlerTransactionWithFee}; | ||
|
|
||
| use mp_utils::service::MadaraServiceId; | ||
| #[async_trait] | ||
| impl MadaraWriteRpcApiV0_1_0Server for Starknet { | ||
| /// Submit a new class v0 declaration transaction, bypassing mempool and all validation. | ||
|
|
@@ -107,6 +107,21 @@ impl MadaraWriteRpcApiV0_1_0Server for Starknet { | |
| .map_err(StarknetRpcApiError::from)?; | ||
| let backend_chain_tip = mc_db::ChainTip::from_storage(fresh_chain_tip); | ||
| self.backend.chain_tip.send_replace(backend_chain_tip); | ||
|
|
||
| // Reset block production executor state if block production is enabled | ||
| let bp_status = self.ctx.service_status(MadaraServiceId::BlockProduction); | ||
| if matches!(bp_status, mp_utils::service::MadaraServiceStatus::On) { | ||
|
||
| if let Some(block_prod_handle) = &self.block_prod_handle { | ||
| tracing::debug!("revertTo: resetting block production state"); | ||
| block_prod_handle | ||
| .reset_state() | ||
| .await | ||
| .context("Resetting block production executor state after reorg") | ||
| .map_err(StarknetRpcApiError::from)?; | ||
| tracing::debug!("revertTo: block production state reset complete"); | ||
| } | ||
| } | ||
|
|
||
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so prettier is for .js, .md files only?