grrowl / redux-scuttlebutt

Distributed replicated redux store
170 stars 14 forks source link

Missing action.timestamps #3

Closed marcusradell closed 8 years ago

marcusradell commented 8 years ago

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?

marcusradell commented 8 years ago

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.

grrowl commented 8 years ago

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.

grrowl commented 8 years ago

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.

marcusradell commented 8 years ago

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.

grrowl commented 8 years ago

I like Swarm's implementation

edit: swarm-stamp moved here

marcusradell commented 8 years ago

That's awesome on first glance. Cheers!