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

fix: replace DHT with private peer discovery #3041

Merged
merged 25 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ab5ac3d
import go-tss lib that removes DHT
brewmaster012 Oct 23, 2024
84a4b29
replace DHT with authenticated discovery
brewmaster012 Oct 25, 2024
331a424
use JSON serialization; add metric
robbwu Oct 25, 2024
21d9d7b
add new telemetry: 8123/connectedpeers; fix deadlock
robbwu Oct 25, 2024
102ccc1
use squashed go-tss commit
brewmaster012 Oct 25, 2024
7e439f2
clean up interface
brewmaster012 Oct 25, 2024
e927e2a
address review comments
brewmaster012 Oct 25, 2024
e772dd6
remove whiteliste peers
brewmaster012 Oct 25, 2024
46c1b60
fmt
brewmaster012 Oct 25, 2024
193dae7
remove rendezvous
brewmaster012 Oct 25, 2024
4394f95
use merged go-tss connection gater
brewmaster012 Oct 28, 2024
743d7cc
use latest go-tss from PR#34
brewmaster012 Oct 29, 2024
a910235
use merged #34 in go-tss lib
brewmaster012 Oct 31, 2024
0e817c3
merged origin/develop
brewmaster012 Oct 31, 2024
26f14d3
add ping RTT to telemetry
brewmaster012 Oct 31, 2024
29eece3
changelog
brewmaster012 Nov 1, 2024
1c9e3ad
make linter happy
brewmaster012 Nov 2, 2024
0e5cf02
pingrtt
brewmaster012 Nov 2, 2024
2aeb341
finer resolution on pingrtt time (milliseconds => nanoseconds)
brewmaster012 Nov 2, 2024
ee9ddd4
Merge remote-tracking branch 'origin/develop' into dht-removal
brewmaster012 Nov 4, 2024
ab06660
removed comments
brewmaster012 Nov 4, 2024
b79af05
Merge remote-tracking branch 'origin/develop' into dht-removal
brewmaster012 Nov 4, 2024
737dafd
Merge remote-tracking branch 'origin/develop' into dht-removal
brewmaster012 Nov 6, 2024
6d5eaa9
bump go-tss to the merged commit in master branch
brewmaster012 Nov 6, 2024
e5b77df
revert back to the go-tss commit
brewmaster012 Nov 6, 2024
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
22 changes: 21 additions & 1 deletion cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"time"

"github.com/cometbft/cometbft/crypto/secp256k1"
"github.com/libp2p/go-libp2p/core/peer"
maddr "github.com/multiformats/go-multiaddr"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"gitlab.com/thorchain/tss/go-tss/conversion"

"github.com/zeta-chain/node/pkg/authz"
"github.com/zeta-chain/node/pkg/chains"
Expand Down Expand Up @@ -205,7 +207,16 @@ func start(_ *cobra.Command, _ []string) error {

telemetryServer.SetIPAddress(cfg.PublicIP)
// Create TSS server
server, err := mc.SetupTSSServer(peers, priKey, preParams, appContext.Config(), tssKeyPass, true)
keygen := appContext.GetKeygen()
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
whitelistedPeers := []peer.ID{}
for _, pk := range keygen.GranteePubkeys {
pid, err := conversion.Bech32PubkeyToPeerID(pk)
if err != nil {
return err
}
whitelistedPeers = append(whitelistedPeers, pid)
}
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
server, err := mc.SetupTSSServer(peers, priKey, preParams, appContext.Config(), tssKeyPass, true, whitelistedPeers)
if err != nil {
return fmt.Errorf("SetupTSSServer error: %w", err)
}
Expand All @@ -221,6 +232,15 @@ func start(_ *cobra.Command, _ []string) error {
masterLogger.Info().Msg("TSS listener received an action to shutdown zetaclientd.")
signalChannel <- syscall.SIGTERM
})
// debug: printout connected peers
go func() {
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
for {
time.Sleep(10 * time.Second)
ps := server.GetKnownPeers()
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
metrics.NumConnectedPeers.Set(float64(len(ps)))
telemetryServer.SetConnectedPeers(ps)
}
}()
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved

