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

Fix: Boolean flag consistent usage #1295

Merged
merged 23 commits into from
Apr 1, 2019
Merged

Conversation

kwek20
Copy link
Contributor

@kwek20 kwek20 commented Jan 22, 2019

Description

Changed arity of rescan, revalidate, remote, zmq-enabled, testnet-no-coo-validation, to 1.

--help not changed due to expected behavior in the help command of a program

Added the following to JCommander/BasicIotaConfig:
--testnet
--fake-config

These options do not change anything but force correct usage of parameters to keep Boolean behavior uniform.

Fixes #930

Following PR need to be merged directly after:
iotaledger/iri-regression-tests#10
iotaledger/tiab#4

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Unit tests, regression tests, node runs

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

@kwek20 kwek20 requested review from karimodm and alon-e January 22, 2019 14:06
@kwek20
Copy link
Contributor Author

kwek20 commented Jan 22, 2019

ERROR com.iota.iri.IRI$IRILauncher - There was a problem parsing commandline arguments: Expected a value after parameter --testnet
The command "bash run_all_stable_tests.sh $VERSION" exited with 255.

--testnet must now have true afterwards

@GalRogozinski
Copy link
Contributor

Why did you add fake-config?

@kwek20
Copy link
Contributor Author

kwek20 commented Jan 28, 2019

@GalRogozinski We decided that we want the same behavior for all arguments, which also includes this argument (only used twice in test cases, maybe we should remove it in another PR?)

@karimodm
Copy link
Contributor

karimodm commented Jan 29, 2019

@kwek20 can you merge into this PR karimodm/iri:docker-arity ? So that Docker won't break.

@kwek20
Copy link
Contributor Author

kwek20 commented Jan 29, 2019

@karimodm I did, sort of. Also forgot to push that, sort of.
Its all good now!

Copy link
Contributor

@karimodm karimodm left a comment

Choose a reason for hiding this comment

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

Actual boolean value passed to the new arity = 1 parameters is not honored.

}

