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 24 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
2 changes: 1 addition & 1 deletion app/write_square.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func finalizeBlobLayout(squareSize uint64, nonreserveStart int, blobTxs []tmprot
if removePFBIndexes[tBlob.parsedIndex] {
continue
}
cursor, _ = shares.NextMultipleOfBlobMinSquareSize(cursor, tBlob.sharesUsed, iSS)
cursor, _ = shares.NextShareIndex(cursor, tBlob.sharesUsed, iSS)
// remove the parsed transaction if it cannot fit into the square
if cursor+tBlob.sharesUsed > maxSharesSize {
removePFBIndexes[tBlob.parsedIndex] = true
Expand Down
62 changes: 9 additions & 53 deletions app/write_square_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,7 @@ func Test_finalizeLayout(t *testing.T) {
[]appns.Namespace{ns1, ns1, ns1},
[][]int{{1000}, {10000}, {100000}},
),
expectedIndexes: [][]uint32{
// BlobMinSquareSize(2) = 2 so the first blob has to start at the
// next multiple of 2 >= 32 which is 32. This blob occupies
// shares 32 to 33.
{32},
// BlobMinSquareSize(20) = 8 so the second blob has to start at
// the next multiple of 8 >= 34 which is 40. This blob occupies
// shares 40 to 59.
{40},
// BlobMinSquareSize(199) = 16 so the third blob has to start at
// the next multiple of 16 >= 60 which is 64. This blob occupies
// shares 64 to 262.
{64},
},
expectedIndexes: [][]uint32{{32}, {35}, {56}},
},
{
squareSize: 32,
Expand All @@ -114,29 +101,9 @@ func Test_finalizeLayout(t *testing.T) {
blobTxs: generateBlobTxsWithNamespaces(
t,
[]appns.Namespace{ns1, ns2, ns1},
[][]int{{100}, {1000}, {1000}},
[][]int{{100}, {900}, {900}}, // 1, 2, 2 shares respectively
),
expectedIndexes: [][]uint32{{32}, {38}, {34}},
},
{
squareSize: 32,
nonreserveStart: 32,
blobTxs: generateBlobTxsWithNamespaces(
t,
[]appns.Namespace{ns1, ns2, ns1},
[][]int{{100}, {1000}, {1000}},
),
expectedIndexes: [][]uint32{{32}, {38}, {34}},
},
{
squareSize: 4,
nonreserveStart: 3,
blobTxs: generateBlobTxsWithNamespaces(
t,
[]appns.Namespace{ns1, ns3, ns2},
[][]int{{100}, {1000}, {420}},
),
expectedIndexes: [][]uint32{{3}, {6}, {4}},
expectedIndexes: [][]uint32{{32}, {35}, {33}},
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
},
{
squareSize: 4,
Expand All @@ -146,7 +113,7 @@ func Test_finalizeLayout(t *testing.T) {
[]appns.Namespace{ns1, ns3, ns3, ns2},
[][]int{{100}, {1000, 1000}, {420}},
),
expectedIndexes: [][]uint32{{4}, {6, 10}, {5}},
expectedIndexes: [][]uint32{{4}, {6, 9}, {5}},
},
{
// no blob txs should make it in the square
Expand All @@ -159,25 +126,14 @@ func Test_finalizeLayout(t *testing.T) {
),
expectedIndexes: [][]uint32{},
},
{
// only two blob txs should make it in the square
squareSize: 4,
nonreserveStart: 4,
blobTxs: generateBlobTxsWithNamespaces(
t,
[]appns.Namespace{ns1, ns2, ns3},
[][]int{{1800}, {1800}, {6000}},
),
expectedIndexes: [][]uint32{{4}, {8}},
},
cmwaters marked this conversation as resolved.
Show resolved Hide resolved
{
// only one blob tx should make it in the square (after reordering)
squareSize: 4,
nonreserveStart: 4,
blobTxs: generateBlobTxsWithNamespaces(
t,
[]appns.Namespace{ns3, ns2, ns1},
[][]int{{2000}, {2000}, {6000}},
[][]int{{2000}, {2000}, {5000}},
),
expectedIndexes: [][]uint32{{4}},
},
Expand All @@ -198,19 +154,19 @@ func Test_finalizeLayout(t *testing.T) {
blobTxs: generateBlobTxsWithNamespaces(
t,
[]appns.Namespace{ns1, ns3, ns3, ns1, ns2, ns2},
[][]int{{100}, {1400, 1000, 200, 200}, {420}},
[][]int{{100}, {1400, 900, 200, 200}, {420}},
),
expectedIndexes: [][]uint32{{4}, {8, 12, 5, 6}, {7}},
expectedIndexes: [][]uint32{{4}, {8, 11, 5, 6}, {7}},
},
{
squareSize: 4,
nonreserveStart: 4,
blobTxs: generateBlobTxsWithNamespaces(
t,
[]appns.Namespace{ns1, ns3, ns3, ns1, ns2, ns2},
[][]int{{100}, {1000, 1400, 200, 200}, {420}},
[][]int{{100}, {900, 1400, 200, 200}, {420}},
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
),
expectedIndexes: [][]uint32{{4}, {8, 12, 5, 6}, {7}},
expectedIndexes: [][]uint32{{4}, {8, 10, 5, 6}, {7}},
},
}
for i, tt := range tests {
Expand Down
8 changes: 8 additions & 0 deletions pkg/appconsts/appconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ const (
// data square.
MinShareCount = DefaultMinSquareSize * DefaultMinSquareSize

// SubtreeRootThreshold dictates the threshold for increasing the sub tree
// root width for blobs. If the number of subtree roots used to create a
// share commitment surpasses this threshold, then the width is increased.
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
// 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

// MaxShareVersion is the maximum value a share version can be.
MaxShareVersion = 127

Expand Down
16 changes: 6 additions & 10 deletions pkg/inclusion/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ type path struct {
// calculateCommitmentPaths calculates all of the paths to subtree roots needed to
// create the commitment for a given blob.
func calculateCommitmentPaths(squareSize, start, blobShareLen int) []path {
// TODO: make the non-interactive defaults optional. by calculating the
// NextMultipleOfBlobMinSquareSize, we are forcing use of the
// non-interactive defaults. If we want to make this optional in the future,
// we have to move this next line out of this function.
start, _ = shares.NextMultipleOfBlobMinSquareSize(start, blobShareLen, squareSize)
start, _ = shares.NextShareIndex(start, blobShareLen, squareSize)
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
startRow, endRow := start/squareSize, (start+blobShareLen-1)/squareSize
normalizedStartIndex := start % squareSize
normalizedEndIndex := (start + blobShareLen) - endRow*squareSize
Expand All @@ -33,11 +29,11 @@ func calculateCommitmentPaths(squareSize, start, blobShareLen int) []path {
end = normalizedEndIndex
}

// subTreeRootMaxHeight is the maximum height of a subtree root that was
// used to generate the commitment. The height is based on the minimum
// square size the blob can fit into. See ADR-008 for more details.
subTreeRootMaxHeight := int(math.Log2(float64(shares.MinSquareSize(blobShareLen))))
minDepth := maxDepth - subTreeRootMaxHeight
// subTreeRootMaxDepth is the maximum height of a subtree root that was
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
// used to generate the commitment. The height is based on the
// SubtreeRootThreshold. See ADR-013 for more details.
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
Loading