mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refcator: move logic of execute_transaction_with_result_closure into execute_transaction_with_commit_condition
This commit is contained in:
@ -133,24 +133,13 @@ where
|
|||||||
|
|
||||||
fn execute_transaction_with_commit_condition(
|
fn execute_transaction_with_commit_condition(
|
||||||
&mut self,
|
&mut self,
|
||||||
_tx: impl ExecutableTx<Self>,
|
tx: impl ExecutableTx<Self>,
|
||||||
_f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
|
f: impl FnOnce(&ExecutionResult<<Self::Evm as Evm>::HaltReason>) -> CommitChanges,
|
||||||
) -> Result<Option<u64>, BlockExecutionError> {
|
) -> Result<Option<u64>, BlockExecutionError> {
|
||||||
Ok(Some(0))
|
// The sum of the transaction's gas limit, Tg, and the gas utilized in this block prior,
|
||||||
}
|
// must be no greater than the block's gasLimit.
|
||||||
|
|
||||||
fn execute_transaction_with_result_closure(
|
|
||||||
&mut self,
|
|
||||||
tx: impl ExecutableTx<Self>
|
|
||||||
+ IntoTxEnv<<E as alloy_evm::Evm>::Tx>
|
|
||||||
+ RecoveredTx<TransactionSigned>,
|
|
||||||
f: impl for<'b> FnOnce(&'b ExecutionResult<<E as alloy_evm::Evm>::HaltReason>),
|
|
||||||
) -> Result<u64, BlockExecutionError> {
|
|
||||||
// Check if it's a system transaction
|
|
||||||
// let signer = tx.signer();
|
|
||||||
// let is_system_transaction = is_system_transaction(tx.tx());
|
|
||||||
|
|
||||||
let block_available_gas = self.evm.block().gas_limit - self.gas_used;
|
let block_available_gas = self.evm.block().gas_limit - self.gas_used;
|
||||||
|
|
||||||
if tx.tx().gas_limit() > block_available_gas {
|
if tx.tx().gas_limit() > block_available_gas {
|
||||||
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
||||||
transaction_gas_limit: tx.tx().gas_limit(),
|
transaction_gas_limit: tx.tx().gas_limit(),
|
||||||
@ -158,25 +147,33 @@ where
|
|||||||
}
|
}
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
let result_and_state = self
|
|
||||||
|
// Execute transaction.
|
||||||
|
let ResultAndState { result, mut state } = self
|
||||||
.evm
|
.evm
|
||||||
.transact(tx)
|
.transact(tx)
|
||||||
.map_err(|err| BlockExecutionError::evm(err, tx.tx().trie_hash()))?;
|
.map_err(|err| BlockExecutionError::evm(err, tx.tx().trie_hash()))?;
|
||||||
let ResultAndState { result, mut state } = result_and_state;
|
|
||||||
f(&result);
|
if !f(&result).should_commit() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
let gas_used = result.gas_used();
|
let gas_used = result.gas_used();
|
||||||
|
|
||||||
|
// append gas used
|
||||||
if !is_system_transaction(tx.tx()) {
|
if !is_system_transaction(tx.tx()) {
|
||||||
self.gas_used += gas_used;
|
self.gas_used += gas_used;
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply patches after
|
// apply patches after
|
||||||
patch_mainnet_after_tx(
|
patch_mainnet_after_tx(
|
||||||
self.evm.block().number,
|
self.evm.block().number.saturating_to(),
|
||||||
self.receipts.len() as u64,
|
self.receipts.len() as u64,
|
||||||
is_system_transaction(tx.tx()),
|
is_system_transaction(tx.tx()),
|
||||||
&mut state,
|
&mut state,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// Push transaction changeset and calculate header bloom filter for receipt.
|
||||||
self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx {
|
self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx {
|
||||||
tx: tx.tx(),
|
tx: tx.tx(),
|
||||||
evm: &self.evm,
|
evm: &self.evm,
|
||||||
@ -185,9 +182,10 @@ where
|
|||||||
cumulative_gas_used: self.gas_used,
|
cumulative_gas_used: self.gas_used,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Commit the state changes.
|
||||||
self.evm.db_mut().commit(state);
|
self.evm.db_mut().commit(state);
|
||||||
|
|
||||||
Ok(gas_used)
|
Ok(Some(gas_used))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish(self) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {
|
fn finish(self) -> Result<(Self::Evm, BlockExecutionResult<R::Receipt>), BlockExecutionError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user