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

p2p: test scenarios support #5962

Merged
merged 48 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
356dd08
add p2p dnsadddr support to netdeploy
algorandskiy Mar 18, 2024
b86c22f
add a minimal p2p cluster test scenario
algorandskiy Mar 28, 2024
3110bf7
Add logging
algorandskiy Mar 29, 2024
c01e430
fixes: peerID string, network data dir vs genesis dir
algorandskiy Mar 29, 2024
7de8e80
fix tests
algorandskiy Apr 1, 2024
4f13174
Make scenarion1s rounds smaller
algorandskiy Apr 1, 2024
06d52dd
add scenario1s-p2p
algorandskiy Apr 1, 2024
3255688
rename hw-p2p to hw-tiny-p2p
algorandskiy Apr 2, 2024
43f91c1
add hw-small-p2p
algorandskiy Apr 2, 2024
e2d6d88
enable metrics on all hello-world-small-p2p nodes
algorandskiy Apr 3, 2024
0b1198a
heapwatch scripts fix - metric and empty {}
algorandskiy Apr 3, 2024
d842a15
emable runtime mertics in hello-world-small-p2p
algorandskiy Apr 3, 2024
018bbd7
add more block data plots
algorandskiy Apr 3, 2024
8545d6c
fix prometheus metrics collection
algorandskiy Apr 5, 2024
9d0d4bc
extend logging
algorandskiy Apr 16, 2024
98e9d4f
more logging
algorandskiy Apr 16, 2024
99e5804
make libp2p logger to log into node.log
algorandskiy Apr 17, 2024
a8bbffe
fix linter
algorandskiy Apr 18, 2024
cae5145
fix scenario1s-p2p Makefile
algorandskiy Apr 18, 2024
4d4222e
log p2p htto host id
algorandskiy Apr 19, 2024
56844bd
implement gossipSubPeer.RoutingAddr
algorandskiy Apr 19, 2024
017d5b7
make gossipSubPeer hashable
algorandskiy Apr 19, 2024
132ab28
set pubsub number workers to 20
algorandskiy May 2, 2024
5a4879d
heapwatch scripts for p2p topology visualization
algorandskiy May 6, 2024
10dc270
add network-related graph stats
algorandskiy May 6, 2024
12aac6e
support topology vizualization for wsnet
algorandskiy May 6, 2024
3e965fe
use StrictNoSign on gossibsub messages
algorandskiy May 9, 2024
fe0d4bb
wip: try yamux high prio fork
algorandskiy May 13, 2024
952b398
copy libp2p muxer to use forked yamux
algorandskiy May 14, 2024
8f6e578
heapwatch metrics viz: fix ip to names resolution
algorandskiy May 14, 2024
0cf4dc4
metric_viz: store html
algorandskiy May 14, 2024
f0ed6e5
metric_viz: nodes filtering
algorandskiy May 14, 2024
739f10f
metric_viz fixes
algorandskiy May 14, 2024
06a0282
metrics_viz: support metrics with tags
algorandskiy May 15, 2024
ea3d65c
fix opensensus metrics names
algorandskiy May 17, 2024
73b9519
metrics_viz refactoring, add metrics_aggs
algorandskiy May 22, 2024
9c3d134
topology scripts: support missing local addr
algorandskiy May 23, 2024
2666244
use connection direction for conn counting instead of stream direction
algorandskiy May 23, 2024
1358067
agreement node.log aggregator
algorandskiy May 30, 2024
6f2d5fc
Add connection timestamp to topology parser
algorandskiy May 31, 2024
c0d2e78
add DNSSecurityFlags=dnssecTXT flag to config
algorandskiy May 31, 2024
e794266
fix outgoing conn counting
algorandskiy May 31, 2024
d05aa9c
add exp backoff to mesh thread
algorandskiy May 31, 2024
b27c949
post rebase fixes
algorandskiy Jun 7, 2024
cb06762
linter fixes
algorandskiy Jun 7, 2024
5942217
round time in agreement log
algorandskiy Jun 3, 2024
78a35fe
Revert "copy libp2p muxer to use forked yamux"
algorandskiy Jun 11, 2024
e59fd47
Revert "wip: try yamux high prio fork"
algorandskiy Jun 11, 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
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ const (
dnssecSRV = 1 << iota
dnssecRelayAddr
dnssecTelemetryAddr
dnssecTXT
)

