iotaledger / iri

IOTA Reference Implementation
Other
1.15k stars 370 forks source link

Investigate testnet code of MilestoneViewModel#findClosestNextMilestone #637

Open anyong opened 6 years ago

anyong commented 6 years ago

public static MilestoneViewModel findClosestNextMilestone(Tangle tangle, int index, boolean testnet, int milestoneStartIndex) throws Exception { + if(!testnet && index <= milestoneStartIndex) { return first(tangle);+ } Pair<Indexable, Persistable> milestonePair = tangle.next(Milestone.class, new IntegerIndex(index)); if(milestonePair != null && milestonePair.hi != null) { return new MilestoneViewModel((Milestone) milestonePair.hi); } return null; }

alon-e commented 5 years ago

AFAICT this is a bug in testnet code. we need now (at least) 2 milestones for a node to get SOLID. this is because tangle.next() w/ the stating index returns null when 1 milestoneVM is present in the DB. (iterator.seek selects the first milestone, and iterator.next will return an invalid iterator).

reproduce:

  1. run testnet node w/ empty DB.

  2. issue (only!) 1 milestone. see that node sees new milestone but does not become solid:

    10/28 18:23:03.863 [Latest Milestone Tracker] INFO  com.iota.iri.MilestoneTracker - Latest milestone has changed from #0 to #1
  3. issue a second milestone:

    10/28 18:23:33.660 [Latest Milestone Tracker] INFO  com.iota.iri.MilestoneTracker - Latest milestone has changed from #1 to #2
    10/28 18:23:37.635 [Solid Milestone Tracker] INFO  com.iota.iri.MilestoneTracker - Latest SOLID SUBTANGLE milestone has changed from #0 to #2

    *notice the gap (jump from 0 to 2)

  4. redo 1 + 2 w/ a version that has: (no !testnet &&)

    if(index <= milestoneStartIndex) {
    return first(tangle);
    }