Skip to content

Commit 412809d

Browse files
authored
Merge pull request #166 from dedis/initialisation-fix-web
Fixes initialisation process on the web frontend
2 parents f101f1a + 3a6ab20 commit 412809d

File tree

16 files changed

+423
-250
lines changed

16 files changed

+423
-250
lines changed

services/dkg/mod.go

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ const (
2424
Setup StatusCode = 1
2525
// Failed is when the actor failed to set up
2626
Failed StatusCode = 2
27+
// Dealing is when the actor is sending its deals
28+
Dealing = 3
29+
// Responding is when the actor sends its responses on the deals
30+
Responding = 4
31+
// Certifying is when the actor is validating its responses
32+
Certifying = 5
33+
// Certified is then the actor is certified
34+
Certified = 6
2735
)
2836

2937
// DKG defines the primitive to start a DKG protocol

services/dkg/pedersen/handler.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
etypes "github.com/dedis/d-voting/contracts/evoting/types"
2525
"github.com/dedis/d-voting/internal/testing/fake"
26+
"github.com/dedis/d-voting/services/dkg"
2627
"github.com/dedis/d-voting/services/dkg/pedersen/types"
2728
"go.dedis.ch/dela"
2829
"go.dedis.ch/dela/core/ordering"
@@ -70,12 +71,14 @@ type Handler struct {
7071

7172
log zerolog.Logger
7273
running bool
74+
75+
status *dkg.Status
7376
}
7477

7578
// NewHandler creates a new handler
7679
func NewHandler(me mino.Address, service ordering.Service, pool pool.Pool,
7780
txnmngr txn.Manager, pubSharesSigner crypto.Signer, handlerData HandlerData,
78-
context serde.Context, electionFac serde.Factory) *Handler {
81+
context serde.Context, electionFac serde.Factory, status *dkg.Status) *Handler {
7982

8083
privKey := handlerData.PrivKey
8184
pubKey := handlerData.PubKey
@@ -101,6 +104,8 @@ func NewHandler(me mino.Address, service ordering.Service, pool pool.Pool,
101104

102105
log: log,
103106
running: false,
107+
108+
status: status,
104109
}
105110
}
106111

