ledger: make conditions for accepting a round vote more strict (check start/end tx depths), and also fix CollapseTransactions() accidentally applying transactions at the root depth
@@ -360,14 +360,6 @@ FINALIZE_ROUNDS:
return
}
- if err := l.AddTransaction(round.Start); err != nil {
- return
- }
-
- if err := l.AddTransaction(round.End); err != nil {
- return
- }
-
if round.End.Depth <= round.Start.Depth {
return
}
@@ -387,6 +379,14 @@ FINALIZE_ROUNDS:
return
}
+ if err := l.AddTransaction(round.Start); err != nil {
+ return
+ }
+
+ if err := l.AddTransaction(round.End); err != nil {
+ return
+ }
+
if !round.End.IsCritical(currentDifficulty) {
return
}
@@ -574,6 +574,11 @@ func (l *Ledger) SyncToLatestRound() {
return
}
+ if round.End.Depth <= round.Start.Depth {
+ wg.Done()
+ return
+ }
+
if round.Index < sys.SyncIfRoundsDifferBy+current.Index {
wg.Done()
return
@@ -1029,12 +1034,12 @@ func (l *Ledger) CollapseTransactions(round uint64, root Transaction, end Transa
for queue.Len() > 0 {
popped := queue.PopFront().(*Transaction)
- order.PushBack(popped)
-
- if popped.Depth-1 <= root.Depth {
+ if popped.Depth <= root.Depth {
continue
}
+ order.PushBack(popped)
+
for _, parentID := range popped.ParentIDs {
if _, seen := visited[parentID]; seen {
continue
