Skip to content

Instantly share code, notes, and snippets.

@mgraczyk
Created June 28, 2018 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgraczyk/c2ed25bace5068cabb900c79224e296c to your computer and use it in GitHub Desktop.
Save mgraczyk/c2ed25bace5068cabb900c79224e296c to your computer and use it in GitHub Desktop.
func (n *Node) IsStronglyPreferred(tx *Transaction) bool {
mutex.RLock()
defer mutex.RUnlock()
stronglyPreferred := true
parents := // ... make map of parent ids
for len(parents) != 0 {
for parentId := range parents {
// [OT] stronglyPreferred could be memoized here for efficiency
// This is a downside of using protocol buffers for state.
// Additional in-memory state can't be stored naturally because
// we don't want to transmit stronglyPreferred over the wire.
if // ... parent exists {
// [OT] Line 2, isPreferred
stronglyPreferred = stronglyPreferred && n.Conflicts[parent.Body.Utxo].Preferred == parent
ancestors := // ... make map of ancestor hashes
}
// ... Handle parent doesn't exist
}
// [OT] Recursion on ancestors
parents = ancestors
}
return stronglyPreferred
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment