Skip to content

Commit

Permalink
Merge branch 'main' into submit_multiple_blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 authored Jan 30, 2024
2 parents 0f2175c + f235d10 commit c51d456
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN uname -a &&\
CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
make build && make cel-key

FROM docker.io/alpine:3.19.0
FROM docker.io/alpine:3.19.1

# Read here why UID 10001: https://github.com/hexops/dockerfile/blob/main/README.md#do-not-use-a-uid-below-10000
ARG UID=10001
Expand Down
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/libp2p/go-libp2p-routing-helpers v0.7.3
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-base32 v0.1.0
github.com/multiformats/go-multiaddr v0.12.1
github.com/multiformats/go-multiaddr v0.12.2
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/multiformats/go-multihash v0.2.3
github.com/open-rpc/meta-schema v0.0.0-20201029221707-1b72ef2ea333
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1831,8 +1831,8 @@ github.com/multiformats/go-multiaddr v0.5.0/go.mod h1:3KAxNkUqLTJ20AAwN4XVX4kZar
github.com/multiformats/go-multiaddr v0.6.0/go.mod h1:F4IpaKZuPP360tOMn2Tpyu0At8w23aRyVqeK0DbFeGM=
github.com/multiformats/go-multiaddr v0.7.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs=
github.com/multiformats/go-multiaddr v0.8.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs=
github.com/multiformats/go-multiaddr v0.12.1 h1:vm+BA/WZA8QZDp1pF1FWhi5CT3g1tbi5GJmqpb6wnlk=
github.com/multiformats/go-multiaddr v0.12.1/go.mod h1:7mPkiBMmLeFipt+nNSq9pHZUeJSt8lHBgH6yhj0YQzE=
github.com/multiformats/go-multiaddr v0.12.2 h1:9G9sTY/wCYajKa9lyfWPmpZAwe6oV+Wb1zcmMS1HG24=
github.com/multiformats/go-multiaddr v0.12.2/go.mod h1:GKyaTYjZRdcUhyOetrxTk9z0cW+jA/YrnqTOvKgi44M=
github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q=
github.com/multiformats/go-multiaddr-dns v0.2.0/go.mod h1:TJ5pr5bBO7Y1B18djPuRsVkduhQH2YqYSbxWJzYGdK0=
Expand Down

0 comments on commit c51d456

Please sign in to comment.