Skip to content

Commit

Permalink
fix(share): return fixed data size in blockstore (#3634)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9fd66a5)
  • Loading branch information
cristaloleg authored and Wondertan committed Aug 21, 2024
1 parent c84dd45 commit 363c859
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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

0 comments on commit 363c859

Please sign in to comment.