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

[nc-1756] jsonrpc enabling #91

Merged

Conversation

Errorific
Copy link
Contributor

@Errorific Errorific commented Oct 18, 2018

PR Details

Clique and Ibft need to be toggle'able by the cli, adds 'IBFT' & 'CLIQUE' as options for --rpc-api and --ws-api

Description

Needed to refactor the way RpcApi's get listed so we could use them across new modules, bunch of changes to support that.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Related Issue

Motivation and Context

Ibft & Clique json rpc should work like the mainnet json rpc

Types of changes

  • Docs change / refactoring / dependency upgrade
  • 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 change)

Special notes for your reviewer:

Release note


Prerequisites:

  • I have read the CONTRIBUTING.md document.
  • This code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added appropriate tests that prove my change is effective
  • New and existing tests pass locally with my changes

package tech.pegasys.pantheon.ethereum.jsonrpc.rpcapi;

public interface RpcApi {
String name();
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really the name, it's the CLI value for turning the service on/off.

A nice future feature would be to have this different depending on the method of interaction i.e. Pantheon CLI / other API(s)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

forgetting the latter part, does renaming it to cliValue() work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

public static final String getValue(final RpcApi rpcapi) {
return rpcapi.name();
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this need to lowercase the name to duplicate the original logic? (as the lowercase name is used in the CLI)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from the docs it looked like the uppercase was used, just we have logic in place that normalises it to the uppercase

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense.

public Map<String, JsonRpcMethod> methods(
final ProtocolContext<CliqueContext> context, final Collection<RpcApi> jsonRpcApis) {
final Map<String, JsonRpcMethod> rpcMethods = new HashMap<>();
if (!jsonRpcApis.contains(CliqueRpcApis.CLIQUE)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For this to be reliable, does there need to be only a single instance of the CliqueRpcApis throughout the system? ...and there doesn't seem to a guard on creating a Clique instance (I'm thinking otherwise the contains() is using equals(), which is the default implementation on RpcApi)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup. Now that we're using RpcApi("NAME") I've got an equals & hashcode on RpcApi that fixes the problem

Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3);

private boolean enabled;
private int port;
private String host;
private Collection<String> corsAllowedDomains = Collections.emptyList();
private Collection<RpcApis> rpcApis;

public enum RpcApis {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure I understand the benefit in replacing the enum with an interface in this case, what benefit does the new type provide?

Copy link
Contributor

Choose a reason for hiding this comment

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

that each module can define its own RPC APIs enable options by implementing the RpcApi interface.
With the enum, you are obliged to define all of the possible values here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as per Roberto. Then as per our discussion I'm refactoring to rather than lots of class instances just the RpcApis packages creating sets of RpcApi("NAME") objects, then having an equals/hashcode that knows how to deal with that

@Errorific Errorific merged commit 0d77c51 into PegaSysEng:master Oct 18, 2018
@Errorific Errorific deleted the feature/NC-1756.jsonrpc_enabling branch October 18, 2018 06:23
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.

4 participants