Commit Graph

48 Commits

Author SHA1 Message Date
Alexis Sellier aacacf872f
cob: Use `EntryId` as the operation identifier
By introducing a small limitation: only allowing entries in the change
graph to be addressable, instead of individual operations; we
drastically simplify the CRDT implementation.

There are four advantages:

1. Op ids are just regular SHA-1s
2. There's no need for relative IDs, ops never refer to other ops within the
   same commit
3. There's no need for a nonce, since commits can't collide, and neither can op IDs
4. `OpId` can just be an alias of `EntryId`

The disadvantage of course, is that we have to be mindful of how we
create op transactions, since each transaction creates an addressable
unit. For example, we must not include multiple patch revisions in the
same transaction.
2023-03-09 17:08:56 +01:00
Alexis Sellier 5f59493c70
cob: Don't require a local fork to exist
Before this change, the identity document would be loaded for the
COB signer. This meant that a fork would be needed for that signer.

After this change, it's no longer necessary, since the identity doc
head is computed from available remotes.

While making those changes, it was also apparent that some of the
identity-related functions had bad names and error types, this
was fixed as well.
2023-03-01 15:40:30 +01:00
Alexis Sellier 06a92d52d9
cob: Use hashes for operation ids
It's fairly easy for a user to (by mistake or intentionally) create two
operations with the same OpId. This patch makes it much less likely,
and ensures that if the OpId is equal, it's because the operations
are identical.
2023-02-27 17:11:48 +01:00
Alexis Sellier e584bd6c1c
crypto: Use `ssh-key` crate for signatures 2023-02-17 11:53:46 +01:00
Alexis Sellier 8cbc3c2403
node: Move to NoiseXK
Move from NoiseNN with a custom authentication protocol, to NoiseXK.
Uses ECDH on the ed25519 curve via the `ec25519` library.
2023-02-15 22:05:04 +01:00
Fintan Halpenny 99c1e2ac52
radicle-cob: simplify trailers module
The macro in the trailers module existed since there were multiple
trailers before the refactoring, so it minimised boilerplate code.

After the refactoring of the code there was only one trailer
left. Remove the macro generation code and replace it with just the
necessary code for the ResourceCommitTrailer.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-02-13 13:30:08 +01:00
xphoniex bdc0ab9881
Update `radicle-git` and `radicle-surf`
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
2023-02-10 22:14:50 +01:00
Fintan Halpenny 3f48c2c516
Rust 1.67
Rust 1.67 was announced[0]. Update the necessary files for running
1.67 and fix the clippy suggestions for string interpolation.

[0]: https://blog.rust-lang.org/2023/01/26/Rust-1.67.0.html

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-02-04 19:30:29 +01:00
Alexis Sellier a50329eb43
cob: Remove redundant indentation
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2023-01-06 13:00:01 +01:00
Alexis Sellier 329af88ca6
cob: Quiet warnings in release mode
We were getting warnings in release mode, since the
debug code is not being run, and some vars are mutable
instead of immutable.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2023-01-06 13:00:01 +01:00
Alexis Sellier b7d0479b5c
cob: Add some more information about `resource`
Signed-off-by: Alexis Sellier <self@cloudhead.io>
2023-01-03 14:28:18 +01:00
Alexis Sellier 2f42bc942c
cob: Make it easy to build histories
Signed-off-by: Alexis Sellier <self@cloudhead.io>
2023-01-03 14:23:47 +01:00
Alexis Sellier 5ee1f42b6a
cob: Have clock value for empty COB state
By using `0` as the clock value for an empty state (without operations),
we simplify transaction code. Previously, there was no clock value for
empty states, which meant that we had to sometimes use an `Option`.
2023-01-01 18:29:47 +01:00
Alexis Sellier 49cd26c0b3
Tidy up COBs code a little
* Move storage impl into `storage::git::cob`
* Rename `change::Create` to `change::Template`
* Rename `change::Storage::create` to `change::Storage::store`

Some of the renames are to further distinguish COBs from Changes, and
the different types of "create" operations within cobs.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-31 09:58:45 +01:00
Alexis Sellier 86e56d2053
cob: Move graph sorting to `evaluate` function
This avoids passing the sorted items as an iterator.

Signed-off-by: Alexis Sellier <self@cloudhead.io>
2022-12-28 19:24:22 +01:00
Alexis Sellier 70260236b2
cob: Simplify graph builder
Since we use `Oid` as the primary graph index, there's no need to keep
a separate index.