@JsonIgnore
@Parameter(names = {"--fake-config"}, description = Config.Descriptions.TESTNET, arity = 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the description Config.Descriptions.TESTNET?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah no, good catch

* @param args the list of program startup arguments
* @return <code>true</code> if this is testnet, otherwise <code>false</code>
*/
private static boolean isTestnet(String[] args) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about parsing the boolean value passed to options that are not --testnet. Is --remote false treated correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No all other parsing happens in JCommander, but this is needed because we instantiate a different config based on testnet, so we have to check that Before using jcommander.. silly

Removing the testnet/mainnet difference is a different issue/pr i think

Copy link
Contributor

Choose a reason for hiding this comment

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

so we have to check that Before using jcommander.. silly

A bit, but do you have a better idea?

@@ -153,7 +170,7 @@ protected void setApiHost(String apiHost) {
}

@JsonIgnore
@Parameter(names = {"--remote"}, description = APIConfig.Descriptions.REMOTE)
@Parameter(names = {"--remote"}, description = APIConfig.Descriptions.REMOTE, arity = 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is not only about setting the arity. If the user passes a false value the functionality should be disabled.

@kwek20
Copy link
Contributor Author

kwek20 commented Feb 1, 2019

@karimodm Can you review again please?

@kwek20 kwek20 requested a review from GalRogozinski February 1, 2019 22:09
@GalRogozinski
Copy link
Contributor

Note that due to a checkstyle exception the code doesn't compile

* @param args the list of program startup arguments
* @return <code>true</code> if this is testnet, otherwise <code>false</code>
*/
private static boolean isTestnet(String[] args) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so we have to check that Before using jcommander.. silly

A bit, but do you have a better idea?

src/main/java/com/iota/iri/conf/BaseIotaConfig.java Outdated Show resolved Hide resolved
protected void setRemote(boolean remote) {
this.apiHost = "0.0.0.0";
if (!remote) this.apiHost = "0.0.0.0";
this.remote = remote;
Copy link
Contributor

Choose a reason for hiding this comment

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

I had a comment that the remote field is not used.
If you are assigning a value to it then it is kind of confusing imo. It makes it look that it is not only about setting apiHost to 0.0.0.0, but you have a field.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we maybe remove the apiHost attribute and make a change in the class using apiHost to check for remote instead and open the listening socket on 0.0.0.0? #makegalhappy

Copy link
Contributor

Choose a reason for hiding this comment

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

We can change getApiHost to check the remote field.
This means that if the user configures both then remote will always win, which may be the desired behavior.

@kwek20,
your call if you want to do that

src/main/java/com/iota/iri/conf/Config.java Outdated Show resolved Hide resolved
src/test/java/com/iota/iri/conf/ConfigTest.java Outdated Show resolved Hide resolved
src/test/java/com/iota/iri/conf/ConfigTest.java Outdated Show resolved Hide resolved
Copy link
Contributor

@karimodm karimodm left a comment

Choose a reason for hiding this comment

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

Just gave an idea on how to turn Gal's comment around. Looks good to me though ;)

protected void setRemote(boolean remote) {
this.apiHost = "0.0.0.0";
if (!remote) this.apiHost = "0.0.0.0";
this.remote = remote;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we maybe remove the apiHost attribute and make a change in the class using apiHost to check for remote instead and open the listening socket on 0.0.0.0? #makegalhappy

@GalRogozinski GalRogozinski added the C-Configuration Component - Configuration label Feb 14, 2019
@kwek20
Copy link
Contributor Author

kwek20 commented Feb 18, 2019

@GalRogozinski @karimodm

Right, for now we have the following scenarios (Defaults are bold):
remote=false, apiHost=localhost: open to localhost
remote=false, apiHost=0.0.0.0: open to everyone
remote=true, apiHost=localhost: open to everyone
remote=true, apiHost=0.0.0.0: open to everyone
remote=false, apiHost=[ip-here]: open to [ip-here]
remote=true, apiHost=[ip-here]: open to everyone -> [ip-here] will be ignored due to the user manually setting remote=true. This behavior is unwanted(Not specific enough). But can be avoided by setting --remote-auth or apiHost to a specific IP, or remote=false. A new PR will be created if this behavior needs to be modified.

Travis fails due to run_all_stable_tests.sh not having the --testnet true change yet. How to add this?

@jakubcech jakubcech added this to the 重庆市 milestone Feb 18, 2019
@GalRogozinski
Copy link
Contributor

Just a reminder to @kwek20
The reason this is not merged is because buildkite and travis fail.
I can take it on myself to fix travis but @kwek20 you have to fix buildkite.

I would say that the easiest way to test for buildkite currently for you is to simply push new commits

kwek20 added a commit to kwek20/iri-regression-tests that referenced this pull request Mar 7, 2019
kwek20 added a commit to iotaledger/tiab that referenced this pull request Mar 7, 2019
Required for changes in iotaledger/iri#1295
Should not be merged before this PR is merged
GalRogozinski pushed a commit to iotaledger/iri-regression-tests that referenced this pull request Mar 12, 2019
@iotaledger iotaledger deleted a comment Mar 12, 2019
@iotaledger iotaledger deleted a comment Mar 13, 2019
@kwek20 kwek20 changed the title Boolean flags Fix: Boolean flag consistent usage Mar 15, 2019
GalRogozinski pushed a commit to iotaledger/tiab that referenced this pull request Mar 19, 2019
Required for changes in iotaledger/iri#1295
Should not be merged before this PR is merged
@iotaledger iotaledger deleted a comment Mar 26, 2019
@iotaledger iotaledger deleted a comment Mar 27, 2019
@GalRogozinski GalRogozinski merged commit 1d69f63 into iotaledger:dev Apr 1, 2019
@jakubcech jakubcech mentioned this pull request May 27, 2019
ahrain added a commit to ahrain/iota-node that referenced this pull request Jun 21, 2019
merlinrabens pushed a commit to merlinrabens/iota-node that referenced this pull request Jun 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-Configuration Component - Configuration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boolean configuration flags have undefined behavior
4 participants