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

refactor milestone signature parameters to be configurable #1322

Merged
merged 7 commits into from
Feb 27, 2019

Conversation

alon-e
Copy link
Contributor

@alon-e alon-e commented Feb 5, 2019

Description

Refactor of milestone signatures to allow easy configuration of a different Coordinator.
with higher Merkle tree depth.

Fixes # (issue)

Type of change

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

How Has This Been Tested?

  • Run locally on Mainnet and Testnet (testing all new flags)
  • giving --testnet-coordinator-signature-mode a bad value, like KERM would give the following error:
02/05 14:15:31.993 [main] ERROR com.iota.iri.IRI$IRILauncher - There was a problem parsing commandline arguments: Invalid value for --testnet-coordinator-signature-mode parameter. Allowed values:[CURLP81, CURLP27, KERL]


if (milestoneIndex < 0 || milestoneIndex >= 0x200000) {
if (milestoneIndex < 0 || milestoneIndex >= maxMilestoneIndex) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will allow higher depths of trees. (and tighter validation for lower trees)

}

@JsonProperty("COORDINATOR_SIGNATURE_MODE")
@Parameter(names = "--testnet-coordinator-signature-mode", description = MilestoneConfig.Descriptions.COORDINATOR_SIGNATURE_MODE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally added a converter and validator, a la compass
https://github.com/iotaledger/compass/blob/3aaf05763cded4a229cc23f8e9cd3d53256948db/compass/conf/BaseConfiguration.java#L49

but the default validation is really good (see PR::test)

/**
* @return {@value Descriptions#NUMBER_OF_KEYS_IN_A_MILESTONE}
*/
int getNumberOfKeysInMilestone();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add default value to the description like in #1159?

private ConsensusConfig config;
private boolean skipValidation;

private int maxMilestoneIndex;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you decide to extract those from the config object and not just use the getters like before.
In my opinion this just saves lots of lines of code...

I think the nicer thing to do is to have HashFactory.ADDRESS.create(config.getCoordinator()).
I suppose maxMilestoneIndex = 1 << config.getNumberOfKeysInMilestone(); can also be done as an automatically calculated config in my opinion.

The thing is that if we do this change here, we will have to do the same design in the rest of the code.

So what I am asking for you is either:

  1. Explain why you think it is better to not use config getters. In this case then I insist that at least the fields will be final. According to DDD services should be stateless. I say that at the very least they should be immutable. (The Hash field won't be immutable, as you well know, but we will solve it)
  2. Move everything back to the config and use getters (what I prefer). There is a reason why the setters are not visible

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be interesting to have a MilestoneService instance that can validate milestones coming from another coo than the one configured (wink, wink ...)

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 reason is that these parameters are fetched, constructed and calculated often. I think it's not efficient to do that, but I get the point of not storing state.

Anyways, I'm not sure I'll be available this week to make the change, if you find time to do it great, if not I'll update when I get to it.

Copy link
Contributor

@GalRogozinski GalRogozinski Feb 18, 2019

Choose a reason for hiding this comment

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

I wouldn't expect this to be the bottleneck in any scenario.
Doing a get should be really fast
I would expect that the HotSpots compiler will optimize inefficiencies that occur

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.

Ready for configurable!

private ConsensusConfig config;
private boolean skipValidation;

private int maxMilestoneIndex;
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be interesting to have a MilestoneService instance that can validate milestones coming from another coo than the one configured (wink, wink ...)

coordinatorSignatureMode = config.getCoordinatorSignatureMode();
coordinatorSecurityLevel = config.getCoordinatorSecurityLevel();
numberOfKeysInMilestone = config.getNumberOfKeysInMilestone();
skipValidation = (config.isTestnet() && config.isDontValidateTestnetMilestoneSig());
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoids very very ugly line

# Conflicts:
#	src/main/java/com/iota/iri/service/milestone/impl/MilestoneServiceImpl.java
@GalRogozinski GalRogozinski force-pushed the feat/MilestoneConfigRefactoring branch from bd6b8b5 to 458a5e4 Compare February 18, 2019 10:40
@iotaledger iotaledger deleted a comment Feb 18, 2019
@iotaledger iotaledger deleted a comment Feb 18, 2019
@GalRogozinski GalRogozinski force-pushed the feat/MilestoneConfigRefactoring branch from a1cb46f to 78d7d64 Compare February 18, 2019 13:16
@GalRogozinski GalRogozinski force-pushed the feat/MilestoneConfigRefactoring branch from 78d7d64 to 0b2698c Compare February 18, 2019 14:08
@alon-e
Copy link
Contributor Author

alon-e commented Feb 19, 2019

great changes! Approved.

@GalRogozinski GalRogozinski merged commit 9bb3b92 into iotaledger:dev Feb 27, 2019
@GalRogozinski GalRogozinski deleted the feat/MilestoneConfigRefactoring branch February 27, 2019 13:37
@jakubcech jakubcech mentioned this pull request Apr 1, 2019
1 task
GalRogozinski pushed a commit to GalRogozinski/iri that referenced this pull request Apr 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants