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

[PAN-2946] - changes in core JSON-RPC method to support ReTestEth #1815

Merged
merged 6 commits into from
Aug 2, 2019

Conversation

shemnon
Copy link
Contributor

@shemnon shemnon commented Aug 1, 2019

PR description

Some of the methods need to have a changeable reference to stuff like
blockchainqueries. For the impacted methods the solution is to wrap them
in a Supplier<> interface. This includes new constructors for re-used methods.

Also include the debug_accountRangeAt method as it'ss namespaced as debug.

Also, rename the getter methods to align with standards.

shemnon added 3 commits August 1, 2019 14:54
Some of the methods need to have a changeable reference to stuff like
blockchainqueries.  For the impacted methods the solution is to wrap them
in a Supplier<> interface.  This includes new constructors for re-used methods.

Also include the debug_accountRangeAt method as it's namespaced as debug.

Also, rename the getter methods to align with standards.
* DebugStorageRange is needed too.
* ethGetBlockByNumber needs the coinbase in a field labeled "author"
  * Set a flag for the previous to by default not send the coinbase in response
  * jsonrpc spec tests to verify author not sent.
* On a rejected transaciton eth_sendRawTransaction wants an hash of Empty
  * again, controlled by a flag with option off
*
@shemnon shemnon marked this pull request as ready for review August 2, 2019 06:00
@Override
protected Object resultByBlockNumber(final JsonRpcRequest request, final long blockNumber) {
final Object[] params = request.getParams();
final String addressHash = parameters.required(params, 2, String.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
final String addressHash = parameters.required(params, 2, String.class);
final Hash addressHash = parameters.required(params, 2, Hash.class);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Retesteth likes to pass in odd length addresses, particularly zero addresses. Which is why I take it in as a string and at line 81 parse it in a lenient fashion. Going straight to hash throws Caused by: java.lang.IllegalArgumentException: Invalid odd-length hex binary representation 0


@Override
protected BlockParameter blockParameter(final JsonRpcRequest request) {
return parameters.required(request.getParams(), 0, BlockParameter.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

The docs say the first parameter should be a number or hash. As is, this will only handle numbers or tags ("latest", "earliest", etc).

If we want to match the spec, we could extend BlockParameter with a new BlockParameterOrHash class. Or we could push back since none of the other JSON-RPC API's work like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The docs say hash, but we never see a hash in practice. If it becomes a retesteth requirement I will probably go the BlockParameterOrHash route, but as of now the docs require a form that is not used.

Copy link
Contributor Author

@shemnon shemnon Aug 2, 2019

Choose a reason for hiding this comment

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

LooksLike DebugStorageRangeAt will need the BlockParameterOrHash treatment. Recent change pushed into ReTestEth needs it now. :(

.get()
.streamAccounts(Bytes32.fromHexStringLenient(addressHash), maxResults + 1)
.collect(Collectors.toList());
Bytes32 nextKey = Bytes32.ZERO;
Copy link
Contributor

Choose a reason for hiding this comment

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

For symmetry with debug_storageRangeAt, I think nextKey should be null (not returned) in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

retesteh requires the zeros return. Not the most fault tolerant code.

@@ -89,6 +102,7 @@
this.timestamp = Quantity.create(header.getTimestamp());
this.ommers = ommers;
this.transactions = transactions;
this.coinbase = includeCoinbase ? header.getCoinbase().toString() : null;
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 it's cleaner to just always include coinbase instead of adding a flag to switch on this. Shouldn't hurt anything if there's extra data returned that users aren't expecting. Kind of odd that it's not a standard field anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only is it not in the JSON-RPC Spec, what reteseth wants is an author field which has the same meaning test wise as coinbase. If we expose it for all I would still want a flag and we expose coinbase not author.

@@ -185,4 +199,10 @@ public String getTimestamp() {
public List<TransactionResult> getTransactions() {
return transactions;
}

@JsonGetter(value = "author")
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 an odd name for this field 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very odd.

@@ -216,28 +216,8 @@ Formatter will be turned on to make this easier to read (one spec per line)

specs.put(EthNewPendingTransactionFilter.class, "eth_newPendingTransactionFilter");

specs.put(EthUninstallFilter.class, "eth_uninstallFilter_NonexistentFilter");
specs.put(EthUninstallFilter.class, "eth_uninstallFilter_FilterIdTooLong");
specs.put(EthUninstallFilter.class, "eth_uninstallFilter_FilterIdNegative");
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened to these - bad merge??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bad merge. Will fix.

* restore missing spec tests
* rename to debig_accountRange
* make sure stack trace come with invalidjsonrpcparams catch
"request": {
"id": 414,
"jsonrpc": "2.0",
"method": "debug_accountRangeAt",
Copy link
Contributor

Choose a reason for hiding this comment

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

This method needs a rename for the tests too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, temporarily. Retesteth is changing the name but is unstable where they changed it.

Copy link
Contributor

@mbaxter mbaxter left a comment

Choose a reason for hiding this comment

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

LGTM pending test fixes

* add BlockParameterOrBlockHash
* Wire up debug_storageRangeAt and debug_accountRange to use it
* spec tests
@shemnon
Copy link
Contributor Author

shemnon commented Aug 2, 2019

BlockParameterOrHash change is in, to both Debug methods.

@shemnon shemnon merged commit 7eac896 into PegaSysEng:master Aug 2, 2019
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.

2 participants