Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dkg: enable peerinfo server #1982

Merged
merged 1 commit into from
Mar 30, 2023
Merged
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
18 changes: 12 additions & 6 deletions dkg/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package dkg
import (
"bytes"
"context"
"encoding/hex"
"fmt"
"time"

Expand All @@ -17,6 +18,7 @@ import (
"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
"github.com/obolnetwork/charon/app/obolapi"
"github.com/obolnetwork/charon/app/peerinfo"
"github.com/obolnetwork/charon/app/version"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/cluster"
Expand Down Expand Up @@ -96,7 +98,7 @@ func Run(ctx context.Context, conf Config) (err error) {
return err
}

clusterID := fmt.Sprintf("%#x", def.DefinitionHash)
defHash := fmt.Sprintf("%#x", def.DefinitionHash)

key, err := p2p.LoadPrivKey(conf.DataDir)
if err != nil {
Expand All @@ -112,7 +114,7 @@ func Run(ctx context.Context, conf Config) (err error) {

logPeerSummary(ctx, pID, peers, def.Operators)

tcpNode, shutdown, err := setupP2P(ctx, key, conf.P2P, peers, clusterID)
tcpNode, shutdown, err := setupP2P(ctx, key, conf.P2P, peers, def.DefinitionHash)
if err != nil {
return err
}
Expand Down Expand Up @@ -159,7 +161,7 @@ func Run(ctx context.Context, conf Config) (err error) {
tp := keycastP2P{
tcpNode: tcpNode,
peers: peers,
clusterID: clusterID,
clusterID: defHash,
}

shares, err = runKeyCast(ctx, def, tp, nodeIdx.PeerIdx)
Expand All @@ -168,7 +170,7 @@ func Run(ctx context.Context, conf Config) (err error) {
}
case "default", "frost":
shares, err = runFrostParallel(ctx, tp, uint32(def.NumValidators), uint32(len(peerMap)),
uint32(def.Threshold), uint32(nodeIdx.ShareIdx), clusterID)
uint32(def.Threshold), uint32(nodeIdx.ShareIdx), defHash)
if err != nil {
return err
}
Expand Down Expand Up @@ -237,7 +239,7 @@ func Run(ctx context.Context, conf Config) (err error) {
}

// setupP2P returns a started libp2p tcp node and a shutdown function.
func setupP2P(ctx context.Context, key *k1.PrivateKey, p2pConf p2p.Config, peers []p2p.Peer, lockHashHex string) (host.Host, func(), error) {
func setupP2P(ctx context.Context, key *k1.PrivateKey, p2pConf p2p.Config, peers []p2p.Peer, defHash []byte) (host.Host, func(), error) {
var peerIDs []peer.ID
for _, p := range peers {
peerIDs = append(peerIDs, p.ID)
Expand All @@ -247,7 +249,7 @@ func setupP2P(ctx context.Context, key *k1.PrivateKey, p2pConf p2p.Config, peers
return nil, nil, err
}

relays, err := p2p.NewRelays(ctx, p2pConf.Relays, lockHashHex)
relays, err := p2p.NewRelays(ctx, p2pConf.Relays, hex.EncodeToString(defHash))
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -275,6 +277,10 @@ func setupP2P(ctx context.Context, key *k1.PrivateKey, p2pConf p2p.Config, peers

go p2p.NewRelayRouter(tcpNode, peerIDs, relays)(ctx)

// Register peerinfo server handler for identification to relays (but do not run peerinfo client).
gitHash, _ := version.GitCommit()
_ = peerinfo.New(tcpNode, peerIDs, version.Version, defHash, gitHash, nil)

return tcpNode, func() {
_ = tcpNode.Close()
}, nil
Expand Down