Signed-off-by: Alexis Sellier <self@cloudhead.io>
2022-12-28 18:01:24 +01:00
Alexis Sellier 57fcb117fc
cob: Remove redundant history indices
Signed-off-by: Alexis Sellier <self@cloudhead.io>
2022-12-28 17:53:00 +01:00
Alexis Sellier 2f07b76fcb
Switch to our own DAG representation for COBs
We're using petgraph to encode an operation based CRDT (each graph node
is an operation) as a DAG, and one of the important things to ensure
is that the final state is not influenced by the order of concurrent
operations. In this case a concurrent operation would mean two potential
graph traversal orders, as there's no direct edge between the two
concurrent ops. This is essential a "partial order" of operations.

To be able to test this, we'd want some kind of control over how
neighbors are iterated over I guess, when there's more than one possible
sort order. Say we have a graph like this:

             ┌────────b◄─────┐
             ▼               │
             a               d
             ▲               │
             └────────c◄─────┘

There are two possible topological traverse orders: [a, b, c, d] and [a,
c, b, d]. Having a way to go through these different orders would
be super handy.

One option would be to allow random order traversal. This would allow us
to test all orders by running the test enough times to likely test all
permutations.

Since petgraph doesn't support this, we implement our own simple DAG in
`radicle-dag`, which implements random-order topological orders.

For now, we don't make explicit use of these improvements, we simply
replace the underlying graph with our own.
2022-12-28 13:34:17 +01:00
Alexis Sellier f6177f85fe
cob: Remove redundant type
Signed-off-by: Alexis Sellier <self@cloudhead.io>
2022-12-27 17:30:06 +01:00
Slack Coder 873ce895ae
cob: panic on badly formatted debug env var
Panic to clear to the operator something is wrong.  Panic'ing like this
is ok in debug mode, but must be avoided in production.

Signed-off-by: Slack Coder <slackcoder@server.ky>
2022-12-26 15:38:39 +01:00
Slack Coder edef49d1ef
Improve client example test determinism
Collaborative object IDs are derived from their commit oid.  These
IDs must be reproducible to support testing the client's example.  All but
one of the parameters used to derive the Object ID is the commit's Author
and committer timestamp.

Introduce an environment variable 'RAD_COMMIT_TIME' to set both Author and
Committer timestamp when creating a commit in the cob module.

Use single variable, instead of Git's two (for author and committer), to
keep the changes simple.  The function being modified returns a single
timestamp which is derived from the author's.

Signed-off-by: Slack Coder <slackcoder@server.ky>
2022-12-26 15:37:55 +01:00
Alexis Sellier 335fcbca89
cob: Return correct clock value for multi-ops
We weren't accounting for batches ops in an entry.
This change should account for it by adding N-1
to the clock value of an entry, where N is the number
of entries.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-13 10:16:18 +01:00
Alexis Sellier 98c1566109
Make `Doc` type payload generic 2022-12-09 22:05:38 +01:00
Alexis Sellier b7c1f091fa
Fix issue with colliding doc files
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-09 14:37:36 +01:00
Fintan Halpenny 5f80ee9671
cobs: allow for batched operations
Sometimes it is more efficient to perform multiple operations at once
and store those in the collaborative object graph together.

Change the contents to be a non-empty sequence of byte sequences,
i.e. NonEmpty<Vec<u8>>. These are stored as blobs in a git tree in
order by their index in the non-empty sequence. They are, in turn,
retrieved in order of their original index.