// Generate a new TSS if keygen is set and add it into the tss server
// If TSS has already been generated, and keygen was successful ; we use the existing TSS
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,6 @@ replace (
github.com/bnb-chain/tss-lib => github.com/zeta-chain/tss-lib v0.0.0-20240916163010-2e6b438bd901
github.com/ethereum/go-ethereum => github.com/zeta-chain/go-ethereum v1.10.26-spc
github.com/libp2p/go-libp2p => github.com/zeta-chain/go-libp2p v0.0.0-20240710192637-567fbaacc2b4
gitlab.com/thorchain/tss/go-tss => github.com/zeta-chain/go-tss v0.0.0-20240916173049-89fee4b0ae7f
gitlab.com/thorchain/tss/go-tss => github.com/zeta-chain/go-tss v0.0.0-20241025050231-a0a541dcc648
//gitlab.com/thorchain/tss/go-tss => ../go-tss
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4204,8 +4204,8 @@ github.com/zeta-chain/go-ethereum v1.10.26-spc h1:NvY4rR9yw52wfxWt7YoFsWbaIwVMyO
github.com/zeta-chain/go-ethereum v1.10.26-spc/go.mod h1:/6CsT5Ceen2WPLI/oCA3xMcZ5sWMF/D46SjM/ayY0Oo=
github.com/zeta-chain/go-libp2p v0.0.0-20240710192637-567fbaacc2b4 h1:FmO3HfVdZ7LzxBUfg6sVzV7ilKElQU2DZm8PxJ7KcYI=
github.com/zeta-chain/go-libp2p v0.0.0-20240710192637-567fbaacc2b4/go.mod h1:TBv5NY/CqWYIfUstXO1fDWrt4bDoqgCw79yihqBspg8=
github.com/zeta-chain/go-tss v0.0.0-20240916173049-89fee4b0ae7f h1:XqUvw9a3EnDa271r5/tjRy90U2l1E8thdWzlrkbrEGE=
github.com/zeta-chain/go-tss v0.0.0-20240916173049-89fee4b0ae7f/go.mod h1:B1FDE6kHs8hozKSX1/iXgCdvlFbS6+FeAupoBHDK0Cc=
github.com/zeta-chain/go-tss v0.0.0-20241025050231-a0a541dcc648 h1:LuvDiopkcze7lj6gVe7qHhwQQg65og6WwlR9fCyxjHM=
github.com/zeta-chain/go-tss v0.0.0-20241025050231-a0a541dcc648/go.mod h1:B1FDE6kHs8hozKSX1/iXgCdvlFbS6+FeAupoBHDK0Cc=
github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138 h1:vck/FcIIpFOvpBUm0NO17jbEtmSz/W/a5Y4jRuSJl6I=
github.com/zeta-chain/keystone/keys v0.0.0-20240826165841-3874f358c138/go.mod h1:U494OsZTWsU75hqoriZgMdSsgSGP1mUL1jX+wN/Aez8=
github.com/zeta-chain/protocol-contracts v1.0.2-athens3.0.20241021075719-d40d2e28467c h1:ZoFxMMZtivRLquXVq1sEVlT45UnTPMO1MSXtc88nDv4=
Expand Down
6 changes: 6 additions & 0 deletions zetaclient/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ var (
},
[]string{"host"},
)

NumConnectedPeers = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: ZetaClientNamespace,
Name: "num_connected_peers",
Help: "The number of connected peers (authenticated keygen peers)",
})
)

// NewMetrics creates a new Metrics instance
Expand Down
33 changes: 26 additions & 7 deletions zetaclient/metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"encoding/json"
"errors"
"fmt"
"github.com/libp2p/go-libp2p/core/peer"
"net/http"
"sync"
"time"
Expand All @@ -30,6 +31,7 @@
status types.Status
ipAddress string
HotKeyBurnRate *BurnRate
connectedPeers []peer.AddrInfo
}

