-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(share/shwap): shwap types improvements
- Loading branch information
Showing
20 changed files
with
458 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/celestiaorg/celestia-app/pkg/da" | ||
"github.com/celestiaorg/rsmt2d" | ||
) | ||
|
||
// Root represents root commitment to multiple Shares. | ||
// In practice, it is a commitment to all the Data in a square. | ||
type Root = da.DataAvailabilityHeader | ||
|
||
// NewRoot generates Root(DataAvailabilityHeader) using the | ||
// provided extended data square. | ||
func NewRoot(eds *rsmt2d.ExtendedDataSquare) (*Root, error) { | ||
dah, err := da.NewDataAvailabilityHeader(eds) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &dah, nil | ||
} | ||
|
||
// RowsWithNamespace inspects the Root for the Namespace and provides | ||
// a slices of Row indexes containing the namespace. | ||
func RowsWithNamespace(root *Root, namespace Namespace) (idxs []int) { | ||
for i, row := range root.RowRoots { | ||
if !namespace.IsOutsideRange(row, row) { | ||
idxs = append(idxs, i) | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package shwap | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/celestiaorg/rsmt2d" | ||
|
||
"github.com/celestiaorg/celestia-node/share" | ||
) | ||
|
||
// NamespacedData stores collections of RowNamespaceData, each representing shares and their proofs | ||
// within a namespace. | ||
type NamespacedData []RowNamespaceData | ||
|
||
// NamespacedDataFromEDS extracts shares for a specific namespace from an EDS, considering | ||
// each row independently. | ||
func NamespacedDataFromEDS( | ||
square *rsmt2d.ExtendedDataSquare, | ||
namespace share.Namespace, | ||
) (NamespacedData, error) { | ||
root, err := share.NewRoot(square) | ||
if err != nil { | ||
return nil, fmt.Errorf("error computing root: %w", err) | ||
} | ||
|
||
rowIdxs := share.RowsWithNamespace(root, namespace) | ||
rows := make(NamespacedData, len(rowIdxs)) | ||
for i, idx := range rowIdxs { | ||
shares := square.Row(uint(idx)) | ||
rows[i], err = RowNamespaceDataFromShares(shares, namespace, idx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to process row %d: %w", idx, err) | ||
} | ||
} | ||
|
||
return rows, nil | ||
} | ||
|
||
// Flatten combines all shares from all rows within the namespace into a single slice. | ||
func (ns NamespacedData) Flatten() []share.Share { | ||
var shares []share.Share | ||
for _, row := range ns { | ||
shares = append(shares, row.Shares...) | ||
} | ||
return shares | ||
} | ||
|
||
// Validate checks the integrity of the NamespacedData against a provided root and namespace. | ||
func (ns NamespacedData) Validate(root *share.Root, namespace share.Namespace) error { | ||
rowIdxs := share.RowsWithNamespace(root, namespace) | ||
if len(rowIdxs) != len(ns) { | ||
return fmt.Errorf("expected %d rows, found %d rows", len(rowIdxs), len(ns)) | ||
} | ||
|
||
for i, row := range ns { | ||
if err := row.Validate(root, namespace, rowIdxs[i]); err != nil { | ||
return fmt.Errorf("validating row: %w", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.