Change the conversion of an `EntryWithClock` to return a non-empty
sequence of `Op`s, which are in turn used to apply many changes in
each `from_history` implementation.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-12-07 17:11:40 +01:00
Alexis Sellier f9c81ab382
Replace `quickcheck` with `qcheck`
The latter is a fork of the former, which adds const generics
and a bunch of other quality of life improvements that aren't
in the original crate due to it being unmaintained.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-04 20:40:54 +01:00
Alexis Sellier 81a1ee5cc2
cob: Implement `Store::remove`
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-02 14:21:50 +01:00
Alexis Sellier 6c0c7b2969
cob: Delete redundant functions
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-02 14:21:50 +01:00
Alexis Sellier 64ce15dbe2
crdt: Include timestamp in `Change`
We can then use the real change timestamp for our COBs.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-02 14:19:25 +01:00
Alexis Sellier d061afdab1
cob: Include commit timestamp in `Entry`
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-02 14:19:25 +01:00
Alexis Sellier 3af2c53bb2
cob: Implement COB removal function
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-01 12:05:44 +01:00
Alexis Sellier dd7052926a
cob: Remove `author` from `Entry`
It was no longer used.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-01 12:05:44 +01:00
Alexis Sellier 5a47023ac0
cob: Change history type to a string
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-01 12:05:44 +01:00
Alexis Sellier f140c6d28e
cob: Add actor to `Entry`
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-01 12:05:44 +01:00
Alexis Sellier e83d47ff45
cob: Compute implicit monotonic clock on changes
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-01 12:05:44 +01:00
Alexis Sellier 1a5b68c2b3
cob: Parametrize `Change` with single signature
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-01 12:05:44 +01:00
Alexis Sellier 86e6fa22a1
cob: Rename default history type
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-11-26 17:52:31 +01:00
Alexis Sellier 01b7686659
Turn `Redactable` into a semilattice
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-11-26 17:13:22 +01:00
Alexis Sellier 5526eceea0
cob: Add new history type, simplify `Content`
Keep the history type in the manifest, but no need to specify it
for all individual changes.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-11-24 13:41:24 +01:00
Dr Maxim Orlovsky 2a6f3c4f55
Update ed25519-compact dependency 2022-11-21 16:07:43 +01:00
Fintan Halpenny c620f873e5
radicle-cob: test parse_refstr
Add quickcheck tests for parse_refstr to ensure the correct
behaviour.

This required adding Arbitrary instances for TypeName and ObjectId, as
well as adding a mechanism for generating Invalid ObjectIds.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-17 17:42:22 +00:00
Fintan Halpenny a985e067a5
Add TypeName & ObjectId parser
Added the `parse_refname` function for parsing a reference into its
`TypeName` and `ObjectId`, if possible.

This replaces the `cob_suffix` function in `radicle`.

This change also fixes the `FromStr` instance of `ObjectId` to use
`from_str` instead of `TryFrom` for bytes.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-17 17:42:21 +00:00
Alexis Sellier 08811b4b87
Various fixes to COBs
* Use the existing conventions for passing a signer to functions.
* Allow replacing git refs when updating cobs.
* Fix the parsing of a cob id.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-11-14 12:40:00 +01:00
Fintan Halpenny 0bd213d15a
radicle-cob: simplify Objects and remove identifier
Objects does not need to be separated by `local` and `remotes`, it
uses `iter` internally, so all references are used regardless.

Simplify Objects by having it be a simple vector of references.

This also means that the `identifier` is not needed. This was only
required to identify the local reference, so it can now be removed.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-08 18:13:54 +00:00
Fintan Halpenny d6416c9be1
radicle-cob: remove Resource on Store
The `Store` trait had a paramter for a `Resource`. This is too
restrictive for implementations, particularly `heartwood`.

Instead, where a unique identifier is needed for the
`object::Storage`, i.e. in `create` and `update`, the identifier
becomes a parameter.

This allows the removal of passing the resource in `list`, `get` and
`changegraph`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-08 18:13:53 +00:00
Fintan Halpenny 4112b0fdc5
radicle-cob: Reference conversion from git2::Reference
It will be common for Reference to be converted from a
`git2::Reference` when one is implementing `object::Storage`.

Provide a `TryFrom` implementation between `git2::Reference` and
`Reference`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-08 14:46:52 +00:00
Fintan Halpenny 6b303bdc97
radicle-cob: Component conversions
`TypeName` and `ObjectId` are expected to be used in reference
names.

Add `From` conversions to `Component` for both of these types to make
it easier for using them with `git-ref-format`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2022-11-08 14:46:51 +00:00
Fintan Halpenny f3c4a53e1e
radicle-cob: port collaborative objects
This is a minimal port of the collaborative objects code from
radicle-link[0].

A `CollaborativeObject` is made up of a `History` of `Change`s that
are expected to be stored in a `git` backend.

The library exposes a CRU series of functions `create`, `get`, `list`,
and `update`.

This implementation differs, to previous one, in that it does not
assume any kind of identity system -- its only assumption is that
identities have an identifier and can be addressed in the `git`
database. This means that it does not require an `author` to be passed
in and it only uses the `resource` (previously `authorizing_identity`)
to store its content-address in the `Change`.

It also foregoes any caching to simplify the port and not make any
early optimisation assumptions.

[0]: https://github.com/radicle-dev/radicle-link/tree/master/cob

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2022-11-04 16:11:18 +00:00