From 637072e8f6349a4919da9b5e5d8b4637c3058ecc Mon Sep 17 00:00:00 2001 From: rene <41963722+renaynay@users.noreply.github.com> Date: Tue, 27 Jun 2023 15:17:02 +0200 Subject: [PATCH 1/2] fix(libs/utils): Use valid ip4 address (#2394) Fixes an issue where `localhost` was not accepted as a valid `--gateway.addr`. Uses net.ResolveIPAddr instead. Found by @tuxcanfly --- libs/utils/address.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libs/utils/address.go b/libs/utils/address.go index a8170e44b9..ae52a03b16 100644 --- a/libs/utils/address.go +++ b/libs/utils/address.go @@ -29,15 +29,14 @@ func ValidateAddr(addr string) (string, error) { return addr, err } - if ip := net.ParseIP(addr); ip == nil { - addrs, err := net.LookupHost(addr) - if err != nil { - return addr, fmt.Errorf("could not resolve %v: %w", addr, err) - } - if len(addrs) == 0 { - return addr, fmt.Errorf("no IP addresses found for DNS record: %v", addr) - } - addr = addrs[0] + ip := net.ParseIP(addr) + if ip != nil { + return addr, nil } - return addr, nil + + resolved, err := net.ResolveIPAddr("ip4", addr) + if err != nil { + return addr, err + } + return resolved.String(), nil } From 0267e21fd1a500bb94960b6a1a1a38dae9a3084d Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 27 Jun 2023 15:17:40 +0200 Subject: [PATCH 2/2] feat: adding spans to shrex getter (#2404) Self explanatory --- share/getters/shrex.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/share/getters/shrex.go b/share/getters/shrex.go index 99da2f8758..08006073d6 100644 --- a/share/getters/shrex.go +++ b/share/getters/shrex.go @@ -12,10 +12,12 @@ import ( "go.opentelemetry.io/otel/metric/instrument" "go.opentelemetry.io/otel/metric/instrument/syncint64" "go.opentelemetry.io/otel/metric/unit" + "go.opentelemetry.io/otel/trace" "github.com/celestiaorg/nmt/namespace" "github.com/celestiaorg/rsmt2d" + "github.com/celestiaorg/celestia-node/libs/utils" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/p2p" "github.com/celestiaorg/celestia-node/share/p2p/peers" @@ -128,6 +130,13 @@ func (sg *ShrexGetter) GetEDS(ctx context.Context, root *share.Root) (*rsmt2d.Ex attempt int err error ) + ctx, span := tracer.Start(ctx, "shrex/get-eds", trace.WithAttributes( + attribute.String("root", root.String()), + )) + defer func() { + utils.SetStatusAndEnd(span, err) + }() + for { if ctx.Err() != nil { sg.metrics.recordEDSAttempt(ctx, attempt, false) @@ -187,6 +196,13 @@ func (sg *ShrexGetter) GetSharesByNamespace( attempt int err error ) + ctx, span := tracer.Start(ctx, "shrex/get-shares-by-namespace", trace.WithAttributes( + attribute.String("root", root.String()), + attribute.String("nid", hex.EncodeToString(id)), + )) + defer func() { + utils.SetStatusAndEnd(span, err) + }() // verify that the namespace could exist inside the roots before starting network requests roots := filterRootsByNamespace(root, id)