Skip to content

Commit

Permalink
Feat: update the snapshot index of the milestone tx to its index
Browse files Browse the repository at this point in the history
This allows us to efficiently query the database for the matching milestone object and it anyway makes sense that a milestone is confirmed by itself
  • Loading branch information
Hans Moog committed Jul 23, 2018
1 parent 127ec4a commit bbd4042
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/com/iota/iri/Milestone.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ public void init(final SpongeFactory.Mode mode, final LedgerValidator ledgerVali
final Validity valid = validateMilestone(mode, t, getIndex(t));
switch (valid) {
case VALID:
t.setIsSnapshot(tangle, true);
MilestoneViewModel milestoneViewModel = MilestoneViewModel.latest(tangle);
if (milestoneViewModel != null && milestoneViewModel.index() > latestMilestoneIndex) {
latestMilestone = milestoneViewModel.getHash();
latestMilestoneIndex = milestoneViewModel.index();
}

// mark the transaction as a snapshot
t.setIsSnapshot(tangle, true);

// set the snapshot index of the transaction (a milestone is verified by
// itself + this allows us to retrieve the matching milestone object
// efficiently)
t.setSnapshot(tangle, milestoneViewModel.index());
break;
case INCOMPLETE:
analyzedMilestoneCandidates.remove(t.getHash());
Expand Down

0 comments on commit bbd4042

Please sign in to comment.