// NewTelemetryServer should only listen to the loopback
Expand All @@ -39,6 +41,7 @@
lastScannedBlockNumber: make(map[int64]uint64),
lastStartTimestamp: time.Now(),
HotKeyBurnRate: NewBurnRate(100),
connectedPeers: make([]peer.AddrInfo, 0),

Check warning on line 44 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L44

Added line #L44 was not covered by tests
}
s := &http.Server{
Addr: ":8123",
Expand All @@ -50,6 +53,18 @@
return hs
}

func (t *TelemetryServer) SetConnectedPeers(peers []peer.AddrInfo) {
t.mu.Lock()
t.connectedPeers = peers
t.mu.Unlock()

Check warning on line 59 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L56-L59

Added lines #L56 - L59 were not covered by tests
}

func (t *TelemetryServer) GetConnectedPeers() []peer.AddrInfo {
t.mu.Lock()
defer t.mu.Unlock()
return t.connectedPeers

Check warning on line 65 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L62-L65

Added lines #L62 - L65 were not covered by tests
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
}

// SetP2PID sets p2pid
func (t *TelemetryServer) SetP2PID(p2pid string) {
t.mu.Lock()
Expand Down Expand Up @@ -145,7 +160,7 @@
router.Handle("/status", http.HandlerFunc(t.statusHandler)).Methods(http.MethodGet)
router.Handle("/ip", http.HandlerFunc(t.ipHandler)).Methods(http.MethodGet)
router.Handle("/hotkeyburnrate", http.HandlerFunc(t.hotKeyFeeBurnRate)).Methods(http.MethodGet)

router.Handle("/connectedpeers", http.HandlerFunc(t.connectedPeersHandler)).Methods(http.MethodGet)

Check warning on line 163 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L163

Added line #L163 was not covered by tests
router.Use(logMiddleware())

return router
Expand Down Expand Up @@ -184,17 +199,14 @@
// p2pHandler returns the p2p id
func (t *TelemetryServer) p2pHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
t.mu.Lock()
defer t.mu.Unlock()
fmt.Fprintf(w, "%s", t.p2pid)
fmt.Fprintf(w, "%s", t.GetP2PID())

Check warning on line 202 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L202

Added line #L202 was not covered by tests
}

// ipHandler returns the ip address
func (t *TelemetryServer) ipHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
t.mu.Lock()
defer t.mu.Unlock()
fmt.Fprintf(w, "%s", t.ipAddress)

fmt.Fprintf(w, "%s", t.GetIPAddress())

Check warning on line 209 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L208-L209

Added lines #L208 - L209 were not covered by tests
}

func (t *TelemetryServer) lastScannedBlockHandler(w http.ResponseWriter, _ *http.Request) {
Expand Down Expand Up @@ -251,6 +263,13 @@
fmt.Fprintf(w, "%v", t.HotKeyBurnRate.GetBurnRate())
}

func (t *TelemetryServer) connectedPeersHandler(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
peers := t.GetConnectedPeers()
data, _ := json.Marshal(peers)
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintf(w, "%s", string(data))

Check warning on line 270 in zetaclient/metrics/telemetry.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/metrics/telemetry.go#L266-L270

Added lines #L266 - L270 were not covered by tests
}

// logMiddleware logs the incoming HTTP request
func logMiddleware() mux.MiddlewareFunc {
return func(handler http.Handler) http.Handler {
Expand Down
2 changes: 2 additions & 0 deletions zetaclient/tss/tss_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
cfg config.Config,
tssPassword string,
enableMonitor bool,
whitelistedPeers []gopeer.ID,
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
) (*tss.TssServer, error) {
bootstrapPeers := peer
log.Info().Msgf("Peers AddrList %v", bootstrapPeers)
Expand Down Expand Up @@ -185,6 +186,7 @@
preParams, // use pre-generated pre-params if non-nil
IP, // for docker test
tssPassword,
whitelistedPeers,

Check warning on line 189 in zetaclient/tss/tss_signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/tss/tss_signer.go#L189

Added line #L189 was not covered by tests
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
log.Error().Err(err).Msg("NewTSS error")
Expand Down
Loading