Skip to content

Commit

Permalink
Merge pull request #166 from dedis/initialisation-fix-web
Browse files Browse the repository at this point in the history
Fixes initialisation process on the web frontend
  • Loading branch information
nkcr authored Sep 22, 2022
2 parents f101f1a + 3a6ab20 commit 412809d
Show file tree
Hide file tree
Showing 16 changed files with 423 additions and 250 deletions.
8 changes: 8 additions & 0 deletions services/dkg/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const (
Setup StatusCode = 1
// Failed is when the actor failed to set up
Failed StatusCode = 2
// Dealing is when the actor is sending its deals
Dealing = 3
// Responding is when the actor sends its responses on the deals
Responding = 4
// Certifying is when the actor is validating its responses
Certifying = 5
// Certified is then the actor is certified
Certified = 6
)

// DKG defines the primitive to start a DKG protocol
Expand Down
11 changes: 10 additions & 1 deletion services/dkg/pedersen/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

etypes "github.com/dedis/d-voting/contracts/evoting/types"
"github.com/dedis/d-voting/internal/testing/fake"
"github.com/dedis/d-voting/services/dkg"
"github.com/dedis/d-voting/services/dkg/pedersen/types"
"go.dedis.ch/dela"
"go.dedis.ch/dela/core/ordering"
Expand Down Expand Up @@ -70,12 +71,14 @@ type Handler struct {

log zerolog.Logger
running bool

status *dkg.Status
}

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

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

log: log,
running: false,

status: status,
}
}

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

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

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

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

// Send back the public DKG key
distKey, err := h.dkg.DistKeyShare()
Expand Down
14 changes: 8 additions & 6 deletions services/dkg/pedersen/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ func (s *Pedersen) NewActor(electionIDBuf []byte, pool pool.Pool, txmngr txn.Man

ctx := jsonserde.NewContext()

status := &dkg.Status{Status: dkg.Initialized}

// link the actor to an RPC by the election ID
h := NewHandler(s.mino.GetAddress(), s.service, pool, txmngr, s.signer,
handlerData, ctx, s.electionFac)
handlerData, ctx, s.electionFac, status)

no := s.mino.WithSegment(electionID)
rpc := mino.MustCreateRPC(no, RPC, h, s.factory)
Expand All @@ -135,7 +137,7 @@ func (s *Pedersen) NewActor(electionIDBuf []byte, pool pool.Pool, txmngr txn.Man
electionFac: s.electionFac,
handler: h,
electionID: electionID,
status: dkg.Status{Status: dkg.Initialized},
status: status,
log: log,
}

Expand Down Expand Up @@ -167,12 +169,12 @@ type Actor struct {
electionFac serde.Factory
handler *Handler
electionID string
status dkg.Status
status *dkg.Status
log zerolog.Logger
}

