A "tangle" in scuttlebutt is a way to define a directed acyclic graph (DAG) of
messages. They are a useful way to determine a partial ordering which is
useful for everything from replication to building multi-writer "records".
There are different types of tangle, but they all must specify:
It is common for the recipe to start with some "root message" and extend out
from that point, checking the validity of messages as they are added. Some
candidate messages may not have connections to the graph, or may be "invalid"
extentions, in which case they are excluded from the tangle.
The most trivial tangle is the classic scuttelbutt feed. In this case, the
tangle for feed A
is defined as:
msg.value.author == A
msg.value.signature
which is the signature of msg.value.content
by A
msg.value.sequence == 1
as your "root"
A
msg.value.sequence == 2
A
msg.value.previous
points to the previous messageThe tangle data these messages carry looks like:
(author, signature, and content have been ommited here to make the backlinking
pattern clearer)
In the case of multiple authors, you need to be able to support a DAG which
branches and merges (because different authors may contribute concurrently,
or while offline).
Diagram where messages X, Y were both published concurrently (so were unaware
of one another). M is aware of both X and Y, and extends the tangle from them.
M is now the new "tip" of the tangle.
The tangle data these messages carry looks like:
Where:
root
is the id of the root message of the the tangleprevious
is an Array of message ids of the tip(s) / leading edges of theNote: the root message cannot include its own id (not known until published),
so it sets it's root
value as null
, which means "I am a root"
The purpose of this tangle is to track the group membership (for a particular
epoch of the group).
We define the members tangle for some id A
as:
A
so long as it has
previous
fieldprevious
In the context of private groups, the addition to a particular epoch is always
published to an earlier epoch (or in the case of the first epoch, to the
Additons feed).
The purpose of the epoch tangle is to track progression of epochs that
constitutes each group.
For some group id G
, where A
is the id of the initial group/init
message
(in epoch 0), then define the epoch tangle for G
as:
A
so long as it has
previous
fieldprevious
The purpose of the group tangle is to clearly identify all messages which are
part of a particular group, and provide partial causal ordering.
For some group id G
, where A
is the id of the initial group/init
message
(in epoch 0), then define the group tangle for G
as:
A
so long as it has
previous
fieldprevious
NOTE: this diagram shows all nice linear tangles for visual simplicity,
remember there may be forks and merges because of concurrent publishing.
Crucially, the group/init
messages are involved in 3 tangles, e.g.
This message says
A
, and the last messages I saw in the group were W, X
A
and the epoch(s) before this one was B