Skip to content

Commit 4e84d80

Browse files
authored
docs: improve README with package comments (#34)
1 parent c20eda9 commit 4e84d80

File tree

9 files changed

+36
-17
lines changed

9 files changed

+36
-17
lines changed

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# go-square
22

3-
`go-square` is a Go library designed to provide utility functions for data square operations.
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/celestiaorg/go-square.svg)](https://pkg.go.dev/github.com/celestiaorg/go-square)
4+
5+
`go-square` is a Go module that provides data structures and utilities for interacting with data squares in the Celestia network. The data square is a special form of block serialization in the Celestia blockchain. This repo deals with the original data square which is distinct from the extended data square. Operations on the extended data square are handled by [rsmt2d](https://github.com/celestiaorg/rsmt2d).
6+
7+
Package | Description
8+
----------|---------------------------------------------------------------------------------------------------------------------
9+
blob | Package blob provides types and functions for working with blobs, blob transactions, and index wrapper transactions.
10+
inclusion | Package inclusion contains functions to generate the blob share commitment from a given blob.
11+
merkle | Package merkle computes a deterministic minimal height Merkle tree hash.
12+
namespace | Package namespace contains the Namespace data structure.
13+
shares | Package shares contains the Share data structure.
14+
square | Package square implements the logic to construct the original data square based on a list of transactions.
415

516
## Installation
617

@@ -38,4 +49,4 @@ make lint
3849

3950
# Perform benchmarking
4051
make bench
41-
```
52+
```

blob/blob.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package blob provides types and functions for working with blobs, blob
2+
// transactions, and index wrapper transactions.
13
package blob
24

35
import (
@@ -98,6 +100,7 @@ func MarshalBlobTx(tx []byte, blobs ...*Blob) ([]byte, error) {
98100
return proto.Marshal(bTx)
99101
}
100102

103+
// Sort sorts the blobs by their namespace.
101104
func Sort(blobs []*Blob) {
102105
sort.SliceStable(blobs, func(i, j int) bool {
103106
return bytes.Compare(blobs[i].Namespace().Bytes(), blobs[j].Namespace().Bytes()) < 0

inclusion/blob_share_commitment_rules.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"golang.org/x/exp/constraints"
88
)
99

10-
// BlobSharesUsedNonInteractiveDefaults returns the number of shares used by a given set
11-
// of blobs share lengths. It follows the blob share commitment rules and
12-
// returns the share indexes for each blob.
10+
// BlobSharesUsedNonInteractiveDefaults returns the number of shares used by a
11+
// given set of blobs share lengths. It follows the blob share commitment rules
12+
// and returns the total shares used and share indexes for each blob.
1313
func BlobSharesUsedNonInteractiveDefaults(cursor, subtreeRootThreshold int, blobShareLens ...int) (sharesUsed int, indexes []uint32) {
1414
start := cursor
1515
indexes = make([]uint32, len(blobShareLens))
@@ -34,13 +34,13 @@ func NextShareIndex(cursor, blobShareLen, subtreeRootThreshold int) int {
3434
// merkle mountain range that makes up the blob share commitment (given the
3535
// subtreeRootThreshold and the BlobMinSquareSize).
3636
treeWidth := SubTreeWidth(blobShareLen, subtreeRootThreshold)
37-
// We round up the cursor to the next multiple of this value i.e. if the cursor
38-
// was at 13 and the tree width was 4, we return 16.
37+
// Round up the cursor to the next multiple of treeWidth. For example, if
38+
// the cursor was at 13 and the tree width is 4, return 16.
3939
return RoundUpByMultipleOf(cursor, treeWidth)
4040
}
4141

4242
// RoundUpByMultipleOf rounds cursor up to the next multiple of v. If cursor is divisible
43-
// by v, then it returns cursor
43+
// by v, then it returns cursor.
4444
func RoundUpByMultipleOf(cursor, v int) int {
4545
if cursor%v == 0 {
4646
return cursor
@@ -54,13 +54,11 @@ func BlobMinSquareSize(shareCount int) int {
5454
return shares.RoundUpPowerOfTwo(int(math.Ceil(math.Sqrt(float64(shareCount)))))
5555
}
5656

57-
// SubTreeWidth determines the maximum number of leaves per subtree in the share
57+
// SubTreeWidth returns the maximum number of leaves per subtree in the share
5858
// commitment over a given blob. The input should be the total number of shares
59-
// used by that blob. The reasoning behind this algorithm is discussed in depth
60-
// in ADR013
61-
// (celestia-app/docs/architecture/adr-013-non-interative-default-rules-for-zero-padding).
59+
// used by that blob. See ADR-013.
6260
func SubTreeWidth(shareCount, subtreeRootThreshold int) int {
63-
// per ADR013, we use a predetermined threshold to determine width of sub
61+
// Per ADR-013, we use a predetermined threshold to determine width of sub
6462
// trees used to create share commitments
6563
s := (shareCount / subtreeRootThreshold)
6664

inclusion/commitment.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func CreateCommitment(blob *blob.Blob, merkleRootFn MerkleRootFn, subtreeRootThr
4343
cursor += treeSize
4444
}
4545

46-
// create the commitments by pushing each leaf set onto an nmt
46+
// create the commitments by pushing each leaf set onto an NMT
4747
subTreeRoots := make([][]byte, len(leafSets))
4848
for i, set := range leafSets {
49-
// create the nmt todo(evan) use nmt wrapper
49+
// Create the NMT. TODO: use NMT wrapper.
5050
tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(ns.NamespaceSize), nmt.IgnoreMaxNamespace(true))
5151
for _, leaf := range set {
5252
// the namespace must be added again here even though it is already
5353
// included in the leaf to ensure that the hash will match that of
54-
// the nmt wrapper (pkg/wrapper). Each namespace is added to keep
54+
// the NMT wrapper (pkg/wrapper). Each namespace is added to keep
5555
// the namespace in the share, and therefore the parity data, while
5656
// also allowing for the manual addition of the parity namespace to
5757
// the parity data.

inclusion/commitment_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/stretchr/testify/require"
1414
)
1515

16-
func Test_MerkleMountainRangeHeights(t *testing.T) {
16+
func TestMerkleMountainRangeSizes(t *testing.T) {
1717
type test struct {
1818
totalSize uint64
1919
squareSize uint64

inclusion/doc.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package inclusion contains functions to generate the blob share commitment
2+
// from a given blob.
3+
package inclusion

namespace/namespace.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package namespace contains the Namespace data structure.
12
package namespace
23

34
import (

shares/shares.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package shares contains the Share data structure.
12
package shares
23

34
import (

square/square.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package square implements the logic to construct the original data square
2+
// based on a list of transactions.
13
package square
24

35
import (

0 commit comments

Comments
 (0)