const (
Expand Down
12 changes: 9 additions & 3 deletions config/localTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@
// 0x01 (dnssecSRV) - validate SRV response
// 0x02 (dnssecRelayAddr) - validate relays' names to addresses resolution
// 0x04 (dnssecTelemetryAddr) - validate telemetry and metrics names to addresses resolution
// 0x08 (dnssecTXT) - validate TXT response
// ...
DNSSecurityFlags uint32 `version[6]:"1"`
DNSSecurityFlags uint32 `version[6]:"1" version[34]:"9"`

// EnablePingHandler controls whether the gossip node would respond to ping messages with a pong message.
EnablePingHandler bool `version[6]:"true"`
Expand Down Expand Up @@ -688,11 +689,16 @@
return cfg.DNSSecurityFlags&dnssecRelayAddr != 0
}

// DNSSecurityTelemeryAddrEnforced returns true if relay name to ip addr resolution enforced
func (cfg Local) DNSSecurityTelemeryAddrEnforced() bool {
// DNSSecurityTelemetryAddrEnforced returns true if relay name to ip addr resolution enforced
func (cfg Local) DNSSecurityTelemetryAddrEnforced() bool {

Check warning on line 693 in config/localTemplate.go

View check run for this annotation

Codecov / codecov/patch

config/localTemplate.go#L693

Added line #L693 was not covered by tests
return cfg.DNSSecurityFlags&dnssecTelemetryAddr != 0
}

// DNSSecurityTXTEnforced returns true if TXT response verification enforced
func (cfg Local) DNSSecurityTXTEnforced() bool {
return cfg.DNSSecurityFlags&dnssecTXT != 0

Check warning on line 699 in config/localTemplate.go

View check run for this annotation

Codecov / codecov/patch

config/localTemplate.go#L698-L699

Added lines #L698 - L699 were not covered by tests
}

// CatchupVerifyCertificate returns true if certificate verification is needed
func (cfg Local) CatchupVerifyCertificate() bool {
return cfg.CatchupBlockValidateMode&catchupValidationModeCertificate == 0
Expand Down
2 changes: 1 addition & 1 deletion config/local_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var defaultLocal = Local{
ConnectionsRateLimitingWindowSeconds: 1,
CrashDBDir: "",
DNSBootstrapID: "<network>.algorand.network?backup=<network>.algorand.net&dedup=<name>.algorand-<network>.(network|net)",
DNSSecurityFlags: 1,
DNSSecurityFlags: 9,
DeadlockDetection: 0,
DeadlockDetectionThreshold: 30,
DisableAPIAuth: false,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/google/go-querystring v1.0.0
github.com/gorilla/mux v1.8.0
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log/v2 v2.5.1
github.com/jmoiron/sqlx v1.2.0
github.com/karalabe/usb v0.0.2
github.com/labstack/echo/v4 v4.9.1
Expand All @@ -47,6 +48,7 @@ require (
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.4
go.opencensus.io v0.24.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/sync v0.6.0
Expand Down Expand Up @@ -101,7 +103,6 @@ require (
github.com/ipfs/boxo v0.10.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipld/go-ipld-prime v0.20.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
Expand Down Expand Up @@ -171,7 +172,6 @@ require (
go.uber.org/fx v1.20.1 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/term v0.18.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion installer/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ConnectionsRateLimitingWindowSeconds": 1,
"CrashDBDir": "",
"DNSBootstrapID": "<network>.algorand.network?backup=<network>.algorand.net&dedup=<name>.algorand-<network>.(network|net)",
"DNSSecurityFlags": 1,
"DNSSecurityFlags": 9,
"DeadlockDetection": 0,
"DeadlockDetectionThreshold": 30,
"DisableAPIAuth": false,
Expand Down
7 changes: 7 additions & 0 deletions logging/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
// source adds file, line and function fields to the event
source() *logrus.Entry

// Entry returns the logrus raw entry
Entry() *logrus.Entry

// Adds a hook to the logger
AddHook(hook logrus.Hook)

Expand Down Expand Up @@ -319,6 +322,10 @@
l.entry.Logger.Formatter = &logrus.JSONFormatter{TimestampFormat: "2006-01-02T15:04:05.000000Z07:00"}
}

func (l logger) Entry() *logrus.Entry {
return l.entry

Check warning on line 326 in logging/log.go

View check run for this annotation

Codecov / codecov/patch

logging/log.go#L325-L326

Added lines #L325 - L326 were not covered by tests
}

func (l logger) source() *logrus.Entry {
event := l.entry

Expand Down
1 change: 1 addition & 0 deletions netdeploy/remote/nodeConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type NodeConfig struct {
DashboardEndpoint string `json:",omitempty"`
DeadlockOverride int `json:",omitempty"` // -1 = Disable deadlock detection, 0 = Use Default for build, 1 = Enable
ConfigJSONOverride string `json:",omitempty"` // Raw json to merge into config.json after other modifications are complete
P2PBootstrap bool // True if this node should be a p2p bootstrap node and registered in DNS

// NodeNameMatchRegex is tested against Name in generated configs and if matched the rest of the configs in this record are applied as a template
NodeNameMatchRegex string `json:",omitempty"`
Expand Down
35 changes: 35 additions & 0 deletions netdeploy/remote/nodecfg/nodeConfigurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ type nodeConfigurator struct {
bootstrappedTrackerDir string
relayEndpoints []srvEntry
metricsEndpoints []srvEntry
p2pBootstrapEndpoints []txtEntry
}

type srvEntry struct {
srvName string
port string
}

type txtEntry struct {
netAddress string
peerID string
}

// ApplyConfigurationToHost attempts to apply the provided configuration to the local host,
// based on the configuration specified for the provided hostName, with node
// directories being created / updated under the specified rootNodeDir
Expand Down Expand Up @@ -248,6 +254,31 @@ func (nc *nodeConfigurator) registerDNSRecords() (err error) {
return
}
}

dnsaddrsFrom := fmt.Sprintf("_dnsaddr.%s.algodev.network", nc.genesisData.Network)
for _, entry := range nc.p2pBootstrapEndpoints {
port, parseErr := strconv.ParseInt(strings.Split(entry.netAddress, ":")[1], 10, 64)
if parseErr != nil {
return parseErr
}
var addrType string
if isIP {
addrType = "ip4"
} else {
addrType = "dnsaddr"
}
addrInfoString := fmt.Sprintf("/%s/%s/tcp/%d/p2p/%s", addrType, nc.dnsName, port, entry.peerID)
to := fmt.Sprintf("dnsaddr=%s", addrInfoString)

fmt.Fprintf(os.Stdout, "...... Adding P2P TXT Record '%s' -> '%s' .\n", dnsaddrsFrom, to)
const priority = 1
const proxied = false
dnsErr := cloudflareDNS.CreateDNSRecord(context.Background(), "TXT", dnsaddrsFrom, to, cloudflare.AutomaticTTL, priority, proxied)
if dnsErr != nil {
return dnsErr
}
}

return
}

Expand Down Expand Up @@ -281,3 +312,7 @@ func (nc *nodeConfigurator) addRelaySrv(srvRecord string, port string) {
func (nc *nodeConfigurator) registerMetricsSrv(srvRecord string, port string) {
nc.metricsEndpoints = append(nc.metricsEndpoints, srvEntry{srvRecord, port})
}

func (nc *nodeConfigurator) addP2PBootstrap(netAddress string, peerID string) {
nc.p2pBootstrapEndpoints = append(nc.p2pBootstrapEndpoints, txtEntry{netAddress, peerID})
}
47 changes: 47 additions & 0 deletions netdeploy/remote/nodecfg/nodeDir.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nodecfg

import (
"encoding/json"
"errors"
"fmt"
"net/url"
"os"
Expand All @@ -27,6 +28,7 @@ import (
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/netdeploy/remote"
"github.com/algorand/go-algorand/network/p2p"
"github.com/algorand/go-algorand/shared/algoh"
"github.com/algorand/go-algorand/util/tokens"
)
Expand Down Expand Up @@ -101,6 +103,12 @@ func (nd *nodeDir) configure() (err error) {
fmt.Fprintf(os.Stdout, "Error during configureNetAddress: %s\n", err)
return
}

if err = nd.configureP2PDNSBootstrap(nd.P2PBootstrap); err != nil {
fmt.Fprintf(os.Stdout, "Error during configureP2PDNSBootstrap: %s\n", err)
return
}

fmt.Println("Done configuring node directory.")
return
}
Expand Down Expand Up @@ -156,6 +164,45 @@ func (nd *nodeDir) configureNetAddress() (err error) {
return
}

func (nd *nodeDir) configureP2PDNSBootstrap(p2pBootstrap bool) error {
if !p2pBootstrap {
return nil
}
fmt.Fprintf(os.Stdout, " - Configuring P2P DNS Bootstrap: %s\n", nd.Name)
if err := nd.ensureConfig(); err != nil {
return err
}
// ensure p2p config params set are what is expected:
// - EnableP2P or EnableP2PHybridMode
// - NetAddress or P2PListenAddress is set
// - EnableGossipService
if !nd.config.EnableP2P && !nd.config.EnableP2PHybridMode {
return errors.New("p2p bootstrap requires EnableP2P or EnableP2PHybridMode to be set")
}
if nd.NetAddress == "" && nd.config.P2PListenAddress == "" {
return errors.New("p2p bootstrap requires NetAddress or P2PListenAddress to be set")
}
if !nd.config.EnableGossipService {
return errors.New("p2p bootstrap requires EnableGossipService to be set")
}

netAddress := nd.NetAddress
if nd.config.P2PListenAddress != "" {
netAddress = nd.config.P2PListenAddress
}

key, err := p2p.GetPrivKey(config.Local{P2PPersistPeerID: true}, nd.dataDir)
if err != nil {
return err
}
peerID, err := p2p.PeerIDFromPublicKey(key.GetPublic())
if err != nil {
return err
}
nd.configurator.addP2PBootstrap(netAddress, peerID.String())
return nil
}

func (nd *nodeDir) configureAPIEndpoint(address string) (err error) {
if err = nd.ensureConfig(); err != nil {
return
Expand Down
2 changes: 2 additions & 0 deletions network/p2p/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"sync"
"time"

"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/network/limitcaller"
"github.com/gorilla/mux"
"github.com/libp2p/go-libp2p"
Expand Down Expand Up @@ -62,6 +63,7 @@
if err != nil {
return nil, err
}
logging.Base().Debugf("MakeHTTPClient made a new P2P host %s for %s", clientStreamHost.ID(), addrInfo.String())

Check warning on line 66 in network/p2p/http.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/http.go#L66

Added line #L66 was not covered by tests

client := libp2phttp.Host{StreamHost: clientStreamHost}

Expand Down
118 changes: 118 additions & 0 deletions network/p2p/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (C) 2019-2024 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

// This package implement a zap.Core in order to wrap lip2p logger into algod's logger.

package p2p

import (
"runtime"

p2plogging "github.com/ipfs/go-log/v2"
"github.com/sirupsen/logrus"
"go.uber.org/zap/zapcore"

"github.com/algorand/go-algorand/logging"
)

// var levelsMap = map[logging.Level]zapcore.Level{
// logging.Debug: zapcore.DebugLevel,
// logging.Info: zapcore.InfoLevel,
// logging.Warn: zapcore.WarnLevel,
// logging.Error: zapcore.ErrorLevel,
// logging.Fatal: zapcore.FatalLevel,
// logging.Panic: zapcore.PanicLevel,
// }

var levelsMap = map[zapcore.Level]logging.Level{
zapcore.DebugLevel: logging.Debug,
zapcore.InfoLevel: logging.Info,
zapcore.WarnLevel: logging.Warn,
zapcore.ErrorLevel: logging.Error,
zapcore.FatalLevel: logging.Fatal,
zapcore.PanicLevel: logging.Panic,
}

// loggingCore implements zapcore.Core
type loggingCore struct {
log logging.Logger
level logging.Level
fields []zapcore.Field
zapcore.Core
}

// EnableP2PLogging enables libp2p logging into the provided logger with the provided level.
func EnableP2PLogging(log logging.Logger, l logging.Level) {
core := loggingCore{
log: log,
level: l,

Check warning on line 61 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L58-L61

Added lines #L58 - L61 were not covered by tests
}
for p2pLevel, logLevel := range levelsMap {
if logLevel == l {
p2plogging.SetAllLoggers(p2plogging.LogLevel(p2pLevel))
break

Check warning on line 66 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L63-L66

Added lines #L63 - L66 were not covered by tests
}
}
p2plogging.SetPrimaryCore(&core)

Check warning on line 69 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L69

Added line #L69 was not covered by tests
}

func (c *loggingCore) Enabled(l zapcore.Level) bool {
return c.log.IsLevelEnabled(c.level)

Check warning on line 73 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L72-L73

Added lines #L72 - L73 were not covered by tests
}

func (c *loggingCore) With(fields []zapcore.Field) zapcore.Core {
return &loggingCore{
log: c.log,
level: c.level,
fields: append(c.fields, fields...),

Check warning on line 80 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L76-L80

Added lines #L76 - L80 were not covered by tests
}
}

func (c *loggingCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
if c.Enabled(e.Level) {
return ce.AddCore(e, c)

Check warning on line 86 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L84-L86

Added lines #L84 - L86 were not covered by tests
}
return ce

Check warning on line 88 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L88

Added line #L88 was not covered by tests
}

func (c *loggingCore) Write(e zapcore.Entry, fields []zapcore.Field) error {
allFields := append(c.fields, fields...)
loggingFields := make(logging.Fields, len(allFields))

Check warning on line 93 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L91-L93

Added lines #L91 - L93 were not covered by tests

for _, f := range allFields {
if len(f.String) > 0 {
loggingFields[f.Key] = f.String
} else if f.Interface != nil {
loggingFields[f.Key] = f.Interface
} else {
loggingFields[f.Key] = f.Integer

Check warning on line 101 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L95-L101

Added lines #L95 - L101 were not covered by tests
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is OK to ignore the field type because they all boil down to one of these three types?

}
event := c.log.WithFields(loggingFields).With("libp2p", e.LoggerName)
event = event.WithFields(logrus.Fields{
"file": e.Caller.File,
"line": e.Caller.Line,
})
if function := runtime.FuncForPC(e.Caller.PC); function != nil {
event = event.With("function", function.Name())

Check warning on line 110 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L104-L110

Added lines #L104 - L110 were not covered by tests
}
event.Entry().Log(logrus.Level(levelsMap[e.Level]), e.Message)
return nil

Check warning on line 113 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L112-L113

Added lines #L112 - L113 were not covered by tests
}

func (c *loggingCore) Sync() error {
return nil

Check warning on line 117 in network/p2p/logger.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/logger.go#L116-L117

Added lines #L116 - L117 were not covered by tests
}
Loading
Loading