Skip to content

Commit

Permalink
Merge pull request #132 from c4dt/e2e_fixes
Browse files Browse the repository at this point in the history
E2e fixes
  • Loading branch information
ineiti authored Mar 1, 2024
2 parents d34d817 + c8744e9 commit ae9e179
Show file tree
Hide file tree
Showing 31 changed files with 1,303 additions and 515 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
target: build
file: Dockerfiles/Dockerfile.dela
platforms: linux/amd64
push: true
Expand Down
22 changes: 12 additions & 10 deletions Dockerfiles/Dockerfile.dela
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM golang:1.20.6-bookworm AS base
RUN apt-get update && apt-get install git
# make sure we're using the same head as d-voting
RUN git clone https://github.com/c4dt/dela.git
WORKDIR /go/dela/cli/crypto
RUN go install
WORKDIR /go/d-voting
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .

FROM base AS build
COPY --from=base /go/dela .
COPY --from=base /go/d-voting .
ENV GOCACHE=/root/.cache/go-build
WORKDIR /go/d-voting/cli/dvoting
RUN go build
ENV PATH=/go/dela/cli/crypto:/go/d-voting/cli/dvoting:${PATH}
RUN --mount=type=cache,target="/root/.cache/go-build" go install
# make sure we're using the same head as d-voting
RUN --mount=type=cache,target="/root/.cache/go-build" cd $( go list -f '{{.Dir}}' go.dedis.ch/dela )/cli/crypto && go install

FROM golang:1.20.6-bookworm
WORKDIR /usr/local/bin
COPY --from=base /go/bin/crypto .
COPY --from=base /go/bin/dvoting .
ENTRYPOINT ["/bin/bash", "-c", "dvoting --config /data/node start --postinstall --proxyaddr :$PROXYPORT --proxykey $PROXYKEY --listen tcp://0.0.0.0:2000 --public $PUBLIC_URL --routing tree --noTLS"]
CMD []
51 changes: 8 additions & 43 deletions contracts/evoting/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

fmt.Fprintln(ctx.Out, "Get form")

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -420,7 +420,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

dela.Logger.Info().Msg(responseBody + respBody)

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand All @@ -444,7 +444,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
return xerrors.Errorf("failed to close form: %v", err)
}

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -482,7 +482,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

// time.Sleep(20 * time.Second)

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand All @@ -506,7 +506,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

