Skip to content

Commit

Permalink
feat(blob/trace): cover blob service with traces (#3113)
Browse files Browse the repository at this point in the history
Cover Blob service with Otel traces. Partly fixes #3112
  • Loading branch information
vgonkivs committed Jan 30, 2024
1 parent b57ad60 commit f235d10
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ import (
"github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
logging "github.com/ipfs/go-log/v2"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/libs/utils"
"github.com/celestiaorg/celestia-node/share"
)

var (
ErrBlobNotFound = errors.New("blob: not found")
ErrInvalidProof = errors.New("blob: invalid proof")

log = logging.Logger("blob")
log = logging.Logger("blob")
tracer = otel.Tracer("blob/service")
)

// GasPrice represents the amount to be paid per gas unit. Fee is set by
Expand Down Expand Up @@ -185,7 +191,11 @@ func (s *Service) Included(
namespace share.Namespace,
proof *Proof,
com Commitment,
) (bool, error) {
) (_ bool, err error) {
ctx, span := tracer.Start(ctx, "included")
defer func() {
utils.SetStatusAndEnd(span, err)
}()
// In the current implementation, LNs will have to download all shares to recompute the commitment.
// To achieve 1. we need to modify Proof structure and to store all subtree roots, that were
// involved in commitment creation and then call `merkle.HashFromByteSlices`(tendermint package).
Expand Down Expand Up @@ -213,24 +223,47 @@ func (s *Service) getByCommitment(
height uint64,
namespace share.Namespace,
commitment Commitment,
) (*Blob, *Proof, error) {
) (_ *Blob, _ *Proof, err error) {
log.Infow("requesting blob",
"height", height,
"namespace", namespace.String())

header, err := s.headerGetter(ctx, height)
ctx, span := tracer.Start(ctx, "get-by-commitment")
defer func() {
utils.SetStatusAndEnd(span, err)
}()
span.SetAttributes(
attribute.Int64("height", int64(height)),
attribute.String("commitment", string(commitment)),
)

getCtx, headerGetterSpan := tracer.Start(ctx, "header-getter")

header, err := s.headerGetter(getCtx, height)
if err != nil {
headerGetterSpan.SetStatus(codes.Error, err.Error())
return nil, nil, err
}

namespacedShares, err := s.shareGetter.GetSharesByNamespace(ctx, header, namespace)
headerGetterSpan.SetStatus(codes.Ok, "")
headerGetterSpan.AddEvent("received eds", trace.WithAttributes(
attribute.Int64("eds-size", int64(len(header.DAH.RowRoots)))))

getCtx, getSharesSpan := tracer.Start(ctx, "get-shares-by-namespace")

namespacedShares, err := s.shareGetter.GetSharesByNamespace(getCtx, header, namespace)
if err != nil {
if errors.Is(err, share.ErrNotFound) {
err = ErrBlobNotFound
}
getSharesSpan.SetStatus(codes.Error, err.Error())
return nil, nil, err
}

getSharesSpan.SetStatus(codes.Ok, "")
getSharesSpan.AddEvent("received shares", trace.WithAttributes(
attribute.Int64("eds-size", int64(len(header.DAH.RowRoots)))))

var (
rawShares = make([]shares.Share, 0)
proofs = make(Proof, 0)
Expand Down Expand Up @@ -260,6 +293,7 @@ func (s *Service) getByCommitment(
}
for _, b := range blobs {
if b.Commitment.Equal(commitment) {
span.AddEvent("blob reconstructed")
return b, &proofs, nil
}
// Falling under this flag means that the data from the last row
Expand Down Expand Up @@ -296,7 +330,11 @@ func (s *Service) getBlobs(
ctx context.Context,
namespace share.Namespace,
header *header.ExtendedHeader,
) ([]*Blob, error) {
) (_ []*Blob, err error) {
ctx, span := tracer.Start(ctx, "get-blobs")
defer func() {
utils.SetStatusAndEnd(span, err)
}()
namespacedShares, err := s.shareGetter.GetSharesByNamespace(ctx, header, namespace)
if err != nil {
return nil, err
Expand Down

0 comments on commit f235d10

Please sign in to comment.