Skip to content

Commit

Permalink
wip: adapt to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed May 31, 2024
1 parent 926e5a3 commit 8c75d6a
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 57 deletions.
12 changes: 6 additions & 6 deletions api/gateway/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"testing"

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

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/go-square/shares"

"github.com/celestiaorg/celestia-node/share/sharetest"
"github.com/celestiaorg/go-square/blob"
)

func Test_dataFromShares(t *testing.T) {
Expand All @@ -23,13 +23,13 @@ func Test_dataFromShares(t *testing.T) {
ns := sharetest.RandV0Namespace()
sss := shares.NewSparseShareSplitter()
for _, data := range testData {
b := coretypes.Blob{
b := blob.Blob{
Data: data,
NamespaceID: ns.ID(),
NamespaceVersion: ns.Version(),
ShareVersion: appconsts.ShareVersionZero,
NamespaceId: ns.ID(),
NamespaceVersion: uint32(ns.Version()),
ShareVersion: uint32(appconsts.ShareVersionZero),
}
err := sss.Write(b)
err := sss.Write(&b)
require.NoError(t, err)
}

Expand Down
12 changes: 7 additions & 5 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"errors"
"fmt"

tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/crypto/merkle"

v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1"
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/x/blob/types"
"github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/inclusion"
"github.com/celestiaorg/nmt"

"github.com/celestiaorg/celestia-node/share"
Expand Down Expand Up @@ -69,7 +71,7 @@ func (p Proof) equal(input Proof) error {

// Blob represents any application-specific binary data that anyone can submit to Celestia.
type Blob struct {
types.Blob `json:"blob"`
blob.Blob `json:"blob"`

Commitment Commitment `json:"commitment"`

Expand Down Expand Up @@ -97,14 +99,14 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data []byte) (*Blob,
return nil, err
}

blob := tmproto.Blob{
blob := blob.Blob{
NamespaceId: namespace.ID(),
Data: data,
ShareVersion: uint32(shareVersion),
NamespaceVersion: uint32(namespace.Version()),
}

com, err := types.CreateCommitment(&blob)
com, err := inclusion.CreateCommitment(&blob, merkle.HashFromByteSlices, appconsts.SubtreeRootThreshold(v1.Version))
if err != nil {
return nil, err
}
Expand Down
17 changes: 13 additions & 4 deletions blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package blob

import (
"bytes"
"fmt"
"math"
"testing"

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

"github.com/celestiaorg/celestia-app/pkg/appconsts"
v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1"
apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
"github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/inclusion"
"github.com/celestiaorg/go-square/merkle"

"github.com/celestiaorg/celestia-node/blob/blobtest"
)
Expand All @@ -35,7 +41,7 @@ func TestBlob(t *testing.T) {
{
name: "compare commitments",
expectedRes: func(t *testing.T) {
comm, err := apptypes.CreateCommitment(&blob[0].Blob)
comm, err := inclusion.CreateCommitment(&blob[0].Blob, merkle.HashFromByteSlices, appconsts.SubtreeRootThreshold(v1.Version))
require.NoError(t, err)
assert.Equal(t, blob[0].Commitment, Commitment(comm))
},
Expand Down Expand Up @@ -80,10 +86,13 @@ func TestBlob(t *testing.T) {
}
}

func convertBlobs(appBlobs ...types.Blob) ([]*Blob, error) {
func convertBlobs(appBlobs ...blob.Blob) ([]*Blob, error) {
blobs := make([]*Blob, 0, len(appBlobs))
for _, b := range appBlobs {
blob, err := NewBlob(b.ShareVersion, append([]byte{b.NamespaceVersion}, b.NamespaceID...), b.Data)
if b.ShareVersion > math.MaxUint8 {
return nil, fmt.Errorf("share version must be <= %d, but it was %d", math.MaxUint8, b.ShareVersion)
}
blob, err := NewBlob(uint8(b.ShareVersion), b.Namespace().Bytes(), b.Data)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions blob/blobtest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package blobtest

import (
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/test/util/testfactory"
"github.com/celestiaorg/go-square/shares"

"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/go-square/blob"
)

// GenerateV0Blobs is a test utility producing v0 share formatted blobs with the
// requested size and random namespaces.
func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]types.Blob, error) {
blobs := make([]types.Blob, 0, len(sizes))
func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]blob.Blob, error) {
blobs := make([]blob.Blob, 0, len(sizes))

for _, size := range sizes {
size := rawBlobSize(appconsts.FirstSparseShareContentSize * size)
Expand All @@ -24,11 +24,11 @@ func GenerateV0Blobs(sizes []int, sameNamespace bool) ([]types.Blob, error) {
if err != nil {
return nil, err
}
appBlob.NamespaceVersion = nid[0]
appBlob.NamespaceID = nid[1:]
appBlob.NamespaceVersion = uint32(nid[0])
appBlob.NamespaceId = nid[1:]
}

blobs = append(blobs, appBlob)
blobs = append(blobs, *appBlob)
}
return blobs, nil
}
Expand Down
23 changes: 11 additions & 12 deletions blob/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ import (
"bytes"
"sort"

"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/shares"

"github.com/celestiaorg/celestia-node/share"
)

// BlobsToShares accepts blobs and convert them to the Shares.
func BlobsToShares(blobs ...*Blob) ([]share.Share, error) {
b := make([]types.Blob, len(blobs))
for i, blob := range blobs {
namespace := blob.Namespace()
b[i] = types.Blob{
NamespaceVersion: namespace[0],
NamespaceID: namespace[1:],
Data: blob.Data,
ShareVersion: uint8(blob.ShareVersion),
func BlobsToShares(nodeBlobs ...*Blob) ([]share.Share, error) {
b := make([]*blob.Blob, len(nodeBlobs))
for i, nodeBlob := range nodeBlobs {
namespace := nodeBlob.Namespace()
b[i] = &blob.Blob{
NamespaceVersion: uint32(namespace[0]),
NamespaceId: namespace[1:],
Data: nodeBlob.Data,
ShareVersion: uint32(nodeBlob.ShareVersion),
}
}

sort.Slice(b, func(i, j int) bool {
val := bytes.Compare(b[i].NamespaceID, b[j].NamespaceID)
val := bytes.Compare(b[i].Namespace().Bytes(), b[j].Namespace().Bytes())
return val < 0
})

Expand Down
4 changes: 2 additions & 2 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ func TestSkipPaddingsAndRetrieveBlob(t *testing.T) {

appBlob, err := blobtest.GenerateV0Blobs([]int{6}, true)
require.NoError(t, err)
appBlob[0].NamespaceVersion = nid[0]
appBlob[0].NamespaceID = nid[1:]
appBlob[0].NamespaceVersion = uint32(nid[0])
appBlob[0].NamespaceId = nid[1:]

blobs, err := convertBlobs(appBlob...)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion core/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rs
}

// Construct the data square from the block's transactions
dataSquare, err := square.Construct(data.Txs.ToSliceOfBytes(), appVersion, appconsts.SquareSizeUpperBound(appVersion))
dataSquare, err := square.Construct(data.Txs.ToSliceOfBytes(), appconsts.SquareSizeUpperBound(appVersion), appconsts.SubtreeRootThreshold(appVersion))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions core/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {
t.Cleanup(cancel)

cfg := DefaultTestConfig()
cfg.ChainID = testChainID
cfg.Genesis.ChainID = testChainID
fetcher, cctx := createCoreFetcher(t, cfg)

generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {
t.Cleanup(cancel)

cfg := DefaultTestConfig()
cfg.ChainID = testChainID
cfg.Genesis.ChainID = testChainID
fetcher, cctx := createCoreFetcher(t, cfg)

generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
Expand Down Expand Up @@ -154,7 +154,7 @@ func fillBlocks(
default:
}

_, err := cctx.FillBlock(16, cfg.Accounts, flags.BroadcastBlock)
_, err := cctx.FillBlock(16, cfg.Genesis.Accounts()[0].PubKey.String(), flags.BroadcastBlock)
require.NoError(t, err)
}
}
Expand Down
5 changes: 3 additions & 2 deletions core/listener_no_race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestListenerWithNonEmptyBlocks(t *testing.T) {

// create one block to store as Head in local store and then unsubscribe from block events
cfg := DefaultTestConfig()
cfg.ChainID = testChainID
cfg.Genesis.ChainID = testChainID
fetcher, cctx := createCoreFetcher(t, cfg)
eds := createEdsPubSub(ctx, t)

Expand All @@ -45,7 +45,8 @@ func TestListenerWithNonEmptyBlocks(t *testing.T) {
empty := share.EmptyRoot()
// TODO extract 16
for i := 0; i < 16; i++ {
_, err := cctx.FillBlock(16, cfg.Accounts, flags.BroadcastBlock)
cfg.Genesis.Accounts()
_, err := cctx.FillBlock(16, cfg.Genesis.Accounts()[0].PubKey.String(), flags.BroadcastBlock)
require.NoError(t, err)
msg, err := sub.Next(ctx)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions core/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestListener(t *testing.T) {

// create one block to store as Head in local store and then unsubscribe from block events
cfg := DefaultTestConfig()
cfg.ChainID = testChainID
cfg.Genesis.ChainID = testChainID
fetcher, _ := createCoreFetcher(t, cfg)

eds := createEdsPubSub(ctx, t)
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestListenerWithWrongChainRPC(t *testing.T) {

// create one block to store as Head in local store and then unsubscribe from block events
cfg := DefaultTestConfig()
cfg.ChainID = testChainID
cfg.Genesis.ChainID = testChainID
fetcher, _ := createCoreFetcher(t, cfg)
eds := createEdsPubSub(ctx, t)

Expand All @@ -107,7 +107,7 @@ func TestListener_DoesNotStoreHistoric(t *testing.T) {

// create one block to store as Head in local store and then unsubscribe from block events
cfg := DefaultTestConfig()
cfg.ChainID = testChainID
cfg.Genesis.ChainID = testChainID
fetcher, cctx := createCoreFetcher(t, cfg)
eds := createEdsPubSub(ctx, t)

Expand Down
4 changes: 2 additions & 2 deletions core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func DefaultTestConfig() *testnode.Config {
cfg.TmConfig.Consensus.TimeoutCommit = time.Millisecond * 200

cfg = cfg.
WithAccounts(accounts).
WithSupressLogs(true)
WithFundedAccounts(accounts...).
WithSuppressLogs(true)

return cfg
}
Expand Down
12 changes: 11 additions & 1 deletion nodebuilder/tests/swamp/swamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"go.uber.org/fx"
"golang.org/x/exp/maps"

"github.com/celestiaorg/celestia-app/v2/test/util/genesis"
"github.com/celestiaorg/celestia-app/v2/test/util/testnode"
libhead "github.com/celestiaorg/go-header"

Expand Down Expand Up @@ -74,6 +75,8 @@ func NewSwamp(t *testing.T, options ...Option) *Swamp {
option(ic)
}

accounts := getAccountPubKeys(ic.Genesis.Accounts())

// Now, we are making an assumption that consensus mechanism is already tested out
// so, we are not creating bridge nodes with each one containing its own core client
// instead we are assigning all created BNs to 1 Core from the swamp
Expand All @@ -84,7 +87,7 @@ func NewSwamp(t *testing.T, options ...Option) *Swamp {
cfg: ic,
Network: mocknet.New(),
ClientContext: cctx,
Accounts: ic.Accounts,
Accounts: accounts,
nodes: map[*nodebuilder.Node]struct{}{},
}

Expand All @@ -93,6 +96,13 @@ func NewSwamp(t *testing.T, options ...Option) *Swamp {
return swp
}

func getAccountPubKeys(accounts []genesis.Account) (pubKeys []string) {
for _, account := range accounts {
pubKeys = append(pubKeys, account.PubKey.String())
}
return pubKeys
}

// cleanup frees up all the resources
// including stop of all created nodes
func (s *Swamp) cleanup() {
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/tests/swamp/swamp_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func FillBlocks(ctx context.Context, cctx testnode.Context, accounts []string, b
time.Sleep(time.Millisecond * 50)
var err error
for i := 0; i < blocks; i++ {
_, err = cctx.FillBlock(bsize, accounts, flags.BroadcastBlock)
_, err = cctx.FillBlock(bsize, accounts[0], flags.BroadcastBlock)
if err != nil {
break
}
Expand Down
9 changes: 5 additions & 4 deletions state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import (
apptypes "github.com/celestiaorg/celestia-app/v2/x/blob/types"
libhead "github.com/celestiaorg/go-header"

"github.com/celestiaorg/celestia-node/blob"
nodeblob "github.com/celestiaorg/celestia-node/blob"
"github.com/celestiaorg/celestia-node/header"
squareblob "github.com/celestiaorg/go-square/blob"
)

const (
Expand Down Expand Up @@ -216,7 +217,7 @@ func (ca *CoreAccessor) SubmitPayForBlob(
ctx context.Context,
fee Int,
gasLim uint64,
blobs []*blob.Blob,
blobs []*nodeblob.Blob,
) (*TxResponse, error) {
signer, err := ca.getSigner(ctx)
if err != nil {
Expand All @@ -227,7 +228,7 @@ func (ca *CoreAccessor) SubmitPayForBlob(
return nil, errors.New("state: no blobs provided")
}

appblobs := make([]*apptypes.Blob, len(blobs))
appblobs := make([]*squareblob.Blob, len(blobs))
for i := range blobs {
if err := blobs[i].Namespace().ValidateForBlob(); err != nil {
return nil, err
Expand Down Expand Up @@ -402,7 +403,7 @@ func (ca *CoreAccessor) SubmitTxWithBroadcastMode(
tx Tx,
mode sdktx.BroadcastMode,
) (*TxResponse, error) {
txResp, err := apptypes.BroadcastTx(ctx, ca.coreConn, mode, tx)
txResp, err := ca.signer.BroadcastTx(ctx, tx)

Check failure on line 406 in state/core_access.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

cannot use tx (variable of type "github.com/tendermint/tendermint/types".Tx) as "github.com/cosmos/cosmos-sdk/x/auth/signing".Tx value in argument to ca.signer.BroadcastTx: "github.com/tendermint/tendermint/types".Tx does not implement "github.com/cosmos/cosmos-sdk/x/auth/signing".Tx (missing method FeeGranter)

Check failure on line 406 in state/core_access.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

cannot use tx (variable of type "github.com/tendermint/tendermint/types".Tx) as "github.com/cosmos/cosmos-sdk/x/auth/signing".Tx value in argument to ca.signer.BroadcastTx: "github.com/tendermint/tendermint/types".Tx does not implement "github.com/cosmos/cosmos-sdk/x/auth/signing".Tx (missing method FeeGranter)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion state/core_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSubmitPayForBlob(t *testing.T) {
appConf.API.Enable = true
appConf.MinGasPrices = fmt.Sprintf("0.002%s", app.BondDenom)

config := testnode.DefaultConfig().WithTendermintConfig(tmCfg).WithAppConfig(appConf).WithAccounts(accounts)
config := testnode.DefaultConfig().WithTendermintConfig(tmCfg).WithAppConfig(appConf).WithFundedAccounts(accounts...)
cctx, _, grpcAddr := testnode.NewNetwork(t, config)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
Loading

0 comments on commit 8c75d6a

Please sign in to comment.