-
Notifications
You must be signed in to change notification settings - Fork 178
/
doc.go
77 lines (57 loc) · 3.2 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Package dkg implements a controller that manages the lifecycle of a Joint
Feldman DKG node, as well as a broker that enables the controller to communicate
with other nodes
# Controller
A new controller must be instantiated for every epoch.
The state-machine can be represented as follows:
+-------+ /Run() +---------+ /EndPhase1() +---------+ /EndPhase2() +---------+ /End() +-----+ +----------+
| Init | -----> | Phase 1 | ------------> | Phase 2 | ------------> | Phase 3 | --------> | End | --> | Shutdown |
+-------+ +---------+ +---------+ +---------+ +-----+ +----------+
| | | | ^
v___________________v_________________________v_________________________v_________________________________|
/Shutdown()
The controller is always in one of 6 states:
- Init: Default state before the instance is started
- Phase 1: 1st phase of the JF DKG protocol while it's running
- Phase 2: 2nd phase ---
- Phase 3: 3rd phase ---
- End: When the DKG protocol is finished
- Shutdown: When the controller and all its routines are stopped
The controller exposes the following functions to trigger transitions:
Run(): Triggers transition from Init to Phase1. Starts the DKG protocol instance
and background communication routines.
EndPhase1(): Triggers transition from Phase 1 to Phase 2.
EndPhase2(): Triggers transition from Phase 2 to Phase 3.
End(): Ends the DKG protocol and records the artifacts in controller. Triggers
transition from Phase 3 to End.
Shutdown(): Can be called from any state to stop the DKG instance.
The End and Shutdown states differ in that the End state can only be arrived at
from Phase 3 and after successfully computing the DKG artifacts. Whereas the
Shutdown state can be reached from any other state.
# Broker
The controller requires a broker to communicate with other nodes over the
network and to read broadcast messages from the DKG smart-contract. A new broker
must be instantiated for every epoch.
The Broker is responsible for:
- converting to and from the message format used by the underlying crypto DKG
package.
- appending dkg instance id to messages to prevent replay attacks
- checking the integrity of incoming messages
- signing and verifying broadcast messages (broadcast messages are signed with
the staking key of the sender)
- forwarding incoming messages (private and broadcast) to the controller via a
channel
- forwarding outgoing messages (private and broadcast) to other nodes.
+------------+ +-------------+
| | | | <--------(tunnel)-----------> network engine <--> Other nodes
| Controller |--| Broker |
| | | | <--(smart-contract client)--> DKG smart-contract
+------------+ +-------------+
To relay private messages, the broker uses a BrokerTunnel to communicate with a
network engine.
To send and receive broadcast messages, the broker communicates with the DKG
smart-contract via a smart-contract client. The broker's Poll method must be
called regularly to read broadcast messages from the smart-contract.
*/
package dkg