From 6673287b177308416f6b93d08b408736258b311c Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Sat, 6 Jul 2024 00:42:47 +1000 Subject: [PATCH] Execute requests before block persist (#7295) Signed-off-by: Gabriel-Trintinalia --- .../hyperledger/besu/evmtool/T8nExecutor.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java index 32ffbe10934..429ad59444f 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java @@ -468,6 +468,44 @@ static T8nResult runTest( } } + var requestProcessorCoordinator = protocolSpec.getRequestProcessorCoordinator(); + if (requestProcessorCoordinator.isPresent()) { + var rpc = requestProcessorCoordinator.get(); + ProcessRequestContext context = + new ProcessRequestContext( + blockHeader, + worldState, + protocolSpec, + receipts, + new CachingBlockHashLookup(blockHeader, blockchain), + OperationTracer.NO_TRACING); + Optional> maybeRequests = rpc.process(context); + Hash requestRoot = BodyValidation.requestsRoot(maybeRequests.orElse(List.of())); + + resultObject.put("requestsRoot", requestRoot.toHexString()); + var deposits = resultObject.putArray("depositRequests"); + RequestUtil.filterRequestsOfType(maybeRequests.orElse(List.of()), DepositRequest.class) + .forEach( + deposit -> { + var obj = deposits.addObject(); + obj.put("pubkey", deposit.getPubkey().toHexString()); + obj.put("withdrawalCredentials", deposit.getWithdrawalCredentials().toHexString()); + obj.put("amount", deposit.getAmount().toHexString()); + obj.put("signature", deposit.getSignature().toHexString()); + obj.put("index", deposit.getIndex().toHexString()); + }); + + var withdrawlRequests = resultObject.putArray("withdrawalRequests"); + RequestUtil.filterRequestsOfType(maybeRequests.orElse(List.of()), WithdrawalRequest.class) + .forEach( + wr -> { + var obj = withdrawlRequests.addObject(); + obj.put("sourceAddress", wr.getSourceAddress().toHexString()); + obj.put("validatorPubkey", wr.getValidatorPubkey().toHexString()); + obj.put("amount", wr.getAmount().toHexString()); + }); + } + worldState.persist(blockHeader); resultObject.put("stateRoot", worldState.rootHash().toHexString()); @@ -510,44 +548,6 @@ static T8nResult runTest( resultObject.put("blobGasUsed", Bytes.ofUnsignedLong(blobGasUsed).toQuantityHexString()); } - var requestProcessorCoordinator = protocolSpec.getRequestProcessorCoordinator(); - if (requestProcessorCoordinator.isPresent()) { - var rpc = requestProcessorCoordinator.get(); - ProcessRequestContext context = - new ProcessRequestContext( - blockHeader, - worldState, - protocolSpec, - receipts, - new CachingBlockHashLookup(blockHeader, blockchain), - OperationTracer.NO_TRACING); - Optional> maybeRequests = rpc.process(context); - Hash requestRoot = BodyValidation.requestsRoot(maybeRequests.orElse(List.of())); - - resultObject.put("requestsRoot", requestRoot.toHexString()); - var deposits = resultObject.putArray("depositRequests"); - RequestUtil.filterRequestsOfType(maybeRequests.orElse(List.of()), DepositRequest.class) - .forEach( - deposit -> { - var obj = deposits.addObject(); - obj.put("pubkey", deposit.getPubkey().toHexString()); - obj.put("withdrawalCredentials", deposit.getWithdrawalCredentials().toHexString()); - obj.put("amount", deposit.getAmount().toHexString()); - obj.put("signature", deposit.getSignature().toHexString()); - obj.put("index", deposit.getIndex().toHexString()); - }); - - var withdrawlRequests = resultObject.putArray("withdrawalRequests"); - RequestUtil.filterRequestsOfType(maybeRequests.orElse(List.of()), WithdrawalRequest.class) - .forEach( - wr -> { - var obj = withdrawlRequests.addObject(); - obj.put("sourceAddress", wr.getSourceAddress().toHexString()); - obj.put("validatorPubkey", wr.getValidatorPubkey().toHexString()); - obj.put("amount", wr.getAmount().toHexString()); - }); - } - ObjectNode allocObject = objectMapper.createObjectNode(); worldState .streamAccounts(Bytes32.ZERO, Integer.MAX_VALUE)