Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement json param validation #2118

Closed
wants to merge 14 commits into from

Conversation

rmoreliovlabs
Copy link
Contributor

Description

  • Implemented deserializers added in #2097.
  • Updated affected tests.

Motivation and Context

We want to align GETH's and RSKJ's behavior when handling requests errors to avoid returning "Internal server error" from RSKJ.

How Has This Been Tested?

Using the payloads from the notion document linked in the ticket CORE-3026 for the methods, for the payloads that should return an error, said error should not be "Internal server error". For example:

curl --location 'http://localhost:4444' \
--header 'Content-Type: application/json' \
--data '{
	"jsonrpc":"2.0",
	"method":"eth_getTransactionCount",
	"params":[
		"0xefd2de7da3e0cc04fa07654f34b8bcb8ebbf1015",
		"first" 
	],
	"id":1
}'

Should return:
{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"Invalid block identifier 'first'"}}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

@asoto-iov
Copy link
Contributor

I think this PR should be merged into the branch json_rpc_param_validation

return callArguments;
}

private boolean isPropertyValidHex(String propertyValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use existent parameters as properties instead of repeat validations along the different parameter classes.

return HexUtils.isHex(propertyValue.toLowerCase(), hasPrefix ? 2 : 0);
}

private void validateAddressProperty(String propertyValue, String propertyName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have Address param with its validation for this.

}
}

private void validateDataProperty(String propertyValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we could use HexDataPam instead

public class BlockIdentifierParam implements Serializable {
private static final long serialVersionUID = 1L;

private static final List<String> STRING_IDENTIFIERS = Arrays.asList("earliest", "latest", "pending");
Copy link
Contributor

Choose a reason for hiding this comment

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

These definitions are being repeated in other places. I thin we should have a common class for them. This is a proposal I did in other PR to solve a similar issue. https://github.com/rsksmart/rskj/pull/2080/files#diff-e15384bdcacb6015dc99ec6de04a4cf59bcab14c86685b1174a995653e88d41b


String eth_getBalance(String address) throws Exception;

String eth_getBalance(String address, Map<String, String> blockRef) throws Exception; // NOSONAR
Copy link
Contributor

Choose a reason for hiding this comment

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

This signature is not fully supported, the new changes doesn't support requireCanonical field as it is being done by the map.
This was commented in slack. I think we should add unit test, because we should be able to detect it automatically.

}
}

private void validateMap(Map<String, String> inputs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As commented above this implementation does not support requireCanonical functionality

import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class BlockRefParamTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

These are all the example cases we should be supported by BlockRefParam class

  • "earliest"
  • "0x0"
  • { "blockNumber": "0x0" }
  • { "blockHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" } (hash of the genesis block on the Ethereum main chain)
  • { "blockHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", "requireCanonical": true }
  • { "blockHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", "requireCanonical": false }

And I think at least we should test them to be sure that we are supporting them.

@rmoreliovlabs
Copy link
Contributor Author

Closing this PR in order to create another one with the correct target branch.

@rmoreliovlabs
Copy link
Contributor Author

New PR: #2121

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

Successfully merging this pull request may close these issues.

3 participants