Skip to content

Commit

Permalink
feat(katana): exit on block production error (#2629)
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy authored Nov 4, 2024
1 parent 82d3a85 commit d09cbcf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
3 changes: 0 additions & 3 deletions crates/katana/core/src/service/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ pub enum BlockProductionError {
#[error(transparent)]
Provider(#[from] ProviderError),

#[error("block mining task cancelled")]
BlockMiningTaskCancelled,

#[error("transaction execution task cancelled")]
ExecutionTaskCancelled,

Expand Down
4 changes: 3 additions & 1 deletion crates/katana/core/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

use block_producer::BlockProductionError;
use futures::channel::mpsc::Receiver;
use futures::stream::{Fuse, Stream, StreamExt};
use katana_executor::ExecutorFactory;
Expand Down Expand Up @@ -47,7 +48,7 @@ impl<EF: ExecutorFactory> BlockProductionTask<EF> {
}

impl<EF: ExecutorFactory> Future for BlockProductionTask<EF> {
type Output = ();
type Output = Result<(), BlockProductionError>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
Expand All @@ -68,6 +69,7 @@ impl<EF: ExecutorFactory> Future for BlockProductionTask<EF> {

Err(error) => {
error!(target: LOG_TARGET, %error, "Mining block.");
return Poll::Ready(Err(error));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/pipeline/src/stage/sequencing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::Result;
use futures::future;
use katana_core::backend::Backend;
use katana_core::service::block_producer::BlockProducer;
use katana_core::service::block_producer::{BlockProducer, BlockProductionError};
use katana_core::service::messaging::{MessagingConfig, MessagingService, MessagingTask};
use katana_core::service::{BlockProductionTask, TransactionMiner};
use katana_executor::ExecutorFactory;
Expand Down Expand Up @@ -52,7 +52,7 @@ impl<EF: ExecutorFactory> Sequencing<EF> {
}
}

fn run_block_production(&self) -> TaskHandle<()> {
fn run_block_production(&self) -> TaskHandle<Result<(), BlockProductionError>> {
let pool = self.pool.clone();
let miner = TransactionMiner::new(pool.add_listener());
let block_producer = self.block_producer.clone();
Expand Down
4 changes: 3 additions & 1 deletion crates/katana/storage/db/src/mdbx/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ impl DbTxMut for Tx<RW> {
fn put<T: Table>(&self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> {
let key = key.encode();
let value = value.compress();
self.inner.put(self.get_dbi::<T>()?, key, value, WriteFlags::UPSERT).unwrap();
self.inner.put(self.get_dbi::<T>()?, &key, value, WriteFlags::UPSERT).map_err(|error| {
DatabaseError::Write { error, table: T::NAME, key: Box::from(key.as_ref()) }
})?;
Ok(())
}

Expand Down

0 comments on commit d09cbcf

Please sign in to comment.