@@ -255,19 +260,23 @@ func (h *Handler) start(start types.Start, deals, resps *list.List, from mino.Ad
255260
// doDKG calls the subsequent DKG steps
256261
func (h *Handler) doDKG(deals, resps *list.List, out mino.Sender, from mino.Address) {
257262
h.log.Info().Str("action", "deal").Msg("new state")
263+
*h.status = dkg.Status{Status: dkg.Dealing}
258264
h.deal(out)
259265

260266
h.log.Info().Str("action", "respond").Msg("new state")
267+
*h.status = dkg.Status{Status: dkg.Responding}
261268
h.respond(deals, out)
262269

263270
h.log.Info().Str("action", "certify").Msg("new state")
271+
*h.status = dkg.Status{Status: dkg.Certifying}
264272
err := h.certify(resps, out)
265273
if err != nil {
266274
dela.Logger.Error().Msgf("failed to certify: %v", err)
267275
return
268276
}
269277

270278
h.log.Info().Str("action", "finalize").Msg("new state")
279+
*h.status = dkg.Status{Status: dkg.Certified}
271280

272281
// Send back the public DKG key
273282
distKey, err := h.dkg.DistKeyShare()

services/dkg/pedersen/mod.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ func (s *Pedersen) NewActor(electionIDBuf []byte, pool pool.Pool, txmngr txn.Man
118118

119119
ctx := jsonserde.NewContext()
120120

121+
status := &dkg.Status{Status: dkg.Initialized}
122+
121123
// link the actor to an RPC by the election ID
122124
h := NewHandler(s.mino.GetAddress(), s.service, pool, txmngr, s.signer,
123-
handlerData, ctx, s.electionFac)
125+
handlerData, ctx, s.electionFac, status)
124126

125127
no := s.mino.WithSegment(electionID)
126128
rpc := mino.MustCreateRPC(no, RPC, h, s.factory)
@@ -135,7 +137,7 @@ func (s *Pedersen) NewActor(electionIDBuf []byte, pool pool.Pool, txmngr txn.Man
135137
electionFac: s.electionFac,
136138
handler: h,
137139
electionID: electionID,
138-
status: dkg.Status{Status: dkg.Initialized},
140+
status: status,
139141
log: log,
140142
}
141143

@@ -167,12 +169,12 @@ type Actor struct {
167169
electionFac serde.Factory
168170
handler *Handler
169171
electionID string
170-
status dkg.Status
172+
status *dkg.Status
171173
log zerolog.Logger
172174
}
173175

174176
func (a *Actor) setErr(err error, args map[string]interface{}) {
175-
a.status = dkg.Status{
177+
*a.status = dkg.Status{
176178
Status: dkg.Failed,
177179
Err: err,
178180
Args: args,
@@ -313,7 +315,7 @@ func (a *Actor) Setup() (kyber.Point, error) {
313315
a.log.Info().Msgf("ok for %s", addr.String())
314316
}
315317

316-
a.status = dkg.Status{Status: dkg.Setup}
318+
*a.status = dkg.Status{Status: dkg.Setup}
317319
evoting.PromElectionDkgStatus.WithLabelValues(a.electionID).Set(float64(dkg.Setup))
318320

319321
return dkgPubKeys[0], nil
@@ -397,7 +399,7 @@ func (a *Actor) MarshalJSON() ([]byte, error) {
397399

398400
// Status implements dkg.Actor
399401
func (a *Actor) Status() dkg.Status {
400-
return a.status
402+
return *a.status
401403
}
402404

403405
func electionExists(service ordering.Service, electionIDBuf []byte) (ordering.Proof, bool) {

services/dkg/pedersen/mod_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestPedersen_InitNonEmptyMap(t *testing.T) {
184184

185185
otherActor := Actor{
186186
handler: NewHandler(fake.NewAddress(0), &fake.Service{}, &fake.Pool{},
187-
fake.Manager{}, fake.Signer{}, handlerData, serdecontext, electionFac),
187+
fake.Manager{}, fake.Signer{}, handlerData, serdecontext, electionFac, nil),
188188
}
189189

190190
requireActorsEqual(t, actor, &otherActor)

web/frontend/src/components/utils/DKGStatus.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ const DKGStatus: FC<DKGStatusProps> = ({ status }) => {
4949
<div>{t('failed')}</div>
5050
</div>
5151
);
52+
case NodeStatus.Dealing:
53+
return (
54+
<div className="flex items-center">
55+
<div className="block h-4 w-4 bg-blue-500 rounded-full mr-2"></div>
56+
<div>{t('dealing')}</div>
57+
</div>
58+
);
59+
case NodeStatus.Responding:
60+
return (
61+
<div className="flex items-center">
62+
<div className="block h-4 w-4 bg-blue-500 rounded-full mr-2"></div>
63+
<div>{t('responding')}</div>
64+
</div>
65+
);
66+
case NodeStatus.Certifying:
67+
return (
68+
<div className="flex items-center">
69+
<div className="block h-4 w-4 bg-blue-500 rounded-full mr-2"></div>
70+
<div>{t('certifying')}</div>
71+
</div>
72+
);
73+
case NodeStatus.Certified:
74+
return (
75+
<div className="flex items-center">
76+
<div className="block h-4 w-4 bg-green-500 rounded-full mr-2"></div>
77+
<div>{t('certified')}</div>
78+
</div>
79+
);
5280
default:
5381
return null;
5482
}

web/frontend/src/language/en.json

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@
132132
"setupNode": "Setup Node",
133133
"statusOpen": "Open",
134134
"failed": "Failed",
135+
"dealing": "Dealing",
136+
"responding": "Responding",
137+
"certifying": "Certifying",
138+
"certified": "Certified",
135139
"opening": "Opening...",
136140
"statusClose": "Closed",
137141
"closing": "Closing...",

web/frontend/src/layout/Footer.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const Footer = () => (
2121
<ProxyInput />
2222
</div>
2323
</div>
24+
<div className="text-center">
25+
version:
26+
{process.env.REACT_APP_VERSION || 'unknown'} - build{' '}
27+
{process.env.REACT_APP_BUILD || 'unknown'} - on{' '}
28+
{process.env.REACT_APP_BUILD_TIME || 'unknown'}
29+
</div>
2430
</footer>
2531
</div>
2632
);

web/frontend/src/mocks/handlers.ts

+48-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ let mockUserDB = setupMockUserDB();
3939
const RESPONSE_TIME = 500;
4040
const CHANGE_STATUS_TIMER = 2000;
4141
const INIT_TIMER = 1000;
42-
const SETUP_TIMER = 2000;
4342
const SHUFFLE_TIMER = 2000;
4443
const DECRYPT_TIMER = 1000;
4544

@@ -63,7 +62,7 @@ export const handlers = [
6362
? {
6463
lastname: 'Bobster',
6564
firstname: 'Alice',
66-
role: UserRole.Voter,
65+
role: UserRole.Admin,
6766
sciper: userId,
6867
}
6968
: {};
@@ -263,16 +262,60 @@ export const handlers = [
263262
const newDKGStatus = new Map(mockDKG.get(ElectionID as string));
264263
let node = '';
265264

266-
mockElections.get(ElectionID as string).Roster.forEach((n) => {
265+
const roster = mockElections.get(ElectionID as string).Roster;
266+
267+
const INCREMENT = 1200;
268+
269+
roster.forEach((n) => {
267270
const p = mockNodeProxyAddresses.get(n);
268271
if (p === body.Proxy) {
269272
node = n;
270273
}
271274
});
272275

273-
newDKGStatus.set(node, NodeStatus.Setup);
276+
const setup = () => {
277+
newDKGStatus.set(node, NodeStatus.Setup);
278+
mockDKG.set(ElectionID as string, newDKGStatus);
279+
};
280+
281+
const certified = () => {
282+
roster.forEach((n) => {
283+
newDKGStatus.set(n, NodeStatus.Certified);
284+
});
285+
mockDKG.set(ElectionID as string, newDKGStatus);
286+
287+
setTimeout(setup, INCREMENT);
288+
};
289+
290+
const certifying = () => {
291+
roster.forEach((n) => {
292+
newDKGStatus.set(n, NodeStatus.Certifying);
293+
});
294+
mockDKG.set(ElectionID as string, newDKGStatus);
295+
296+
setTimeout(certified, INCREMENT);
297+
};
298+
299+
const responding = () => {
300+
roster.forEach((n) => {
301+
newDKGStatus.set(n, NodeStatus.Responding);
302+
});
303+
mockDKG.set(ElectionID as string, newDKGStatus);
304+
305+
setTimeout(certifying, INCREMENT);
306+
};
307+
308+
const dealing = () => {
309+
roster.forEach((n) => {
310+
newDKGStatus.set(n, NodeStatus.Dealing);
311+
});
312+
mockDKG.set(ElectionID as string, newDKGStatus);
313+
314+
setTimeout(responding, INCREMENT);
315+
};
316+
317+
setTimeout(dealing, INCREMENT);
274318

275-
setTimeout(() => mockDKG.set(ElectionID as string, newDKGStatus), SETUP_TIMER);
276319
break;
277320
case Action.BeginDecryption:
278321
setTimeout(

0 commit comments

Comments
 (0)