Skip to content

Commit 9fd66a5

Browse files
authored
fix(share): return fixed data size in blockstore (#3634)
1 parent 04c05ff commit 9fd66a5

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

share/eds/blockstore.go

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
8+
9+
share_ipld "github.com/celestiaorg/celestia-node/share/ipld"
710

811
bstore "github.com/ipfs/boxo/blockstore"
912
"github.com/ipfs/boxo/datastore/dshelp"
@@ -14,6 +17,8 @@ import (
1417
ipld "github.com/ipfs/go-ipld-format"
1518
)
1619

20+
var enableFixedDataSize = os.Getenv("CELESTIA_CONST_DATA_SIZE") == "1"
21+
1722
var _ bstore.Blockstore = (*blockstore)(nil)
1823

1924
var (
@@ -80,6 +85,13 @@ func (bs *blockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error
8085
}
8186

8287
func (bs *blockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) {
88+
if enableFixedDataSize {
89+
// For now we return a fixed result, which is a max of possible values (see above).
90+
// Motivation behind such behavior is described here:
91+
// https://github.com/celestiaorg/celestia-node/issues/3630
92+
return share_ipld.LeafNodeSize, nil
93+
}
94+
8395
blockstr, err := bs.getReadOnlyBlockstore(ctx, cid)
8496
if err == nil {
8597
defer closeAndLog("blockstore", blockstr)

share/ipld/nmt.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ const (
3939
// NmtHashSize is the size of a digest created by an NMT in bytes.
4040
NmtHashSize = 2*share.NamespaceSize + sha256.Size
4141

42-
// innerNodeSize is the size of data in inner nodes.
43-
innerNodeSize = NmtHashSize * 2
42+
// InnerNodeSize is the size of data in inner nodes.
43+
InnerNodeSize = NmtHashSize * 2
4444

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

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

107107
return []*ipld.Link{{Cid: leftCid}, {Cid: rightCid}}
108-
case leafNodeSize:
108+
case LeafNodeSize:
109109
return nil
110110
}
111111
}

0 commit comments

Comments
 (0)