Skip to content

Commit

Permalink
Some small improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed May 8, 2024
1 parent bc0aede commit dbba4a6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 55 deletions.
48 changes: 12 additions & 36 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ use fuel_core_types::{
executor::{
Error as ExecutorError,
Event as ExecutorEvent,
ExecutionResult,
ForcedTransactionFailure,
Result as ExecutorResult,
TransactionExecutionResult,
Expand Down Expand Up @@ -255,7 +254,7 @@ where
let block = partial_block
.generate(&message_ids[..], *event_inbox_root)
.map_err(ExecutorError::BlockHeaderError)?;
Self::uncommitted_block_result(block, execution_data)
Ok(Self::uncommitted_block_result(block, execution_data))
}

pub fn validate_without_commit(
Expand All @@ -266,7 +265,7 @@ where
let (block_executor, storage_tx) =
self.into_executor(consensus_params_version)?;
let execution_data = block_executor.validate_block(block, storage_tx)?;
Self::uncommitted_validation_result(block, execution_data)
Ok(Self::uncommitted_validation_result(block, execution_data))
}

fn into_executor(
Expand All @@ -288,41 +287,10 @@ where
Ok((executor, storage_tx))
}

fn uncommitted_block_result(
block: Block,
data: ExecutionData,
) -> ExecutorResult<UncommittedResult<Changes>> {
let ExecutionData {
coinbase,
used_gas,
tx_status,
skipped_transactions,
events,
changes,
..
} = data;

let finalized_block_id = block.id();

debug!(
"Block {:#x} fees: {} gas: {}",
finalized_block_id, coinbase, used_gas
);

let result = ExecutionResult {
block,
skipped_transactions,
tx_status,
events,
};

Ok(UncommittedResult::new(result, changes))
}

fn uncommitted_validation_result(
block: &Block,
data: ExecutionData,
) -> ExecutorResult<UncommittedValidationResult<Changes>> {
) -> UncommittedValidationResult<Changes> {
let ExecutionData {
coinbase,
used_gas,
Expand All @@ -346,7 +314,15 @@ where
events,
};

Ok(UncommittedValidationResult::new(result, changes))
UncommittedValidationResult::new(result, changes)
}

fn uncommitted_block_result(
block: Block,
data: ExecutionData,
) -> UncommittedResult<Changes> {
let result = Self::uncommitted_validation_result(&block, data);
result.into_execution_result(block)
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/services/importer/src/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ where
return Err(Error::ExecuteGenesis)
}

// TODO: Pass `block` into `ExecutionBlock::Validation` by ref
let (
ValidationResult {
skipped_transactions,
Expand Down
19 changes: 1 addition & 18 deletions crates/services/upgradable-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,24 +500,7 @@ where

match output {
fuel_core_wasm_executor::utils::ReturnType::V1(result) => {
let (
ExecutionResult {
skipped_transactions,
tx_status,
events,
..
},
changes,
) = result?.into();

Ok(Uncommitted::new(
ValidationResult {
skipped_transactions,
tx_status,
events,
},
changes,
))
Ok(result?.into_validation_result())
}
}
}
Expand Down
53 changes: 53 additions & 0 deletions crates/types/src/services/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,59 @@ pub struct ValidationResult {
pub events: Vec<Event>,
}

impl<DatabaseTransaction> UncommittedValidationResult<DatabaseTransaction> {
/// Convert the `UncommittedValidationResult` into the `UncommittedResult`.
pub fn into_execution_result(
self,
block: Block,
) -> UncommittedResult<DatabaseTransaction> {
let Self {
result:
ValidationResult {
skipped_transactions,
tx_status,
events,
},
changes,
} = self;
UncommittedResult::new(
ExecutionResult {
block,
skipped_transactions,
tx_status,
events,
},
changes,
)
}
}

impl<DatabaseTransaction> UncommittedResult<DatabaseTransaction> {
/// Convert the `UncommittedResult` into the `UncommittedValidationResult`.
pub fn into_validation_result(
self,
) -> UncommittedValidationResult<DatabaseTransaction> {
let Self {
result:
ExecutionResult {
skipped_transactions,
tx_status,
events,
..
},
changes,
} = self;
UncommittedValidationResult::new(
ValidationResult {
skipped_transactions,
tx_status,
events,
},
changes,
)
}
}

/// The event represents some internal state changes caused by the block execution.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down

0 comments on commit dbba4a6

Please sign in to comment.