func (a *Actor) setErr(err error, args map[string]interface{}) {
a.status = dkg.Status{
*a.status = dkg.Status{
Status: dkg.Failed,
Err: err,
Args: args,
Expand Down Expand Up @@ -313,7 +315,7 @@ func (a *Actor) Setup() (kyber.Point, error) {
a.log.Info().Msgf("ok for %s", addr.String())
}

a.status = dkg.Status{Status: dkg.Setup}
*a.status = dkg.Status{Status: dkg.Setup}
evoting.PromElectionDkgStatus.WithLabelValues(a.electionID).Set(float64(dkg.Setup))

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

// Status implements dkg.Actor
func (a *Actor) Status() dkg.Status {
return a.status
return *a.status
}

func electionExists(service ordering.Service, electionIDBuf []byte) (ordering.Proof, bool) {
Expand Down
2 changes: 1 addition & 1 deletion services/dkg/pedersen/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestPedersen_InitNonEmptyMap(t *testing.T) {

otherActor := Actor{
handler: NewHandler(fake.NewAddress(0), &fake.Service{}, &fake.Pool{},
fake.Manager{}, fake.Signer{}, handlerData, serdecontext, electionFac),
fake.Manager{}, fake.Signer{}, handlerData, serdecontext, electionFac, nil),
}

requireActorsEqual(t, actor, &otherActor)
Expand Down
28 changes: 28 additions & 0 deletions web/frontend/src/components/utils/DKGStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,34 @@ const DKGStatus: FC<DKGStatusProps> = ({ status }) => {
<div>{t('failed')}</div>
</div>
);
case NodeStatus.Dealing:
return (
<div className="flex items-center">
<div className="block h-4 w-4 bg-blue-500 rounded-full mr-2"></div>
<div>{t('dealing')}</div>
</div>
);
case NodeStatus.Responding:
return (
<div className="flex items-center">
<div className="block h-4 w-4 bg-blue-500 rounded-full mr-2"></div>
<div>{t('responding')}</div>
</div>
);
case NodeStatus.Certifying:
return (
<div className="flex items-center">
<div className="block h-4 w-4 bg-blue-500 rounded-full mr-2"></div>
<div>{t('certifying')}</div>
</div>
);
case NodeStatus.Certified:
return (
<div className="flex items-center">
<div className="block h-4 w-4 bg-green-500 rounded-full mr-2"></div>
<div>{t('certified')}</div>
</div>
);
default:
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions web/frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
"setupNode": "Setup Node",
"statusOpen": "Open",
"failed": "Failed",
"dealing": "Dealing",
"responding": "Responding",
"certifying": "Certifying",
"certified": "Certified",
"opening": "Opening...",
"statusClose": "Closed",
"closing": "Closing...",
Expand Down
6 changes: 6 additions & 0 deletions web/frontend/src/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const Footer = () => (
<ProxyInput />
</div>
</div>
<div className="text-center">
version:
{process.env.REACT_APP_VERSION || 'unknown'} - build{' '}
{process.env.REACT_APP_BUILD || 'unknown'} - on{' '}
{process.env.REACT_APP_BUILD_TIME || 'unknown'}
</div>
</footer>
</div>
);
Expand Down
53 changes: 48 additions & 5 deletions web/frontend/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ let mockUserDB = setupMockUserDB();
const RESPONSE_TIME = 500;
const CHANGE_STATUS_TIMER = 2000;
const INIT_TIMER = 1000;
const SETUP_TIMER = 2000;
const SHUFFLE_TIMER = 2000;
const DECRYPT_TIMER = 1000;

Expand All @@ -63,7 +62,7 @@ export const handlers = [
? {
lastname: 'Bobster',
firstname: 'Alice',
role: UserRole.Voter,
role: UserRole.Admin,
sciper: userId,
}
: {};
Expand Down Expand Up @@ -263,16 +262,60 @@ export const handlers = [
const newDKGStatus = new Map(mockDKG.get(ElectionID as string));
let node = '';

mockElections.get(ElectionID as string).Roster.forEach((n) => {
const roster = mockElections.get(ElectionID as string).Roster;

const INCREMENT = 1200;

roster.forEach((n) => {
const p = mockNodeProxyAddresses.get(n);
if (p === body.Proxy) {
node = n;
}
});

newDKGStatus.set(node, NodeStatus.Setup);
const setup = () => {
newDKGStatus.set(node, NodeStatus.Setup);
mockDKG.set(ElectionID as string, newDKGStatus);
};

const certified = () => {
roster.forEach((n) => {
newDKGStatus.set(n, NodeStatus.Certified);
});
mockDKG.set(ElectionID as string, newDKGStatus);

setTimeout(setup, INCREMENT);
};

const certifying = () => {
roster.forEach((n) => {
newDKGStatus.set(n, NodeStatus.Certifying);
});
mockDKG.set(ElectionID as string, newDKGStatus);

setTimeout(certified, INCREMENT);
};

const responding = () => {
roster.forEach((n) => {
newDKGStatus.set(n, NodeStatus.Responding);
});
mockDKG.set(ElectionID as string, newDKGStatus);

setTimeout(certifying, INCREMENT);
};

const dealing = () => {
roster.forEach((n) => {
newDKGStatus.set(n, NodeStatus.Dealing);
});
mockDKG.set(ElectionID as string, newDKGStatus);

setTimeout(responding, INCREMENT);
};

setTimeout(dealing, INCREMENT);

setTimeout(() => mockDKG.set(ElectionID as string, newDKGStatus), SETUP_TIMER);
break;
case Action.BeginDecryption:
setTimeout(
Expand Down
Loading

0 comments on commit 412809d

Please sign in to comment.