From 1428ed4f55a99c0a25dcb1b11eb913fe0ada6de4 Mon Sep 17 00:00:00 2001 From: Daniel Lehrner Date: Wed, 17 Jul 2024 13:50:46 +0200 Subject: [PATCH] add worldstate to traceEndBlock Signed-off-by: Daniel Lehrner --- .../besu/services/TraceServiceImpl.java | 5 +++-- .../besu/services/TraceServiceImplTest.java | 14 +++++++++++--- .../blockcreation/AbstractBlockCreator.java | 2 +- .../services/tracer/BlockAwareOperationTracer.java | 4 +++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java index 6a0804b6f4..96e83bd881 100644 --- a/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java +++ b/besu/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java @@ -194,6 +194,7 @@ public class TraceServiceImpl implements TraceService { final BlockHeader header = block.getHeader(); tracer.traceStartBlock(block.getHeader(), block.getBody()); + final WorldUpdater worldUpdater = chainUpdater.getNextUpdater(); block .getBody() .getTransactions() @@ -209,7 +210,6 @@ public class TraceServiceImpl implements TraceService { .map(parent -> calculateExcessBlobGasForParent(protocolSpec, parent)) .orElse(BlobGas.ZERO)); - final WorldUpdater worldUpdater = chainUpdater.getNextUpdater(); final TransactionProcessingResult result = transactionProcessor.processTransaction( worldUpdater, @@ -224,7 +224,8 @@ public class TraceServiceImpl implements TraceService { results.add(result); }); - tracer.traceEndBlock(block.getHeader(), block.getBody()); + tracer.traceEndBlock( + block.getHeader(), block.getBody(), blockchainQueries.getWorldStateArchive().getMutable()); return results; } diff --git a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java index 1e734f6231..7835f7cccc 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/TraceServiceImplTest.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.evm.worldstate.WorldView; import org.hyperledger.besu.plugin.data.BlockBody; import org.hyperledger.besu.plugin.data.BlockHeader; @@ -128,7 +129,9 @@ class TraceServiceImplTest { any(), eq(tx), anyBoolean(), any(), any(), anyLong(), any(), anyLong()); }); - verify(opTracer).traceEndBlock(tracedBlock.getHeader(), tracedBlock.getBody()); + verify(opTracer) + .traceEndBlock( + tracedBlock.getHeader(), tracedBlock.getBody(), worldStateArchive.getMutable()); } @Test @@ -183,7 +186,11 @@ class TraceServiceImplTest { anyLong()); }); - verify(opTracer).traceEndBlock(tracedBlock.getHeader(), tracedBlock.getBody()); + verify(opTracer) + .traceEndBlock( + tracedBlock.getHeader(), + tracedBlock.getBody(), + worldStateArchive.getMutable()); }); } @@ -319,7 +326,8 @@ class TraceServiceImplTest { } @Override - public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { + public void traceEndBlock( + final BlockHeader blockHeader, final BlockBody blockBody, final WorldState worldState) { if (!traceEndBlockCalled.add(blockHeader.getBlockHash())) { fail("traceEndBlock already called for block " + blockHeader); } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index 78c32842ff..05775ec907 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -308,7 +308,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { transactionResults.getSelectedTransactions(), ommers, withdrawals, maybeRequests); final Block block = new Block(blockHeader, blockBody); - operationTracer.traceEndBlock(blockHeader, blockBody); + operationTracer.traceEndBlock(blockHeader, blockBody, disposableWorldState); timings.register("blockAssembled"); return new BlockCreationResult(block, transactionResults, timings); } catch (final SecurityModuleException ex) { diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/tracer/BlockAwareOperationTracer.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/tracer/BlockAwareOperationTracer.java index b84c4b69f3..64e7527165 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/tracer/BlockAwareOperationTracer.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/tracer/BlockAwareOperationTracer.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.plugin.services.tracer; import org.hyperledger.besu.evm.tracing.OperationTracer; +import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.plugin.data.BlockBody; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.ProcessableBlockHeader; @@ -46,7 +47,8 @@ public interface BlockAwareOperationTracer extends OperationTracer { * @param blockHeader the header of the block which is traced * @param blockBody the body of the block which is traced */ - default void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) {} + default void traceEndBlock( + final BlockHeader blockHeader, final BlockBody blockBody, final WorldState worldState) {} /** * When building a block this API is called at the start of the process