Skip to content

Commit

Permalink
Handling transaction revert in eth_estimateGas
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoreliovlabs committed Nov 14, 2024
1 parent 83269bd commit d08229f
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,7 @@ public String call(CallArgumentsParam argsParam, BlockIdentifierParam bnOrId) {
} else {
res = callConstant(args, block);
}
if (res.isRevert()) {
Pair<String, byte[]> programRevert = decodeProgramRevert(res);
String revertReason = programRevert.getLeft();
byte[] revertData = programRevert.getRight();
if (revertData == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError();
}

if (revertReason == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertData);
}

throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertReason, revertData);
}
handleTransactionRevert(res);
hReturn = HexUtils.toUnformattedJsonHex(res.getHReturn());

return hReturn;
Expand Down Expand Up @@ -193,6 +180,9 @@ public String estimateGas(CallArgumentsParam args, @Nonnull BlockIdentifierParam
snapshot
);

ProgramResult res = executor.getResult();
handleTransactionRevert(res);

estimation = internalEstimateGas(executor.getResult());

return estimation;
Expand Down Expand Up @@ -357,4 +347,22 @@ private ProgramResult callConstantWithState(CallArguments args, Block executionB
hexArgs.getFromAddress()
);
}

private void handleTransactionRevert(ProgramResult res) {
if (res.isRevert()) {
Pair<String, byte[]> programRevert = decodeProgramRevert(res);
String revertReason = programRevert.getLeft();
byte[] revertData = programRevert.getRight();

if (revertData == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError();
}

if (revertReason == null) {
throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertData);
}

throw RskJsonRpcRequestException.transactionRevertedExecutionError(revertReason, revertData);
}
}
}

0 comments on commit d08229f

Please sign in to comment.