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

revert!: rsmt2d#277 and rsmt2d#287 #295

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 0 additions & 48 deletions default_tree.go

This file was deleted.

20 changes: 8 additions & 12 deletions extendeddatacrossword_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestRepairExtendedDataSquare(t *testing.T) {
flattened[12], flattened[13] = nil, nil

// Re-import the data square.
eds, err := ImportExtendedDataSquare(flattened, codec, DefaultTreeName)
eds, err := ImportExtendedDataSquare(flattened, codec, NewDefaultTree)
if err != nil {
t.Errorf("ImportExtendedDataSquare failed: %v", err)
}
Expand All @@ -67,7 +67,7 @@ func TestRepairExtendedDataSquare(t *testing.T) {
flattened[12], flattened[13], flattened[14] = nil, nil, nil

// Re-import the data square.
eds, err := ImportExtendedDataSquare(flattened, codec, DefaultTreeName)
eds, err := ImportExtendedDataSquare(flattened, codec, NewDefaultTree)
if err != nil {
t.Errorf("ImportExtendedDataSquare failed: %v", err)
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func BenchmarkRepair(b *testing.B) {

// Generate a new range original data square then extend it
square := genRandDS(originalDataWidth, shareSize)
eds, err := ComputeExtendedDataSquare(square, codec, DefaultTreeName)
eds, err := ComputeExtendedDataSquare(square, codec, NewDefaultTree)
if err != nil {
b.Error(err)
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func BenchmarkRepair(b *testing.B) {
}

// Re-import the data square.
eds, _ = ImportExtendedDataSquare(flattened, codec, DefaultTreeName)
eds, _ = ImportExtendedDataSquare(flattened, codec, NewDefaultTree)

b.StartTimer()

Expand All @@ -301,7 +301,7 @@ func createTestEds(codec Codec, shareSize int) *ExtendedDataSquare {
eds, err := ComputeExtendedDataSquare([][]byte{
ones, twos,
threes, fours,
}, codec, DefaultTreeName)
}, codec, NewDefaultTree)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -390,14 +390,8 @@ func TestCorruptedEdsReturnsErrByzantineData_UnorderedShares(t *testing.T) {

codec := NewLeoRSCodec()

edsWidth := 4 // number of shares per row/column in the extended data square
odsWidth := edsWidth / 2 // number of shares per row/column in the original data square
err := RegisterTree("testing-tree", newConstructor(uint64(odsWidth), nmt.NamespaceIDSize(namespaceSize)))
assert.NoError(t, err)

// create a DA header
eds := createTestEdsWithNMT(t, codec, shareSize, namespaceSize, 1, 2, 3, 4)

assert.NotNil(t, eds)
dAHeaderRoots, err := eds.getRowRoots()
assert.NoError(t, err)
Expand Down Expand Up @@ -442,8 +436,10 @@ func createTestEdsWithNMT(t *testing.T, codec Codec, shareSize, namespaceSize in
for i, shareValue := range sharesValue {
shares[i] = bytes.Repeat([]byte{byte(shareValue)}, shareSize)
}
edsWidth := 4 // number of shares per row/column in the extended data square
odsWidth := edsWidth / 2 // number of shares per row/column in the original data square

eds, err := ComputeExtendedDataSquare(shares, codec, "testing-tree")
eds, err := ComputeExtendedDataSquare(shares, codec, newConstructor(uint64(odsWidth), nmt.NamespaceIDSize(namespaceSize)))
require.NoError(t, err)

return eds
Expand Down
36 changes: 7 additions & 29 deletions extendeddatasquare.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,29 @@ import (
type ExtendedDataSquare struct {
*dataSquare
codec Codec
treeName string
originalDataWidth uint
}

func (eds *ExtendedDataSquare) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
DataSquare [][]byte `json:"data_square"`
Codec string `json:"codec"`
Tree string `json:"tree"`
}{
DataSquare: eds.dataSquare.Flattened(),
Codec: eds.codec.Name(),
Tree: eds.treeName,
})
}

func (eds *ExtendedDataSquare) UnmarshalJSON(b []byte) error {
var aux struct {
DataSquare [][]byte `json:"data_square"`
Codec string `json:"codec"`
Tree string `json:"tree"`
}

err := json.Unmarshal(b, &aux)
if err != nil {
if err := json.Unmarshal(b, &aux); err != nil {
return err
}

if aux.Tree == "" {
aux.Tree = DefaultTreeName
}

importedEds, err := ImportExtendedDataSquare(aux.DataSquare, codecs[aux.Codec], aux.Tree)
importedEds, err := ImportExtendedDataSquare(aux.DataSquare, codecs[aux.Codec], NewDefaultTree)
if err != nil {
return err
}
Expand All @@ -60,7 +50,7 @@ func (eds *ExtendedDataSquare) UnmarshalJSON(b []byte) error {
func ComputeExtendedDataSquare(
data [][]byte,
codec Codec,
treeName string,
treeCreatorFn TreeConstructorFn,
) (*ExtendedDataSquare, error) {
if len(data) > codec.MaxChunks() {
return nil, errors.New("number of chunks exceeds the maximum")
Expand All @@ -71,18 +61,12 @@ func ComputeExtendedDataSquare(
if err != nil {
return nil, err
}

treeCreatorFn, err := TreeFn(treeName)
if err != nil {
return nil, err
}

ds, err := newDataSquare(data, treeCreatorFn, uint(chunkSize))
if err != nil {
return nil, err
}

eds := ExtendedDataSquare{dataSquare: ds, codec: codec, treeName: treeName}
eds := ExtendedDataSquare{dataSquare: ds, codec: codec}
err = eds.erasureExtendSquare(codec)
if err != nil {
return nil, err
Expand All @@ -95,7 +79,7 @@ func ComputeExtendedDataSquare(
func ImportExtendedDataSquare(
data [][]byte,
codec Codec,
treeName string,
treeCreatorFn TreeConstructorFn,
) (*ExtendedDataSquare, error) {
if len(data) > 4*codec.MaxChunks() {
return nil, errors.New("number of chunks exceeds the maximum")
Expand All @@ -106,18 +90,12 @@ func ImportExtendedDataSquare(
if err != nil {
return nil, err
}

treeCreatorFn, err := TreeFn(treeName)
if err != nil {
return nil, err
}

ds, err := newDataSquare(data, treeCreatorFn, uint(chunkSize))
if err != nil {
return nil, err
}

eds := ExtendedDataSquare{dataSquare: ds, codec: codec, treeName: treeName}
eds := ExtendedDataSquare{dataSquare: ds, codec: codec}
err = validateEdsWidth(eds.width)
if err != nil {
return nil, err
Expand Down Expand Up @@ -248,7 +226,7 @@ func (eds *ExtendedDataSquare) erasureExtendCol(codec Codec, i uint) error {
}

func (eds *ExtendedDataSquare) deepCopy(codec Codec) (ExtendedDataSquare, error) {
imported, err := ImportExtendedDataSquare(eds.Flattened(), codec, eds.treeName)
imported, err := ImportExtendedDataSquare(eds.Flattened(), codec, eds.createTreeFn)
return *imported, err
}

Expand Down
Loading
Loading