-
Notifications
You must be signed in to change notification settings - Fork 14
/
WorkingGroup.rho
191 lines (189 loc) · 7.81 KB
/
WorkingGroup.rho
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
new trace, rl(`rho:registry:lookup`),
insertArbitrary(`rho:registry:insertArbitrary`),
WorkingGroup, TestFundWG, closeWG,
rCh, toJim, toDan, testsPass in {
/**
* Test Scenario: Dan and Jim are starting a working group
* to control, for example, a fund. Note that neither Dan
* nor Jim has the fund in scope; they can only invoke it
* (to pay someone) by mutual action.
*/
contract TestFundWG(@unsealers /\ Map, @quorum /\ Int, ret) = {
new fund in {
WorkingGroup!(unsealers, quorum, *fund, *ret) |
contract fund(@"pay", whom, @amt, ret) = {
// manipulate amt just to show we did some computation here
ret!(amt - 1)
}
}
}
|
// Sealer / Unsealer pairs (aka brands) are available from the MultiSigRevVault contract.
rl!(`rho:id:b9s6j3xeobgset4ndn64hje64grfcj7a43eekb3fh43yso5ujiecfn`, *rCh) |
for (@(_, *MultiSigRevVault) <- rCh) {
trace!("got MultiSigRevVault") |
// Dan makes a brand, sends the unsealer on toJim,
// and uses the sealer on his agreement to pay Bob 100
// once he gets the wg from Jim on toDan.
new ch, ex, dcCh, sealCh, pEx, pOk in {
MultiSigRevVault!("makeSealerUnsealer", *dcCh) |
for (@(*dcSealer, *dcUnsealer) <- dcCh) {
trace!("got dc brand") |
toJim!(*dcUnsealer) |
for(wg <- toDan) {
wg!("agree", *ex, "DC", "un-signed/sealed proposal", *ch) |
for (@problem <- ex) {
trace!(problem)
}
|
dcSealer!(("pay", "Bob", 100), *sealCh) | for (@sealedProposal <- sealCh) {
wg!("agree", *pEx, "DC", sealedProposal, *pOk) |
// Either Dan or Jim may be the deciding vote.
for (@voteResult <- pOk) {
trace!(["DC vote result", voteResult]) |
// vote to close the WG
dcSealer!(*closeWG, *sealCh) | for (@sealedProposal <- sealCh) {
wg!("modifyMembership", *pEx, "DC", sealedProposal, *pOk) |
// Either Dan or Jim may be the deciding vote.
for (@(true, result) <- pOk) {
testsPass!(result)
}
}
}
}
}
}
}
|
// Jim makes a brand and uses his and Dan's unsealers
// to make a FundWG, which he sends on toDan.
// Jim uses his sealer on his agreement to pay Bob 100.
new ch, ex, jwCh, sealCh, pEx, pOk in {
MultiSigRevVault!("makeSealerUnsealer", *jwCh) |
for (@(*jwSealer, *jwUnsealer) <- jwCh; dcUnsealer <- toJim) {
trace!("got jw brand") |
TestFundWG!({"DC": *dcUnsealer, "JW": *jwUnsealer}, 2, *ch) | for (wg <- ch) {
toDan!(*wg) |
jwSealer!(("pay", "Bob", 100), *sealCh) | for (@sealedProposal <- sealCh) {
wg!("agree", *pEx, "JW", sealedProposal, *pOk) |
// Either Dan or Jim may be the deciding vote.
for (@voteResult <- pOk) {
trace!(["JW vote result", voteResult]) |
// vote to close the WG
jwSealer!(*closeWG, *sealCh) | for (@sealedProposal <- sealCh) {
wg!("modifyMembership", *pEx, "JW", sealedProposal, *pOk) |
// Either Dan or Jim may be the deciding vote.
for (@(true, result) <- pOk) {
testsPass!(result)
}
}
}
}
}
}
}
|
contract closeWG(_oldMem, ret) = { ret!({}) }
|
contract testsPass(@result) = {
trace!(["membership size", result]) |
new uriCh in {
insertArbitrary!(*WorkingGroup, *uriCh) | for (@uri <- uriCh) {
trace!(["WorkingGroup registered at", uri])
}
}
}
|
contract WorkingGroup(
@initialMembership /\ Map, // member name to unsealer
@quorum /\ Int,
sharedPower,
ret
) = {
// trace!(["WorkingGroup", unsealers.size(), quorum]) |
new self, pendingCh, memCh in {
pendingCh!({}) |
memCh!(initialMembership) |
ret!(*self) |
contract self(@"getMembership", ret) = {
for (@mem <<- memCh) { ret!(mem) }
} |
contract self(
@method /\ String, // agree or modifyMembership
ej, // ejector - channel for exceptional outcome (ISSUE: failed experiment?)
@by /\ String,
@sealedProposal,
ret
) = {
new unsCh, rCh in {
// trace!([method, by]) |
for (@unsealers <<- memCh) {
match unsealers.get(by) {
Nil => ej!({"message": "by ${by} not known" %% {"by": by}})
whoseUnsealer => {
// trace!(["found unsealer...", by]) |
@whoseUnsealer!(sealedProposal, *unsCh) |
for (@(ok, what) <- unsCh) {
match ok {
false => ej!({"message": what})
true => {
for(@pending <- pendingCh) {
match (pending.get(what)) {
Nil => {
// trace!(["new proposal by", by]) |
pendingCh!(pending.set(what, Set(by))) |
ret!((false, quorum - 1))
}
supporters => {
// trace!(["adding", by, supporters.size()]) |
match (supporters.size() + 1 >= quorum) {
false => {
pendingCh!(pending.set(what, supporters.union(Set(by)))) |
ret!((false, quorum - (supporters.size() + 1)))
}
true => {
// trace!(["proposal carries", what]) |
pendingCh!(pending.delete(what)) |
match (method, what) {
("modifyMembership", *f) => {
new ch in {
for (@oldMem <- memCh) {
f!(oldMem, *ch) |
for (@newMem /\ Map <- ch) {
memCh!(newMem) |
rCh!(newMem.size())
}
}
}
}
// We want to send an arbitrary number of processes
// (...args) => sharedPower!(...args)
// but I don't see how, so...
("agree", (m, a1)) => sharedPower!(m, a1, *rCh)
("agree", (m, a1, a2)) => sharedPower!(m, a1, a2, *rCh)
("agree", (m, a1, a2, a3)) => sharedPower!(m, a1, a2, a3, *rCh)
("agree", (m, a1, a2, a3, a4)) => sharedPower!(m, a1, a2, a3, a4, *rCh)
("agree", (m, a1, a2, a3, a4, a5)) => sharedPower!(m, a1, a2, a3, a4, a5, *rCh)
("agree", x) => sharedPower!(x, *rCh)
x => ej!({"message": "bad method?"})
} |
for (@result <- rCh) {
ret!((true, result))
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}