[devnet] separate logging p2p (#7549)

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
This commit is contained in:
ledgerwatch 2023-05-19 23:08:45 +01:00 committed by GitHub
parent 7272c00681
commit c919283b0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 14 deletions

View File

@ -108,7 +108,7 @@ func main() {
realaddr := conn.LocalAddr().(*net.UDPAddr)
if natm != nil {
if !realaddr.IP.IsLoopback() && natm.SupportsMapping() {
go nat.Map(natm, nil, "udp", realaddr.Port, realaddr.Port, "ethereum discovery")
go nat.Map(natm, nil, "udp", realaddr.Port, realaddr.Port, "ethereum discovery", logger)
}
if ext, err := natm.ExternalIP(); err == nil {
realaddr = &net.UDPAddr{IP: ext, Port: realaddr.Port}

View File

@ -133,7 +133,7 @@ func (server *Server) mapNATPort(ctx context.Context, realAddr *net.UDPAddr) {
go func() {
defer debug.LogPanic()
nat.Map(server.natInterface, ctx.Done(), "udp", realAddr.Port, realAddr.Port, "ethereum discovery")
nat.Map(server.natInterface, ctx.Done(), "udp", realAddr.Port, realAddr.Port, "ethereum discovery", server.logger)
}()
}

View File

@ -29,6 +29,7 @@ import (
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/p2p/discover/v4wire"
"github.com/ledgerwatch/erigon/p2p/enode"
"github.com/ledgerwatch/log/v3"
)
func TestUDPv4_Lookup(t *testing.T) {
@ -36,11 +37,12 @@ func TestUDPv4_Lookup(t *testing.T) {
t.Skip("fix me on win please")
}
t.Parallel()
logger := log.New()
ctx := context.Background()
ctx = contextWithReplyTimeout(ctx, time.Second)
test := newUDPTestContext(ctx, t)
test := newUDPTestContext(ctx, t, logger)
defer test.close()
// Lookup on empty table returns no nodes.
@ -74,6 +76,7 @@ func TestUDPv4_LookupIterator(t *testing.T) {
t.Skip("fix me on win please")
}
t.Parallel()
logger := log.New()
// Set up RandomNodes() to use expected keys instead of generating random ones.
testNetPrivateKeys := lookupTestnet.privateKeys()
@ -86,7 +89,7 @@ func TestUDPv4_LookupIterator(t *testing.T) {
ctx = contextWithReplyTimeout(ctx, time.Second)
ctx = contextWithPrivateKeyGenerator(ctx, privateKeyGenerator)
test := newUDPTestContext(ctx, t)
test := newUDPTestContext(ctx, t, logger)
defer test.close()
// Seed table with initial nodes.
@ -121,7 +124,8 @@ func TestUDPv4_LookupIterator(t *testing.T) {
// method is called.
func TestUDPv4_LookupIteratorClose(t *testing.T) {
t.Parallel()
test := newUDPTest(t)
logger := log.New()
test := newUDPTest(t, logger)
defer test.close()
// Seed table with initial nodes.

View File

@ -110,22 +110,22 @@ const (
// Map adds a port mapping on m and keeps it alive until c is closed.
// This function is typically invoked in its own goroutine.
func Map(m Interface, c <-chan struct{}, protocol string, extport, intport int, name string) {
func Map(m Interface, c <-chan struct{}, protocol string, extport, intport int, name string, logger log.Logger) {
if !m.SupportsMapping() {
panic("Port mapping is not supported")
}
logger := log.New("proto", protocol, "extport", extport, "intport", intport, "interface", m)
logger1 := logger.New("proto", protocol, "extport", extport, "intport", intport, "interface", m)
refresh := time.NewTimer(mapTimeout)
defer func() {
refresh.Stop()
logger.Trace("Deleting port mapping")
logger1.Trace("Deleting port mapping")
m.DeleteMapping(protocol, extport, intport)
}()
if err := m.AddMapping(protocol, extport, intport, name, mapTimeout); err != nil {
logger.Debug("Couldn't add port mapping", "err", err)
logger1.Debug("Couldn't add port mapping", "err", err)
} else {
logger.Info("Mapped network port")
logger1.Info("Mapped network port")
}
for {
select {
@ -134,9 +134,9 @@ func Map(m Interface, c <-chan struct{}, protocol string, extport, intport int,
return
}
case <-refresh.C:
logger.Trace("Refreshing port mapping")
logger1.Trace("Refreshing port mapping")
if err := m.AddMapping(protocol, extport, intport, name, mapTimeout); err != nil {
logger.Debug("Couldn't add port mapping", "err", err)
logger1.Debug("Couldn't add port mapping", "err", err)
}
refresh.Reset(mapTimeout)
}

View File

@ -609,7 +609,7 @@ func (srv *Server) setupDiscovery(ctx context.Context) error {
go func() {
defer debug.LogPanic()
defer srv.loopWG.Done()
nat.Map(srv.NAT, srv.quit, "udp", realaddr.Port, realaddr.Port, "ethereum discovery")
nat.Map(srv.NAT, srv.quit, "udp", realaddr.Port, realaddr.Port, "ethereum discovery", srv.logger)
}()
}
}
@ -721,7 +721,7 @@ func (srv *Server) setupListening(ctx context.Context) error {
go func() {
defer debug.LogPanic()
defer srv.loopWG.Done()
nat.Map(srv.NAT, srv.quit, "tcp", tcp.Port, tcp.Port, "ethereum p2p")
nat.Map(srv.NAT, srv.quit, "tcp", tcp.Port, tcp.Port, "ethereum p2p", srv.logger)
}()
}
}