Skip to content

Commit

Permalink
Optimize transaction past cone check (iotaledger#1153)
Browse files Browse the repository at this point in the history
* WIP debugging of markers and heavy Tangle walking issue

* Clean up debug prints
  • Loading branch information
jonastheis authored Mar 29, 2021
1 parent 972041d commit b72204b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/tangle/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (u *Utils) TransactionApprovedByMessage(transactionID ledgerstate.Transacti
continue
}

bookedParents := make(MessageIDs, 0)
u.tangle.Storage.Message(messageID).Consume(func(message *Message) {
for _, parentID := range message.StrongParents() {
var parentBooked bool
Expand All @@ -132,13 +133,26 @@ func (u *Utils) TransactionApprovedByMessage(transactionID ledgerstate.Transacti
continue
}

if u.MessageApprovedBy(attachmentMessageID, parentID) {
// First check all of the parents to avoid unnecessary checks and possible walking.
if attachmentMessageID == parentID {
approved = true
return
}

bookedParents = append(bookedParents, parentID)
}
})
if approved {
return
}

// Only now check all parents.
for _, bookedParent := range bookedParents {
if u.MessageApprovedBy(attachmentMessageID, bookedParent) {
approved = true
return
}
}
if approved {
return
}
Expand Down

0 comments on commit b72204b

Please sign in to comment.