Skip to content

Commit 662d17d

Browse files
authored
chore: expose generate subtree roots method (#106)
This PR exposes a method to generate the subtree roots. It will be handy in downstream repos (will be using it in Celestia-node) instead of re-implementing it. Will be cherry picking this change to v1.x to be able to use it now
1 parent b264600 commit 662d17d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: inclusion/commitment.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ type MerkleRootFn func([][]byte) []byte
1515
// [data square layout rationale]: ../../specs/src/specs/data_square_layout.md
1616
// [blob share commitment rules]: ../../specs/src/specs/data_square_layout.md#blob-share-commitment-rules
1717
func CreateCommitment(blob *sh.Blob, merkleRootFn MerkleRootFn, subtreeRootThreshold int) ([]byte, error) {
18+
subTreeRoots, err := GenerateSubtreeRoots(blob, subtreeRootThreshold)
19+
if err != nil {
20+
return nil, err
21+
}
22+
return merkleRootFn(subTreeRoots), nil
23+
}
24+
25+
// GenerateSubtreeRoots generates the subtree roots of a blob.
26+
// See [data square layout rationale] and [blob share commitment rules].
27+
//
28+
// [data square layout rationale]: ../../specs/src/specs/data_square_layout.md
29+
// [blob share commitment rules]: ../../specs/src/specs/data_square_layout.md#blob-share-commitment-rules
30+
func GenerateSubtreeRoots(blob *sh.Blob, subtreeRootThreshold int) ([][]byte, error) {
1831
shares, err := splitBlobs(blob)
1932
if err != nil {
2033
return nil, err
@@ -65,7 +78,7 @@ func CreateCommitment(blob *sh.Blob, merkleRootFn MerkleRootFn, subtreeRootThres
6578
}
6679
subTreeRoots[i] = root
6780
}
68-
return merkleRootFn(subTreeRoots), nil
81+
return subTreeRoots, nil
6982
}
7083

7184
func CreateCommitments(blobs []*sh.Blob, merkleRootFn MerkleRootFn, subtreeRootThreshold int) ([][]byte, error) {

0 commit comments

Comments
 (0)