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

Enable validation of milestones with additional hash modes and security levels #1041

Merged
merged 10 commits into from
Oct 15, 2018

Conversation

alon-e
Copy link
Contributor

@alon-e alon-e commented Oct 7, 2018

Description

Enable validation of milestones with additional hash modes (CURLP27, CURLP81, KERL) and security levels (1, 2, 3)

Type of change

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

How Has This Been Tested?

  • Unit tests added for the different milestones with actually signed milestones from testing network
  • all combinations tested on a local testnet.

Checklist:

Please delete items that are not relevant.

  • 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 added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@alon-e alon-e added T-Enhancement C-Consensus E-Refactor Epic - Improving code readability and maintainability labels Oct 7, 2018
@alon-e alon-e force-pushed the feat/milestonesSecLvl branch from eadfb46 to bd3c30d Compare October 7, 2018 10:49
@iotaledger iotaledger deleted a comment Oct 8, 2018
@iotaledger iotaledger deleted a comment Oct 8, 2018
@iotaledger iotaledger deleted a comment Oct 8, 2018
@iotaledger iotaledger deleted a comment Oct 8, 2018
@iotaledger iotaledger deleted a comment Oct 8, 2018
@iotaledger iotaledger deleted a comment Oct 8, 2018
@iotaledger iotaledger deleted a comment Oct 8, 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.

Besides the naming convention I want to start treating codacy-bot like a human reviewer.
When it puts a comment either:

  1. Do the change
  2. Comment that the request is out of scope (like for the Npath complexity of an existing method)
  3. Argue that the pmd rule should be removed (I deleted some comments and I shall fix the pmd promptly)

}

@Test
public void milestoneValidationCURLP27() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Stick with test naming conventions. Append ore prepend the word "test" (with proper capitalization).
Reason:
We currently use an old version of the maven surefire plugin that only runs tests that follow convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you sure? afaik this is only for the test file name.

from a local mvn test run:

[INFO] Running com.iota.iri.MilestoneTrackerTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.276 s - in com.iota.iri.MilestoneTrackerTest

from travis: (https://travis-ci.org/iotaledger/iri/jobs/438230685#L995-L999)

[INFO] Running com.iota.iri.MilestoneTrackerTest
10/07 10:53:11.658 [main] INFO  c.i.i.s.r.RocksDBPersistenceProvider - Initializing Database Backend... 
10/07 10:53:11.717 [main] INFO  c.i.i.s.r.RocksDBPersistenceProvider - RocksDB persistence provider initialized.
10/07 10:53:12.396 [main] INFO  com.iota.iri.storage.Tangle - Shutting down Tangle Persistence Providers... 
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.742 s - in com.iota.iri.MilestoneTrackerTest

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}

@Test
public void milestoneValidationKERL() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

}

@Test
public void milestoneValidationCURLP27SecLvl3() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

}

@Test
public void milestoneValidationKERLSecLvl3() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

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.

Mainly style comments

@@ -198,23 +197,29 @@ private Validity validateMilestone(SpongeFactory.Mode mode, TransactionViewModel
else {
for (final List<TransactionViewModel> bundleTransactionViewModels : bundleTransactions) {

//if (Arrays.equals(bundleTransactionViewModels.get(0).getHash(),transactionViewModel.getHash())) {
if (bundleTransactionViewModels.get(0).getHash().equals(transactionViewModel.getHash())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to have bundleTransactionViewModels.get(0).getHash() be stored as a local variable outside the loop.
It can even be final because the loop opened a new scope.

if (bundleTransactionViewModels.get(0).getHash().equals(transactionViewModel.getHash())) {
//the signed transaction - which references the confirmed transactions and contains the Merkle tree siblings.
final TransactionViewModel siblingsTx = bundleTransactionViewModels.get(securityLevel);
Copy link
Contributor

Choose a reason for hiding this comment

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

if you change the line you can always remove the final

bb.put(digest);
}

final byte[] digests = bb.array();
Copy link
Contributor

Choose a reason for hiding this comment

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

locally scoped final

byte[] address = ISS.address(mode, digests);

//validate Merkle path
final byte[] merkleRoot = ISS.getMerkleRoot(mode, address,
Copy link
Contributor

Choose a reason for hiding this comment

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

locally scoped final

}

@Test
public void milestoneValidationCURLP27() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -4,8 +4,7 @@
import com.iota.iri.controllers.AddressViewModel;
import com.iota.iri.controllers.MilestoneViewModel;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.hash.ISS;
import com.iota.iri.hash.SpongeFactory;
import com.iota.iri.hash.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

I looked into it and apparently it is hard for static code analysis tools to handle stars. I will test later if it works better with checkstyle but currently I think it will be the same problem...

signatureFragmentTrits)),
transactionViewModel2.trits(), 0, index, numOfKeysInMilestone);
for (int i = 0; i < securityLevel; i++) {
ISSInPlace.digest(mode, signedHash, ISS.NUMBER_OF_FRAGMENT_CHUNKS * i, bundleTransactionViewModels.get(i).getSignature(), 0, digest);
Copy link
Contributor

Choose a reason for hiding this comment

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

Later on checkstyle will fail this becuase the line is too long

@BeforeClass
public static void beforeClass() throws Exception {


Copy link
Contributor

Choose a reason for hiding this comment

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

While changing this remove all those whitespaces.
I usually don't mind them too much but you went overboard here.

alon-e added 2 commits October 8, 2018 16:55
…/milestonesSecLvl

# Conflicts:
#	src/test/java/com/iota/iri/MilestoneTrackerTest.java
expand imports
remove blank lines
break lines
@iotaledger iotaledger deleted a comment Oct 10, 2018
@iotaledger iotaledger deleted a comment Oct 10, 2018
@iotaledger iotaledger deleted a comment Oct 10, 2018
@iotaledger iotaledger deleted a comment Oct 10, 2018
@iotaledger iotaledger deleted a comment Oct 10, 2018
@iotaledger iotaledger deleted a comment Oct 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-Consensus E-Refactor Epic - Improving code readability and maintainability T-Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants