Skip to content

Commit

Permalink
Merge pull request #284 from dedis/upgrade-to-go1.21
Browse files Browse the repository at this point in the history
Upgrade to go1.21
  • Loading branch information
jbsv authored Apr 10, 2024
2 parents 33fd2a3 + 3932401 commit c31b948
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 251 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/go_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Set up Go ^1.19
uses: actions/setup-go@v3
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: ^1.19
go-version: "1.21"

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Lint
run: make lint

Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/go_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
test:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest] # macos-latest
platform: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{matrix.platform}}
env:
LLVL: trace
steps:
- name: Set up Go ^1.19
uses: actions/setup-go@v3
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: ^1.19
go-version: "1.21"

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Test without coverage
env:
CRY_LVL: "warn"
Expand Down
98 changes: 72 additions & 26 deletions dkg/pedersen/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strconv"
"sync"

"github.com/dedis/debugtools/channel"
"github.com/rs/zerolog"
"go.dedis.ch/debugtools/channel"
"go.dedis.ch/dela"
"go.dedis.ch/dela/dkg/pedersen/types"
"go.dedis.ch/dela/mino"
Expand Down Expand Up @@ -106,7 +106,12 @@ func (s *instance) getState() *state {
}

// handleMessage implements dkgInstance. It handles the DKG messages.
func (s *instance) handleMessage(ctx context.Context, msg serde.Message, from mino.Address, out mino.Sender) error {
func (s *instance) handleMessage(
ctx context.Context,
msg serde.Message,
from mino.Address,
out mino.Sender,
) error {
// We expect a Start message or a decrypt request at first, but we might
// receive other messages in the meantime, like a Deal.
switch msg := msg.(type) {
Expand Down Expand Up @@ -194,8 +199,10 @@ func (s *instance) handleMessage(ctx context.Context, msg serde.Message, from mi
// start is called when the node has received its start message. Note that we
// might have already received some deals from other nodes in the meantime. The
// function handles the DKG creation protocol.
func (s *instance) start(ctx context.Context, start types.Start, deals channel.Timed[types.Deal],
resps channel.Timed[types.Response], from mino.Address, out mino.Sender) error {
func (s *instance) start(
ctx context.Context, start types.Start, deals channel.Timed[types.Deal],
resps channel.Timed[types.Response], from mino.Address, out mino.Sender,
) error {

err := s.startRes.switchState(sharing)
if err != nil {
Expand Down Expand Up @@ -227,8 +234,10 @@ func (s *instance) start(ctx context.Context, start types.Start, deals channel.T
}

// doDKG calls the subsequent DKG steps
func (s *instance) doDKG(ctx context.Context, deals channel.Timed[types.Deal],
resps channel.Timed[types.Response], out mino.Sender, from mino.Address) error {
func (s *instance) doDKG(
ctx context.Context, deals channel.Timed[types.Deal],
resps channel.Timed[types.Response], out mino.Sender, from mino.Address,
) error {

defer func() {
s.Lock()
Expand Down Expand Up @@ -315,7 +324,11 @@ func (s *instance) deal(ctx context.Context, out mino.Sender) error {
return nil
}

func (s *instance) respond(ctx context.Context, deals channel.Timed[types.Deal], out mino.Sender) error {
func (s *instance) respond(
ctx context.Context,
deals channel.Timed[types.Deal],
out mino.Sender,
) error {
numReceivedDeals := 0

participants := s.startRes.getParticipants()
Expand Down Expand Up @@ -346,7 +359,11 @@ func (s *instance) respond(ctx context.Context, deals channel.Timed[types.Deal],
// - Resharing with leaving or joining node: (n_common + (n_new - 1)) * n_old,
// nodes that are doing a resharing will broadcast their own deals
// - Resharing with staying node: (n_common + n_new) * n_old
func (s *instance) certify(ctx context.Context, resps channel.Timed[types.Response], expected int) error {
func (s *instance) certify(
ctx context.Context,
resps channel.Timed[types.Response],
expected int,
) error {

responsesReceived := 0

Expand Down Expand Up @@ -414,8 +431,10 @@ func (s *instance) finalize(ctx context.Context, from mino.Address, out mino.Sen
}

// handleDeal process the Deal and send the responses to the other nodes.
func (s *instance) handleDeal(ctx context.Context, msg types.Deal,
out mino.Sender, to []mino.Address) error {
func (s *instance) handleDeal(
ctx context.Context, msg types.Deal,
out mino.Sender, to []mino.Address,
) error {

deal := &pedersen.Deal{
Index: msg.GetIndex(),
Expand Down Expand Up @@ -466,7 +485,12 @@ func (s *instance) handleDeal(ctx context.Context, msg types.Deal,
return nil
}

func (s *instance) finalizeReshare(ctx context.Context, nt nodeType, out mino.Sender, from mino.Address) error {
func (s *instance) finalizeReshare(
ctx context.Context,
nt nodeType,
out mino.Sender,
from mino.Address,
) error {
// Send back the public DKG key
publicKey := s.startRes.getDistKey()

Expand Down Expand Up @@ -508,8 +532,14 @@ func (s *instance) finalizeReshare(ctx context.Context, nt nodeType, out mino.Se

// reshare handles the resharing request. Acts differently for the new
// and old and common nodes
func (s *instance) reshare(ctx context.Context, out mino.Sender,
from mino.Address, msg types.StartResharing, reshares channel.Timed[types.Reshare], resps channel.Timed[types.Response]) error {
func (s *instance) reshare(
ctx context.Context,
out mino.Sender,
from mino.Address,
msg types.StartResharing,
reshares channel.Timed[types.Reshare],
resps channel.Timed[types.Response],
) error {

err := s.startRes.switchState(resharing)
if err != nil {
Expand All @@ -534,8 +564,14 @@ func (s *instance) reshare(ctx context.Context, out mino.Sender,
// doReshare is called when the node has received its reshare message. Note that
// we might have already received some deals from other nodes in the meantime.
// The function handles the DKG resharing protocol.
func (s *instance) doReshare(ctx context.Context, start types.StartResharing,
from mino.Address, out mino.Sender, reshares channel.Timed[types.Reshare], resps channel.Timed[types.Response]) error {
func (s *instance) doReshare(
ctx context.Context,
start types.StartResharing,
from mino.Address,
out mino.Sender,
reshares channel.Timed[types.Reshare],
resps channel.Timed[types.Response],
) error {

s.log.Info().Msgf("resharing with %v", start.GetAddrsNew())

Expand Down Expand Up @@ -668,8 +704,10 @@ func (s *instance) doReshare(ctx context.Context, start types.StartResharing,
// sendDealsResharing is similar to sendDeals except that it creates
// dealResharing which has more data than Deal. Only the old nodes call this
// function.
func (s *instance) sendDealsResharing(ctx context.Context, out mino.Sender,
participants []mino.Address, publicCoeff []kyber.Point) error {
func (s *instance) sendDealsResharing(
ctx context.Context, out mino.Sender,
participants []mino.Address, publicCoeff []kyber.Point,
) error {

s.log.Trace().Msgf("%v is generating its deals", s.me)

Expand All @@ -692,7 +730,7 @@ func (s *instance) sendDealsResharing(ctx context.Context, out mino.Sender,
),
)

//dealResharing contains the public coefficients as well
// dealResharing contains the public coefficients as well
dealResharingMsg := types.NewReshare(dealMsg, publicCoeff)

s.log.Trace().Msgf("%s sent dealResharing %d", s.me, i)
Expand All @@ -714,8 +752,10 @@ func (s *instance) sendDealsResharing(ctx context.Context, out mino.Sender,

// receiveDealsResharing is similar to receiveDeals except that it receives the
// dealResharing. Only the new or common nodes call this function
func (s *instance) receiveDealsResharing(ctx context.Context, nt nodeType,
resharingRequest types.StartResharing, out mino.Sender, reshares channel.Timed[types.Reshare]) error {
func (s *instance) receiveDealsResharing(
ctx context.Context, nt nodeType,
resharingRequest types.StartResharing, out mino.Sender, reshares channel.Timed[types.Reshare],
) error {

s.log.Trace().Msgf("%v is handling deals from other nodes", s.me)

Expand Down Expand Up @@ -780,8 +820,10 @@ func (s *instance) receiveDealsResharing(ctx context.Context, nt nodeType,
return nil
}

func (s *instance) handleDecrypt(out mino.Sender, msg types.DecryptRequest,
from mino.Address) error {
func (s *instance) handleDecrypt(
out mino.Sender, msg types.DecryptRequest,
from mino.Address,
) error {

if !s.startRes.Done() {
return xerrors.Errorf("you must first initialize DKG. Did you call setup() first?")
Expand All @@ -801,8 +843,10 @@ func (s *instance) handleDecrypt(out mino.Sender, msg types.DecryptRequest,
return nil
}

func (s *instance) handleReencryptRequest(out mino.Sender, msg types.ReencryptRequest,
from mino.Address) error {
func (s *instance) handleReencryptRequest(
out mino.Sender, msg types.ReencryptRequest,
from mino.Address,
) error {

if !s.startRes.Done() {
return xerrors.Errorf("you must first initialize DKG. Did you call setup() first?")
Expand Down Expand Up @@ -841,8 +885,10 @@ func (s *instance) getUI(K, pubk kyber.Point) *share.PubShare {
}
}

func (s *instance) handleVerifiableDecrypt(out mino.Sender,
msg types.VerifiableDecryptRequest, from mino.Address) error {
func (s *instance) handleVerifiableDecrypt(
out mino.Sender,
msg types.VerifiableDecryptRequest, from mino.Address,
) error {

type job struct {
index int // index where to put the response
Expand Down
2 changes: 1 addition & 1 deletion dkg/pedersen/dkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"
"time"

"github.com/dedis/debugtools/channel"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"go.dedis.ch/debugtools/channel"
"go.dedis.ch/dela"
"go.dedis.ch/dela/dkg/pedersen/types"
"go.dedis.ch/dela/mino"
Expand Down
5 changes: 0 additions & 5 deletions dkg/pedersen/resharing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pedersen

import (
"fmt"
"math/rand"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -27,10 +26,6 @@ const testMessage = "Hello World"
// resharingUnsuccessful message showing that resharing didn't work
const resharingUnsuccessful = "Resharing was not successful"

func init() {
rand.Seed(0)
}

// This test creates a dkg committee then creates another committee (that can
// share some nodes with the old committee) and then redistributes the secret to
// the new commitee. Using minoch as the underlying network
Expand Down
14 changes: 8 additions & 6 deletions dkg/pedersen/verifiable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"go.dedis.ch/kyber/v3/xof/keccak"
)

var randGen *rand.Rand

func init() {
rand.Seed(0)
randGen = rand.New(rand.NewSource(0))
}

func Test_VerifiableEncrypt_NotInit(t *testing.T) {
Expand Down Expand Up @@ -57,7 +59,7 @@ func Test_VerifiableEncDec_minoch(t *testing.T) {
// agreed data among the participants and embed it as a point. The result is
// the generator that we are seeking.
agreedData := make([]byte, 32)
_, err := rand.Read(agreedData)
_, err := randGen.Read(agreedData)
require.NoError(t, err)
GBar := suite.Point().Embed(agreedData, keccak.New(agreedData))

Expand Down Expand Up @@ -93,12 +95,12 @@ func Test_VerifiableEncDec_minoch(t *testing.T) {

t.Log("generating the message and encrypting it ...")

// generating random messages in batch and encrypt them
// generating random value messages in batch and encrypt them
keys := make([][29]byte, batchSize)

var ciphertexts []types.Ciphertext
for i := 0; i < batchSize; i++ {
_, err = rand.Read(keys[i][:])
_, err = randGen.Read(keys[i][:])
require.NoError(t, err)

ciphertext, remainder, err := actors[0].VerifiableEncrypt(keys[i][:], GBar)
Expand Down Expand Up @@ -137,7 +139,7 @@ func Test_VerifiableEncDec_minogrpc(t *testing.T) {
// agreed data among the participants and embed it as a point. The result is
// the generator that we are seeking.
agreedData := make([]byte, 32)
_, err := rand.Read(agreedData)
_, err := randGen.Read(agreedData)
require.NoError(t, err)
GBar := suite.Point().Embed(agreedData, keccak.New(agreedData))

Expand Down Expand Up @@ -193,7 +195,7 @@ func Test_VerifiableEncDec_minogrpc(t *testing.T) {
msg := make([][29]byte, batchSize)
var ciphertexts []types.Ciphertext
for i := 0; i < batchSize; i++ {
_, err = rand.Read(msg[i][:])
_, err = randGen.Read(msg[i][:])
require.NoError(t, err)

ciphertext, remainder, err := actors[0].VerifiableEncrypt(msg[i][:], GBar)
Expand Down
Loading

0 comments on commit c31b948

Please sign in to comment.