Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions node/pkg/internal/testutils/testdata/tss5/guardian0.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions node/pkg/internal/testutils/testdata/tss5/guardian1.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions node/pkg/internal/testutils/testdata/tss5/guardian2.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions node/pkg/internal/testutils/testdata/tss5/guardian3.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions node/pkg/internal/testutils/testdata/tss5/guardian4.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions node/pkg/tss/cnfgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ func (s *GuardianStorage) SetInnerFields() error {
s.IdentitiesKeep.partyIds = make([]*common.PartyID, numGuardians)
s.IdentitiesKeep.pemkeyToIndex = make(map[string]int)
s.IdentitiesKeep.vaav1PubToIdentity = make(map[ethcommon.Address]int)
s.IdentitiesKeep.partyidToIndex = make(map[string]int)
// Since the guardians are sorted by key, we can use their position as their index.
for i := range numGuardians {
s.IdentitiesKeep.peerCerts[i] = s.IdentitiesKeep.Identities[i].Cert
s.IdentitiesKeep.partyIds[i] = s.IdentitiesKeep.Identities[i].Pid
s.IdentitiesKeep.pemkeyToIndex[string(s.IdentitiesKeep.Identities[i].KeyPEM)] = i
s.IdentitiesKeep.partyidToIndex[string(s.IdentitiesKeep.Identities[i].Pid.GetID())] = i

if s.IdentitiesKeep.Identities[i].VAAv1PubKey != nil {
s.IdentitiesKeep.vaav1PubToIdentity[*(s.IdentitiesKeep.Identities[i].VAAv1PubKey)] = i
Expand Down
4 changes: 1 addition & 3 deletions node/pkg/tss/comm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,12 @@ func (s *server) send(msg tss.Sendable) {

func (s *server) enqueueRedialRequest(rqst redialRequest) {
select {
case <-s.ctx.Done():
return
case s.requestRedial <- rqst:
s.logger.Debug("requested redial", zap.String("hostname", rqst.hostname))

return
default:
s.logger.Warn("couldn't send request to redial", zap.String("hostname", rqst.hostname))
s.logger.Debug("channel to request redial blocked dropping redial request to", zap.String("hostname", rqst.hostname))
}
}

Expand Down
11 changes: 9 additions & 2 deletions node/pkg/tss/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ type IdentitiesKeep struct {
// maps and slices to ensure quick lookups.
pemkeyToIndex map[string]int
vaav1PubToIdentity map[ethcommon.Address]int
partyidToIndex map[string]int
peerCerts []*x509.Certificate
partyIds []*common.PartyID
}

// TODO: consider moving the following functions to the identity/identities responsibility.
var errUnknownPartyID = fmt.Errorf("unknown partyID")

func (ids *IdentitiesKeep) fetchIdentityFromPartyID(senderPid *common.PartyID) (*Identity, error) {
return ids.fetchIdentityFromKeyPEM(PEM(senderPid.GetID()))
pos, ok := ids.partyidToIndex[string(senderPid.GetID())]
if !ok {
return nil, errUnknownPartyID
}

return ids.fetchIdentityFromIndex(SenderIndex(pos))
}

var errUnknownPubkey = fmt.Errorf("unknown public key")
Expand Down
8 changes: 4 additions & 4 deletions node/pkg/tss/implementation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func TestBadInputs(t *testing.T) {
bts, err := v.Marshal()
a.NoError(err)

engine.LeaderIdentity = PEM(engine.Self.Pid.GetID())
engine.LeaderIdentity = engine.Self.KeyPEM

t.Run("Bad Version", func(t *testing.T) {
err = engine.handleUnicastVaaV1(&tsscommv1.Unicast_Vaav1{
Expand Down Expand Up @@ -826,7 +826,7 @@ func TestDefaultSameLeader(t *testing.T) {
for _, e := range engines {
a.Equal(e.LeaderIdentity, leader)

if bytes.Equal(PEM(e.Self.Pid.GetID()), leader) {
if bytes.Equal(e.Self.KeyPEM, leader) {
a.True(e.isleader)
} else {
a.False(e.isleader)
Expand Down Expand Up @@ -1049,7 +1049,7 @@ func TestNoFaultsFlow(t *testing.T) {

engines[0].isleader = true
for _, engine := range engines {
engine.LeaderIdentity = PEM(engines[0].Self.Pid.GetID())
engine.LeaderIdentity = engines[0].Self.KeyPEM
engine.SetGuardianSetState(gst)
a.NoError(engine.Start(ctx))
}
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func TestNoFaultsFlow(t *testing.T) {
defer cancel()

for _, engine := range engines {
engine.LeaderIdentity = PEM(e.Self.Pid.GetID())
engine.LeaderIdentity = e.Self.KeyPEM
engine.SetGuardianSetState(gst)
a.NoError(engine.Start(ctx))
}
Expand Down
13 changes: 11 additions & 2 deletions node/pkg/tss/internal/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"crypto/ecdsa"
"crypto/sha512"
"encoding/hex"
"fmt"

engine "github.com/certusone/wormhole/node/pkg/tss"
Expand Down Expand Up @@ -68,9 +70,13 @@ func (cnfg *SetupConfigs) IntoMaps() (keyToEngineIdentity map[string]*engine.Ide
return nil, nil, err
}

pidbytes := sha512.Sum512_256(bts)
// convert the byte array to a string representation for use as the party ID
pid := hex.EncodeToString(pidbytes[:])

keyToEngineIdentity[string(bts)] = &engine.Identity{
Pid: &common.PartyID{
ID: string(bts),
ID: string(pid),
},
KeyPEM: bts,
CertPem: peer.TlsX509,
Expand All @@ -92,15 +98,18 @@ func (cnfg *SetupConfigs) IntoMaps() (keyToEngineIdentity map[string]*engine.Ide
// then sets the communication index according to the sorted order.
func SortIdentities(unsortedIdentities map[string]*engine.Identity) []*engine.Identity {
pids := make([]*common.PartyID, 0, len(unsortedIdentities))
pidsToCertKey := make(map[string]string, len(unsortedIdentities))
for _, p := range unsortedIdentities {
pids = append(pids, p.Pid)
pidsToCertKey[string(p.Pid.GetID())] = string(p.KeyPEM)
}

sortedPids := common.SortPartyIDs(pids)

sortedIDS := make([]*engine.Identity, len(sortedPids))
for i, pid := range sortedPids {
sortedIDS[i] = unsortedIdentities[string(pid.GetID())]
key := pidsToCertKey[string(pid.GetID())]
sortedIDS[i] = unsortedIdentities[key]
sortedIDS[i].CommunicationIndex = engine.SenderIndex(i)
}

Expand Down
6 changes: 3 additions & 3 deletions node/pkg/tss/internal/cmd/dkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {
srvr := createServer(gst, keygen)
go func() {
if err := srvr.Run(ctx); err != nil {
logger.Error("Failed to run server", zap.Error(err))
logger.Fatal("Server stopped", zap.Error(err))

cancel() // stop the context if the server fails to run
}
Expand All @@ -66,7 +66,7 @@ func main() {

func run(ctx context.Context, keygen engine.KeyGenerator, gst *engine.GuardianStorage, cnfgs *cmd.SetupConfigs) {
for i := range 10 { // The loop should converge after 2~3 iterations.
logger.Info("Making DKG Attemp", zap.Int("attempt", i))
logger.Info("Starting new DKG session", zap.Int("session", i))

resChn, err := keygen.StartDKG(party.DkgTask{
Threshold: gst.Threshold,
Expand All @@ -85,7 +85,7 @@ func run(ctx context.Context, keygen engine.KeyGenerator, gst *engine.GuardianSt

return
case <-time.After(time.Second * 20):
logger.Error("FAILED DKG. Starting an additional session")
logger.Info("No progress. Retrying...", zap.Int("session", i))

continue
}
Expand Down
Loading