Skip to content

Commit

Permalink
Execute requests before block persist (#7295)
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia authored Jul 5, 2024
1 parent d2b42d5 commit 6673287
Showing 1 changed file with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Request>> 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());
Expand Down Expand Up @@ -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<List<Request>> 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)
Expand Down

0 comments on commit 6673287

Please sign in to comment.