Skip to content

Commit

Permalink
Add Blob.Index and fix Blob.Proof Serialization (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferret-san committed Mar 18, 2024
1 parent 7eac889 commit 64f0484
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 59 deletions.
16 changes: 8 additions & 8 deletions .github/auto_request_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Check failure on line 18 in .github/auto_request_review.yml

View workflow job for this annotation

GitHub Actions / lint / yamllint

18:5 [key-duplicates] duplication of key "celestia" in mapping
- team:celestia
files:
'**':
- code-owners
- rollkit
- celestia
'**/*Dockerfile':
- devops
'.github/**':
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/housekeeping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ linters-settings:
- name: package-comments
disabled: true
goimports:
local-prefixes: github.com/rollkit
local-prefixes: github.com/celestia
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
32 changes: 14 additions & 18 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"`
Expand Down Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/rollkit/celestia-openrpc
module github.com/celestiaorg/celestia-openrpc

go 1.20

Expand Down
2 changes: 1 addition & 1 deletion types/appconsts/versioned_consts.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 7 additions & 2 deletions types/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -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)
}
Expand All @@ -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
}

Expand All @@ -105,5 +109,6 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data []byte) (*Blob,
ShareVersion: uint32(shareVersion),
NamespaceVersion: 0,
Commitment: []byte{},
Index: -1,
}, nil
}
4 changes: 2 additions & 2 deletions types/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions types/blob/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion types/blob/share_splitting.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion types/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/celestiaorg/go-header"

Check failure on line 7 in types/header/header.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `goimports`-ed with -local github.com/celestia (goimports)
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
Expand Down
2 changes: 1 addition & 1 deletion types/share/info_byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions types/share/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions types/share/padding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/share/reserved_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions types/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions types/share/share_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions types/share/split_sparse_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 64f0484

Please sign in to comment.