Skip to content

Commit

Permalink
chore(deps): upgrade to celestia-app v2.0.0 (celestiaorg#3453)
Browse files Browse the repository at this point in the history
Update celestia-node to use celestia-app v2.0.0. A few changes that were needed:
- celestia-app v1.x had a shares package. celestia-app v2.x uses the shares package from go-square.
- celestia-app v1.x had a blob.types package with `CreateCommitment`. celestia-app v2.x uses `CreateCommitment` from the go-square inclusion package.
- I had to update extended header verification to allow `header.Version.App = 2`. Added unit tests.
- celestia-app v1.x had a lot of functionality included in the `signer`. celestia-app v2.x split a `txClient` from the `signer`. See: celestiaorg/celestia-app#3433
- ~~I had to update `core_access.go` a lot. Mostly inspired by celestiaorg#3451


## Testing

I ran a [script](https://gist.github.com/rootulp/73ee382b4d533cb9da27fc675e9047c0) with: celestia-app v2.0.0-rc2  and configured it to upgrade at block height 3. celestia-node (built from this PR) continued to work:

```
2024-07-09T18:13:27.040-0400	INFO	header/store	store/store.go:367	new head	{"height": 2, "hash": "8776AEAF4114BD7E88E8DEC38445720D0BD857335BED99649957A43BB845EC87"}
2024-07-09T18:13:38.065-0400	INFO	header/store	store/store.go:367	new head	{"height": 3, "hash": "63D5C64521A964290BD21658314DDF60146AE419FE99026003048F74D2886B35"}
2024-07-09T18:13:49.093-0400	INFO	header/store	store/store.go:367	new head	{"height": 4, "hash": "FC7900918E716697A7CD6D9A4865B261F3E71D181F366E765AA53CF475223F9A"}
```
  • Loading branch information
rootulp authored and sebasti810 committed Aug 14, 2024
1 parent b743cca commit 07516e7
Show file tree
Hide file tree
Showing 78 changed files with 670 additions and 410 deletions.
2 changes: 1 addition & 1 deletion api/gateway/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/gorilla/mux"

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

"github.com/celestiaorg/celestia-node/share"
)
Expand Down
16 changes: 8 additions & 8 deletions api/gateway/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"testing"

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

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

"github.com/celestiaorg/celestia-node/share/sharetest"
)
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
40 changes: 23 additions & 17 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import (
"errors"
"fmt"

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

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

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

// appVersion is the current application version of celestia-app.
const appVersion = v2.Version

var errEmptyShares = errors.New("empty shares")

// The Proof is a set of nmt proofs that can be verified only through
Expand Down Expand Up @@ -56,7 +61,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 @@ -84,18 +89,18 @@ 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(appVersion))
if err != nil {
return nil, err
}
return &Blob{Blob: blob, Commitment: com, namespace: namespace, index: -1}, nil
return &Blob{Blob: &blob, Commitment: com, namespace: namespace, index: -1}, nil
}

// Namespace returns blob's namespace.
Expand Down Expand Up @@ -157,18 +162,19 @@ func (b *Blob) MarshalJSON() ([]byte, error) {
}

func (b *Blob) UnmarshalJSON(data []byte) error {
var blob jsonBlob
err := json.Unmarshal(data, &blob)
var jsonBlob jsonBlob
err := json.Unmarshal(data, &jsonBlob)
if err != nil {
return err
}

b.Blob.NamespaceVersion = uint32(blob.Namespace.Version())
b.Blob.NamespaceId = blob.Namespace.ID()
b.Blob.Data = blob.Data
b.Blob.ShareVersion = blob.ShareVersion
b.Commitment = blob.Commitment
b.namespace = blob.Namespace
b.index = blob.Index
b.Blob = &blob.Blob{}
b.Blob.NamespaceVersion = uint32(jsonBlob.Namespace.Version())
b.Blob.NamespaceId = jsonBlob.Namespace.ID()
b.Blob.Data = jsonBlob.Data
b.Blob.ShareVersion = jsonBlob.ShareVersion
b.Commitment = jsonBlob.Commitment
b.namespace = jsonBlob.Namespace
b.index = jsonBlob.Index
return nil
}
21 changes: 14 additions & 7 deletions blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (

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

apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
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 Down Expand Up @@ -36,7 +39,11 @@ 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(appVersion),
)
require.NoError(t, err)
assert.Equal(t, blob[0].Commitment, Commitment(comm))
},
Expand Down Expand Up @@ -78,7 +85,7 @@ func TestBlob(t *testing.T) {

newBlob := &Blob{}
require.NoError(t, newBlob.UnmarshalJSON(data))
require.True(t, bytes.Equal(blob[0].Blob.Data, newBlob.Data))
require.True(t, bytes.Equal(blob[0].Blob.GetData(), newBlob.Data))
require.True(t, bytes.Equal(blob[0].Commitment, newBlob.Commitment))
},
},
Expand All @@ -89,10 +96,10 @@ 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)
for _, appBlob := range appBlobs {
blob, err := NewBlob(uint8(appBlob.GetShareVersion()), appBlob.Namespace().Bytes(), appBlob.GetData())
if err != nil {
return nil, err
}
Expand Down
18 changes: 9 additions & 9 deletions blob/blobtest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ package blobtest

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

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

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

// 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)
appBlob := testfactory.GenerateRandomBlob(size)
if !sameNamespace {
nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7))
namespace, err := share.NewBlobNamespaceV0(tmrand.Bytes(7))
if err != nil {
return nil, err
}
appBlob.NamespaceVersion = nid[0]
appBlob.NamespaceID = nid[1:]
appBlob.NamespaceVersion = uint32(namespace[0])
appBlob.NamespaceId = namespace[1:]
}

