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

feat!: pack squares densely by implementing ADR013 #1604

Merged
merged 33 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
973f8a1
feat!: pack squares densly by implementing ADR013
evan-forbes Apr 6, 2023
9a93941
fix: linter
evan-forbes Apr 6, 2023
0185f6b
refactor: rename to subtreewidth
evan-forbes Apr 6, 2023
3cc81ba
chore: better docs
evan-forbes Apr 7, 2023
052f570
chore: docs
evan-forbes Apr 7, 2023
3726499
chore: docs
evan-forbes Apr 7, 2023
6b0353f
chore: incorporate feedback
evan-forbes Apr 7, 2023
06a8da1
Merge branch 'evan/dense-square' of github.com:celestiaorg/lazyledger…
evan-forbes Apr 7, 2023
ad22606
chore: docs
evan-forbes Apr 7, 2023
77ae1e3
chore: linter
evan-forbes Apr 7, 2023
cb988b9
Merge branch 'main' into evan/dense-square
evan-forbes Apr 10, 2023
f74b6eb
refactor: better local var name
evan-forbes Apr 11, 2023
1d4f815
refactor: change name SubtreeRootHeightThreshold -> SubtreeRootSizeTh…
evan-forbes Apr 11, 2023
643a18e
chore: update docs and include link
evan-forbes Apr 12, 2023
551650a
fix!: add the blob min square size back and use the min of it and the…
evan-forbes Apr 13, 2023
cbd4a9c
chore: name update, and update algo per discussion
evan-forbes Apr 13, 2023
99add7a
fix: typo
evan-forbes Apr 17, 2023
dd8a14f
fix: typo
evan-forbes Apr 18, 2023
01ae46d
fix: docs
evan-forbes Apr 18, 2023
276e0dc
fix: remove max(s, DefaultMinSquareSize)
evan-forbes Apr 18, 2023
3615971
fix: height -> depth
evan-forbes Apr 18, 2023
c84b42a
chore: add max in docs
evan-forbes Apr 18, 2023
81509f8
chore: docs
evan-forbes Apr 18, 2023
d4ead8d
Merge branch 'evan/dense-square' of github.com:celestiaorg/lazyledger…
evan-forbes Apr 18, 2023
2ccb521
chore: height -> depth
evan-forbes Apr 19, 2023
442ff7d
chore: linter
evan-forbes Apr 19, 2023
c51feee
Merge branch 'evan/dense-square' of https://github.com/celestiaorg/ce…
evan-forbes Apr 19, 2023
68149a1
Merge branch 'main' into evan/dense-square
evan-forbes Apr 19, 2023
4dd34c9
fix: use clearer description
evan-forbes Apr 19, 2023
0b2802e
chore: rename test
evan-forbes Apr 20, 2023
74c4b24
chore: testing changes
evan-forbes Apr 20, 2023
b0dde1f
fix: test
evan-forbes Apr 20, 2023
7ac3247
chore: actually remove invalid check
evan-forbes Apr 20, 2023
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
15 changes: 5 additions & 10 deletions pkg/appconsts/appconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,11 @@ const (
// data square.
MinShareCount = DefaultMinSquareSize * DefaultMinSquareSize

// SubtreeRootThreshold dictates the threashold for increasing the sub
// tree root height for blobs. If the number of subtree roots used to create
// a share commitment surpasses this threshold, then the height is
// increased. The rationale for this value is described in more detail in
// ADR013 (./docs/architecture/adr-013). Note that this value should not
// drop below the max square size. That could result in the caculating a sub
// tree width for a blob that is larger than whatever the actual suquare
// size for that block. Having a value that is larger than the square is
// simply wasteful in that the proofs for large blobs are unnecessarily
// large.
// SubtreeRootThreshold works as a target value for the number of subtree roots in the
// share commitment. If a blob contains more shares than this number, than the height
// of the subtree roots will gradually increases to so that the amount remains within that limit.
Comment on lines +76 to +77
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// share commitment. If a blob contains more shares than this number, than the height
// of the subtree roots will gradually increases to so that the amount remains within that limit.
// share commitment. If a blob contains more shares than this number, then the height
// of the subtree roots will increase so that the number of subtree roots remains below the threshold.

// The rationale for this value is described in more detail in ADR013
// (./docs/architecture/adr-013).
// ADR013 https://github.com/celestiaorg/celestia-app/blob/e905143e8fe138ce6085ae9a5c1af950a2d87638/docs/architecture/adr-013-non-interactive-default-rules-for-zero-padding.md //nolint: lll
SubtreeRootThreshold = DefaultMaxSquareSize

Expand Down
6 changes: 3 additions & 3 deletions pkg/inclusion/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func calculateCommitmentPaths(squareSize, start, blobShareLen int) []path {
end = normalizedEndIndex
}

// subTreeRootMaxHeight is the maximum height of a subtree root that was
// subTreeRootMaxDepth is the maximum depth of a subtree root that was
// used to generate the commitment. The height is based on the
// SubtreeRootThreshold. See ADR-013 for more details.
subTreeRootMaxHeight := int(math.Log2(float64(shares.SubTreeWidth(blobShareLen))))
minDepth := maxDepth - subTreeRootMaxHeight
subTreeRootMaxDepth := int(math.Log2(float64(shares.SubTreeWidth(blobShareLen))))
minDepth := maxDepth - subTreeRootMaxDepth
coords := calculateSubTreeRootCoordinates(maxDepth, minDepth, start, end)
for _, c := range coords {
paths = append(paths, path{
Expand Down
15 changes: 2 additions & 13 deletions pkg/shares/non_interactive_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func BlobMinSquareSize(shareCount int) int {
return RoundUpPowerOfTwo(int(math.Ceil(math.Sqrt(float64(shareCount)))))
}

// SubTreeWidth determines the number of leaves per subtree in the share
// SubTreeWidth determines the maximum number of leaves per subtree in the share
// commitment over a given blob. The input should be the total number of shares
// used by that blob. The reasoning behind this algorithm is discussed in depth
// in ADR013
Expand All @@ -113,11 +113,7 @@ func SubTreeWidth(shareCount int) int {

// use the minimum of the subtree width and the min square size, this
// gurarantees that a valid value is returned
s = min(s, BlobMinSquareSize(shareCount))

// using a value below the min square size is wasteful, see ADR013 for more
// details
return max(s, appconsts.DefaultMinSquareSize)
return min(s, BlobMinSquareSize(shareCount))
}

func min[T constraints.Integer](i, j T) T {
Expand All @@ -127,13 +123,6 @@ func min[T constraints.Integer](i, j T) T {
return j
}

func max[T constraints.Integer](i, j T) T {
if i > j {
return i
}
return j
}

// isStartOfRow returns true if cursor is at the start of a row
func isStartOfRow(cursor, squareSize int) bool {
return cursor == 0 || cursor%squareSize == 0
Expand Down
3 changes: 1 addition & 2 deletions pkg/shares/non_interactive_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func Test_roundUpBy(t *testing.T) {
}
}

func TestMinSquareSize(t *testing.T) {
func TestBlobMinSquareSize(t *testing.T) {
type testCase struct {
shareCount int
want int
Expand Down Expand Up @@ -475,7 +475,6 @@ func TestSubTreeWidth(t *testing.T) {
t.Run(fmt.Sprintf("shareCount %d", tc.shareCount), func(t *testing.T) {
got := SubTreeWidth(tc.shareCount)
assert.Equal(t, tc.want, got, i)
assert.GreaterOrEqual(t, got, appconsts.DefaultMinSquareSize)
})
}
}