#build

ssb-causal-sort

Causally sort a collection of scuttlebutt messages

1 unstable release

0.1.1 Oct 15, 2020

#922 in #build

AGPL-3.0

9KB
156 lines

Causally sort a collection of messages.

Returns messages sorted from newest to oldest.

If message b includes a reference to message a then we say that message b must have been published after message a, assuming these assumptions hold:

  • The hash function is not broken (Two different sets of bytes return the same hash.)
  • The person publishing message b has not guessed a valid hash of a message before it was published (extremely unlikely.)
  • The person publishing message b is not a time traveller.

This function uses daggy to build a dag of references between messages and then topologically sorts them.

If a message is not referenced by any messages you can expect it to be sorted to the start of the results (it is so new no one has referenced it yet).

Dependencies

~4.5MB
~73K SLoC