Skip to content

Commit

Permalink
Refactor: take blockchain out of MainnetTransactionProcessor (#6962)
Browse files Browse the repository at this point in the history
Remove an unused parameter in MainnetTransactionProcessor, as well as
all code supporting sending that parameter.

Signed-off-by: Danno Ferrin <danno@numisight.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
shemnon and macfarla authored Apr 22, 2024
1 parent 32dae8f commit 381e692
Show file tree
Hide file tree
Showing 20 changed files with 6 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ private List<TransactionProcessingResult> trace(
final WorldUpdater worldUpdater = chainUpdater.getNextUpdater();
final TransactionProcessingResult result =
transactionProcessor.processTransaction(
blockchain,
worldUpdater,
header,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public TransactionTrace apply(final TransactionTrace transactionTrace) {
final BlockHashLookup blockHashLookup = new CachingBlockHashLookup(header, blockchain);
result =
transactionProcessor.processTransaction(
blockchain,
chainUpdater.getNextUpdater(),
header,
transactionTrace.getTransaction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public <T> Optional<T> beforeTransactionInBlock(
transaction, header, blockchain, transactionProcessor, blobGasPrice));
} else {
transactionProcessor.processTransaction(
blockchain,
mutableWorldState.updater(),
header,
transaction,
Expand All @@ -134,7 +133,6 @@ public <T> Optional<T> afterTransactionInBlock(
(transaction, blockHeader, blockchain, transactionProcessor, blobGasPrice) -> {
final ProtocolSpec spec = protocolSchedule.getByBlockHeader(blockHeader);
transactionProcessor.processTransaction(
blockchain,
mutableWorldState.updater(),
blockHeader,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private BlockReplay.TransactionAction<TransactionTrace> prepareReplayAction(
chainedUpdater = chainedUpdater.updater();
final TransactionProcessingResult result =
transactionProcessor.processTransaction(
blockchain,
chainedUpdater,
header,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ private TransactionProcessingResult processTransaction(
final OperationTracer tracer,
final Wei blobGasPrice) {
return transactionProcessor.processTransaction(
blockchain,
worldUpdater,
header,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public void traceTransactionShouldReturnResultFromProcessTransaction() {
final WorldUpdater updater = mock(WorldUpdater.class);
when(mutableWorldState.updater()).thenReturn(updater);
when(transactionProcessor.processTransaction(
eq(blockchain),
eq(updater),
eq(blockHeader),
eq(transaction),
Expand Down Expand Up @@ -269,7 +268,6 @@ public void traceTransactionToFileShouldReturnResultFromProcessTransaction() thr
final WorldUpdater stackedUpdater = mock(StackedUpdater.class);
when(updater.updater()).thenReturn(stackedUpdater);
when(transactionProcessor.processTransaction(
eq(blockchain),
eq(stackedUpdater),
eq(blockHeader),
eq(transaction),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ private TransactionProcessingResult processTransaction(
final BlockHashLookup blockHashLookup =
new CachingBlockHashLookup(blockSelectionContext.processableBlockHeader(), blockchain);
return transactionProcessor.processTransaction(
blockchain,
worldStateUpdater,
blockSelectionContext.processableBlockHeader(),
pendingTransaction.getTransaction(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ protected void ensureTransactionIsValid(
final long gasRemaining,
final long processingTime) {
when(transactionProcessor.processTransaction(
any(), any(), any(), eq(tx), any(), any(), any(), anyBoolean(), any(), any()))
any(), any(), eq(tx), any(), any(), any(), anyBoolean(), any(), any()))
.thenAnswer(
invocation -> {
if (processingTime > 0) {
Expand All @@ -1370,7 +1370,7 @@ protected void ensureTransactionIsInvalid(
final TransactionInvalidReason invalidReason,
final long processingTime) {
when(transactionProcessor.processTransaction(
any(), any(), any(), eq(tx), any(), any(), any(), anyBoolean(), any(), any()))
any(), any(), eq(tx), any(), any(), any(), anyBoolean(), any(), any()))
.thenAnswer(
invocation -> {
if (processingTime > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public void shouldTraceSStoreOperation() {
final WorldUpdater createTransactionUpdater = worldState.updater();
TransactionProcessingResult result =
transactionProcessor.processTransaction(
blockchain,
createTransactionUpdater,
genesisBlockHeader,
createTransaction,
Expand Down Expand Up @@ -133,7 +132,6 @@ public void shouldTraceSStoreOperation() {
final WorldUpdater storeUpdater = worldState.updater();
result =
transactionProcessor.processTransaction(
blockchain,
storeUpdater,
genesisBlockHeader,
executeTransaction,
Expand Down Expand Up @@ -172,7 +170,6 @@ public void shouldTraceContractCreation() {
new BytesValueRLPInput(Bytes.fromHexString(CONTRACT_CREATION_TX), false));
final BlockHeader genesisBlockHeader = genesisBlock.getHeader();
transactionProcessor.processTransaction(
blockchain,
worldStateArchive
.getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash())
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public BlockProcessingResult processBlock(

final TransactionProcessingResult result =
transactionProcessor.processTransaction(
blockchain,
worldStateUpdater,
blockHeader,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator;
Expand Down Expand Up @@ -101,7 +100,6 @@ public MainnetTransactionProcessor(
/**
* Applies a transaction to the current system state.
*
* @param blockchain The current blockchain
* @param worldState The current world state
* @param blockHeader The current block header
* @param transaction The transaction to process
Expand All @@ -115,7 +113,6 @@ public MainnetTransactionProcessor(
* @see TransactionValidationParams
*/
public TransactionProcessingResult processTransaction(
final Blockchain blockchain,
final WorldUpdater worldState,
final ProcessableBlockHeader blockHeader,
final Transaction transaction,
Expand All @@ -125,7 +122,6 @@ public TransactionProcessingResult processTransaction(
final TransactionValidationParams transactionValidationParams,
final Wei blobGasPrice) {
return processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand All @@ -141,7 +137,6 @@ public TransactionProcessingResult processTransaction(
/**
* Applies a transaction to the current system state.
*
* @param blockchain The current blockchain
* @param worldState The current world state
* @param blockHeader The current block header
* @param transaction The transaction to process
Expand All @@ -156,7 +151,6 @@ public TransactionProcessingResult processTransaction(
* @see TransactionValidationParams
*/
public TransactionProcessingResult processTransaction(
final Blockchain blockchain,
final WorldUpdater worldState,
final ProcessableBlockHeader blockHeader,
final Transaction transaction,
Expand All @@ -167,7 +161,6 @@ public TransactionProcessingResult processTransaction(
final OperationTracer operationTracer,
final Wei blobGasPrice) {
return processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand All @@ -183,18 +176,16 @@ public TransactionProcessingResult processTransaction(
/**
* Applies a transaction to the current system state.
*
* @param blockchain The current blockchain
* @param worldState The current world state
* @param blockHeader The current block header
* @param transaction The transaction to process
* @param operationTracer The tracer to record results of each EVM operation
* @param miningBeneficiary The address which is to receive the transaction fee
* @param operationTracer The tracer to record results of each EVM operation
* @param blockHashLookup The {@link BlockHashLookup} to use for BLOCKHASH operations
* @param isPersistingPrivateState Whether the resulting private state will be persisted
* @return the transaction result
*/
public TransactionProcessingResult processTransaction(
final Blockchain blockchain,
final WorldUpdater worldState,
final ProcessableBlockHeader blockHeader,
final Transaction transaction,
Expand All @@ -204,7 +195,6 @@ public TransactionProcessingResult processTransaction(
final Boolean isPersistingPrivateState,
final Wei blobGasPrice) {
return processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand All @@ -220,19 +210,17 @@ public TransactionProcessingResult processTransaction(
/**
* Applies a transaction to the current system state.
*
* @param blockchain The current blockchain
* @param worldState The current world state
* @param blockHeader The current block header
* @param transaction The transaction to process
* @param operationTracer The tracer to record results of each EVM operation
* @param miningBeneficiary The address which is to receive the transaction fee
* @param operationTracer The tracer to record results of each EVM operation
* @param blockHashLookup The {@link BlockHashLookup} to use for BLOCKHASH operations
* @param isPersistingPrivateState Whether the resulting private state will be persisted
* @param transactionValidationParams The transaction validation parameters to use
* @return the transaction result
*/
public TransactionProcessingResult processTransaction(
final Blockchain blockchain,
final WorldUpdater worldState,
final ProcessableBlockHeader blockHeader,
final Transaction transaction,
Expand All @@ -243,7 +231,6 @@ public TransactionProcessingResult processTransaction(
final TransactionValidationParams transactionValidationParams,
final Wei blobGasPrice) {
return processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand All @@ -257,7 +244,6 @@ public TransactionProcessingResult processTransaction(
}

public TransactionProcessingResult processTransaction(
final Blockchain ignoredBlockchain,
final WorldUpdater worldState,
final ProcessableBlockHeader blockHeader,
final Transaction transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public BlockProcessingResult processBlock(
// depend on public state
final TransactionProcessingResult result =
transactionProcessor.processTransaction(
blockchain,
worldStateUpdater,
blockHeader,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public BlockProcessingResult processBlock(

final TransactionProcessingResult result =
transactionProcessor.processTransaction(
blockchain,
worldStateUpdater,
blockHeader,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ public Optional<TransactionSimulatorResult> processWithWorldUpdater(
final Transaction transaction = maybeTransaction.get();
final TransactionProcessingResult result =
transactionProcessor.processTransaction(
blockchain,
updater,
blockHeaderToProcess,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator;
Expand Down Expand Up @@ -69,7 +68,6 @@ class MainnetTransactionProcessorTest {
@Mock private AbstractMessageProcessor contractCreationProcessor;
@Mock private AbstractMessageProcessor messageCallProcessor;

@Mock private Blockchain blockchain;
@Mock private WorldUpdater worldState;
@Mock private ProcessableBlockHeader blockHeader;
@Mock private Transaction transaction;
Expand Down Expand Up @@ -124,7 +122,6 @@ void shouldWarmCoinbaseIfRequested() {

var transactionProcessor = createTransactionProcessor(true);
transactionProcessor.processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand All @@ -138,7 +135,6 @@ void shouldWarmCoinbaseIfRequested() {

transactionProcessor = createTransactionProcessor(false);
transactionProcessor.processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand Down Expand Up @@ -187,7 +183,6 @@ void shouldTraceEndTxOnFailingTransaction(final Exception exception) {
var transactionProcessor = createTransactionProcessor(true);
try {
transactionProcessor.processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand Down Expand Up @@ -237,7 +232,6 @@ void shouldCallTransactionValidatorWithExpectedTransactionValidationParams() {
var transactionProcessor = createTransactionProcessor(false);

transactionProcessor.processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private ProtocolSpec mockProtocolSpec() {
final MainnetTransactionProcessor mockPublicTransactionProcessor =
mock(MainnetTransactionProcessor.class);
when(mockPublicTransactionProcessor.processTransaction(
any(), any(), any(), any(), any(), any(), anyBoolean(), any(), any()))
any(), any(), any(), any(), any(), anyBoolean(), any(), any()))
.thenReturn(
TransactionProcessingResult.successful(
Collections.emptyList(), 0, 0, Bytes.EMPTY, ValidationResult.valid()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ private void mockProcessorStatusForTransaction(
}

when(transactionProcessor.processTransaction(
any(),
any(),
any(),
eq(transaction),
Expand All @@ -758,7 +757,6 @@ private void mockProcessorStatusForTransaction(
private void verifyTransactionWasProcessed(final Transaction expectedTransaction) {
verify(transactionProcessor)
.processTransaction(
any(),
any(),
any(),
eq(expectedTransaction),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseEipSpec;
import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseSpec;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.evm.account.Account;
Expand Down Expand Up @@ -248,14 +247,11 @@ private void traceTestSpecs(final String test, final List<GeneralStateTestCaseEi
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(blockHeader);
final MainnetTransactionProcessor processor = protocolSpec.getTransactionProcessor();
final WorldUpdater worldStateUpdater = worldState.updater();
final ReferenceTestBlockchain blockchain =
new ReferenceTestBlockchain(blockHeader.getNumber());
final Stopwatch timer = Stopwatch.createStarted();
// Todo: EIP-4844 use the excessBlobGas of the parent instead of BlobGas.ZERO
final Wei blobGasPrice = protocolSpec.getFeeMarket().blobGasPricePerGas(BlobGas.ZERO);
final TransactionProcessingResult result =
processor.processTransaction(
blockchain,
worldStateUpdater,
blockHeader,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams;
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
import org.hyperledger.besu.ethereum.referencetests.BonsaiReferenceTestWorldState;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestEnv;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules;
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState;
Expand Down Expand Up @@ -253,8 +252,6 @@ static T8nResult runTest(
final BlockHeader blockHeader = referenceTestEnv.updateFromParentValues(protocolSpec);
final MainnetTransactionProcessor processor = protocolSpec.getTransactionProcessor();
final WorldUpdater worldStateUpdater = worldState.updater();
final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(blockHeader.getNumber());

final Wei blobGasPrice =
protocolSpec
.getFeeMarket()
Expand Down Expand Up @@ -297,7 +294,6 @@ static T8nResult runTest(
tracer.traceStartTransaction(worldStateUpdater, transaction);
result =
processor.processTransaction(
blockchain,
worldStateUpdater,
blockHeader,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ public static void executeTest(final GeneralStateTestCaseEipSpec spec) {
.blobGasPricePerGas(blockHeader.getExcessBlobGas().orElse(BlobGas.ZERO));
final TransactionProcessingResult result =
processor.processTransaction(
blockchain,
worldStateUpdater,
worldStateUpdater,
blockHeader,
transaction,
blockHeader.getCoinbase(),
Expand Down

0 comments on commit 381e692

Please sign in to comment.