blobs = append(blobs, appBlob)
Expand Down
7 changes: 3 additions & 4 deletions blob/commitment_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"bytes"
"fmt"

coretypes "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/v2/pkg/proof"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/nmt/namespace"

Expand All @@ -33,8 +32,8 @@ type CommitmentProof struct {
NamespaceID namespace.ID `json:"namespace_id"`
// RowProof is the proof of the rows containing the blob's data to the
// data root.
RowProof coretypes.RowProof `json:"row_proof"`
NamespaceVersion uint8 `json:"namespace_version"`
RowProof proof.RowProof `json:"row_proof"`
NamespaceVersion uint8 `json:"namespace_version"`
}

func (com Commitment) String() string {
Expand Down
36 changes: 16 additions & 20 deletions blob/helper.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
package blob

import (
"bytes"
"sort"

"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/shares"
apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
squareblob "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([]*squareblob.Blob, len(nodeBlobs))
for i, nodeBlob := range nodeBlobs {
namespace := nodeBlob.Namespace()
b[i] = &squareblob.Blob{
NamespaceVersion: uint32(namespace[0]),
NamespaceId: namespace[1:],
Data: nodeBlob.Data,
ShareVersion: nodeBlob.ShareVersion,
}
}

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

rawShares, err := shares.SplitBlobs(b...)
Expand All @@ -37,11 +33,11 @@ func BlobsToShares(blobs ...*Blob) ([]share.Share, error) {
return shares.ToBytes(rawShares), nil
}

// ToAppBlobs converts node's blob type to the blob type from celestia-app.
func ToAppBlobs(blobs ...*Blob) []*apptypes.Blob {
appBlobs := make([]*apptypes.Blob, 0, len(blobs))
// ToAppBlobs converts node's blob type to the blob type from go-square.
func ToAppBlobs(blobs ...*Blob) []*squareblob.Blob {
appBlobs := make([]*squareblob.Blob, len(blobs))
for i := range blobs {
appBlobs[i] = &blobs[i].Blob
appBlobs[i] = blobs[i].Blob
}
return appBlobs
}
Expand Down
57 changes: 57 additions & 0 deletions blob/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package blob

import (
"bytes"
"testing"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
squareblob "github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/namespace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBlobsToShares(t *testing.T) {
t.Run("should sort blobs by namespace in ascending order", func(t *testing.T) {
namespaceA := namespace.MustNewV0(bytes.Repeat([]byte{0xa}, 10)).Bytes()
namespaceB := namespace.MustNewV0(bytes.Repeat([]byte{0xb}, 10)).Bytes()

blobA, err := NewBlob(appconsts.ShareVersionZero, namespaceA, []byte("dataA"))
require.NoError(t, err)
blobB, err := NewBlob(appconsts.ShareVersionZero, namespaceB, []byte("dataB"))
require.NoError(t, err)

got, err := BlobsToShares(blobB, blobA)
require.NoError(t, err)
assert.Equal(t, got[0][:appconsts.NamespaceSize], namespaceA)
assert.Equal(t, got[1][:appconsts.NamespaceSize], namespaceB)
assert.IsIncreasing(t, got)
})
}

func TestToAppBlobs(t *testing.T) {
namespaceA := namespace.MustNewV0(bytes.Repeat([]byte{0xa}, 10))
namespaceB := namespace.MustNewV0(bytes.Repeat([]byte{0xb}, 10))

blobA, err := NewBlob(appconsts.ShareVersionZero, namespaceA.Bytes(), []byte("dataA"))
require.NoError(t, err)
blobB, err := NewBlob(appconsts.ShareVersionZero, namespaceB.Bytes(), []byte("dataB"))
require.NoError(t, err)

got := ToAppBlobs(blobA, blobB)
want := []*squareblob.Blob{
{
NamespaceId: blobA.NamespaceId,
NamespaceVersion: blobA.NamespaceVersion,
Data: blobA.Data,
ShareVersion: blobA.ShareVersion,
},
{
NamespaceId: blobB.NamespaceId,
NamespaceVersion: blobB.NamespaceVersion,
Data: blobB.Data,
ShareVersion: blobB.ShareVersion,
},
}
assert.Equal(t, want, got)
}
2 changes: 1 addition & 1 deletion blob/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

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

// parser helps to collect shares and transform them into a blob.
Expand Down
Loading

0 comments on commit 07516e7

Please sign in to comment.