Skip to content

Commit

Permalink
feat!: bump app v1.0.0-rc0 (#2253)
Browse files Browse the repository at this point in the history
Co-authored-by: Rootul Patel <[email protected]>
Co-authored-by: Wondertan <[email protected]>
  • Loading branch information
3 people authored May 29, 2023
1 parent e5efcb0 commit 9359b65
Show file tree
Hide file tree
Showing 46 changed files with 337 additions and 559 deletions.
6 changes: 5 additions & 1 deletion api/gateway/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ func (h *Handler) getShares(ctx context.Context, height uint64, nID namespace.ID
}

func dataFromShares(input []share.Share) (data [][]byte, err error) {
sequences, err := shares.ParseShares(input)
appShares, err := shares.FromBytes(input)
if err != nil {
return nil, err
}
sequences, err := shares.ParseShares(appShares, false)
if err != nil {
return nil, err
}
Expand Down
133 changes: 29 additions & 104 deletions api/gateway/share_test.go
Original file line number Diff line number Diff line change
@@ -1,129 +1,52 @@
package gateway

import (
"bytes"
_ "embed"
"encoding/base64"
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
coretypes "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/pkg/shares"
)

func Test_dataFromShares(t *testing.T) {
type testCase struct {
name string
input [][]byte
want [][]byte
wantErr bool
testData := [][]byte{
[]byte("beep"),
[]byte("beeap"),
[]byte("BEEEEAHP"),
}

smallTxInput := padShare([]uint8{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, // namespace id
0x1, // info byte
0x0, 0x0, 0x0, 0x2, // 1 byte (unit) + 1 byte (unit length) = 2 bytes sequence length
0x0, 0x0, 0x0, 17, // reserved bytes
0x1, // unit length of first transaction
0xa, // data of first transaction
})
smallTxData := []byte{0x1, 0xa}

largeTxInput := [][]byte{
fillShare([]uint8{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, // namespace id
0x1, // info byte
0x0, 0x0, 0x2, 0x2, // 512 (unit) + 2 (unit length) = 514 sequence length
0x0, 0x0, 0x0, 17, // reserved bytes
128, 4, // unit length of transaction is 512
}, 0xc), // data of transaction
padShare(append([]uint8{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, // namespace id
0x0, // info byte
0x0, 0x0, 0x0, 0x0, // reserved bytes
}, bytes.Repeat([]byte{0xc}, 19)..., // continuation data of transaction
)),
}
largeTxData := []byte{128, 4}
largeTxData = append(largeTxData, bytes.Repeat([]byte{0xc}, 512)...)

largePfbTxInput := [][]byte{
fillShare([]uint8{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, // namespace id
0x1, // info byte
0x0, 0x0, 0x2, 0x2, // 512 (unit) + 2 (unit length) = 514 sequence length
0x0, 0x0, 0x0, 17, // reserved bytes
128, 4, // unit length of transaction is 512
}, 0xc), // data of transaction
padShare(append([]uint8{
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, // namespace id
0x0, // info byte
0x0, 0x0, 0x0, 0x0, // reserved bytes
}, bytes.Repeat([]byte{0xc}, 19)..., // continuation data of transaction
)),
ns := namespace.RandomBlobNamespace()
sss := shares.NewSparseShareSplitter()
for _, data := range testData {
b := coretypes.Blob{
Data: data,
NamespaceID: ns.ID,
NamespaceVersion: ns.Version,
ShareVersion: appconsts.ShareVersionZero,
}
err := sss.Write(b)
require.NoError(t, err)
}
largePfbTxData := []byte{128, 4}
largePfbTxData = append(largePfbTxData, bytes.Repeat([]byte{0xc}, 512)...)

testCases := []testCase{
{
name: "empty",
input: [][]byte{},
want: nil,
wantErr: false,
},
{
name: "returns an error when shares contain two different namespaces",
input: [][]byte{
{0, 0, 0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 2},
},
want: nil,
wantErr: true,
},
{
name: "returns raw data of a single tx share",
input: [][]byte{smallTxInput},
want: [][]byte{smallTxData},
wantErr: false,
},
{
name: "returns raw data of a large tx that spans two shares",
input: largeTxInput,
want: [][]byte{largeTxData},
wantErr: false,
},
{
name: "returns raw data of a large PFB tx that spans two shares",
input: largePfbTxInput,
want: [][]byte{largePfbTxData},
wantErr: false,
},
}
sssShares := sss.Export()

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got, err := dataFromShares(tc.input)
if tc.wantErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tc.want, got)
})
rawSSSShares := make([][]byte, len(sssShares))
for i := 0; i < len(sssShares); i++ {
d := sssShares[i].ToBytes()
rawSSSShares[i] = d
}
}

// padShare returns a share padded with trailing zeros.
func padShare(share []byte) (paddedShare []byte) {
return fillShare(share, 0)
}
parsedSSSShares, err := dataFromShares(rawSSSShares)
require.NoError(t, err)

// fillShare returns a share filled with filler so that the share length
// is equal to appconsts.ShareSize.
func fillShare(share []byte, filler byte) (paddedShare []byte) {
return append(share, bytes.Repeat([]byte{filler}, appconsts.ShareSize-len(share))...)
require.Equal(t, testData, parsedSSSShares)
}

// sharesBase64JSON is the base64 encoded share data from Blockspace Race
Expand All @@ -137,6 +60,8 @@ var sharesBase64JSON string
//
// https://github.com/celestiaorg/celestia-app/issues/1816
func Test_dataFromSharesBSR(t *testing.T) {
t.Skip("skip until sharesBase64JSON is regenerated with v1 compatibility")

var sharesBase64 []string
err := json.Unmarshal([]byte(sharesBase64JSON), &sharesBase64)
assert.NoError(t, err)
Expand Down
13 changes: 10 additions & 3 deletions core/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"github.com/filecoin-project/dagstore"
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/da"
appshares "github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/pkg/square"
"github.com/celestiaorg/rsmt2d"

"github.com/celestiaorg/celestia-node/share"
Expand All @@ -22,12 +23,18 @@ func extendBlock(data types.Data) (*rsmt2d.ExtendedDataSquare, error) {
if len(data.Txs) == 0 && data.SquareSize == uint64(1) {
return nil, nil
}
shares, err := appshares.Split(data, true)

sqr, err := square.Construct(data.Txs.ToSliceOfBytes(), appconsts.MaxSquareSize)
if err != nil {
return nil, err
}

return da.ExtendShares(data.SquareSize, appshares.ToBytes(shares))
shares := make([][]byte, len(sqr))
for i, s := range sqr {
shares[i] = s.ToBytes()
}

return da.ExtendShares(shares)
}

// storeEDS will only store extended block if it is not empty and doesn't already exist.
Expand Down
12 changes: 7 additions & 5 deletions core/eds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
func TestTrulyEmptySquare(t *testing.T) {
data := types.Data{
Txs: []types.Tx{},
Blobs: []types.Blob{},
SquareSize: 1,
}

Expand All @@ -27,17 +26,20 @@ func TestTrulyEmptySquare(t *testing.T) {
assert.Nil(t, eds)
}

// TestNonEmptySquareWithZeroTxs tests that a non-empty square with no
// transactions or blobs computes the correct data root (not the minimum DAH).
// TestNonZeroSquareSize tests that the DAH hash of a block with no transactions
// is equal to the DAH hash for an empty root even if SquareSize is set to
// something non-zero. Technically, this block data is invalid because the
// construction of the square is deterministic, and the rules which dictate the
// square size do not allow for empty block data. However, should that ever
// occur, we need to ensure that the correct data root is generated.
func TestNonEmptySquareWithZeroTxs(t *testing.T) {
data := types.Data{
Txs: []types.Tx{},
Blobs: []types.Blob{},
SquareSize: 16,
}

eds, err := extendBlock(data)
require.NoError(t, err)
dah := da.NewDataAvailabilityHeader(eds)
assert.NotEqual(t, share.EmptyRoot().Hash(), dah.Hash())
assert.Equal(t, share.EmptyRoot().Hash(), dah.Hash())
}
2 changes: 1 addition & 1 deletion core/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-app/testutil/testnode"
"github.com/celestiaorg/celestia-app/test/util/testnode"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share/eds"
Expand Down
3 changes: 1 addition & 2 deletions core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/celestiaorg/celestia-app/testutil/testnode"
"github.com/celestiaorg/celestia-app/test/util/testnode"
)

// TestConfig encompasses all the configs required to run test Tendermint + Celestia App tandem.
Expand Down Expand Up @@ -79,7 +79,6 @@ func StartTestNodeWithConfig(t *testing.T, cfg *TestConfig) testnode.Context {
state,
kr,
"private",
nil,
)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion core/testing_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/celestiaorg/celestia-app/testutil/testnode"
"github.com/celestiaorg/celestia-app/test/util/testnode"
)

/*
Expand Down
2 changes: 1 addition & 1 deletion das/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (m *mockSampler) discover(ctx context.Context, newHeight uint64, emit liste
emit(ctx, &header.ExtendedHeader{
Commit: &types.Commit{},
RawHeader: header.RawHeader{Height: int64(newHeight)},
DAH: &header.DataAvailabilityHeader{RowsRoots: make([][]byte, 0)},
DAH: &header.DataAvailabilityHeader{RowRoots: make([][]byte, 0)},
})
}

Expand Down
4 changes: 2 additions & 2 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ type benchGetterStub struct {

func newBenchGetter() benchGetterStub {
return benchGetterStub{header: &header.ExtendedHeader{
DAH: &header.DataAvailabilityHeader{RowsRoots: make([][]byte, 0)}}}
DAH: &header.DataAvailabilityHeader{RowRoots: make([][]byte, 0)}}}
}

func (m benchGetterStub) GetByHeight(context.Context, uint64) (*header.ExtendedHeader, error) {
Expand All @@ -362,7 +362,7 @@ func (m getterStub) GetByHeight(_ context.Context, height uint64) (*header.Exten
return &header.ExtendedHeader{
Commit: &types.Commit{},
RawHeader: header.RawHeader{Height: int64(height)},
DAH: &header.DataAvailabilityHeader{RowsRoots: make([][]byte, 0)}}, nil
DAH: &header.DataAvailabilityHeader{RowRoots: make([][]byte, 0)}}, nil
}

func (m getterStub) GetRangeByHeight(context.Context, uint64, uint64) ([]*header.ExtendedHeader, error) {
Expand Down
4 changes: 2 additions & 2 deletions das/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ func (m *metrics) observeSample(
}
m.sampleTime.Record(ctx, sampleTime.Seconds(),
attribute.Bool(failedLabel, err != nil),
attribute.Int(headerWidthLabel, len(h.DAH.RowsRoots)),
attribute.Int(headerWidthLabel, len(h.DAH.RowRoots)),
attribute.String(jobTypeLabel, string(jobType)),
)

m.sampled.Add(ctx, 1,
attribute.Bool(failedLabel, err != nil),
attribute.Int(headerWidthLabel, len(h.DAH.RowsRoots)),
attribute.Int(headerWidthLabel, len(h.DAH.RowRoots)),
attribute.String(jobTypeLabel, string(jobType)),
)

Expand Down
6 changes: 3 additions & 3 deletions das/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (w *worker) sample(ctx context.Context, timeout time.Duration, height uint6
"type", w.state.jobType,
"height", h.Height(),
"hash", h.Hash(),
"square width", len(h.DAH.RowsRoots),
"square width", len(h.DAH.RowRoots),
"data root", h.DAH.String(),
"err", err,
"finished (s)", time.Since(start),
Expand Down Expand Up @@ -150,7 +150,7 @@ func (w *worker) sample(ctx context.Context, timeout time.Duration, height uint6
"type", w.state.jobType,
"height", h.Height(),
"hash", h.Hash(),
"square width", len(h.DAH.RowsRoots),
"square width", len(h.DAH.RowRoots),
"data root", h.DAH.String(),
"finished (s)", time.Since(start),
)
Expand Down Expand Up @@ -179,7 +179,7 @@ func (w *worker) getHeader(ctx context.Context, height uint64) (*header.Extended
"got header from header store",
"height", h.Height(),
"hash", h.Hash(),
"square width", len(h.DAH.RowsRoots),
"square width", len(h.DAH.RowRoots),
"data root", h.DAH.String(),
"finished (s)", time.Since(start),
)
Expand Down
Loading

0 comments on commit 9359b65

Please sign in to comment.