Skip to content

Commit

Permalink
Feat: updated more code
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Apr 5, 2022
1 parent f1a5f04 commit 3d8c7c6
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions packages/ledger/branchdag/branchdag.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,39 +129,31 @@ func (b *BranchDAG) SetBranchConfirmed(branchID BranchID) (modified bool) {
b.inclusionStateMutex.Lock()
defer b.inclusionStateMutex.Unlock()

confirmationWalker := walker.New[BranchID]().Push(branchID)
rejectedWalker := walker.New[BranchID]()
rejectionWalker := walker.New[BranchID]()

for confirmationWalker.HasNext() {
currentBranchID := confirmationWalker.Next()

b.Storage.CachedBranch(currentBranchID).Consume(func(branch *Branch) {
for confirmationWalker := NewBranchIDs(branchID).Iterator(); confirmationWalker.HasNext(); {
b.Storage.CachedBranch(confirmationWalker.Next()).Consume(func(branch *Branch) {
if modified = branch.setInclusionState(Confirmed); !modified {
return
}

for it := branch.Parents().Iterator(); it.HasNext(); {
confirmationWalker.Push(it.Next())
}
confirmationWalker.PushAll(branch.Parents().Slice()...)

for it := branch.Conflicts().Iterator(); it.HasNext(); {
b.Storage.CachedConflictMembers(it.Next()).Consume(func(conflictMember *ConflictMember) {
if conflictMember.BranchID() != currentBranchID {
rejectedWalker.Push(conflictMember.BranchID())
}
})
}
b.Utils.forEachConflictingBranchID(branch, func(conflictingBranchID BranchID) bool {
rejectionWalker.Push(conflictingBranchID)
return true
})
})
}

for rejectedWalker.HasNext() {
b.Storage.CachedBranch(rejectedWalker.Next()).Consume(func(branch *Branch) {
for rejectionWalker.HasNext() {
b.Storage.CachedBranch(rejectionWalker.Next()).Consume(func(branch *Branch) {
if modified = branch.setInclusionState(Rejected); !modified {
return
}

b.Storage.CachedChildBranches(branch.ID()).Consume(func(childBranch *ChildBranch) {
rejectedWalker.Push(childBranch.ChildBranchID())
rejectionWalker.Push(childBranch.ChildBranchID())
})
})
}
Expand Down

0 comments on commit 3d8c7c6

Please sign in to comment.