Skip to content

Commit 773ed37

Browse files
committed
review
1 parent 30e9837 commit 773ed37

14 files changed

Lines changed: 153 additions & 810 deletions

File tree

libs/utils/close.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
logging "github.com/ipfs/go-log/v2"
77
)
88

9+
// CloseAndLog closes the closer and logs any error that occurs. The function is handy wrapping
10+
// to group closing and logging in one call for defer statements.
911
func CloseAndLog(log logging.StandardLogger, name string, closer io.Closer) {
1012
if err := closer.Close(); err != nil {
1113
log.Warnf("closing %s: %s", name, err)

share/shwap/namespace_data.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,35 @@ func (nd NamespacedData) Validate(root *share.AxisRoots, namespace share.Namespa
4040
}
4141

4242
// ReadFrom reads the binary form of NamespacedData from the provided reader.
43-
func (nd *NamespacedData) ReadFrom(reader io.Reader) error {
43+
func (nd *NamespacedData) ReadFrom(reader io.Reader) (int64, error) {
4444
var data []RowNamespaceData
45+
var n int64
4546
for {
4647
var pbRow pb.RowNamespaceData
47-
_, err := serde.Read(reader, &pbRow)
48+
nn, err := serde.Read(reader, &pbRow)
49+
n += int64(nn)
4850
if err != nil {
4951
if errors.Is(err, io.EOF) {
5052
// all rows have been read
5153
*nd = data
52-
return nil
54+
return n, nil
5355
}
54-
return err
56+
return n, err
5557
}
5658
row := RowNamespaceDataFromProto(&pbRow)
5759
data = append(data, row)
5860
}
5961
}
62+
63+
func (nd NamespacedData) WriteTo(writer io.Writer) (int64, error) {
64+
var n int64
65+
for _, row := range nd {
66+
pbRow := row.ToProto()
67+
nn, err := serde.Write(writer, pbRow)
68+
n += int64(nn)
69+
if err != nil {
70+
return n, err
71+
}
72+
}
73+
return n, nil
74+
}

share/shwap/p2p/shrex/shrexeds/pb/extended_data_square.pb.go renamed to share/shwap/p2p/shrex/pb/shrex.pb.go

Lines changed: 63 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

share/shwap/p2p/shrex/shrexeds/pb/extended_data_square.proto renamed to share/shwap/p2p/shrex/pb/shrex.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
syntax = "proto3";
22

3-
option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/shrexeds/pb";
3+
option go_package = "github.com/celestiaorg/celestia-node/share/shwap/p2p/shrex/pb";
44

55
enum Status {
66
INVALID = 0;
@@ -9,6 +9,6 @@ enum Status {
99
INTERNAL = 3; // internal server error
1010
}
1111

12-
message EDSResponse {
12+
message Response {
1313
Status status = 1;
1414
}

share/shwap/p2p/shrex/shrex_getter/shrex_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/binary"
66
"errors"
7+
"sync/atomic"
78
"testing"
89
"time"
910

@@ -14,7 +15,6 @@ import (
1415
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
1516
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
17-
"go.uber.org/atomic"
1818

1919
libhead "github.com/celestiaorg/go-header"
2020
"github.com/celestiaorg/nmt"
@@ -62,7 +62,9 @@ func TestShrexGetter(t *testing.T) {
6262
getter := NewGetter(edsClient, ndClient, fullPeerManager, archivalPeerManager, light.Window)
6363
require.NoError(t, getter.Start(ctx))
6464

65-
height := atomic.NewUint64(1)
65+
height := atomic.Uint64{}
66+
height.Add(1)
67+
6668
t.Run("ND_Available, total data size > 1mb", func(t *testing.T) {
6769
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
6870
t.Cleanup(cancel)

0 commit comments

Comments
 (0)