Increase rescan performance of old milestones after IRI restart #1204
Changes from all commits
fd8bc46
8cc8b07
cb06146
0af00d8
75d47a7
2ea3fb1
cec8165
f21156b
85db77f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
import com.iota.iri.service.milestone.MilestoneException; | ||
import com.iota.iri.service.milestone.MilestoneService; | ||
import com.iota.iri.service.milestone.MilestoneSolidifier; | ||
import com.iota.iri.service.milestone.MilestoneValidity; | ||
import com.iota.iri.service.snapshot.Snapshot; | ||
import com.iota.iri.service.snapshot.SnapshotProvider; | ||
import com.iota.iri.storage.Tangle; | ||
|
@@ -26,10 +25,6 @@ | |
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.iota.iri.service.milestone.MilestoneValidity.INCOMPLETE; | ||
import static com.iota.iri.service.milestone.MilestoneValidity.INVALID; | ||
import static com.iota.iri.service.milestone.MilestoneValidity.VALID; | ||
|
||
/** | ||
* Creates a tracker that automatically detects new milestones by incorporating a background worker that periodically | ||
* checks all transactions that are originating from the coordinator address and that exposes the found latest milestone | ||
|
@@ -188,9 +183,9 @@ public Hash getLatestMilestoneHash() { | |
} | ||
|
||
@Override | ||
public MilestoneValidity analyzeMilestoneCandidate(Hash transactionHash) throws MilestoneException { | ||
public boolean processMilestoneCandidate(Hash transactionHash) throws MilestoneException { | ||
try { | ||
return analyzeMilestoneCandidate(TransactionViewModel.fromHash(tangle, transactionHash)); | ||
return processMilestoneCandidate(TransactionViewModel.fromHash(tangle, transactionHash)); | ||
} catch (Exception e) { | ||
throw new MilestoneException("unexpected error while analyzing the transaction " + transactionHash, e); | ||
} | ||
|
@@ -203,14 +198,19 @@ public MilestoneValidity analyzeMilestoneCandidate(Hash transactionHash) throws | |
* {@link MilestoneSolidifier} that takes care of requesting the missing parts of the milestone bundle.<br /> | ||
*/ | ||
@Override | ||
public MilestoneValidity analyzeMilestoneCandidate(TransactionViewModel transaction) throws MilestoneException { | ||
public boolean processMilestoneCandidate(TransactionViewModel transaction) throws MilestoneException { | ||
try { | ||
if (coordinatorAddress.equals(transaction.getAddressHash()) && | ||
transaction.getCurrentIndex() == 0) { | ||
|
||
int milestoneIndex = milestoneService.getMilestoneIndex(transaction); | ||
|
||
switch (milestoneService.validateMilestone(transaction, SpongeFactory.Mode.CURLP27, 1)) { | ||
// if the milestone is older than our ledger start point: we already processed it in the past | ||
if (milestoneIndex <= snapshotProvider.getInitialSnapshot().getIndex()) { | ||
return true; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Alon's beef was that the He didn't say anything about your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I have a better idea... Instead of adding another enum to validity (IRRELEVANT) (which doesn't make much sense), If the I think this makes the most sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree w/ @GalRogozinski that returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i changed it accordingly |
||
|
||
switch (milestoneService.validateMilestone(transaction, milestoneIndex, SpongeFactory.Mode.CURLP27, 1)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try not to ignore codacy. Even thought the way you did it is less verbose, I think it is still clearer and more readable to have the default case inside the switch brackets. You can also add a little comment: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this is really unnecessary here since the switch is used as a faster / easier to read version of an if then else if then but if you think it helps i can add an empty default with that comment .. :P |
||
case VALID: | ||
if (milestoneIndex > latestMilestoneIndex) { | ||
setLatestMilestone(transaction.getHash(), milestoneIndex); | ||
|
@@ -221,22 +221,21 @@ public MilestoneValidity analyzeMilestoneCandidate(TransactionViewModel transact | |
} | ||
|
||
transaction.isMilestone(tangle, snapshotProvider.getInitialSnapshot(), true); | ||
|
||
return VALID; | ||
break; | ||
|
||
case INCOMPLETE: | ||
milestoneSolidifier.add(transaction.getHash(), milestoneIndex); | ||
|
||
transaction.isMilestone(tangle, snapshotProvider.getInitialSnapshot(), true); | ||
|
||
return INCOMPLETE; | ||
return false; | ||
|
||
default: | ||
return INVALID; | ||
// we can consider the milestone candidate processed and move on w/o farther action | ||
} | ||
} | ||
|
||
return INVALID; | ||
return true; | ||
} catch (Exception e) { | ||
throw new MilestoneException("unexpected error while analyzing the " + transaction, e); | ||
} | ||
|
@@ -350,7 +349,7 @@ private void analyzeMilestoneCandidates() throws MilestoneException { | |
} | ||
|
||
Hash candidateTransactionHash = milestoneCandidatesToAnalyze.pollFirst(); | ||
if(analyzeMilestoneCandidate(candidateTransactionHash) == INCOMPLETE) { | ||
if(!processMilestoneCandidate(candidateTransactionHash)) { | ||
seenMilestoneCandidates.remove(candidateTransactionHash); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,10 +160,9 @@ public void resetCorruptedMilestone(int index) throws MilestoneException { | |
} | ||
|
||
@Override | ||
public MilestoneValidity validateMilestone(TransactionViewModel transactionViewModel, SpongeFactory.Mode mode, | ||
int securityLevel) throws MilestoneException { | ||
public MilestoneValidity validateMilestone(TransactionViewModel transactionViewModel, int milestoneIndex, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice addition of parameter |
||
SpongeFactory.Mode mode, int securityLevel) throws MilestoneException { | ||
|
||
int milestoneIndex = getMilestoneIndex(transactionViewModel); | ||
if (milestoneIndex < 0 || milestoneIndex >= 0x200000) { | ||
return INVALID; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on the name change