chore: bump go-waku to also log output from go-libp2p into geth.log

This commit is contained in:
Richard Ramos 2023-02-01 19:40:32 -04:00 committed by RichΛrd
parent 1c660c3525
commit 03c61e8847
11 changed files with 196 additions and 194 deletions

View File

@ -1 +1 @@
0.128.3
0.129.0

6
go.mod
View File

@ -25,7 +25,7 @@ require (
github.com/hashicorp/go-version v1.2.0
github.com/imdario/mergo v0.3.12
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log v1.0.5 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/keighl/metabolize v0.0.0-20150915210303-97ab655d4034
github.com/kilic/bls12-381 v0.0.0-20200607163746-32e1441c8a9f
@ -75,9 +75,10 @@ require github.com/fogleman/gg v1.3.0
require (
github.com/gorilla/sessions v1.2.1
github.com/ipfs/go-log/v2 v2.5.1
github.com/meirf/gopart v0.0.0-20180520194036-37e9492a85a8
github.com/rmg/iso4217 v1.0.0
github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f
github.com/waku-org/go-waku v0.4.1-0.20230202011116-c3b5ab95abae
github.com/yeqown/go-qrcode/v2 v2.2.1
github.com/yeqown/go-qrcode/writer/standard v1.2.1
)
@ -151,7 +152,6 @@ require (
github.com/holiman/uint256 v1.2.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/klauspost/compress v1.15.10 // indirect

4
go.sum
View File

@ -2067,8 +2067,8 @@ github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZFimdqfZb9cZwT1S3VJP9j3AE6bdNd9boXM=
github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f h1:nmu8iajX6wTDkoVMOJNfIxXzko7kXcFlSyXYLIMQZkk=
github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f/go.mod h1:sI14mN/sM8inIb2x2b462wydSEFyOyuDKI1cjiVIIpM=
github.com/waku-org/go-waku v0.4.1-0.20230202011116-c3b5ab95abae h1:YBZycRlAK+T77wRiNzshOq7SJ5Lt/R/uxRcF+Rmn+Xk=
github.com/waku-org/go-waku v0.4.1-0.20230202011116-c3b5ab95abae/go.mod h1:sI14mN/sM8inIb2x2b462wydSEFyOyuDKI1cjiVIIpM=
github.com/waku-org/go-zerokit-rln v0.1.7-wakuorg h1:2vVIBCtBih2w1K9ll8YnToTDZvbxcgbsClsPlJS/kkg=
github.com/waku-org/go-zerokit-rln v0.1.7-wakuorg/go.mod h1:GlyaVeEWNEBxVJrWC6jFTvb4LNb9d9qnjdS6EiWVUvk=
github.com/wealdtech/go-ens/v3 v3.5.0 h1:Huc9GxBgiGweCOGTYomvsg07K2QggAqZpZ5SuiZdC8o=

View File

@ -4,6 +4,8 @@ import (
"os"
"strings"
logging "github.com/ipfs/go-log/v2"
"github.com/ethereum/go-ethereum/log"
)
@ -67,7 +69,9 @@ func enableRootLog(levelStr string, handler log.Handler) error {
levelStr = "INFO"
}
level, err := log.LvlFromString(strings.ToLower(levelStr))
levelStr = strings.ToLower(levelStr)
level, err := log.LvlFromString(levelStr)
if err != nil {
return err
}
@ -75,5 +79,13 @@ func enableRootLog(levelStr string, handler log.Handler) error {
filteredHandler := log.LvlFilterHandler(level, handler)
log.Root().SetHandler(filteredHandler)
// go-libp2p logger
lvl, err := logging.LevelFromString(levelStr)
if err != nil {
return err
}
logging.SetAllLoggers(lvl)
return nil
}

View File

@ -8,8 +8,6 @@ import (
"github.com/status-im/status-go/server"
logging "github.com/ipfs/go-log"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p/enode"
gethrpc "github.com/ethereum/go-ethereum/rpc"
@ -310,12 +308,6 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig, telemetryServe
cfg.MaxMessageSize = nodeConfig.WakuV2Config.MaxMessageSize
}
lvl, err := logging.LevelFromString("info")
if err != nil {
panic(err)
}
logging.SetAllLoggers(lvl)
w, err := wakuv2.New(nodeConfig.NodeKey, nodeConfig.ClusterConfig.Fleet, cfg, logutils.ZapLogger(), b.appDB, b.timeSource())
if err != nil {

View File

@ -5,7 +5,6 @@ import (
"crypto/ecdsa"
"encoding/binary"
"errors"
"fmt"
"math"
"net"
"strconv"
@ -13,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
ma "github.com/multiformats/go-multiaddr"
"github.com/waku-org/go-waku/logging"
"github.com/waku-org/go-waku/waku/v2/utils"
"go.uber.org/zap"
)
@ -26,7 +24,7 @@ func (w *WakuNode) newLocalnode(priv *ecdsa.PrivateKey) (*enode.LocalNode, error
return enode.NewLocalNode(db, priv), nil
}
func (w *WakuNode) updateLocalNode(localnode *enode.LocalNode, wsAddr []ma.Multiaddr, ipAddr *net.TCPAddr, udpPort uint, wakuFlags utils.WakuEnrBitfield, advertiseAddr *net.IP, shouldAutoUpdate bool, log *zap.Logger) error {
func (w *WakuNode) updateLocalNode(localnode *enode.LocalNode, multiaddrs []ma.Multiaddr, ipAddr *net.TCPAddr, udpPort uint, wakuFlags utils.WakuEnrBitfield, advertiseAddr *net.IP, shouldAutoUpdate bool, log *zap.Logger) error {
localnode.SetFallbackUDP(int(udpPort))
localnode.Set(enr.WithEntry(utils.WakuENRField, wakuFlags))
localnode.SetFallbackIP(net.IP{127, 0, 0, 1})
@ -69,21 +67,22 @@ func (w *WakuNode) updateLocalNode(localnode *enode.LocalNode, wsAddr []ma.Multi
}
}
// Adding websocket multiaddresses
// Adding extra multiaddresses. It will to add as many multiaddresses as possible
// without exceeding the enr max size of 300bytes
var addrAggr []ma.Multiaddr
var err error
for i := len(multiaddrs) - 1; i >= 0; i-- {
addrAggr = append(addrAggr, multiaddrs[0:i]...)
err = func() (err error) {
defer func() {
if e := recover(); e != nil {
err = errors.New("could not write enr record")
}
}()
var fieldRaw []byte
for _, addr := range wsAddr {
p2p, err := addr.ValueForProtocol(ma.P_P2P)
if err != nil {
return err
}
p2pAddr, err := ma.NewMultiaddr("/p2p/" + p2p)
if err != nil {
return fmt.Errorf("could not create p2p addr: %w", err)
}
maRaw := addr.Decapsulate(p2pAddr).Bytes()
for _, addr := range addrAggr {
maRaw := addr.Bytes()
maSize := make([]byte, 2)
binary.BigEndian.PutUint16(maSize, uint16(len(maRaw)))
@ -95,22 +94,38 @@ func (w *WakuNode) updateLocalNode(localnode *enode.LocalNode, wsAddr []ma.Multi
localnode.Set(enr.WithEntry(utils.MultiaddrENRField, fieldRaw))
}
// This is to trigger the signing record err due to exceeding 300bytes limit
_ = localnode.Node()
return nil
}()
if err == nil {
break
}
}
// In case multiaddr could not be populated at all
if err != nil {
localnode.Delete(enr.WithEntry(utils.MultiaddrENRField, struct{}{}))
}
return nil
}
func isPrivate(addr candidateAddr) bool {
return addr.ip.IP.IsPrivate()
func isPrivate(addr *net.TCPAddr) bool {
return addr.IP.IsPrivate()
}
func isExternal(addr candidateAddr) bool {
return !isPrivate(addr) && !addr.ip.IP.IsLoopback() && !addr.ip.IP.IsUnspecified()
func isExternal(addr *net.TCPAddr) bool {
return !isPrivate(addr) && !addr.IP.IsLoopback() && !addr.IP.IsUnspecified()
}
func isLoopback(addr candidateAddr) bool {
return addr.ip.IP.IsLoopback()
func isLoopback(addr *net.TCPAddr) bool {
return addr.IP.IsLoopback()
}
func filterIP(ss []candidateAddr, fn func(candidateAddr) bool) (ret []candidateAddr) {
func filterIP(ss []*net.TCPAddr, fn func(*net.TCPAddr) bool) (ret []*net.TCPAddr) {
for _, s := range ss {
if fn(s) {
ret = append(ret, s)
@ -119,12 +134,25 @@ func filterIP(ss []candidateAddr, fn func(candidateAddr) bool) (ret []candidateA
return
}
type candidateAddr struct {
ip *net.TCPAddr
maddr ma.Multiaddr
}
func extractIPAddressForENR(addr ma.Multiaddr) (*net.TCPAddr, error) {
// It's a p2p-circuit address. We shouldnt use these
// for building the ENR record default keys
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err == nil {
return nil, errors.New("can't use IP address from a p2p-circuit address")
}
// ws and wss addresses are handled by the multiaddr key
// they shouldnt be used for building the ENR record default keys
_, err = addr.ValueForProtocol(ma.P_WS)
if err == nil {
return nil, errors.New("can't use IP address from a ws address")
}
_, err = addr.ValueForProtocol(ma.P_WSS)
if err == nil {
return nil, errors.New("can't use IP address from a wss address")
}
func extractIP(addr ma.Multiaddr) (*net.TCPAddr, error) {
var ipStr string
dns4, err := addr.ValueForProtocol(ma.P_DNS4)
if err != nil {
@ -154,76 +182,86 @@ func extractIP(addr ma.Multiaddr) (*net.TCPAddr, error) {
}, nil
}
func selectMostExternalAddress(addresses []ma.Multiaddr) (ma.Multiaddr, *net.TCPAddr, error) {
var ipAddrs []candidateAddr
func selectMostExternalAddress(addresses []ma.Multiaddr) (*net.TCPAddr, error) {
var ipAddrs []*net.TCPAddr
for _, addr := range addresses {
ipAddr, err := extractIP(addr)
ipAddr, err := extractIPAddressForENR(addr)
if err != nil {
continue
}
ipAddrs = append(ipAddrs, candidateAddr{
ip: ipAddr,
maddr: addr,
})
ipAddrs = append(ipAddrs, ipAddr)
}
externalIPs := filterIP(ipAddrs, isExternal)
if len(externalIPs) > 0 {
return externalIPs[0].maddr, externalIPs[0].ip, nil
return externalIPs[0], nil
}
privateIPs := filterIP(ipAddrs, isPrivate)
if len(privateIPs) > 0 {
return privateIPs[0].maddr, privateIPs[0].ip, nil
return privateIPs[0], nil
}
loopback := filterIP(ipAddrs, isLoopback)
if len(loopback) > 0 {
return loopback[0].maddr, loopback[0].ip, nil
return loopback[0], nil
}
return nil, nil, errors.New("could not obtain ip address")
return nil, errors.New("could not obtain ip address")
}
func selectWSListenAddress(addresses []ma.Multiaddr, extAddr ma.Multiaddr) ([]ma.Multiaddr, error) {
extAddrDNS, err := extAddr.ValueForProtocol(ma.P_DNS4)
var extAddrIP string
if err != nil {
extAddrIP, err = extAddr.ValueForProtocol(ma.P_IP4)
func decapsulateP2P(addr ma.Multiaddr) (ma.Multiaddr, error) {
p2p, err := addr.ValueForProtocol(ma.P_P2P)
if err != nil {
return nil, err
}
p2pAddr, err := ma.NewMultiaddr("/p2p/" + p2p)
if err != nil {
return nil, err
}
addr = addr.Decapsulate(p2pAddr)
return addr, nil
}
func decapsulateCircuitRelayAddr(addr ma.Multiaddr) (ma.Multiaddr, error) {
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err != nil {
return nil, errors.New("not a circuit relay address")
}
// We remove the node's multiaddress from the addr
addr, _ = ma.SplitFunc(addr, func(c ma.Component) bool {
return c.Protocol().Code == ma.P_CIRCUIT
})
return addr, nil
}
func selectWSSListenAddresses(addresses []ma.Multiaddr) ([]ma.Multiaddr, error) {
var result []ma.Multiaddr
for _, addr := range addresses {
// Filter addresses that match the extAddr
if extAddrDNS != "" {
dns4, err := addr.ValueForProtocol(ma.P_DNS4)
if err != nil {
// It's a p2p-circuit address. We dont use these at this stage yet
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err == nil {
continue
}
if dns4 != extAddrDNS {
continue
}
} else {
ip4, err := addr.ValueForProtocol(ma.P_IP4)
if err != nil {
continue
}
if ip4 != extAddrIP {
continue
}
}
_, err := addr.ValueForProtocol(ma.P_WS)
if err == nil {
result = append(result, addr)
// Only WSS with a domain name are allowed
_, err = addr.ValueForProtocol(ma.P_DNS4)
if err != nil {
continue
}
_, err = addr.ValueForProtocol(ma.P_WSS)
if err != nil {
continue
}
addr, err = decapsulateP2P(addr)
if err == nil {
result = append(result, addr)
}
@ -232,22 +270,57 @@ func selectWSListenAddress(addresses []ma.Multiaddr, extAddr ma.Multiaddr) ([]ma
return result, nil
}
func selectCircuitRelayListenAddresses(addresses []ma.Multiaddr) ([]ma.Multiaddr, error) {
var result []ma.Multiaddr
for _, addr := range addresses {
addr, err := decapsulateCircuitRelayAddr(addr)
if err != nil {
continue
}
result = append(result, addr)
}
return result, nil
}
func (w *WakuNode) getENRAddresses(addrs []ma.Multiaddr) (extAddr *net.TCPAddr, multiaddr []ma.Multiaddr, err error) {
extAddr, err = selectMostExternalAddress(addrs)
if err != nil {
return nil, nil, err
}
wssAddrs, err := selectWSSListenAddresses(addrs)
if err != nil {
return nil, nil, err
}
multiaddr = append(multiaddr, wssAddrs...)
// to use WSS, you should have a valid certificate with a domain name.
// that means you're reachable. So circuit relay addresses are ignored
if len(wssAddrs) == 0 {
circuitAddrs, err := selectCircuitRelayListenAddresses(addrs)
if err != nil {
return nil, nil, err
}
multiaddr = append(multiaddr, circuitAddrs...)
}
return
}
func (w *WakuNode) setupENR(ctx context.Context, addrs []ma.Multiaddr) error {
extAddr, ipAddr, err := selectMostExternalAddress(addrs)
ipAddr, multiaddresses, err := w.getENRAddresses(addrs)
if err != nil {
w.log.Error("obtaining external address", zap.Error(err))
return err
}
wsAddresses, err := selectWSListenAddress(addrs, extAddr)
err = w.updateLocalNode(w.localNode, multiaddresses, ipAddr, w.opts.udpPort, w.wakuFlag, w.opts.advertiseAddr, w.opts.discV5autoUpdate, w.log)
if err != nil {
w.log.Error("obtaining websocket addresses", zap.Error(err))
return err
}
err = w.updateLocalNode(w.localNode, wsAddresses, ipAddr, w.opts.udpPort, w.wakuFlag, w.opts.advertiseAddr, w.opts.discV5autoUpdate, w.log)
if err != nil {
w.log.Error("obtaining ENR record from multiaddress", logging.MultiAddrs("multiaddr", extAddr), zap.Error(err))
w.log.Error("updating localnode ENR record", zap.Error(err))
return err
}

View File

@ -112,7 +112,6 @@ func defaultStoreFactory(w *WakuNode) store.Store {
// New is used to instantiate a WakuNode using a set of WakuNodeOptions
func New(opts ...WakuNodeOption) (*WakuNode, error) {
params := new(WakuNodeParameters)
params.libP2POpts = DefaultLibP2POptions
opts = append(DefaultWakuNodeOptions, opts...)
@ -123,6 +122,10 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) {
}
}
if params.logger == nil {
params.logger = utils.Logger()
}
if params.privKey == nil {
prvKey, err := crypto.GenerateKey()
if err != nil {

View File

@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/p2p/enode"
logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/config"
@ -29,6 +30,7 @@ import (
"github.com/waku-org/go-waku/waku/v2/timesource"
"github.com/waku-org/go-waku/waku/v2/utils"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// Default userAgent
@ -111,7 +113,6 @@ type WakuNodeOption func(*WakuNodeParameters) error
// Default options used in the libp2p node
var DefaultWakuNodeOptions = []WakuNodeOption{
WithDiscoverParams(150),
WithLogger(utils.Logger()),
}
// MultiAddresses return the list of multiaddresses configured in the node
@ -138,6 +139,15 @@ func (w WakuNodeParameters) AddressFactory() basichost.AddrsFactory {
func WithLogger(l *zap.Logger) WakuNodeOption {
return func(params *WakuNodeParameters) error {
params.logger = l
logging.SetPrimaryCore(l.Core())
return nil
}
}
// WithLogLevel is a WakuNodeOption that sets the log level for go-waku
func WithLogLevel(lvl zapcore.Level) WakuNodeOption {
return func(params *WakuNodeParameters) error {
logging.SetAllLoggers(logging.LogLevel(lvl))
return nil
}
}

View File

@ -1,13 +1,9 @@
package utils
import (
"crypto/ecdsa"
"encoding/binary"
"errors"
"fmt"
"math"
"net"
"strconv"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
@ -48,95 +44,6 @@ func NewWakuEnrBitfield(lightpush, filter, store, relay bool) WakuEnrBitfield {
return v
}
// GetENRandIP returns a enr Node and TCP address obtained from a multiaddress. priv key and protocols supported
func GetENRandIP(addrs []multiaddr.Multiaddr, wakuFlags WakuEnrBitfield, privK *ecdsa.PrivateKey) (*enode.Node, error) {
r := &enr.Record{}
for _, addr := range addrs {
storeInMultiaddrsKey := false
var multiaddrItems []multiaddr.Multiaddr
_, err := addr.ValueForProtocol(multiaddr.P_WS)
if err == nil {
storeInMultiaddrsKey = true
multiaddrItems = append(multiaddrItems, addr)
}
_, err = addr.ValueForProtocol(multiaddr.P_WSS)
if err == nil {
storeInMultiaddrsKey = true
multiaddrItems = append(multiaddrItems, addr)
}
if !storeInMultiaddrsKey {
var ip string
dns4, err := addr.ValueForProtocol(multiaddr.P_DNS4)
if err != nil {
ip, err = addr.ValueForProtocol(multiaddr.P_IP4)
if err != nil {
return nil, err
}
} else {
netIP, err := net.ResolveIPAddr("ip4", dns4)
if err != nil {
return nil, err
}
ip = netIP.String()
}
portStr, err := addr.ValueForProtocol(multiaddr.P_TCP)
if err != nil {
return nil, err
}
port, err := strconv.Atoi(portStr)
if err != nil {
return nil, err
}
if port > 0 && port <= math.MaxUint16 {
r.Set(enr.TCP(uint16(port))) // lgtm [go/incorrect-integer-conversion]
} else {
return nil, fmt.Errorf("could not set port %d", port)
}
r.Set(enr.IP(net.ParseIP(ip)))
} else {
p2p, err := addr.ValueForProtocol(multiaddr.P_P2P)
if err != nil {
return nil, err
}
p2pAddr, err := multiaddr.NewMultiaddr("/p2p/" + p2p)
if err != nil {
return nil, fmt.Errorf("could not create p2p addr: %w", err)
}
var fieldRaw []byte
for _, ma := range multiaddrItems {
maRaw := ma.Decapsulate(p2pAddr).Bytes()
maSize := make([]byte, 2)
binary.BigEndian.PutUint16(maSize, uint16(len(maRaw)))
fieldRaw = append(fieldRaw, maSize...)
fieldRaw = append(fieldRaw, maRaw...)
}
if len(fieldRaw) != 0 {
r.Set(enr.WithEntry(MultiaddrENRField, fieldRaw))
}
}
}
r.Set(enr.WithEntry(WakuENRField, wakuFlags))
err := enode.SignV4(r, privK)
if err != nil {
return nil, err
}
node, err := enode.New(enode.ValidSchemes, r)
return node, err
}
// EnodeToMultiaddress converts an enode into a multiaddress
func enodeToMultiAddr(node *enode.Node) (multiaddr.Multiaddr, error) {
pubKey := EcdsaPubKeyToSecp256k1PublicKey(node.Pubkey())

View File

@ -44,6 +44,9 @@ func InitLogger(encoding string, output string) {
if len(outputParts) == 2 {
cfg.File = outputParts[1]
} else {
if len(outputParts) > 2 || outputParts[0] != "file" {
panic("invalid output format")
}
cfg.File = "./waku.log"
}
}
@ -51,4 +54,6 @@ func InitLogger(encoding string, output string) {
logging.SetupLogging(cfg)
log = logging.Logger("gowaku").Desugar()
logging.SetAllLoggers(logging.LevelInfo)
}

2
vendor/modules.txt vendored
View File

@ -985,7 +985,7 @@ github.com/vacp2p/mvds/transport
github.com/waku-org/go-discover/discover
github.com/waku-org/go-discover/discover/v4wire
github.com/waku-org/go-discover/discover/v5wire
# github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f
# github.com/waku-org/go-waku v0.4.1-0.20230202011116-c3b5ab95abae
## explicit; go 1.18
github.com/waku-org/go-waku/logging
github.com/waku-org/go-waku/waku/persistence