mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: Box<dyn Error> -> StageError (#721)
* chore(stages): replace Box<dyn Error> with StageError * chore: fix tests * chore: fmt
This commit is contained in:
committed by
GitHub
parent
19f4132eb4
commit
9d6be78f4b
@ -245,7 +245,7 @@ impl<DB: Database, U: SyncStateUpdater> Pipeline<DB, U> {
|
||||
}
|
||||
Err(err) => {
|
||||
self.events_sender.send(PipelineEvent::Error { stage_id }).await?;
|
||||
return Err(PipelineError::Stage(StageError::Fatal(err)))
|
||||
return Err(PipelineError::Stage(StageError::Fatal(Box::new(err))))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -631,12 +631,12 @@ mod tests {
|
||||
mod utils {
|
||||
use super::*;
|
||||
use async_trait::async_trait;
|
||||
use std::{collections::VecDeque, error::Error};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
pub(crate) struct TestStage {
|
||||
id: StageId,
|
||||
exec_outputs: VecDeque<Result<ExecOutput, StageError>>,
|
||||
unwind_outputs: VecDeque<Result<UnwindOutput, Box<dyn Error + Send + Sync>>>,
|
||||
unwind_outputs: VecDeque<Result<UnwindOutput, StageError>>,
|
||||
}
|
||||
|
||||
impl TestStage {
|
||||
@ -649,10 +649,7 @@ mod tests {
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn add_unwind(
|
||||
mut self,
|
||||
output: Result<UnwindOutput, Box<dyn Error + Send + Sync>>,
|
||||
) -> Self {
|
||||
pub(crate) fn add_unwind(mut self, output: Result<UnwindOutput, StageError>) -> Self {
|
||||
self.unwind_outputs.push_back(output);
|
||||
self
|
||||
}
|
||||
@ -678,7 +675,7 @@ mod tests {
|
||||
&mut self,
|
||||
_: &mut Transaction<'_, DB>,
|
||||
_input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>> {
|
||||
) -> Result<UnwindOutput, StageError> {
|
||||
self.unwind_outputs
|
||||
.pop_front()
|
||||
.unwrap_or_else(|| panic!("Test stage {} unwound too many times.", self.id))
|
||||
|
||||
@ -77,5 +77,5 @@ pub trait Stage<DB: Database>: Send + Sync {
|
||||
&mut self,
|
||||
tx: &mut Transaction<'_, DB>,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>>;
|
||||
) -> Result<UnwindOutput, StageError>;
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ impl<DB: Database, D: BodyDownloader, C: Consensus> Stage<DB> for BodyStage<D, C
|
||||
&mut self,
|
||||
tx: &mut Transaction<'_, DB>,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>> {
|
||||
) -> Result<UnwindOutput, StageError> {
|
||||
// Cursors to unwind bodies, ommers, transactions and tx hash to number
|
||||
let mut body_cursor = tx.cursor_mut::<tables::BlockBodies>()?;
|
||||
let mut ommers_cursor = tx.cursor_mut::<tables::BlockOmmers>()?;
|
||||
|
||||
@ -299,7 +299,7 @@ impl<DB: Database> Stage<DB> for ExecutionStage {
|
||||
&mut self,
|
||||
tx: &mut Transaction<'_, DB>,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>> {
|
||||
) -> Result<UnwindOutput, StageError> {
|
||||
// Acquire changeset cursors
|
||||
let mut account_changeset = tx.cursor_dup_mut::<tables::AccountChangeSet>()?;
|
||||
let mut storage_changeset = tx.cursor_dup_mut::<tables::StorageChangeSet>()?;
|
||||
|
||||
@ -142,7 +142,7 @@ impl<DB: Database, D: HeaderDownloader, C: Consensus, H: HeadersClient, S: Statu
|
||||
&mut self,
|
||||
tx: &mut Transaction<'_, DB>,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>> {
|
||||
) -> Result<UnwindOutput, StageError> {
|
||||
// TODO: handle bad block
|
||||
tx.unwind_table_by_walker::<tables::CanonicalHeaders, tables::HeaderNumbers>(
|
||||
input.unwind_to + 1,
|
||||
|
||||
@ -120,7 +120,7 @@ impl<DB: Database> Stage<DB> for SenderRecoveryStage {
|
||||
&mut self,
|
||||
tx: &mut Transaction<'_, DB>,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>> {
|
||||
) -> Result<UnwindOutput, StageError> {
|
||||
// Lookup latest tx id that we should unwind to
|
||||
let latest_tx_id = tx.get_block_body_by_num(input.unwind_to)?.last_tx_index();
|
||||
tx.unwind_table_by_num::<tables::TxSenders>(latest_tx_id)?;
|
||||
|
||||
@ -84,7 +84,7 @@ impl<DB: Database> Stage<DB> for TotalDifficultyStage {
|
||||
&mut self,
|
||||
tx: &mut Transaction<'_, DB>,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>> {
|
||||
) -> Result<UnwindOutput, StageError> {
|
||||
tx.unwind_table_by_num_hash::<tables::HeaderTD>(input.unwind_to)?;
|
||||
Ok(UnwindOutput { stage_progress: input.unwind_to })
|
||||
}
|
||||
|
||||
@ -64,10 +64,7 @@ pub(crate) trait UnwindStageTestRunner: StageTestRunner {
|
||||
fn validate_unwind(&self, input: UnwindInput) -> Result<(), TestRunnerError>;
|
||||
|
||||
/// Run [Stage::unwind] and return a receiver for the result.
|
||||
async fn unwind(
|
||||
&self,
|
||||
input: UnwindInput,
|
||||
) -> Result<UnwindOutput, Box<dyn std::error::Error + Send + Sync>> {
|
||||
async fn unwind(&self, input: UnwindInput) -> Result<UnwindOutput, StageError> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let (db, mut stage) = (self.tx().inner_raw(), self.stage());
|
||||
tokio::spawn(async move {
|
||||
|
||||
Reference in New Issue
Block a user