Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(share): return fixed data size in blockstore #3634

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions share/eds/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"context"
"errors"
"fmt"
"os"

share_ipld "github.com/celestiaorg/celestia-node/share/ipld"
bstore "github.com/ipfs/boxo/blockstore"
"github.com/ipfs/boxo/datastore/dshelp"
blocks "github.com/ipfs/go-block-format"
Expand All @@ -14,6 +16,8 @@
ipld "github.com/ipfs/go-ipld-format"
)

var enableFixedDataSize = os.Getenv("CELESTIA_CONST_DATA_SIZE") == "1"

var _ bstore.Blockstore = (*blockstore)(nil)

var (
Expand Down Expand Up @@ -79,7 +83,16 @@
return nil, err
}

const maxDataSize = max(share_ipld.InnerNodeSize, share_ipld.LeafNodeSize)
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved

func (bs *blockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
if enableFixedDataSize {
// For now we return a fixed result, which is a max of possible values (see above).
// Motivation behind such behaviour is described here:

Check failure on line 91 in share/eds/blockstore.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

`behaviour` is a misspelling of `behavior` (misspell)
// https://github.com/celestiaorg/celestia-node/issues/3630
return maxDataSize, nil
}

blockstr, err := bs.getReadOnlyBlockstore(ctx, cid)
if err == nil {
defer closeAndLog("blockstore", blockstr)
Expand Down
12 changes: 6 additions & 6 deletions share/ipld/nmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const (
// NmtHashSize is the size of a digest created by an NMT in bytes.
NmtHashSize = 2*share.NamespaceSize + sha256.Size

// innerNodeSize is the size of data in inner nodes.
innerNodeSize = NmtHashSize * 2
// InnerNodeSize is the size of data in inner nodes.
InnerNodeSize = NmtHashSize * 2

// leafNodeSize is the size of data in leaf nodes.
leafNodeSize = share.NamespaceSize + appconsts.ShareSize
// LeafNodeSize is the size of data in leaf nodes.
LeafNodeSize = share.NamespaceSize + appconsts.ShareSize

// cidPrefixSize is the size of the prepended buffer of the CID encoding
// for NamespacedSha256. For more information, see:
Expand Down Expand Up @@ -100,12 +100,12 @@ func (n nmtNode) Links() []*ipld.Link {
switch len(n.RawData()) {
default:
panic(fmt.Sprintf("unexpected size %v", len(n.RawData())))
case innerNodeSize:
case InnerNodeSize:
leftCid := MustCidFromNamespacedSha256(n.RawData()[:NmtHashSize])
rightCid := MustCidFromNamespacedSha256(n.RawData()[NmtHashSize:])

return []*ipld.Link{{Cid: leftCid}, {Cid: rightCid}}
case leafNodeSize:
case LeafNodeSize:
return nil
}
}
Expand Down
Loading