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 all 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
12 changes: 12 additions & 0 deletions share/eds/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"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"
Expand All @@ -14,6 +17,8 @@ import (
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 @@ -80,6 +85,13 @@ func (bs *blockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error
}

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 behavior is described here:
// https://github.com/celestiaorg/celestia-node/issues/3630
return share_ipld.LeafNodeSize, 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