time.Sleep(10 * time.Second)

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand All @@ -525,7 +525,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {
return xerrors.Errorf("failed to combine shares: %v", err)
}

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand All @@ -540,7 +540,7 @@ func (a *scenarioTestAction) Execute(ctx node.Context) error {

fmt.Fprintln(ctx.Out, "Get form result")

form, err = getForm(serdecontext, formFac, formID, service)
form, err = types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -639,7 +639,7 @@ func setupSimpleForm(ctx node.Context, secret kyber.Scalar, proxyAddr1 string,
return "", types.Form{}, nil, xerrors.Errorf("failed to decode formID '%s': %v", formID, err)
}

form, err := getForm(serdecontext, formFac, formID, service)
form, err := types.FormFromStore(serdecontext, formFac, formID, service.GetStore())
if err != nil {
return "", types.Form{}, nil, xerrors.Errorf(getFormErr, err)
}
Expand Down Expand Up @@ -811,41 +811,6 @@ func updateDKG(secret kyber.Scalar, proxyAddr, formIDHex, action string) (int, e
return 0, nil
}

// getForm gets the form from the snap. Returns the form ID NOT hex
// encoded.
func getForm(ctx serde.Context, formFac serde.Factory, formIDHex string,
srv ordering.Service) (types.Form, error) {

var form types.Form

formID, err := hex.DecodeString(formIDHex)
if err != nil {
return form, xerrors.Errorf("failed to decode formIDHex: %v", err)
}

proof, err := srv.GetProof(formID)
if err != nil {
return form, xerrors.Errorf("failed to get proof: %v", err)
}

formBuff := proof.GetValue()
if len(formBuff) == 0 {
return form, xerrors.Errorf("form does not exist")
}

message, err := formFac.Deserialize(ctx, formBuff)
if err != nil {
return form, xerrors.Errorf("failed to deserialize Form: %v", err)
}

form, ok := message.(types.Form)
if !ok {
return form, xerrors.Errorf("wrong message type: %T", message)
}

return form, nil
}

func createSignedErr(err error) error {
return xerrors.Errorf("failed to create signed request: %v", err)
}
Expand Down
17 changes: 1 addition & 16 deletions contracts/evoting/evoting.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 35 additions & 2 deletions contracts/evoting/types/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const (
PubSharesSubmitted Status = 4
// ResultAvailable is when the ballots have been decrypted
ResultAvailable Status = 5
// Canceled is when the form has been cancel
// Canceled is when the form has been canceled
Canceled Status = 6
)

// BallotsPerBlock to improve performance, so that (de)serializing only touches
// 100 ballots at a time.
var BallotsPerBlock = uint32(100)

// TestCastBallots: if true, automatically fills every block with ballots.
// TestCastBallots if true, automatically fills every block with ballots.
var TestCastBallots = false

// formFormat contains the supported formats for the form. Right now
Expand Down Expand Up @@ -158,6 +158,39 @@ func (e FormFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message,
return message, nil
}

// FormFromStore returns a form from the store given the formIDHex.
// An error indicates a wrong storage of the form.
func FormFromStore(ctx serde.Context, formFac serde.Factory, formIDHex string,
store store.Readable) (Form, error) {

form := Form{}

formIDBuf, err := hex.DecodeString(formIDHex)
if err != nil {
return form, xerrors.Errorf("failed to decode formIDHex: %v", err)
}

formBuff, err := store.Get(formIDBuf)
if err != nil {
return form, xerrors.Errorf("while getting data for form: %v", err)
}
if len(formBuff) == 0 {
return form, xerrors.Errorf("no form found")
}

message, err := formFac.Deserialize(ctx, formBuff)
if err != nil {
return form, xerrors.Errorf("failed to deserialize Form: %v", err)
}

form, ok := message.(Form)
if !ok {
return form, xerrors.Errorf("wrong message type: %T", message)
}

return form, nil
}

// ChunksPerBallot returns the number of chunks of El Gamal pairs needed to
// represent an encrypted ballot, knowing that one chunk is 29 bytes at most.
func (e *Form) ChunksPerBallot() int {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
)

replace (
go.dedis.ch/dela => github.com/c4dt/dela v0.0.0-20240125143006-d9bfc5ad2f59
go.dedis.ch/dela => github.com/c4dt/dela v0.0.0-20240301123018-73bff7b74d2f
go.dedis.ch/dela-apps => github.com/c4dt/dela-apps v0.0.0-20231121155105-f3a8a6f4b3b8
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/c4dt/dela v0.0.0-20240125143006-d9bfc5ad2f59 h1:mYFBc395DeUmimRIgB/Xk+AGXfuDcYWADM/qvocBkW4=
github.com/c4dt/dela v0.0.0-20240125143006-d9bfc5ad2f59/go.mod h1:Oh/WK8JMO0POQg7nR3u436u+HwsZwPqPzDWAasgmFAU=
github.com/c4dt/dela v0.0.0-20240301123018-73bff7b74d2f h1:xaUQ/rK337VOD45CjFn6xlDSj6iaTvDxiNjt04pmhrM=
github.com/c4dt/dela v0.0.0-20240301123018-73bff7b74d2f/go.mod h1:Oh/WK8JMO0POQg7nR3u436u+HwsZwPqPzDWAasgmFAU=
github.com/c4dt/dela-apps v0.0.0-20231121155105-f3a8a6f4b3b8 h1:ELho4tnVG7lM3c2I42Q5IGNyuk/2FQCterA2zVQGvms=
github.com/c4dt/dela-apps v0.0.0-20231121155105-f3a8a6f4b3b8/go.mod h1:Rky9YH7R02zSOirr2BhhdJs/9VH4+rxqkQxHU3UTQRA=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
2 changes: 1 addition & 1 deletion integration/dvotingdela.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func newDVotingNode(t require.TestingT, path string, randSource rand.Source) dVo

formFac := etypes.NewFormFactory(etypes.CiphervoteFactory{}, rosterFac)

dkg := pedersen.NewPedersen(onet, srvc, pool, formFac, signer)
dkg := pedersen.NewPedersen(onet, srvc, db, pool, formFac, signer)

evoting.RegisterContract(exec, evoting.NewContract(accessService, dkg, rosterFac))

Expand Down
23 changes: 1 addition & 22 deletions integration/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,7 @@ func openForm(m txManager, formID []byte) error {
func getForm(formFac serde.Factory, formID []byte,
service ordering.Service) (types.Form, error) {

form := types.Form{}

proof, err := service.GetProof(formID)
if err != nil {
return form, xerrors.Errorf("failed to GetProof: %v", err)
}

if proof == nil {
return form, xerrors.Errorf("form does not exist: %v", err)
}

message, err := formFac.Deserialize(serdecontext, proof.GetValue())
if err != nil {
return form, xerrors.Errorf("failed to deserialize Form: %v", err)
}

form, ok := message.(types.Form)
if !ok {
return form, xerrors.Errorf("wrong message type: %T", message)
}

return form, nil
return types.FormFromStore(serdecontext, formFac, hex.EncodeToString(formID), service.GetStore())
}

// for integration tests
Expand Down
18 changes: 15 additions & 3 deletions internal/testing/fake/ordering.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,28 @@ func (f Service) GetProof(key []byte) (ordering.Proof, error) {
// service.
func (f Service) GetStore() store.Readable {
return readable{
snap: f.BallotSnap,
snap: f.BallotSnap,
forms: f.Forms,
context: f.Context,
}
}

type readable struct {
snap *InMemorySnapshot
snap *InMemorySnapshot
forms map[string]formTypes.Form
context serde.Context
}

func (fr readable) Get(key []byte) ([]byte, error) {
return fr.snap.Get(key)
ret, err := fr.snap.Get(key)
if err != nil || ret != nil {
return ret, err
}
val, ok := fr.forms[hex.EncodeToString(key)]
if !ok {
return nil, xerrors.Errorf("this key doesn't exist")
}
return val.Serialize(fr.context)
}

// Watch implements ordering.Service. It returns the events that occurred within
Expand Down
Loading

0 comments on commit ae9e179

Please sign in to comment.