Skip to content

Commit

Permalink
use newer openrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferret-san committed Aug 13, 2024
1 parent d72cd21 commit 3ab47c9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ RUN . ~/.bashrc && NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-solidity

FROM debian:bookworm-20231218 as wasm-base
WORKDIR /workspace
RUN apt-get update && apt-get install -y curl build-essential=12.9
RUN apt-get update --fix-missing && apt-get install -y curl build-essential=12.9

FROM wasm-base as wasm-libs-builder
# clang / lld used by soft-float wasm
Expand Down
63 changes: 46 additions & 17 deletions das/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,35 @@ func (c *CelestiaDA) Store(ctx context.Context, message []byte) ([]byte, error)

startColumn := blobIndex % squareSize

firstShare, err := c.ReadClient.Share.GetShare(ctx, header, int(startRow), int(startColumn))
nodeShare, err := c.ReadClient.Share.GetShare(ctx, header, int(startRow), int(startColumn))
if err != nil {
celestiaFailureCounter.Inc(1)
log.Warn("Failed to get first share for the blob", "err", err)
return nil, err
}

sharesLength, err := firstShare.SequenceLen()
if err != nil || sharesLength == 0 {
// need to convert to app share
firstShare, err := share.NewShare(*nodeShare)
if err != nil {
celestiaFailureCounter.Inc(1)
log.Warn("Failed to convert share to app share type", "err", err)
return nil, err
}
sequenceLength, err := firstShare.SequenceLen()
if err != nil {
celestiaFailureCounter.Inc(1)
log.Warn("Failed to get blob sequence length", "err", err)
return nil, err
}

sharesLength := share.SparseSharesNeeded(sequenceLength)

if sharesLength == 0 {
celestiaFailureCounter.Inc(1)
log.Warn("Shares length zero for blob", "err", err)
return nil, fmt.Errorf("Blob found, but has shares length zero")
}

startIndexOds := blobIndex - odsSize*startRow
blobPointer := types.BlobPointer{
BlockHeight: height,
Expand Down Expand Up @@ -393,20 +408,6 @@ func (c *CelestiaDA) Read(ctx context.Context, blobPointer *types.BlobPointer) (
return c.returnErrorHelper(fmt.Errorf("Data Root mismatch, header.DataHash=%v, blobPointer.DataRoot=%v", header.DataHash, hex.EncodeToString(blobPointer.DataRoot[:])))
}

proofs, err := c.ReadClient.Blob.GetProof(ctx, blobPointer.BlockHeight, *c.Namespace, blobPointer.TxCommitment[:])
if err != nil {
return c.returnErrorHelper(fmt.Errorf("Error retrieving proof, err=%v", err))
}

sharesLength := uint64(0)
for _, proof := range *proofs {
sharesLength += uint64(proof.End()) - uint64(proof.Start())
}

if sharesLength != blobPointer.SharesLength {
return c.returnErrorHelper(fmt.Errorf("Share length mismatch, sharesLength=%v, blobPointer.SharesLength=%v", sharesLength, blobPointer.SharesLength))
}

blob, err := c.ReadClient.Blob.Get(ctx, blobPointer.BlockHeight, *c.Namespace, blobPointer.TxCommitment[:])
if err != nil {
// return an empty batch of data because we could not find the blob from the sequencer message
Expand Down Expand Up @@ -450,6 +451,34 @@ func (c *CelestiaDA) Read(ctx context.Context, blobPointer *types.BlobPointer) (
return c.returnErrorHelper(fmt.Errorf("start and end row are the same and startColumn >= endColumn, startColumn=%v, endColumn+1=%v", startColumn, endColumn+1))
}

nodeShare, err := c.ReadClient.Share.GetShare(ctx, header, int(startRow), int(startColumn))
if err != nil {
celestiaFailureCounter.Inc(1)
log.Warn("Failed to get first share for the blob", "err", err)
return nil, nil, err
}

// need to convert to app share
firstShare, err := share.NewShare(*nodeShare)
if err != nil {
celestiaFailureCounter.Inc(1)
log.Warn("Failed to convert share to app share type", "err", err)
return nil, nil, err
}
sequenceLength, err := firstShare.SequenceLen()
if err != nil {
celestiaFailureCounter.Inc(1)
log.Warn("Failed to get blob sequence length", "err", err)
return nil, nil, err
}

sharesLength := share.SparseSharesNeeded(sequenceLength)

if uint64(sharesLength) != blobPointer.SharesLength || sharesLength == 0 {
celestiaFailureCounter.Inc(1)
return c.returnErrorHelper(fmt.Errorf("Share length mismatch, sharesLength=%v, blobPointer.SharesLength=%v", sharesLength, blobPointer.SharesLength))
}

rows := [][][]byte{}
for i := startRow; i <= endRow; i++ {
rows = append(rows, eds.Row(uint(i)))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.10
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.9
github.com/cavaliergopher/grab/v3 v3.0.1
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240603174346-256ddd020a0a
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240813195623-e38feb19b4c6
github.com/celestiaorg/nmt v0.20.0
github.com/celestiaorg/rsmt2d v0.11.0
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ github.com/cavaliergopher/grab/v3 v3.0.1 h1:4z7TkBfmPjmLAAmkkAZNX/6QJ1nNFdv3SdIH
github.com/cavaliergopher/grab/v3 v3.0.1/go.mod h1:1U/KNnD+Ft6JJiYoYBAimKH2XrYptb8Kl3DFGmsjpq4=
github.com/celestiaorg/celestia-core v1.29.0-tm-v0.34.29 h1:Fd7ymPUzExPGNl2gZw4i5S74arMw+iDHLE78M/cCxl4=
github.com/celestiaorg/celestia-core v1.29.0-tm-v0.34.29/go.mod h1:xrICN0PBhp3AdTaZ8q4wS5Jvi32V02HNjaC2EsWiEKk=
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240603174346-256ddd020a0a h1:T9vsMQvvYvA/1FObT0eqL0J+XJJx/wG6Jzf+DH+IFxc=
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240603174346-256ddd020a0a/go.mod h1:7kEhBB4KZh4vw3v5pMuMocNgYOk8uOpFZTo0cNpRjXc=
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240813194139-2763b3a8a0d0 h1:5Gn9ROiWhl6rUuN/F7uHKBLEk13N9sGdYaIPWvwbzxc=
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240813194139-2763b3a8a0d0/go.mod h1:7kEhBB4KZh4vw3v5pMuMocNgYOk8uOpFZTo0cNpRjXc=
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240813195623-e38feb19b4c6 h1:dhkq67slPJf3zIoQVTCHd4Zz871FB+kg5WEa68X+YDQ=
github.com/celestiaorg/celestia-openrpc v0.4.1-0.20240813195623-e38feb19b4c6/go.mod h1:7kEhBB4KZh4vw3v5pMuMocNgYOk8uOpFZTo0cNpRjXc=
github.com/celestiaorg/go-fraud v0.2.0 h1:aaq2JiW0gTnhEdac3l51UCqSyJ4+VjFGTTpN83V4q7I=
github.com/celestiaorg/go-fraud v0.2.0/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc=
github.com/celestiaorg/go-header v0.4.1 h1:bjbUcKDnhrJJ9EoE7vtPpgleNLVjc2S+cB4/qe8nQmo=
Expand Down

0 comments on commit 3ab47c9

Please sign in to comment.