grrowl / redux-scuttlebutt

Distributed replicated redux store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing action.timestamps

marcusradell opened this issue · comments

https://github.com/grrowl/redux-scuttlebutt/blob/master/src/orderedHistory.js#L38

If two actions get the same timestamps, won't that make the order of the actions indeterministic?
Also, shouldn't the timestamp either always or never be present on the action? Why not throw instead to avoid bad timestamps?

Seems like scuttlebutt has some crude/simple solution to that issue:
https://github.com/dominictarr/scuttlebutt/blob/master/index.js#L7

It uses:
https://github.com/dominictarr/monotonic-timestamp

So monotonic-timestamp basically adds some minimal number to the next timestamp if it is the same as the previous.

You're correct — scuttlebutt generates them with monotonic-timestamp but that seems locally unique. We should move to a Lamport Timestamps, I'm taking a look at options for a better base class to inherit from.

It seems that line of code is for non-gossip actions (currently anything beginning with @). We record them in history and set the timestamp to either be the action's @scuttlebot/TIMESTAMP, or that of most recent snapshot before it.

edit: adding better comments to this bit, thanks.

I see, that explains it.

Closing this issue. But as a sidenote, do you know of any existing timestamp lib that suits your needs? I will need to solve the exact same problem, so interested in what's out there.

I'm reading about Lamport timestamps, and it seems like it shouldn't be too hard to roll your own.

That's awesome on first glance. Cheers!