You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ARCHITECTURE.md
+16-20Lines changed: 16 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,20 +34,18 @@ This repository contains a gRPC server which coordinates multi-party threshold p
34
34
-`task` contains the logic for task computation
35
35
-`protocol` contains the logic for protocol computation
36
36
-`communicator` defines the communicator
37
-
-`group` defines a created group
38
37
-`error` contains definitions of error variants
39
38
-`utils` contains a few helper functions
40
39
41
-
## Protobuf API
42
-
TODO
43
-
44
40
## Persistence
45
41
Most of the server state is persisted throughout server restarts, but some state is deliberately ephemeral and kept only in the RAM. The ephemeral state is mostly data which changes "rapidly", namely activity timestamps and messages exchanged during protocol computation.
46
42
47
43
Persistence is handled in the `state` module, with the exception of `task_store`, which is only used within `state`. This is to decouple the logic from bookkeeping.
48
44
45
+
The `persistence` module is supposed to be a "dumb" interface for communicating with the DB. In particular, it shouldn't validate data, perform complex logic, etc...
46
+
49
47
## State machines and state changes
50
-
Much of the actual logic can be easily modelled using state machines. We use typestates to enforce valid state transitions. For example, a running task cannot change into a voting task.
48
+
Much of the actual logic can be easily modeled using state machines. We use typestates to enforce valid state transitions. For example, a running task cannot change into a voting task.
51
49
52
50
Functions which update some state return a state change enum, which enforces handling of all possible situations and explicitly defines the logic. For example, saving a vote in a voting task can have three outcomes:
53
51
- The task is accepted and transitions into a running task
@@ -77,12 +75,11 @@ Adding new protocols must be coordinated with the `meesign-crypto` repository.
77
75
78
76
Protocols are defined throughout several places in the codebase:
79
77
1. The `proto/meesign.proto` files in this and `meesign-crypto` repositories define a `ProtocolType` enumeration. Both must be extended.
80
-
2. A few trait implementations for `ProtocolType` must be extended in `main.rs`.
81
-
3. Another `ProtocolType` enum must be extended in `persistence/enums.rs`.
82
-
4. The `protocol_type` enum must be extended in the DB migrations.
83
-
5. A module should be added into `protocols`, similar to other protocols defined there.
84
-
6. The module needs to create a type implementing the `Protocol` trait for each of its variants, for example `<protocol>Group`, `<protocol>Sign`, ...
85
-
7. The module should use constants from `meesign_crypto::protocols::<protocol>`.
78
+
2. A few trait implementations for `ProtocolType` must be extended in `persistence/enums.rs`.
79
+
3. The `protocol_type` enum must be extended in the DB migrations.
80
+
4. A module should be added into `protocols`, similar to other protocols defined there.
81
+
5. The module needs to create a type implementing the `Protocol` trait for each of its variants, for example `<protocol>Group`, `<protocol>Sign`, ...
82
+
6. The module should use constants from `meesign_crypto::protocols::<protocol>`.
86
83
87
84
The overall structure should reflect the way other protocols are implemented. See the `protocols/frost.rs` module for example.
88
85
@@ -91,13 +88,12 @@ Adding new task types must be coordinated with the `meesign-client` repository.
91
88
92
89
If the task follows the usual task phases (voting, declined, running, failed, finished), then it should follow the structure of other task types already established in this repo. Otherwise, it must be handled exceptionally.
93
90
94
-
Protocols are defined throughout several places in the codebase:
95
-
1. The `proto/meesign.proto` files in this and `meesign-crypto` repositories define a `ProtocolType` enumeration. Both must be extended.
96
-
2. A few trait implementations for `ProtocolType` must be extended in `main.rs`.
97
-
3. Another `ProtocolType` enum must be extended in `persistence/enums.rs`.
98
-
4. The `protocol_type` enum must be extended in the DB migrations.
99
-
5. A module should be added into `protocols`, similar to other protocols defined there.
100
-
6. The module needs to create a type implementing the `Protocol` trait for each of its variants, for example `<protocol>Group`, `<protocol>Sign`, ...
101
-
7. The module should use constants from `meesign_crypto::protocols::<protocol>`.
91
+
Here is a general process for when the new task type follows the usual task phases:
92
+
1. The `proto/meesign.proto` file defines a `TaskType` enumeration. It must be extended.
93
+
2. A few trait implementations for `TaskType` must be extended in `persistence/enums.rs`.
94
+
3. The `task_type` enum must be extended in the DB migrations.
95
+
4. The `RunningTaskContext` enum in `tasks/mod.rs` must be extended.
96
+
5. A module should be added into `tasks`, similar to other tasks defined there.
97
+
6. The module needs to create a type implementing the `RunningTask` trait.
102
98
103
-
The overall structure should reflect the way other protocols are implemented. See the `protocols/frost.rs` module for example.
99
+
The overall structure should reflect the way other tasks are implemented. See the `tasks/sign.rs` module for example.
0 commit comments