Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Obtain features of a node #1062

Merged
merged 10 commits into from
Nov 1, 2018
Merged

Conversation

kwek20
Copy link
Contributor

@kwek20 kwek20 commented Oct 16, 2018

Description

This PR adds a field called features to the getNodeInfo() API call.
It includes a list of features this node has enabled.

All features are calculated after construction of the node, and before loading of the node, through the Features enum. This enum also contains all the possible features a node can have.

Discussion: What should the actual feature list be?

Fixes #1039
Solves #854

Type of change

  • Enhancement (a non-breaking change which adds functionality)

How Has This Been Tested?

  • Ran getNodeInfo() and the expected features are send back
  • Unit tests do not break

Checklist:

  • My code follows the style guidelines for 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
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@chrisdukakis
Copy link

What do you think about a list of accessible commands? Simple as this:

{
    "accessibleCommands": [
        "getTransactionsToApprove",
        "attachToTangle",
        "storeTransactions",
        "etc..."
     ]
}

import com.iota.iri.conf.IotaConfig;

public enum Feature {
ATTACH_TO_TANGLE("attachToTange"),
Copy link
Contributor

Choose a reason for hiding this comment

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

attachToTange -> attachToTangle


for (String disabled : configuration.getRemoteLimitApi()) {
switch (disabled) {
case "attachToTange":
Copy link
Contributor

Choose a reason for hiding this comment

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

attachToTange -> attachToTangle

@jakubcech
Copy link
Contributor

Not sure if this is expecting some more commits still. Just pointing out that this should have a form of features that are enabled, not just commands that are available. To make the contract clear, you should be able to query a node and discover that PoW is enabled in a clear way, regardless of the logic that enables/disables the remote PoW (which now is attachToTangle not in the remote limit list). Just listing that attachToTangle is available doesn't make that clear unless it's documented (which this should be as a scenario anyway). That's also why we just didn't go with a list of commands after some discussions @chrisdukakis.

Also, #1038 is about request limits.

@kwek20
Copy link
Contributor Author

kwek20 commented Oct 17, 2018

@jakubcech I just need to add comments and some test cases i think could be useful
The list of commands should definitely be useful, still don't know why we don't have that in the Api.java.
Not part of this PR though.

Good point on the Abstraction of feature names!

@iotaledger iotaledger deleted a comment Oct 25, 2018
Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Nice docs

Just a few changes please

* @param instance the instance of this node
* @return A list of features
*/
public static Feature[] calculateFeatures(Iota instance) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this receive IotaConfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be, but maybe some day we have to calculate features based on external factors outside of the config. Like only enable X if the database is up to date.

Or want to change to that when we have the need for it, and use config for now?

Copy link
Contributor

Choose a reason for hiding this comment

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

use configs for now
global scope is evil

/**
* Calculates all features for this Iota node
* @param instance the instance of this node
* @return A list of the features in readable name format
Copy link
Contributor

Choose a reason for hiding this comment

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

We are returning an array not a list


List<String> featureNames = Arrays.stream(features)
.map(feature -> feature.toString())
.collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

it is better to do .toArray(Sting[]::new)

* @param instance the instance of this node
* @return A list of the features in readable name format
*/
public static String[] calculateFeatureNames(Iota instance) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this receive IotaConfig?

It doesn't need the whole instance

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Can you also add the changes from commit from iotaledger/iri-regression#67 here?
The iri-regression is now part of this repository.

Thanks

Feature[] features = calculateFeatures(instance);

String[] featureNames = Arrays.stream(features)
.map(feature -> feature.toString()).toArray(String[]::new);
Copy link
Contributor

Choose a reason for hiding this comment

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

just a style thing I want to follow

Can you put the toArray on a new line? like it was before with collect

@@ -22,6 +22,7 @@ Feature: Test API calls on Machine 1
|appName |
|appVersion |
|duration |
|features |
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

@iotaledger iotaledger deleted a comment Nov 1, 2018
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.

As a developer, I want to be able to programmatically discover whether an IRI node support remote PoW
4 participants