From 8619c905a679eed253621106db69d91329263289 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 12 Dec 2024 00:31:44 +0200 Subject: [PATCH 1/7] feat(shwap): implement GetRow --- nodebuilder/share/mocks/api.go | 15 ++++++++++ nodebuilder/share/share.go | 19 +++++++++++++ share/availability/light/availability_test.go | 6 +++- share/shwap/getter.go | 2 ++ share/shwap/getters/cascade.go | 12 ++++++++ share/shwap/getters/mock/getter.go | 15 ++++++++++ share/shwap/getters/testing.go | 17 +++++++++++ share/shwap/p2p/bitswap/getter.go | 25 +++++++++++++++++ share/shwap/p2p/shrex/shrex_getter/shrex.go | 4 +++ share/shwap/row.go | 28 +++++++++++++++++++ store/getter.go | 15 ++++++++++ store/getter_test.go | 20 +++++++++++++ xtoken.json | 1 + 13 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 xtoken.json diff --git a/nodebuilder/share/mocks/api.go b/nodebuilder/share/mocks/api.go index 7fde2338cc..d392f39f5b 100644 --- a/nodebuilder/share/mocks/api.go +++ b/nodebuilder/share/mocks/api.go @@ -84,6 +84,21 @@ func (mr *MockModuleMockRecorder) GetRange(arg0, arg1, arg2, arg3 interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRange", reflect.TypeOf((*MockModule)(nil).GetRange), arg0, arg1, arg2, arg3) } +// GetRow mocks base method. +func (m *MockModule) GetRow(arg0 context.Context, arg1 uint64, arg2 int) (shwap.Row, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRow", arg0, arg1, arg2) + ret0, _ := ret[0].(shwap.Row) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRow indicates an expected call of GetRow. +func (mr *MockModuleMockRecorder) GetRow(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRow", reflect.TypeOf((*MockModule)(nil).GetRow), arg0, arg1, arg2) +} + // GetSamples mocks base method. func (m *MockModule) GetSamples(arg0 context.Context, arg1 *header.ExtendedHeader, arg2 []shwap.SampleCoords) ([]shwap.Sample, error) { m.ctrl.T.Helper() diff --git a/nodebuilder/share/share.go b/nodebuilder/share/share.go index 783018fe47..46df1e2379 100644 --- a/nodebuilder/share/share.go +++ b/nodebuilder/share/share.go @@ -50,6 +50,8 @@ type Module interface { GetSamples(ctx context.Context, header *header.ExtendedHeader, indices []shwap.SampleCoords) ([]shwap.Sample, error) // GetEDS gets the full EDS identified by the given extended header. GetEDS(ctx context.Context, height uint64) (*rsmt2d.ExtendedDataSquare, error) + // GetRow gets all shares from specified row. + GetRow(context.Context, uint64, int) (shwap.Row, error) // GetNamespaceData gets all shares from an EDS within the given namespace. // Shares are returned in a row-by-row order if the namespace spans multiple rows. GetNamespaceData( @@ -77,6 +79,11 @@ type API struct { ctx context.Context, height uint64, ) (*rsmt2d.ExtendedDataSquare, error) `perm:"read"` + GetRow func( + context.Context, + uint64, + int, + ) (shwap.Row, error) `perm:"read"` GetNamespaceData func( ctx context.Context, height uint64, @@ -108,6 +115,10 @@ func (api *API) GetEDS(ctx context.Context, height uint64) (*rsmt2d.ExtendedData return api.Internal.GetEDS(ctx, height) } +func (api *API) GetRow(ctx context.Context, height uint64, rowIdx int) (shwap.Row, error) { + return api.Internal.GetRow(ctx, height, rowIdx) +} + func (api *API) GetRange(ctx context.Context, height uint64, start, end int) (*GetRangeResult, error) { return api.Internal.GetRange(ctx, height, start, end) } @@ -196,3 +207,11 @@ func (m module) GetNamespaceData( } return m.getter.GetNamespaceData(ctx, header, namespace) } + +func (m module) GetRow(ctx context.Context, height uint64, rowIdx int) (shwap.Row, error) { + header, err := m.hs.GetByHeight(ctx, height) + if err != nil { + return shwap.Row{}, err + } + return m.getter.GetRow(ctx, header, rowIdx) +} diff --git a/share/availability/light/availability_test.go b/share/availability/light/availability_test.go index 191c286938..df441c46a1 100644 --- a/share/availability/light/availability_test.go +++ b/share/availability/light/availability_test.go @@ -290,7 +290,7 @@ func (g successGetter) checkOnce(t *testing.T) { } } -func (g successGetter) GetSamples(_ context.Context, hdr *header.ExtendedHeader, +func (g successGetter) GetSamples(_ context.Context, _ *header.ExtendedHeader, indices []shwap.SampleCoords, ) ([]shwap.Sample, error) { g.Lock() @@ -305,6 +305,10 @@ func (g successGetter) GetSamples(_ context.Context, hdr *header.ExtendedHeader, return smpls, nil } +func (g successGetter) GetRow(_ context.Context, _ *header.ExtendedHeader, _ int) (shwap.Row, error) { + panic("not implemented") +} + func (g successGetter) GetEDS(_ context.Context, _ *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { panic("not implemented") } diff --git a/share/shwap/getter.go b/share/shwap/getter.go index 9e0a5d3131..f60b8377ef 100644 --- a/share/shwap/getter.go +++ b/share/shwap/getter.go @@ -39,6 +39,8 @@ type Getter interface { // GetEDS gets the full EDS identified by the given extended header. GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) + // GetRow gets all shares from the specified row. + GetRow(ctx context.Context, header *header.ExtendedHeader, rowIdx int) (Row, error) // GetNamespaceData gets all shares from an EDS within the given namespace. // Shares are returned in a row-by-row order if the namespace spans multiple rows. // Inclusion of returned data could be verified using Verify method on NamespacedShares. diff --git a/share/shwap/getters/cascade.go b/share/shwap/getters/cascade.go index 39ceb2fdb1..c9ac091ddd 100644 --- a/share/shwap/getters/cascade.go +++ b/share/shwap/getters/cascade.go @@ -71,6 +71,18 @@ func (cg *CascadeGetter) GetEDS( return cascadeGetters(ctx, cg.getters, get) } +// GetRow gets row shares from any of registered shwap.Getters in cascading +// order. +func (cg *CascadeGetter) GetRow(ctx context.Context, header *header.ExtendedHeader, rowIdx int) (shwap.Row, error) { + ctx, span := tracer.Start(ctx, "cascade/get-row") + defer span.End() + + get := func(ctx context.Context, get shwap.Getter) (shwap.Row, error) { + return get.GetRow(ctx, header, rowIdx) + } + return cascadeGetters(ctx, cg.getters, get) +} + // GetNamespaceData gets NamespacedShares from any of registered shwap.Getters in cascading // order. func (cg *CascadeGetter) GetNamespaceData( diff --git a/share/shwap/getters/mock/getter.go b/share/shwap/getters/mock/getter.go index 7e4dacb24a..ade35b39f8 100644 --- a/share/shwap/getters/mock/getter.go +++ b/share/shwap/getters/mock/getter.go @@ -68,6 +68,21 @@ func (mr *MockGetterMockRecorder) GetNamespaceData(arg0, arg1, arg2 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNamespaceData", reflect.TypeOf((*MockGetter)(nil).GetNamespaceData), arg0, arg1, arg2) } +// GetRow mocks base method. +func (m *MockGetter) GetRow(arg0 context.Context, arg1 *header.ExtendedHeader, arg2 int) (shwap.Row, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRow", arg0, arg1, arg2) + ret0, _ := ret[0].(shwap.Row) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRow indicates an expected call of GetRow. +func (mr *MockGetterMockRecorder) GetRow(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRow", reflect.TypeOf((*MockGetter)(nil).GetRow), arg0, arg1, arg2) +} + // GetSamples mocks base method. func (m *MockGetter) GetSamples(arg0 context.Context, arg1 *header.ExtendedHeader, arg2 []shwap.SampleCoords) ([]shwap.Sample, error) { m.ctrl.T.Helper() diff --git a/share/shwap/getters/testing.go b/share/shwap/getters/testing.go index a3ee53753d..c244204aba 100644 --- a/share/shwap/getters/testing.go +++ b/share/shwap/getters/testing.go @@ -58,6 +58,23 @@ func (seg *SingleEDSGetter) GetSamples(ctx context.Context, hdr *header.Extended return smpls, nil } +func (seg *SingleEDSGetter) GetRow( + ctx context.Context, + header *header.ExtendedHeader, + rowIdx int, +) (shwap.Row, error) { + err := seg.checkRoots(header.DAH) + if err != nil { + return shwap.Row{}, err + } + + axisHalf, err := seg.EDS.AxisHalf(ctx, rsmt2d.Row, rowIdx) + if err != nil { + return shwap.Row{}, err + } + return axisHalf.ToRow(), nil +} + // GetEDS returns a kept EDS if the correct root is given. func (seg *SingleEDSGetter) GetEDS( _ context.Context, diff --git a/share/shwap/p2p/bitswap/getter.go b/share/shwap/p2p/bitswap/getter.go index db2938663c..f3598cf240 100644 --- a/share/shwap/p2p/bitswap/getter.go +++ b/share/shwap/p2p/bitswap/getter.go @@ -134,6 +134,31 @@ func (g *Getter) GetSamples( return smpls, nil } +func (g *Getter) GetRow(ctx context.Context, hdr *header.ExtendedHeader, rowIdx int) (shwap.Row, error) { + ctx, span := tracer.Start(ctx, "get-eds") + defer span.End() + blk, err := NewEmptyRowBlock(hdr.Height(), rowIdx, len(hdr.DAH.RowRoots)) + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, "NewEmptyRowBlock") + return shwap.Row{}, err + } + + isArchival := g.isArchival(hdr) + span.SetAttributes(attribute.Bool("is_archival", isArchival)) + + ses, release := g.getSession(isArchival) + defer release() + + err = Fetch(ctx, g.exchange, hdr.DAH, []Block{blk}, WithFetcher(ses)) + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, "Fetch") + return shwap.Row{}, err + } + return blk.Container, nil +} + // GetEDS uses [RowBlock] and [Fetch] to get half of the first EDS quadrant(ODS) and // recomputes the whole EDS from it. // We fetch the ODS or Q1 to ensure better compatibility with archival nodes that only diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex.go b/share/shwap/p2p/shrex/shrex_getter/shrex.go index 6c91a44736..88247cdc4b 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex.go @@ -150,6 +150,10 @@ func (sg *Getter) GetSamples(context.Context, *header.ExtendedHeader, []shwap.Sa return nil, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) } +func (sg *Getter) GetRow(_ context.Context, _ *header.ExtendedHeader, _ int) (shwap.Row, error) { + return shwap.Row{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) +} + func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { var err error ctx, span := tracer.Start(ctx, "shrex/get-eds") diff --git a/share/shwap/row.go b/share/shwap/row.go index 7057680573..91083724f0 100644 --- a/share/shwap/row.go +++ b/share/shwap/row.go @@ -2,6 +2,7 @@ package shwap import ( "bytes" + "encoding/json" "fmt" "github.com/celestiaorg/celestia-app/v3/pkg/wrapper" @@ -171,6 +172,33 @@ func (r *Row) verifyInclusion(roots *share.AxisRoots, idx int) error { return nil } +// MarshalJSON encodes row to the json encoded bytes. +func (r Row) MarshalJSON() ([]byte, error) { + jsonRow := struct { + Shares []libshare.Share `json:"shares"` + Side RowSide `json:"side"` + }{ + Shares: r.halfShares, + Side: r.side, + } + return json.Marshal(&jsonRow) +} + +// UnmarshalJSON decodes json bytes to the row. +func (r *Row) UnmarshalJSON(data []byte) error { + jsonRow := struct { + Shares []libshare.Share `json:"shares"` + Side RowSide `json:"side"` + }{} + err := json.Unmarshal(data, &jsonRow) + if err != nil { + return err + } + r.halfShares = jsonRow.Shares + r.side = jsonRow.Side + return nil +} + // ToProto converts a RowSide to its protobuf representation. func (s RowSide) ToProto() pb.Row_HalfSide { if s == Left { diff --git a/store/getter.go b/store/getter.go index 1315561730..7a4111eec1 100644 --- a/store/getter.go +++ b/store/getter.go @@ -71,6 +71,21 @@ func (g *Getter) GetEDS(ctx context.Context, h *header.ExtendedHeader) (*rsmt2d. return rsmt2d.ExtendedDataSquare, nil } +func (g *Getter) GetRow(ctx context.Context, h *header.ExtendedHeader, rowIdx int) (shwap.Row, error) { + acc, err := g.store.GetByHeight(ctx, h.Height()) + if err != nil { + if errors.Is(err, ErrNotFound) { + return shwap.Row{}, shwap.ErrNotFound + } + return shwap.Row{}, fmt.Errorf("get accessor from store:%w", err) + } + axisHalf, err := acc.AxisHalf(ctx, rsmt2d.Row, rowIdx) + if err != nil { + return shwap.Row{}, fmt.Errorf("get axis half from accessor:%w", err) + } + return axisHalf.ToRow(), nil +} + func (g *Getter) GetNamespaceData( ctx context.Context, h *header.ExtendedHeader, diff --git a/store/getter_test.go b/store/getter_test.go index b0b027fc19..0042f43ecf 100644 --- a/store/getter_test.go +++ b/store/getter_test.go @@ -69,6 +69,26 @@ func TestStoreGetter(t *testing.T) { require.ErrorIs(t, err, shwap.ErrNotFound) }) + t.Run("GetRow", func(t *testing.T) { + eds, roots := randomEDS(t) + eh := headertest.RandExtendedHeaderWithRoot(t, roots) + height := height.Add(1) + eh.RawHeader.Height = int64(height) + + err := edsStore.PutODSQ4(ctx, eh.DAH, height, eds) + require.NoError(t, err) + + for i := 0; i < len(eh.DAH.RowRoots); i++ { + row, err := sg.GetRow(ctx, eh, i) + require.NoError(t, err) + retreivedShrs, err := row.Shares() + require.NoError(t, err) + edsShrs, err := libshare.FromBytes(eds.Row(uint(i))) + require.NoError(t, err) + require.Equal(t, edsShrs, retreivedShrs) + } + }) + t.Run("GetNamespaceData", func(t *testing.T) { ns := libshare.RandomNamespace() eds, roots := edstest.RandEDSWithNamespace(t, ns, 8, 16) diff --git a/xtoken.json b/xtoken.json new file mode 100644 index 0000000000..059a3d2486 --- /dev/null +++ b/xtoken.json @@ -0,0 +1 @@ +{"x-token": "cdb1b3af1f4f7d841e948ed4a62cae4d4c1ee722"} From 03b733ffc201b779f4735d8a28ba255bf1df67e1 Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Thu, 12 Dec 2024 14:08:13 +0200 Subject: [PATCH 2/7] apply suggestions Co-authored-by: Hlib Kanunnikov --- share/shwap/getter.go | 2 +- store/getter.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/share/shwap/getter.go b/share/shwap/getter.go index f60b8377ef..f56c8edc63 100644 --- a/share/shwap/getter.go +++ b/share/shwap/getter.go @@ -39,7 +39,7 @@ type Getter interface { // GetEDS gets the full EDS identified by the given extended header. GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) - // GetRow gets all shares from the specified row. + // GetRow gets Row by its index committed to the given extended header. GetRow(ctx context.Context, header *header.ExtendedHeader, rowIdx int) (Row, error) // GetNamespaceData gets all shares from an EDS within the given namespace. // Shares are returned in a row-by-row order if the namespace spans multiple rows. diff --git a/store/getter.go b/store/getter.go index 7a4111eec1..7a94c408ac 100644 --- a/store/getter.go +++ b/store/getter.go @@ -77,11 +77,11 @@ func (g *Getter) GetRow(ctx context.Context, h *header.ExtendedHeader, rowIdx in if errors.Is(err, ErrNotFound) { return shwap.Row{}, shwap.ErrNotFound } - return shwap.Row{}, fmt.Errorf("get accessor from store:%w", err) + return shwap.Row{}, fmt.Errorf("getting accessor from store: %w", err) } axisHalf, err := acc.AxisHalf(ctx, rsmt2d.Row, rowIdx) if err != nil { - return shwap.Row{}, fmt.Errorf("get axis half from accessor:%w", err) + return shwap.Row{}, fmt.Errorf("getting axis half from accessor: %w", err) } return axisHalf.ToRow(), nil } From 3c7b6747f9bfb7d67a542cd29096265416687e2b Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 12 Dec 2024 14:18:25 +0200 Subject: [PATCH 3/7] fix nits --- share/shwap/p2p/bitswap/getter.go | 1 + share/shwap/row.go | 30 ++++++++++++++++++++++++++---- share/shwap/row_test.go | 24 ++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/share/shwap/p2p/bitswap/getter.go b/share/shwap/p2p/bitswap/getter.go index f3598cf240..f008809833 100644 --- a/share/shwap/p2p/bitswap/getter.go +++ b/share/shwap/p2p/bitswap/getter.go @@ -137,6 +137,7 @@ func (g *Getter) GetSamples( func (g *Getter) GetRow(ctx context.Context, hdr *header.ExtendedHeader, rowIdx int) (shwap.Row, error) { ctx, span := tracer.Start(ctx, "get-eds") defer span.End() + blk, err := NewEmptyRowBlock(hdr.Height(), rowIdx, len(hdr.DAH.RowRoots)) if err != nil { span.RecordError(err) diff --git a/share/shwap/row.go b/share/shwap/row.go index 91083724f0..abf699acd0 100644 --- a/share/shwap/row.go +++ b/share/shwap/row.go @@ -176,10 +176,10 @@ func (r *Row) verifyInclusion(roots *share.AxisRoots, idx int) error { func (r Row) MarshalJSON() ([]byte, error) { jsonRow := struct { Shares []libshare.Share `json:"shares"` - Side RowSide `json:"side"` + Side string `json:"side"` }{ Shares: r.halfShares, - Side: r.side, + Side: r.side.toString(), } return json.Marshal(&jsonRow) } @@ -188,14 +188,14 @@ func (r Row) MarshalJSON() ([]byte, error) { func (r *Row) UnmarshalJSON(data []byte) error { jsonRow := struct { Shares []libshare.Share `json:"shares"` - Side RowSide `json:"side"` + Side string `json:"side"` }{} err := json.Unmarshal(data, &jsonRow) if err != nil { return err } r.halfShares = jsonRow.Shares - r.side = jsonRow.Side + r.side = toRowSide(jsonRow.Side) return nil } @@ -214,3 +214,25 @@ func sideFromProto(side pb.Row_HalfSide) RowSide { } return Right } + +func (s RowSide) toString() string { + switch s { + case Left: + return "LEFT" + case Right: + return "RIGHT" + default: + panic("invalid row side") + } +} + +func toRowSide(s string) RowSide { + switch s { + case "LEFT": + return Left + case "RIGHT": + return Right + default: + panic("invalid row side") + } +} diff --git a/share/shwap/row_test.go b/share/shwap/row_test.go index 16bce3893b..407b06a33c 100644 --- a/share/shwap/row_test.go +++ b/share/shwap/row_test.go @@ -1,6 +1,7 @@ package shwap import ( + "encoding/json" "testing" "github.com/stretchr/testify/require" @@ -20,11 +21,30 @@ func TestRowShares(t *testing.T) { row, err := RowFromEDS(eds, rowIdx, side) require.NoError(t, err) require.Equal(t, side, row.side) + } + } +} +func TestRowMarshal(t *testing.T) { + const odsSize = 8 + eds := edstest.RandEDS(t, odsSize) + for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { + for _, side := range []RowSide{Left, Right} { + shrs := eds.Row(uint(rowIdx)) + shares, err := libshare.FromBytes(shrs) + require.NoError(t, err) + + row := RowFromShares(shares, side) + rowData, err := json.Marshal(row) + require.NoError(t, err) + + decodedRow := &Row{} + err = json.Unmarshal(rowData, decodedRow) + require.NoError(t, err) extended, err := row.Shares() require.NoError(t, err) - require.Len(t, extended, odsSize*2) - require.Equal(t, Both, row.side) + require.Equal(t, side, decodedRow.side) + require.Equal(t, shares, extended) } } } From 75308a1efe3bca1a0b90078d63dc2cfaf3ea81ca Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 13 Dec 2024 13:45:32 +0200 Subject: [PATCH 4/7] make ToString() public --- share/shwap/row.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/shwap/row.go b/share/shwap/row.go index abf699acd0..13a531a0e9 100644 --- a/share/shwap/row.go +++ b/share/shwap/row.go @@ -179,7 +179,7 @@ func (r Row) MarshalJSON() ([]byte, error) { Side string `json:"side"` }{ Shares: r.halfShares, - Side: r.side.toString(), + Side: r.side.ToString(), } return json.Marshal(&jsonRow) } @@ -215,7 +215,7 @@ func sideFromProto(side pb.Row_HalfSide) RowSide { return Right } -func (s RowSide) toString() string { +func (s RowSide) ToString() string { switch s { case Left: return "LEFT" From 49e055fb3ac0c8c244b5fa6217f0196a2aa4a81a Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Fri, 13 Dec 2024 13:51:52 +0200 Subject: [PATCH 5/7] rename to String() --- share/shwap/row.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/shwap/row.go b/share/shwap/row.go index 13a531a0e9..1ae5732da9 100644 --- a/share/shwap/row.go +++ b/share/shwap/row.go @@ -179,7 +179,7 @@ func (r Row) MarshalJSON() ([]byte, error) { Side string `json:"side"` }{ Shares: r.halfShares, - Side: r.side.ToString(), + Side: r.side.String(), } return json.Marshal(&jsonRow) } @@ -215,7 +215,7 @@ func sideFromProto(side pb.Row_HalfSide) RowSide { return Right } -func (s RowSide) ToString() string { +func (s RowSide) String() string { switch s { case Left: return "LEFT" From 1d0a5820b0a8e96a2f15234bd902f2e9892aa002 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Mon, 16 Dec 2024 12:49:51 +0200 Subject: [PATCH 6/7] adapt changes --- share/shwap/row.go | 8 ++++++-- share/shwap/row_test.go | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/share/shwap/row.go b/share/shwap/row.go index 1ae5732da9..87faff4875 100644 --- a/share/shwap/row.go +++ b/share/shwap/row.go @@ -178,7 +178,7 @@ func (r Row) MarshalJSON() ([]byte, error) { Shares []libshare.Share `json:"shares"` Side string `json:"side"` }{ - Shares: r.halfShares, + Shares: r.shares, Side: r.side.String(), } return json.Marshal(&jsonRow) @@ -194,7 +194,7 @@ func (r *Row) UnmarshalJSON(data []byte) error { if err != nil { return err } - r.halfShares = jsonRow.Shares + r.shares = jsonRow.Shares r.side = toRowSide(jsonRow.Side) return nil } @@ -221,6 +221,8 @@ func (s RowSide) String() string { return "LEFT" case Right: return "RIGHT" + case Both: + return "BOTH" default: panic("invalid row side") } @@ -232,6 +234,8 @@ func toRowSide(s string) RowSide { return Left case "RIGHT": return Right + case "BOTH": + return Both default: panic("invalid row side") } diff --git a/share/shwap/row_test.go b/share/shwap/row_test.go index 407b06a33c..87ab6226e1 100644 --- a/share/shwap/row_test.go +++ b/share/shwap/row_test.go @@ -21,6 +21,11 @@ func TestRowShares(t *testing.T) { row, err := RowFromEDS(eds, rowIdx, side) require.NoError(t, err) require.Equal(t, side, row.side) + + extended, err := row.Shares() + require.NoError(t, err) + require.Len(t, extended, odsSize*2) + require.Equal(t, Both, row.side) } } } @@ -30,21 +35,24 @@ func TestRowMarshal(t *testing.T) { eds := edstest.RandEDS(t, odsSize) for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { for _, side := range []RowSide{Left, Right} { - shrs := eds.Row(uint(rowIdx)) - shares, err := libshare.FromBytes(shrs) + row, err := RowFromEDS(eds, rowIdx, side) require.NoError(t, err) - - row := RowFromShares(shares, side) rowData, err := json.Marshal(row) require.NoError(t, err) decodedRow := &Row{} err = json.Unmarshal(rowData, decodedRow) require.NoError(t, err) - extended, err := row.Shares() - require.NoError(t, err) + require.Equal(t, side, decodedRow.side) + extended, err := decodedRow.Shares() + require.NoError(t, err) + + shares, err := row.Shares() + require.NoError(t, err) + require.Equal(t, shares, extended) + require.Equal(t, row.side, decodedRow.side) } } } From 6a61fc72207b907bac8949ff82a8179f3342c4c6 Mon Sep 17 00:00:00 2001 From: vgonkivs Date: Thu, 9 Jan 2025 13:30:47 +0200 Subject: [PATCH 7/7] fixes --- share/shwap/p2p/shrex/shrex_getter/shrex.go | 2 +- share/shwap/row_test.go | 2 +- xtoken.json | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 xtoken.json diff --git a/share/shwap/p2p/shrex/shrex_getter/shrex.go b/share/shwap/p2p/shrex/shrex_getter/shrex.go index 88247cdc4b..142b3f3ab2 100644 --- a/share/shwap/p2p/shrex/shrex_getter/shrex.go +++ b/share/shwap/p2p/shrex/shrex_getter/shrex.go @@ -151,7 +151,7 @@ func (sg *Getter) GetSamples(context.Context, *header.ExtendedHeader, []shwap.Sa } func (sg *Getter) GetRow(_ context.Context, _ *header.ExtendedHeader, _ int) (shwap.Row, error) { - return shwap.Row{}, fmt.Errorf("getter/shrex: GetShare %w", shwap.ErrOperationNotSupported) + return shwap.Row{}, fmt.Errorf("getter/shrex: GetRow %w", shwap.ErrOperationNotSupported) } func (sg *Getter) GetEDS(ctx context.Context, header *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) { diff --git a/share/shwap/row_test.go b/share/shwap/row_test.go index 87ab6226e1..3cf80befca 100644 --- a/share/shwap/row_test.go +++ b/share/shwap/row_test.go @@ -34,7 +34,7 @@ func TestRowMarshal(t *testing.T) { const odsSize = 8 eds := edstest.RandEDS(t, odsSize) for rowIdx := 0; rowIdx < odsSize*2; rowIdx++ { - for _, side := range []RowSide{Left, Right} { + for _, side := range []RowSide{Left, Right, Both} { row, err := RowFromEDS(eds, rowIdx, side) require.NoError(t, err) rowData, err := json.Marshal(row) diff --git a/xtoken.json b/xtoken.json deleted file mode 100644 index 059a3d2486..0000000000 --- a/xtoken.json +++ /dev/null @@ -1 +0,0 @@ -{"x-token": "cdb1b3af1f4f7d841e948ed4a62cae4d4c1ee722"}