From 64f04840aa97d4deb821b654b1fb59167d242bd1 Mon Sep 17 00:00:00 2001 From: Diego <31937514+Ferret-san@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:49:03 -0400 Subject: [PATCH] Add Blob.Index and fix Blob.Proof Serialization (#108) --- .github/auto_request_review.yml | 16 +++++++-------- .github/workflows/housekeeping.yml | 6 +++--- .golangci.yml | 2 +- README.md | 2 +- api.go | 32 +++++++++++++---------------- client_test.go | 8 ++++---- go.mod | 2 +- types/appconsts/versioned_consts.go | 2 +- types/blob/blob.go | 9 ++++++-- types/blob/blob_test.go | 4 ++-- types/blob/commitment.go | 4 ++-- types/blob/share_splitting.go | 2 +- types/header/header.go | 2 +- types/share/info_byte.go | 2 +- types/share/namespace.go | 4 ++-- types/share/padding.go | 4 ++-- types/share/reserved_bytes.go | 2 +- types/share/share.go | 6 +++--- types/share/share_builder.go | 4 ++-- types/share/split_sparse_shares.go | 4 ++-- types/state/state.go | 2 +- 21 files changed, 60 insertions(+), 59 deletions(-) diff --git a/.github/auto_request_review.yml b/.github/auto_request_review.yml index a31206d..6f52d6d 100644 --- a/.github/auto_request_review.yml +++ b/.github/auto_request_review.yml @@ -3,24 +3,24 @@ reviewers: - code-owners groups: code-owners: - - Nashqueue - - tzdybal - - gupadhyaya - rollkit: - - Manav-Aggarwal + - Bidon15 + - Ferret-san + - distractedm1nd + - YazzyYaz + celestia: + - Wondertan - S1nus - - tuxcanfly + - vgonkivs devops: - smuu - sysrex - jrmanes - - Bidon15 celestia: - team:celestia files: '**': - code-owners - - rollkit + - celestia '**/*Dockerfile': - devops '.github/**': diff --git a/.github/workflows/housekeeping.yml b/.github/workflows/housekeeping.yml index 8ead350..60dc56c 100644 --- a/.github/workflows/housekeeping.yml +++ b/.github/workflows/housekeeping.yml @@ -11,7 +11,7 @@ jobs: # ignore dependabot PRs if: ${{ github.actor != 'dependabot[bot]' }} name: Add issues and PRs to project and add grooming label - uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.2.2 + uses: celestiaorg/.github/.github/workflows/reusable_housekeeping.yml@v0.2.2 secrets: inherit permissions: issues: write @@ -20,12 +20,12 @@ jobs: run-labels: true labels-to-add: "needs-grooming" run-projects: true - project-url: https://github.com/orgs/rollkit/projects/7 + project-url: https://github.com/orgs/celestiaorg/projects/7 auto-add-reviewer: name: Auto add reviewer to PR if: github.event.pull_request - uses: rollkit/.github/.github/workflows/reusable_housekeeping.yml@v0.2.2 + uses: celestiaorg/.github/.github/workflows/reusable_housekeeping.yml@v0.2.2 secrets: inherit permissions: issues: write diff --git a/.golangci.yml b/.golangci.yml index 2fe26b1..151a81b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -34,4 +34,4 @@ linters-settings: - name: package-comments disabled: true goimports: - local-prefixes: github.com/rollkit + local-prefixes: github.com/celestia diff --git a/README.md b/README.md index d6aa494..4a6ad4e 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ OpenRPC is a client of [celestia-node RPC](https://docs.celestia.org/developers/node-api/), without depenencies on celestia-node/celestia-app/cosmos-sdk. -This is a temporary measure to resolve dependency issues when celestia-node is imported by rollkit. +This is a temporary measure to resolve dependency issues when celestia-node is imported by celestia. diff --git a/api.go b/api.go index d4c6548..4b1758e 100644 --- a/api.go +++ b/api.go @@ -14,12 +14,12 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" - "github.com/rollkit/celestia-openrpc/types/blob" - "github.com/rollkit/celestia-openrpc/types/das" - "github.com/rollkit/celestia-openrpc/types/header" - "github.com/rollkit/celestia-openrpc/types/node" - "github.com/rollkit/celestia-openrpc/types/share" - "github.com/rollkit/celestia-openrpc/types/state" + "github.com/celestiaorg/celestia-openrpc/types/blob" + "github.com/celestiaorg/celestia-openrpc/types/das" + "github.com/celestiaorg/celestia-openrpc/types/header" + "github.com/celestiaorg/celestia-openrpc/types/node" + "github.com/celestiaorg/celestia-openrpc/types/share" + "github.com/celestiaorg/celestia-openrpc/types/state" ) // Proof embeds the fraud.Proof interface type to provide a concrete type for JSON serialization. @@ -38,7 +38,7 @@ type DASAPI struct { } type BlobAPI struct { - Submit func(context.Context, []*blob.Blob, *SubmitOptions) (uint64, error) `perm:"write"` + Submit func(context.Context, []*blob.Blob, GasPrice) (uint64, error) `perm:"write"` Get func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Blob, error) `perm:"read"` GetAll func(context.Context, uint64, []share.Namespace) ([]*blob.Blob, error) `perm:"read"` GetProof func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Proof, error) `perm:"read"` @@ -168,16 +168,12 @@ type NodeAPI struct { AuthNew func(ctx context.Context, perms []auth.Permission) ([]byte, error) `perm:"admin"` } -// SubmitOptions contains the information about fee and gasLimit price in order to configure the Submit request. -type SubmitOptions struct { - Fee int64 - GasLimit uint64 -} +// GasPrice represents the amount to be paid per gas unit. Fee is set by +// multiplying GasPrice by GasLimit, which is determined by the blob sizes. +type GasPrice float64 -// DefaultSubmitOptions creates a default fee and gas price values. -func DefaultSubmitOptions() *SubmitOptions { - return &SubmitOptions{ - Fee: -1, - GasLimit: 0, - } +// DefaultGasPrice returns the default gas price, letting node automatically +// determine the Fee based on the passed blob sizes. +func DefaultGasPrice() GasPrice { + return -1.0 } diff --git a/client_test.go b/client_test.go index 6e43113..b1aac04 100644 --- a/client_test.go +++ b/client_test.go @@ -15,8 +15,8 @@ import ( "github.com/ory/dockertest/v3" "github.com/stretchr/testify/suite" - "github.com/rollkit/celestia-openrpc/types/blob" - "github.com/rollkit/celestia-openrpc/types/share" + "github.com/celestiaorg/celestia-openrpc/types/blob" + "github.com/celestiaorg/celestia-openrpc/types/share" ) type TestSuite struct { @@ -72,7 +72,7 @@ func (t *TestSuite) SetupSuite() { buf := new(bytes.Buffer) opts.StdOut = buf opts.StdErr = buf - _, err = resource.Exec([]string{"/bin/celestia", "bridge", "auth", "admin", "--node.store", "/home/celestia/bridge"}, opts) + _, err = resource.Exec([]string{"/bin/celestia", "bridge", "auth", "admin", "--node.store", "/home/celestiaorg/bridge"}, opts) if err != nil { t.Failf("Could not execute command", "error: %v\n", err) } @@ -131,7 +131,7 @@ func (t *TestSuite) TestRoundTrip() { t.Require().NoError(err) // write blob to DA - height, err := client.Blob.Submit(ctx, []*blob.Blob{blobBlob}, nil) + height, err := client.Blob.Submit(ctx, []*blob.Blob{blobBlob}, DefaultGasPrice()) t.Require().NoError(err) t.Require().NotZero(height) diff --git a/go.mod b/go.mod index 6262d59..cba004f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rollkit/celestia-openrpc +module github.com/celestiaorg/celestia-openrpc go 1.20 diff --git a/types/appconsts/versioned_consts.go b/types/appconsts/versioned_consts.go index 9e9a66f..7004bda 100644 --- a/types/appconsts/versioned_consts.go +++ b/types/appconsts/versioned_consts.go @@ -1,6 +1,6 @@ package appconsts -import v1 "github.com/rollkit/celestia-openrpc/types/appconsts/v1" +import v1 "github.com/celestiaorg/celestia-openrpc/types/appconsts/v1" const ( LatestVersion = v1.Version diff --git a/types/blob/blob.go b/types/blob/blob.go index b81406e..4754ef1 100644 --- a/types/blob/blob.go +++ b/types/blob/blob.go @@ -8,8 +8,8 @@ import ( "github.com/celestiaorg/nmt" - "github.com/rollkit/celestia-openrpc/types/appconsts" - "github.com/rollkit/celestia-openrpc/types/share" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/share" ) const ( @@ -48,6 +48,7 @@ type jsonBlob struct { Data []byte `json:"data"` ShareVersion uint32 `json:"share_version"` Commitment Commitment `json:"commitment"` + Index int `json:"index"` } // Blob represents any application-specific binary data that anyone can submit to Celestia. @@ -58,6 +59,7 @@ type Blob struct { ShareVersion uint32 `protobuf:"varint,3,opt,name=share_version,json=shareVersion,proto3" json:"share_version,omitempty"` NamespaceVersion uint32 `protobuf:"varint,4,opt,name=namespace_version,json=namespaceVersion,proto3" json:"namespace_version,omitempty"` Commitment []byte `protobuf:"bytes,5,opt,name=commitment,proto3" json:"commitment,omitempty"` + Index int `protobuf:"varint,6,opt,name=index,proto3" json:"index,omitempty"` } func (b *Blob) MarshalJSON() ([]byte, error) { @@ -66,6 +68,7 @@ func (b *Blob) MarshalJSON() ([]byte, error) { Data: b.Data, ShareVersion: b.ShareVersion, Commitment: b.Commitment, + Index: b.Index, } return json.Marshal(blob) } @@ -81,6 +84,7 @@ func (b *Blob) UnmarshalJSON(data []byte) error { b.ShareVersion = blob.ShareVersion b.Commitment = blob.Commitment b.Namespace = blob.Namespace + b.Index = blob.Index return nil } @@ -105,5 +109,6 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data []byte) (*Blob, ShareVersion: uint32(shareVersion), NamespaceVersion: 0, Commitment: []byte{}, + Index: -1, }, nil } diff --git a/types/blob/blob_test.go b/types/blob/blob_test.go index 656db3f..f66fc9f 100644 --- a/types/blob/blob_test.go +++ b/types/blob/blob_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/rollkit/celestia-openrpc/types/appconsts" - appns "github.com/rollkit/celestia-openrpc/types/namespace" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + appns "github.com/celestiaorg/celestia-openrpc/types/namespace" ) func TestBlobMarshalUnmarshal(t *testing.T) { diff --git a/types/blob/commitment.go b/types/blob/commitment.go index 406605a..acb5cb5 100644 --- a/types/blob/commitment.go +++ b/types/blob/commitment.go @@ -5,8 +5,8 @@ import ( "github.com/celestiaorg/nmt" - "github.com/rollkit/celestia-openrpc/types/appconsts" - "github.com/rollkit/celestia-openrpc/types/share" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/share" ) // CreateCommitment generates the share commitment for a given blob. diff --git a/types/blob/share_splitting.go b/types/blob/share_splitting.go index d1eb7a1..34a25c6 100644 --- a/types/blob/share_splitting.go +++ b/types/blob/share_splitting.go @@ -1,6 +1,6 @@ package blob -import "github.com/rollkit/celestia-openrpc/types/share" +import "github.com/celestiaorg/celestia-openrpc/types/share" // SplitBlobs splits the provided blobs into shares. func SplitBlobs(blobs ...Blob) ([]share.Share, error) { diff --git a/types/header/header.go b/types/header/header.go index 18600af..6dd2448 100644 --- a/types/header/header.go +++ b/types/header/header.go @@ -7,7 +7,7 @@ import ( "github.com/celestiaorg/go-header" cmjson "github.com/cometbft/cometbft/libs/json" - "github.com/rollkit/celestia-openrpc/types/core" + "github.com/celestiaorg/celestia-openrpc/types/core" ) // RawHeader is an alias to core.Header. It is diff --git a/types/share/info_byte.go b/types/share/info_byte.go index d911b03..6b5c505 100644 --- a/types/share/info_byte.go +++ b/types/share/info_byte.go @@ -3,7 +3,7 @@ package share import ( "fmt" - "github.com/rollkit/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" ) // InfoByte is a byte with the following structure: the first 7 bits are diff --git a/types/share/namespace.go b/types/share/namespace.go index d9a674e..76f36c9 100644 --- a/types/share/namespace.go +++ b/types/share/namespace.go @@ -7,8 +7,8 @@ import ( "github.com/celestiaorg/nmt/namespace" - "github.com/rollkit/celestia-openrpc/types/appconsts" - appns "github.com/rollkit/celestia-openrpc/types/namespace" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + appns "github.com/celestiaorg/celestia-openrpc/types/namespace" ) // Various reserved namespaces. diff --git a/types/share/padding.go b/types/share/padding.go index 5b4b202..1fc4b22 100644 --- a/types/share/padding.go +++ b/types/share/padding.go @@ -4,8 +4,8 @@ import ( "bytes" "errors" - "github.com/rollkit/celestia-openrpc/types/appconsts" - "github.com/rollkit/celestia-openrpc/types/namespace" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/namespace" ) // NamespacePaddingShare returns a share that acts as padding. Namespace padding diff --git a/types/share/reserved_bytes.go b/types/share/reserved_bytes.go index dd1fbda..8f03855 100644 --- a/types/share/reserved_bytes.go +++ b/types/share/reserved_bytes.go @@ -4,7 +4,7 @@ import ( "encoding/binary" "fmt" - "github.com/rollkit/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" ) // NewReservedBytes returns a byte slice of length diff --git a/types/share/share.go b/types/share/share.go index 542a20a..b6d0a78 100644 --- a/types/share/share.go +++ b/types/share/share.go @@ -7,9 +7,9 @@ import ( "github.com/celestiaorg/nmt" - "github.com/rollkit/celestia-openrpc/types/appconsts" - "github.com/rollkit/celestia-openrpc/types/core" - "github.com/rollkit/celestia-openrpc/types/namespace" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/core" + "github.com/celestiaorg/celestia-openrpc/types/namespace" ) // Root represents root commitment to multiple Shares. diff --git a/types/share/share_builder.go b/types/share/share_builder.go index 9373338..5fc83b2 100644 --- a/types/share/share_builder.go +++ b/types/share/share_builder.go @@ -4,8 +4,8 @@ import ( "encoding/binary" "errors" - "github.com/rollkit/celestia-openrpc/types/appconsts" - "github.com/rollkit/celestia-openrpc/types/namespace" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/namespace" ) type Builder struct { diff --git a/types/share/split_sparse_shares.go b/types/share/split_sparse_shares.go index 2006446..f4c8969 100644 --- a/types/share/split_sparse_shares.go +++ b/types/share/split_sparse_shares.go @@ -6,8 +6,8 @@ import ( "golang.org/x/exp/slices" - "github.com/rollkit/celestia-openrpc/types/appconsts" - "github.com/rollkit/celestia-openrpc/types/namespace" + "github.com/celestiaorg/celestia-openrpc/types/appconsts" + "github.com/celestiaorg/celestia-openrpc/types/namespace" ) // SparseShareSplitter lazily splits blobs into shares that will eventually be diff --git a/types/state/state.go b/types/state/state.go index 03fcb92..6374a85 100644 --- a/types/state/state.go +++ b/types/state/state.go @@ -8,7 +8,7 @@ import ( coretypes "github.com/cometbft/cometbft/types" - "github.com/rollkit/celestia-openrpc/types/sdk" + "github.com/celestiaorg/celestia-openrpc/types/sdk" ) // Balance is an alias to the Coin type from Cosmos-SDK.