Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Revert Reason #1603

Merged
merged 24 commits into from
Jul 4, 2019
Merged

Revert Reason #1603

merged 24 commits into from
Jul 4, 2019

Conversation

pinges
Copy link
Contributor

@pinges pinges commented Jun 25, 2019

PR description

This will include the revert reason associated with revert evm operation as an additional field in the transaction receipt when retrieved via the eth_getTransactionReceipt rpc call.

Fixed Issue(s)

If available, add the revert reason thrown inside a contract to the Transaction Receipt returned via a rpc calls.

@CLAassistant
Copy link

CLAassistant commented Jun 25, 2019

CLA assistant check
All committers have signed the CLA.

@pinges pinges requested review from rain-on, jframe and CjHare June 25, 2019 05:57
Copy link
Contributor

@jframe jframe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good apart from the missing tests

@@ -115,7 +144,9 @@ public void writeTo(final RLPOutput out) {
out.writeLongScalar(cumulativeGasUsed);
out.writeBytesValue(bloomFilter.getBytes());
out.writeList(logs, Log::writeTo);

if (withRevertReason && revertReason.isPresent()) {
out.writeBytesValue(BytesValue.wrap(revertReason.get().getBytes(StandardCharsets.UTF_8)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone has asked for the reason, but it doesn't exist, should we include an empty string?
I.e. Client requested the RevertReason explicitly, probably should give it to them (even if it doesn't exist).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think an empty string makes sense as an empty string is a valid revert reason. And returning a null for the revert reason as it does now makes more sense as there is no revert reason value to return.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 null return value for a null revert reason.

In this context null and an empty string would have different meanings i.e. no revert message vs an empty revert message.

import java.util.Arrays;
import java.util.Optional;

public class BlockDataGeneratorWithReason extends BlockDataGenerator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just be done with Mocking?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be but theres a BlockDataGenerator that already exists. And the code is nicer using the data generator rather than adding mock. I've also added a receipt(revertReason) method to the existing BlockDataGenerator remove need for this extra BlockDataGenerator class.

Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not keen on the EthGetTransactionReceiptRaw naming, I think it's disingenuous, it is just a EthGetTransactionReceipt

import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.tx.RawTransactionManager;

public class CallSmartContractFunctionWithRevert implements Transaction<EthSendTransaction> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What in this class links to WithRevert? ...as it looks like a generic smart contract function invocation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to CallSmartContractFunction

import org.web3j.protocol.core.Response;
import org.web3j.protocol.core.methods.response.TransactionReceipt;

public class EthRawRequestFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is bunk.

The one method in the class is calling eth_getTransactionReceipt, we have simply extended that function to include an additional field. Why not put this new method in Eth?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this rpc request method into the custom rpc factory

@jframe jframe marked this pull request as ready for review July 3, 2019 00:47
Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only Javadoc issues in this pass


/**
* Creates an instance of a state root-encoded transaction receipt.
*
* @param stateRoot the state root for the world state after the transaction has been processed
* @param cumulativeGasUsed the total amount of gas consumed in the block after this transaction
* @param logs the logs generated within the transaction
* @param revertReason whether storing the revert reason is for failed transactions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammer.

@param revertReason whether to store the revert reason for failed transactions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the revert reason not a flag whether or not to store the revert reason. So have updated this and the below constructor to reflect this.

@@ -69,32 +85,40 @@ private TransactionReceipt(
* @param status the status code for the transaction (1 for success and 0 for failure)
* @param cumulativeGasUsed the total amount of gas consumed in the block after this transaction
* @param logs the logs generated within the transaction
* @param revertReason the revert reason
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param revertReason whether to store the revert reason for failed transactions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, the java doc was misleading have updated to the same as the java doc for the other constructor

@@ -115,7 +144,9 @@ public void writeTo(final RLPOutput out) {
out.writeLongScalar(cumulativeGasUsed);
out.writeBytesValue(bloomFilter.getBytes());
out.writeList(logs, Log::writeTo);

if (withRevertReason && revertReason.isPresent()) {
out.writeBytesValue(BytesValue.wrap(revertReason.get().getBytes(StandardCharsets.UTF_8)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 null return value for a null revert reason.

In this context null and an empty string would have different meanings i.e. no revert message vs an empty revert message.

@@ -95,6 +97,13 @@ default boolean isSuccessful() {
* @return the validation result, with the reason for failure (if applicable.)
*/
ValidationResult<TransactionInvalidReason> getValidationResult();

/**
* Returns the reason a transaction was reverted (if applicable).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing word.

Returns the reason why a transaction was reverted (if applicable).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants