Commit 67f35f07 authored by protolambda's avatar protolambda

op-node: update libp2p, fix minor p2p api issues

parent ec8e9b0c
...@@ -12,27 +12,27 @@ require ( ...@@ -12,27 +12,27 @@ require (
github.com/ethereum/go-ethereum v1.10.26 github.com/ethereum/go-ethereum v1.10.26
github.com/fsnotify/fsnotify v1.6.0 github.com/fsnotify/fsnotify v1.6.0
github.com/golang/snappy v0.0.4 github.com/golang/snappy v0.0.4
github.com/google/go-cmp v0.5.8 github.com/google/go-cmp v0.5.9
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8 github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8
github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/holiman/uint256 v1.2.0 github.com/holiman/uint256 v1.2.0
github.com/ipfs/go-datastore v0.6.0 github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-ds-leveldb v0.5.0 github.com/ipfs/go-ds-leveldb v0.5.0
github.com/libp2p/go-libp2p v0.23.3 github.com/libp2p/go-libp2p v0.25.1
github.com/libp2p/go-libp2p-pubsub v0.8.1 github.com/libp2p/go-libp2p-pubsub v0.9.0
github.com/libp2p/go-libp2p-testing v0.12.0 github.com/libp2p/go-libp2p-testing v0.12.0
github.com/mattn/go-isatty v0.0.17 github.com/mattn/go-isatty v0.0.17
github.com/multiformats/go-multiaddr v0.7.0 github.com/multiformats/go-multiaddr v0.8.0
github.com/multiformats/go-multiaddr-dns v0.3.1 github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/olekukonko/tablewriter v0.0.5 github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.13.0 github.com/prometheus/client_golang v1.14.0
github.com/schollz/progressbar/v3 v3.13.0 github.com/schollz/progressbar/v3 v3.13.0
github.com/stretchr/testify v1.8.1 github.com/stretchr/testify v1.8.1
github.com/urfave/cli v1.22.9 github.com/urfave/cli v1.22.9
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa golang.org/x/crypto v0.4.0
golang.org/x/term v0.4.0 golang.org/x/term v0.5.0
) )
require ( require (
...@@ -44,9 +44,9 @@ require ( ...@@ -44,9 +44,9 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/btcutil v1.1.0 // indirect github.com/btcsuite/btcd/btcutil v1.1.0 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.0.4 // indirect github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.4.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
...@@ -57,6 +57,7 @@ require ( ...@@ -57,6 +57,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect github.com/elastic/gosigar v0.14.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fjl/memsize v0.0.1 // indirect github.com/fjl/memsize v0.0.1 // indirect
github.com/flynn/noise v1.0.0 // indirect github.com/flynn/noise v1.0.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect github.com/francoispqt/gojay v1.2.13 // indirect
...@@ -71,11 +72,13 @@ require ( ...@@ -71,11 +72,13 @@ require (
github.com/golang/mock v1.6.0 // indirect github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gopacket v1.1.19 // indirect github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20221203041831-ce31453925ec // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-bexpr v0.1.11 // indirect github.com/hashicorp/go-bexpr v0.1.11 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e // indirect github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/huin/goupnp v1.0.3 // indirect github.com/huin/goupnp v1.0.3 // indirect
...@@ -88,29 +91,24 @@ require ( ...@@ -88,29 +91,24 @@ require (
github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/compress v1.15.10 // indirect github.com/klauspost/compress v1.15.15 // indirect
github.com/klauspost/cpuid/v2 v2.1.1 // indirect github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/koron/go-ssdp v0.0.3 // indirect github.com/koron/go-ssdp v0.0.3 // indirect
github.com/kr/text v0.2.0 // indirect github.com/kr/pretty v0.3.1 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect
github.com/libp2p/go-mplex v0.7.0 // indirect github.com/libp2p/go-mplex v0.7.0 // indirect
github.com/libp2p/go-msgio v0.2.0 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.1.0 // indirect github.com/libp2p/go-nat v0.1.0 // indirect
github.com/libp2p/go-netroute v0.2.0 // indirect github.com/libp2p/go-netroute v0.2.1 // indirect
github.com/libp2p/go-openssl v0.1.0 // indirect
github.com/libp2p/go-reuseport v0.2.0 // indirect github.com/libp2p/go-reuseport v0.2.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.0 // indirect github.com/libp2p/go-yamux/v4 v4.0.0 // indirect
github.com/lucas-clemente/quic-go v0.29.1 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.50 // indirect github.com/miekg/dns v1.1.50 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
...@@ -122,34 +120,39 @@ require ( ...@@ -122,34 +120,39 @@ require (
github.com/morikuni/aec v1.0.0 // indirect github.com/morikuni/aec v1.0.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.1.1 // indirect github.com/multiformats/go-multibase v0.1.1 // indirect
github.com/multiformats/go-multicodec v0.6.0 // indirect github.com/multiformats/go-multicodec v0.8.1 // indirect
github.com/multiformats/go-multihash v0.2.1 // indirect github.com/multiformats/go-multihash v0.2.1 // indirect
github.com/multiformats/go-multistream v0.3.3 // indirect github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect github.com/multiformats/go-varint v0.0.7 // indirect
github.com/nxadm/tail v1.4.8 // indirect github.com/onsi/ginkgo/v2 v2.8.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 // indirect github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/tsdb v0.10.0 // indirect github.com/prometheus/tsdb v0.10.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-18 v0.2.0 // indirect
github.com/quic-go/qtls-go1-19 v0.2.0 // indirect
github.com/quic-go/qtls-go1-20 v0.1.0 // indirect
github.com/quic-go/quic-go v0.32.0 // indirect
github.com/quic-go/webtransport-go v0.5.1 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect github.com/rivo/uniseg v0.4.3 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect github.com/rjeczalik/notify v0.9.2 // indirect
github.com/rs/cors v1.8.2 // indirect github.com/rs/cors v1.8.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sirupsen/logrus v1.8.1 // indirect github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/status-im/keycard-go v0.0.0-20211109104530-b0e0482ba91d // indirect github.com/status-im/keycard-go v0.0.0-20211109104530-b0e0482ba91d // indirect
github.com/stretchr/objx v0.5.0 // indirect github.com/stretchr/objx v0.5.0 // indirect
...@@ -157,27 +160,28 @@ require ( ...@@ -157,27 +160,28 @@ require (
github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.5.0 // indirect github.com/tklauser/numcpus v0.5.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/atomic v1.10.0 // indirect go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect go.uber.org/dig v1.16.1 // indirect
go.uber.org/zap v1.23.0 // indirect go.uber.org/fx v1.19.1 // indirect
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b // indirect go.uber.org/multierr v1.9.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5 // indirect golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/tools v0.1.12 // indirect golang.org/x/tools v0.6.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.4.0 // indirect gotest.tools/v3 v3.4.0 // indirect
lukechampine.com/blake3 v1.1.7 // indirect lukechampine.com/blake3 v1.1.7 // indirect
nhooyr.io/websocket v1.8.7 // indirect
) )
replace github.com/ethereum/go-ethereum v1.10.26 => github.com/ethereum-optimism/op-geth v0.0.0-20230214215134-401b7fd3309b replace github.com/ethereum/go-ethereum v1.10.26 => github.com/ethereum-optimism/op-geth v0.0.0-20230214215134-401b7fd3309b
This diff is collapsed.
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/sync" "github.com/ipfs/go-datastore/sync"
leveldb "github.com/ipfs/go-ds-leveldb" leveldb "github.com/ipfs/go-ds-leveldb"
lconf "github.com/libp2p/go-libp2p/config"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
...@@ -171,27 +170,19 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -171,27 +170,19 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error {
for _, v := range strings.Split(ctx.GlobalString(flags.HostMux.Name), ",") { for _, v := range strings.Split(ctx.GlobalString(flags.HostMux.Name), ",") {
v = strings.ToLower(strings.TrimSpace(v)) v = strings.ToLower(strings.TrimSpace(v))
var mc lconf.MsMuxC
var err error
switch v { switch v {
case "yamux": case "yamux":
mc, err = p2p.YamuxC() conf.HostMux = append(conf.HostMux, p2p.YamuxC())
case "mplex": case "mplex":
mc, err = p2p.MplexC() conf.HostMux = append(conf.HostMux, p2p.MplexC())
default: default:
return fmt.Errorf("could not recognize mux %s", v) return fmt.Errorf("could not recognize mux %s", v)
} }
if err != nil {
return fmt.Errorf("failed to make %s constructor: %w", v, err)
}
conf.HostMux = append(conf.HostMux, mc)
} }
secArr := strings.Split(ctx.GlobalString(flags.HostSecurity.Name), ",") secArr := strings.Split(ctx.GlobalString(flags.HostSecurity.Name), ",")
for _, v := range secArr { for _, v := range secArr {
v = strings.ToLower(strings.TrimSpace(v)) v = strings.ToLower(strings.TrimSpace(v))
var sc lconf.MsSecC
var err error
switch v { switch v {
case "none": // no security, for debugging etc. case "none": // no security, for debugging etc.
if len(conf.HostSecurity) > 0 || len(secArr) > 1 { if len(conf.HostSecurity) > 0 || len(secArr) > 1 {
...@@ -199,16 +190,12 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error { ...@@ -199,16 +190,12 @@ func loadLibp2pOpts(conf *p2p.Config, ctx *cli.Context) error {
} }
conf.NoTransportSecurity = true conf.NoTransportSecurity = true
case "noise": case "noise":
sc, err = p2p.NoiseC() conf.HostSecurity = append(conf.HostSecurity, p2p.NoiseC())
case "tls": case "tls":
sc, err = p2p.TlsC() conf.HostSecurity = append(conf.HostSecurity, p2p.TlsC())
default: default:
return fmt.Errorf("could not recognize security %s", v) return fmt.Errorf("could not recognize security %s", v)
} }
if err != nil {
return fmt.Errorf("failed to make %s constructor: %w", v, err)
}
conf.HostSecurity = append(conf.HostSecurity, sc)
} }
conf.PeersLo = ctx.GlobalUint(flags.PeersLo.Name) conf.PeersLo = ctx.GlobalUint(flags.PeersLo.Name)
......
...@@ -8,8 +8,9 @@ import ( ...@@ -8,8 +8,9 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
lconf "github.com/libp2p/go-libp2p/config" "github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core" "github.com/libp2p/go-libp2p/core"
"github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/connmgr"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
...@@ -19,8 +20,6 @@ import ( ...@@ -19,8 +20,6 @@ import (
"github.com/libp2p/go-libp2p/p2p/net/conngater" "github.com/libp2p/go-libp2p/p2p/net/conngater"
cmgr "github.com/libp2p/go-libp2p/p2p/net/connmgr" cmgr "github.com/libp2p/go-libp2p/p2p/net/connmgr"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
) )
...@@ -64,8 +63,8 @@ type Config struct { ...@@ -64,8 +63,8 @@ type Config struct {
StaticPeers []core.Multiaddr StaticPeers []core.Multiaddr
HostMux []lconf.MsMuxC HostMux []libp2p.Option
HostSecurity []lconf.MsSecC HostSecurity []libp2p.Option
NoTransportSecurity bool NoTransportSecurity bool
PeersLo uint PeersLo uint
......
...@@ -7,13 +7,14 @@ import ( ...@@ -7,13 +7,14 @@ import (
"sync" "sync"
"time" "time"
"github.com/libp2p/go-libp2p/core/network" libp2p "github.com/libp2p/go-libp2p"
lconf "github.com/libp2p/go-libp2p/config" lconf "github.com/libp2p/go-libp2p/config"
"github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/connmgr"
"github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/metrics" "github.com/libp2p/go-libp2p/core/metrics"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/sec/insecure"
basichost "github.com/libp2p/go-libp2p/p2p/host/basic" basichost "github.com/libp2p/go-libp2p/p2p/host/basic"
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoreds" "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoreds"
"github.com/libp2p/go-libp2p/p2p/muxer/mplex" "github.com/libp2p/go-libp2p/p2p/muxer/mplex"
...@@ -157,7 +158,7 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter) (host.Host, ...@@ -157,7 +158,7 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter) (host.Host,
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to make listen addr: %w", err) return nil, fmt.Errorf("failed to make listen addr: %w", err)
} }
tcpTransport, err := lconf.TransportConstructor( tcpTransport := libp2p.Transport(
tcp.NewTCPTransport, tcp.NewTCPTransport,
tcp.WithConnectionTimeout(time.Minute*60)) // break unused connections tcp.WithConnectionTimeout(time.Minute*60)) // break unused connections
if err != nil { if err != nil {
...@@ -170,50 +171,36 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter) (host.Host, ...@@ -170,50 +171,36 @@ func (conf *Config) Host(log log.Logger, reporter metrics.Reporter) (host.Host,
nat = basichost.NewNATManager nat = basichost.NewNATManager
} }
p2pConf := &lconf.Config{ opts := []libp2p.Option{
libp2p.Identity(conf.Priv),
// Explicitly set the user-agent, so we can differentiate from other Go libp2p users. // Explicitly set the user-agent, so we can differentiate from other Go libp2p users.
UserAgent: conf.UserAgent, libp2p.UserAgent(conf.UserAgent),
tcpTransport,
PeerKey: conf.Priv, libp2p.WithDialTimeout(conf.TimeoutDial),
Transports: []lconf.TptC{tcpTransport},
Muxers: conf.HostMux,
SecurityTransports: conf.HostSecurity,
Insecure: conf.NoTransportSecurity,
PSK: nil, // TODO: expose private subnet option to CLI / testing
DialTimeout: conf.TimeoutDial,
// No relay services, direct connections between peers only. // No relay services, direct connections between peers only.
RelayCustom: false, libp2p.DisableRelay(),
Relay: false,
EnableRelayService: false,
RelayServiceOpts: nil,
// host will start and listen to network directly after construction from config. // host will start and listen to network directly after construction from config.
ListenAddrs: []ma.Multiaddr{listenAddr}, libp2p.ListenAddrs(listenAddr),
libp2p.ConnectionGater(connGtr),
AddrsFactory: nil, libp2p.ConnectionManager(connMngr),
ConnectionGater: connGtr, //libp2p.ResourceManager(nil), // TODO use resource manager interface to manage resources per peer better.
ConnManager: connMngr, libp2p.NATManager(nat),
ResourceManager: nil, // TODO use resource manager interface to manage resources per peer better. libp2p.Peerstore(ps),
NATManager: nat, libp2p.BandwidthReporter(reporter), // may be nil if disabled
Peerstore: ps, libp2p.MultiaddrResolver(madns.DefaultResolver),
Reporter: reporter, // may be nil if disabled
MultiaddrResolver: madns.DefaultResolver,
// Ping is a small built-in libp2p protocol that helps us check/debug latency between peers. // Ping is a small built-in libp2p protocol that helps us check/debug latency between peers.
DisablePing: false, libp2p.Ping(true),
Routing: nil,
EnableAutoRelay: false, // don't act as auto relay service
// Help peers with their NAT reachability status, but throttle to avoid too much work. // Help peers with their NAT reachability status, but throttle to avoid too much work.
AutoNATConfig: lconf.AutoNATConfig{ libp2p.EnableNATService(),
ForceReachability: nil, libp2p.AutoNATServiceRateLimit(10, 5, time.Second*60),
EnableService: true,
ThrottleGlobalLimit: 10,
ThrottlePeerLimit: 5,
ThrottleInterval: time.Second * 60,
},
// TODO: hole punching is new, need to review differences with NAT manager options
EnableHolePunching: false,
HolePunchingOptions: nil,
} }
h, err := p2pConf.NewNode() opts = append(opts, conf.HostMux...)
if conf.NoTransportSecurity {
opts = append(opts, libp2p.Security(insecure.ID, insecure.NewWithIdentity))
} else {
opts = append(opts, conf.HostSecurity...)
}
h, err := libp2p.New(opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -257,34 +244,18 @@ func addrFromIPAndPort(ip net.IP, port uint16) (ma.Multiaddr, error) { ...@@ -257,34 +244,18 @@ func addrFromIPAndPort(ip net.IP, port uint16) (ma.Multiaddr, error) {
return ma.NewMultiaddr(fmt.Sprintf("/%s/%s/tcp/%d", ipScheme, ip.String(), port)) return ma.NewMultiaddr(fmt.Sprintf("/%s/%s/tcp/%d", ipScheme, ip.String(), port))
} }
func YamuxC() (lconf.MsMuxC, error) { func YamuxC() libp2p.Option {
mtpt, err := lconf.MuxerConstructor(yamux.DefaultTransport) return libp2p.Muxer("/yamux/1.0.0", yamux.DefaultTransport)
if err != nil {
return lconf.MsMuxC{}, err
}
return lconf.MsMuxC{MuxC: mtpt, ID: "/yamux/1.0.0"}, nil
} }
func MplexC() (lconf.MsMuxC, error) { func MplexC() libp2p.Option {
mtpt, err := lconf.MuxerConstructor(mplex.DefaultTransport) return libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport)
if err != nil {
return lconf.MsMuxC{}, err
}
return lconf.MsMuxC{MuxC: mtpt, ID: "/mplex/6.7.0"}, nil
} }
func NoiseC() (lconf.MsSecC, error) { func NoiseC() libp2p.Option {
stpt, err := lconf.SecurityConstructor(noise.New) return libp2p.Security(noise.ID, noise.New)
if err != nil {
return lconf.MsSecC{}, err
}
return lconf.MsSecC{SecC: stpt, ID: noise.ID}, nil
} }
func TlsC() (lconf.MsSecC, error) { func TlsC() libp2p.Option {
stpt, err := lconf.SecurityConstructor(tls.New) return libp2p.Security(tls.ID, tls.New)
if err != nil {
return lconf.MsSecC{}, err
}
return lconf.MsSecC{SecC: stpt, ID: tls.ID}, nil
} }
...@@ -11,12 +11,11 @@ import ( ...@@ -11,12 +11,11 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/sync" "github.com/ipfs/go-datastore/sync"
lconf "github.com/libp2p/go-libp2p/config" "github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/connmgr"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/muxer/yamux"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
tswarm "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" tswarm "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -34,9 +33,6 @@ import ( ...@@ -34,9 +33,6 @@ import (
func TestingConfig(t *testing.T) *Config { func TestingConfig(t *testing.T) *Config {
p, _, err := crypto.GenerateSecp256k1Key(rand.Reader) p, _, err := crypto.GenerateSecp256k1Key(rand.Reader)
require.NoError(t, err, "failed to generate new p2p priv key") require.NoError(t, err, "failed to generate new p2p priv key")
mtpt, err := lconf.MuxerConstructor(yamux.DefaultTransport)
require.NoError(t, err)
mux := lconf.MsMuxC{MuxC: mtpt, ID: "/yamux/1.0.0"}
return &Config{ return &Config{
Priv: (p).(*crypto.Secp256k1PrivateKey), Priv: (p).(*crypto.Secp256k1PrivateKey),
...@@ -45,7 +41,7 @@ func TestingConfig(t *testing.T) *Config { ...@@ -45,7 +41,7 @@ func TestingConfig(t *testing.T) *Config {
ListenIP: net.IP{127, 0, 0, 1}, ListenIP: net.IP{127, 0, 0, 1},
ListenTCPPort: 0, // bind to any available port ListenTCPPort: 0, // bind to any available port
StaticPeers: nil, StaticPeers: nil,
HostMux: []lconf.MsMuxC{mux}, HostMux: []libp2p.Option{YamuxC()},
NoTransportSecurity: true, NoTransportSecurity: true,
PeersLo: 1, PeersLo: 1,
PeersHi: 10, PeersHi: 10,
...@@ -96,15 +92,6 @@ func TestP2PFull(t *testing.T) { ...@@ -96,15 +92,6 @@ func TestP2PFull(t *testing.T) {
pB, _, err := crypto.GenerateSecp256k1Key(rand.Reader) pB, _, err := crypto.GenerateSecp256k1Key(rand.Reader)
require.NoError(t, err, "failed to generate new p2p priv key") require.NoError(t, err, "failed to generate new p2p priv key")
mplexC, err := MplexC()
require.NoError(t, err)
yamuxC, err := YamuxC()
require.NoError(t, err)
noiseC, err := NoiseC()
require.NoError(t, err)
tlsC, err := TlsC()
require.NoError(t, err)
confA := Config{ confA := Config{
Priv: (pA).(*crypto.Secp256k1PrivateKey), Priv: (pA).(*crypto.Secp256k1PrivateKey),
DisableP2P: false, DisableP2P: false,
...@@ -112,8 +99,8 @@ func TestP2PFull(t *testing.T) { ...@@ -112,8 +99,8 @@ func TestP2PFull(t *testing.T) {
ListenIP: net.IP{127, 0, 0, 1}, ListenIP: net.IP{127, 0, 0, 1},
ListenTCPPort: 0, // bind to any available port ListenTCPPort: 0, // bind to any available port
StaticPeers: nil, StaticPeers: nil,
HostMux: []lconf.MsMuxC{yamuxC, mplexC}, HostMux: []libp2p.Option{YamuxC(), MplexC()},
HostSecurity: []lconf.MsSecC{noiseC, tlsC}, HostSecurity: []libp2p.Option{NoiseC(), TlsC()},
NoTransportSecurity: false, NoTransportSecurity: false,
PeersLo: 1, PeersLo: 1,
PeersHi: 10, PeersHi: 10,
...@@ -242,15 +229,6 @@ func TestDiscovery(t *testing.T) { ...@@ -242,15 +229,6 @@ func TestDiscovery(t *testing.T) {
logB := testlog.Logger(t, log.LvlError).New("host", "B") logB := testlog.Logger(t, log.LvlError).New("host", "B")
logC := testlog.Logger(t, log.LvlError).New("host", "C") logC := testlog.Logger(t, log.LvlError).New("host", "C")
mplexC, err := MplexC()
require.NoError(t, err)
yamuxC, err := YamuxC()
require.NoError(t, err)
noiseC, err := NoiseC()
require.NoError(t, err)
tlsC, err := TlsC()
require.NoError(t, err)
discDBA, err := enode.OpenDB("") // "" = memory db discDBA, err := enode.OpenDB("") // "" = memory db
require.NoError(t, err) require.NoError(t, err)
discDBB, err := enode.OpenDB("") discDBB, err := enode.OpenDB("")
...@@ -269,8 +247,8 @@ func TestDiscovery(t *testing.T) { ...@@ -269,8 +247,8 @@ func TestDiscovery(t *testing.T) {
ListenIP: net.IP{127, 0, 0, 1}, ListenIP: net.IP{127, 0, 0, 1},
ListenTCPPort: 0, // bind to any available port ListenTCPPort: 0, // bind to any available port
StaticPeers: nil, StaticPeers: nil,
HostMux: []lconf.MsMuxC{yamuxC, mplexC}, HostMux: []libp2p.Option{YamuxC(), MplexC()},
HostSecurity: []lconf.MsSecC{noiseC, tlsC}, HostSecurity: []libp2p.Option{NoiseC(), TlsC()},
NoTransportSecurity: false, NoTransportSecurity: false,
PeersLo: 1, PeersLo: 1,
PeersHi: 10, PeersHi: 10,
......
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
"github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/connmgr"
"github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/host"
p2pmetrics "github.com/libp2p/go-libp2p/core/metrics" p2pmetrics "github.com/libp2p/go-libp2p/core/metrics"
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
"github.com/ethereum-optimism/optimism/op-node/metrics" "github.com/ethereum-optimism/optimism/op-node/metrics"
...@@ -76,8 +75,7 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l ...@@ -76,8 +75,7 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l
} }
// notify of any new connections/streams/etc. // notify of any new connections/streams/etc.
n.host.Network().Notify(NewNetworkNotifier(log, metrics)) n.host.Network().Notify(NewNetworkNotifier(log, metrics))
// unregister identify-push handler. Only identifying on dial is fine, and more robust against spam // note: the IDDelta functionality was removed from libP2P, and no longer needs to be explicitly disabled.
n.host.RemoveStreamHandler(identify.IDDelta)
n.gs, err = NewGossipSub(resourcesCtx, n.host, rollupCfg, setup, metrics) n.gs, err = NewGossipSub(resourcesCtx, n.host, rollupCfg, setup, metrics)
if err != nil { if err != nil {
return fmt.Errorf("failed to start gossipsub router: %w", err) return fmt.Errorf("failed to start gossipsub router: %w", err)
......
...@@ -108,19 +108,19 @@ func dumpPeer(id peer.ID, nw network.Network, pstore peerstore.Peerstore, connMg ...@@ -108,19 +108,19 @@ func dumpPeer(id peer.ID, nw network.Network, pstore peerstore.Peerstore, connMg
info.NodeID = enode.PubkeyToIDV4((*decredSecp.PublicKey)(typedPub).ToECDSA()) info.NodeID = enode.PubkeyToIDV4((*decredSecp.PublicKey)(typedPub).ToECDSA())
} }
} }
if dat, err := pstore.Get(id, "ProtocolVersion"); err != nil { if dat, err := pstore.Get(id, "ProtocolVersion"); err == nil {
protocolVersion, ok := dat.(string) protocolVersion, ok := dat.(string)
if ok { if ok {
info.ProtocolVersion = protocolVersion info.ProtocolVersion = protocolVersion
} }
} }
if dat, err := pstore.Get(id, "AgentVersion"); err != nil { if dat, err := pstore.Get(id, "AgentVersion"); err == nil {
agentVersion, ok := dat.(string) agentVersion, ok := dat.(string)
if ok { if ok {
info.UserAgent = agentVersion info.UserAgent = agentVersion
} }
} }
if dat, err := pstore.Get(id, "ENR"); err != nil { if dat, err := pstore.Get(id, "ENR"); err == nil {
enodeData, ok := dat.(*enode.Node) enodeData, ok := dat.(*enode.Node)
if ok { if ok {
info.ENR = enodeData.String() info.ENR = enodeData.String()
...@@ -134,15 +134,17 @@ func dumpPeer(id peer.ID, nw network.Network, pstore peerstore.Peerstore, connMg ...@@ -134,15 +134,17 @@ func dumpPeer(id peer.ID, nw network.Network, pstore peerstore.Peerstore, connMg
} }
} }
info.Connectedness = nw.Connectedness(id) info.Connectedness = nw.Connectedness(id)
if protocols, err := pstore.GetProtocols(id); err != nil { if protocols, err := pstore.GetProtocols(id); err == nil {
info.Protocols = protocols for _, id := range protocols {
info.Protocols = append(info.Protocols, string(id))
}
} }
// get the first connection direction, if any (will default to unknown when there are no connections) // get the first connection direction, if any (will default to unknown when there are no connections)
for _, c := range nw.ConnsToPeer(id) { for _, c := range nw.ConnsToPeer(id) {
info.Direction = c.Stat().Direction info.Direction = c.Stat().Direction
break break
} }
if dat, err := pstore.Get(id, "optimismChainID"); err != nil { if dat, err := pstore.Get(id, "optimismChainID"); err == nil {
chID, ok := dat.(uint64) chID, ok := dat.(uint64)
if ok { if ok {
info.ChainID = chID info.ChainID = chID
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment