Open staltz opened 1 year ago
The pseudocode I shared above may be general enough for linear feed formats too, so we don't have to implement an if/else in db2. After all, a linear feed is by definition a type of DAG feed.
Base and thus state is used for feed validation and for EBT. We don't need EBT so that leaves feed validation. In your diagrams there can be an exception. Lets say your phone was offline for a day. So your computer has latest: 5, while phone has lets say 2. When the phone produces a new message, it's previous is going to be 2 and when you get that message on your computer, you won't have 2 in previous anymore. So maybe for minibutt think of state as just a cache, that most likely will have previous, but sometimes you might have to fetch the message from storage. Both in the case you illustrated and in the one I wrote.
it's previous is going to be 2 and when you get that message on your computer, you won't have 2 in previous anymore.
You mean that the desktop won't have 2 anymore because it was deleted due to sliced replication?
Oh i meant in the base index. Just that we need to also sometime get from disk. Sliced is a bigger problem but this is mainly a problem if one machine is far behind.
Hmm, I have a difficulty seeing this, so let me put it on paper
---
title: "Desktop: latest is 5"
---
graph LR;
0-->1-->2
2-->3a[3]
2-->3b[3']
3a & 3b-->4
4-->5
---
title: "Mobile: latest is 2"
---
graph LR;
0-->1-->2
---
title: "Mobile: latest is 3"
---
graph LR;
0-->1-->2-. new .->3[3'']
graph LR;
0-->1-->2
2-->3a[3]
2-->3b[3']
3a & 3b-->4
4-->5
2-. new .-3c[3'']
Applying that to the pseudocode:
- Let
new
be the new minibutt message, andlatest
(array) be the existing minibutt message(s) (fromstate
)- Pass
new
andlatest
to minibutt validation- If
new.previous
is contained inside thelatest
set, then
- subtracting
new.previous
fromlatest
- AND insert
new
tolatest
- Else, just insert
new
to thelatest
Yeah I can see how step (2) is going to be a problem, because new = 3''
but latest = [5]
and they are not connected. So indeed we need to fetch it from disk (if it has not been deleted!). So yes you're right about the cache.
But (3) is going to be skipped because new.previous = 2
is not in latest
. Step (4) is going to run, and that's fine, it gives us latest = [3'', 5]
and that's sounds correct.
About (2) failing due to msg 2
not being in disk anymore, we could use a rule of thumb to just ignore 3''
deeming it too old. What do you think?
About (2) failing due to msg
2
not being in disk anymore, we could use a rule of thumb to just ignore3''
deeming it too old. What do you think?
Actually, I'm not sure about this. Maybe the new message is merging many "heads", some old heads and some new heads, so maybe the merge is valuable even if one of the heads is very old. And anyway with sliced replication, it is always the case where one or more "oldest" messages have missing previous
from disk.
Base index to become feedId => [{offset, sequence}, ...]
.
State to become feedId => [latest nativeMsg, ...]
.
When appending a new minibutt message:
new
be the new minibutt message, and latest
(array) be the existing minibutt message(s) (from state
)new.previous
messages from (preferably) latest
if it exists, or from disknew
and new.previous
to minibutt validationnew.previous
is contained inside the latest
set, then
new.previous
from latest
new
to latest
new
to the latest
When it comes to implementing minibutt with ssb-db2, one of the obstacles is figuring out what are the latest messages. So far, for linear feeds, there has been only one latest message. For DAG feeds, there might be multiple latest messages.
From the perspective of ssb-db2, there is the base index that maps
feedId => {offset, sequence}
of the latest message. Also the "state" in db2 is a map offeedId => latest nativeMsg
.Base index will have to become
feedId => [{offset, sequence}, ...]
.State will have to become
feedId => [latest nativeMsg, ...]
.When appending a new minibutt message, the procedure will have to be something like:
new
be the new minibutt message, andlatest
(array) be the existing minibutt message(s) (fromstate
)new
andlatest
to minibutt validationnew.previous
is contained inside thelatest
set, thennew.previous
fromlatest
new
tolatest
new
to thelatest
Example
latest = [2]
new = 3
new.previous = 2
So rule (3) applies and we "subtract" 2 from latest, and insert
3
, so the new latest becomeslatest = [3]
latest = [3]
new = 3'
new.previous = 2
So rule (4) applies and we just insert
3'
, so the new latest becomeslatest = [3, 3']
latest = [3, 3']
new = 3''
new.previous = 2
So rule (4) applies and we just insert
3''
, so the new latest becomeslatest = [3, 3', 3'']
latest = [3, 3', 3'']
new = 4
new.previous = [3, 3']
So rule (3) applies and we "subtract" [3, 3'] from latest, and insert
4
, so the new latest becomeslatest = [3'', 4]