Skip to content

Commit

Permalink
fixing signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Jan 31, 2024
1 parent 59aae62 commit 5d29a7e
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 51 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ require (
github.com/prometheus/client_golang v1.18.0
github.com/pyroscope-io/client v0.7.2
github.com/pyroscope-io/otel-profiling-go v0.5.0
github.com/rollkit/go-da v0.3.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -288,7 +289,6 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rollkit/go-da v0.3.0 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2121,10 +2121,6 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rollkit/go-da v0.2.0 h1:rNpWBa2inczgZ955ky3wy8FbrMajzVbm0UfbBGzm5UE=
github.com/rollkit/go-da v0.2.0/go.mod h1:Kef0XI5ecEKd3TXzI8S+9knAUJnZg0svh2DuXoCsPlM=
github.com/rollkit/go-da v0.3.0 h1:fxvlQEvVvjyvMnSKJ9NTyw1XVj9QGQOGrzwC4UHuQ9M=
github.com/rollkit/go-da v0.3.0/go.mod h1:Kef0XI5ecEKd3TXzI8S+9knAUJnZg0svh2DuXoCsPlM=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
Expand Down
3 changes: 2 additions & 1 deletion nodebuilder/blob/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions nodebuilder/da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ type Module interface {
type API struct {
Internal struct {
MaxBlobSize func(ctx context.Context) (uint64, error) `perm:"read"`
Get func(ctx context.Context, ids []da.ID) ([]da.Blob, error) `perm:"read"`
Get func(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) `perm:"read"`
GetIDs func(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) `perm:"read"`
Commit func(ctx context.Context, blobs []da.Blob, ns da.Namespace) ([]da.Commitment, error) `perm:"read"`
Validate func(ctx context.Context, ids []da.ID, proofs []da.Proof) ([]bool, error) `perm:"read"`
Submit func(context.Context, []da.Blob, *da.SubmitOptions) ([]da.ID, []da.Proof, error) `perm:"write"`
Validate func(context.Context, []da.ID, []da.Proof, da.Namespace) ([]bool, error) `perm:"read"`
Submit func(context.Context, []da.Blob, float64, da.Namespace) ([]da.ID, []da.Proof, error) `perm:"write"`
}
}

func (api *API) MaxBlobSize(ctx context.Context) (uint64, error) {
return api.Internal.MaxBlobSize(ctx)
}

func (api *API) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) {
return api.Internal.Get(ctx, ids)
func (api *API) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) {
return api.Internal.Get(ctx, ids, ns)
}

func (api *API) GetIDs(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) {
Expand All @@ -40,6 +40,6 @@ func (api *API) Commit(ctx context.Context, blobs []da.Blob, ns da.Namespace) ([
return api.Internal.Commit(ctx, blobs, ns)
}

func (api *API) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof) ([]bool, error) {
return api.Internal.Validate(ctx, ids, proofs)
func (api *API) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, ns da.Namespace) ([]bool, error) {
return api.Internal.Validate(ctx, ids, proofs, ns)
}
61 changes: 36 additions & 25 deletions nodebuilder/da/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func (s *Service) MaxBlobSize(context.Context) (uint64, error) {
}

// Get returns Blob for each given ID, or an error.
func (s *Service) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) {
func (s *Service) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) {
blobs := make([]da.Blob, 0, len(ids))
for _, id := range ids {
height, commitment, namespace := splitID(id)
log.Debugw("getting blob", "height", height, "commitment", commitment, "namespace", share.Namespace(namespace))
currentBlob, err := s.blobServ.Get(ctx, height, namespace, commitment)
log.Debugw("got blob", "height", height, "commitment", commitment, "namespace", share.Namespace(namespace))
height, commitment := splitID(id)
log.Debugw("getting blob", "height", height, "commitment", commitment, "namespace", share.Namespace(ns))
currentBlob, err := s.blobServ.Get(ctx, height, ns, commitment)
log.Debugw("got blob", "height", height, "commitment", commitment, "namespace", share.Namespace(ns))
if err != nil {
return nil, err
}
Expand All @@ -63,7 +63,7 @@ func (s *Service) GetIDs(ctx context.Context, height uint64, namespace da.Namesp
return nil, err
}
for _, b := range blobs {
ids = append(ids, makeID(height, b.Commitment, namespace))
ids = append(ids, makeID(height, b.Commitment))
}
return ids, nil
}
Expand All @@ -75,23 +75,28 @@ func (s *Service) Commit(_ context.Context, daBlobs []da.Blob, namespace da.Name
}

// Submit submits the Blobs to Data Availability layer.
func (s *Service) Submit(ctx context.Context, daBlobs []da.Blob, opts *da.SubmitOptions) ([]da.ID, []da.Proof, error) {
blobs, commitments, err := s.blobsAndCommitments(daBlobs, opts.Namespace)
func (s *Service) Submit(
ctx context.Context,
daBlobs []da.Blob,
gasPrice float64,
namespace da.Namespace,
) ([]da.ID, []da.Proof, error) {
blobs, commitments, err := s.blobsAndCommitments(daBlobs, namespace)
if err != nil {
return nil, nil, err
}

height, err := s.blobServ.Submit(ctx, blobs, blob.GasPrice(opts.GasPrice))
height, err := s.blobServ.Submit(ctx, blobs, blob.GasPrice(gasPrice))
if err != nil {
log.Error("failed to submit blobs", "height", height, "gas price", opts.GasPrice)
log.Error("failed to submit blobs", "height", height, "gas price", gasPrice)
return nil, nil, err
}
log.Info("successfully submitted blobs", "height", height, "gas price", opts.GasPrice)
log.Info("successfully submitted blobs", "height", height, "gas price", gasPrice)
ids := make([]da.ID, len(daBlobs))
proofs := make([]da.Proof, len(daBlobs))
for i, commitment := range commitments {
ids[i] = makeID(height, commitment, opts.Namespace)
proof, err := s.blobServ.GetProof(ctx, height, opts.Namespace, commitment)
ids[i] = makeID(height, commitment)
proof, err := s.blobServ.GetProof(ctx, height, namespace, commitment)
if err != nil {
return nil, nil, err
}
Expand All @@ -104,7 +109,8 @@ func (s *Service) Submit(ctx context.Context, daBlobs []da.Blob, opts *da.Submit
return ids, proofs, nil
}

// blobsAndCommitments converts []da.Blob to []*blob.Blob and generates corresponding []da.Commitment
// blobsAndCommitments converts []da.Blob to []*blob.Blob and generates corresponding
// []da.Commitment
func (s *Service) blobsAndCommitments(
daBlobs []da.Blob, namespace da.Namespace,
) ([]*blob.Blob, []da.Commitment, error) {
Expand All @@ -128,7 +134,12 @@ func (s *Service) blobsAndCommitments(

// Validate validates Commitments against the corresponding Proofs. This should be possible without
// retrieving the Blobs.
func (s *Service) Validate(ctx context.Context, ids []da.ID, daProofs []da.Proof) ([]bool, error) {
func (s *Service) Validate(
ctx context.Context,
ids []da.ID,
daProofs []da.Proof,
namespace da.Namespace,
) ([]bool, error) {
included := make([]bool, len(ids))
proofs := make([]*blob.Proof, len(ids))
for _, daProof := range daProofs {
Expand All @@ -140,28 +151,28 @@ func (s *Service) Validate(ctx context.Context, ids []da.ID, daProofs []da.Proof
proofs = append(proofs, proof)
}
for i, id := range ids {
height, commitment, namespace := splitID(id)
// TODO(tzdybal): for some reason, if proof doesn't match commitment, API returns (false, "blob: invalid proof")
// but analysis of the code in celestia-node implies this should never happen - maybe it's caused by openrpc?
// there is no way of gently handling errors here, but returned value is fine for us
height, commitment := splitID(id)
// TODO(tzdybal): for some reason, if proof doesn't match commitment, API returns (false, "blob:
// invalid proof") but analysis of the code in celestia-node implies this should never happen -
// maybe it's caused by openrpc? there is no way of gently handling errors here, but returned
// value is fine for us
isIncluded, _ := s.blobServ.Included(ctx, height, namespace, proofs[i], commitment)
included = append(included, isIncluded)
}
return included, nil
}

func makeID(height uint64, commitment da.Commitment, namespace da.Namespace) da.ID {
id := make([]byte, heightLen+len(commitment)+len(namespace))
func makeID(height uint64, commitment da.Commitment) da.ID {
id := make([]byte, heightLen+len(commitment))
binary.LittleEndian.PutUint64(id, height)
copy(id[heightLen:], commitment)
copy(id[heightLen+len(commitment):], namespace)
return id
}

func splitID(id da.ID) (uint64, da.Commitment, da.Namespace) {
func splitID(id da.ID) (uint64, da.Commitment) {
if len(id) <= heightLen {
return 0, nil, nil
return 0, nil
}
commitment := id[heightLen:]
return binary.LittleEndian.Uint64(id[:heightLen]), commitment, id[heightLen+len(commitment):]
return binary.LittleEndian.Uint64(id[:heightLen]), commitment
}
3 changes: 2 additions & 1 deletion nodebuilder/das/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion nodebuilder/fraud/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion nodebuilder/header/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion nodebuilder/node/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion nodebuilder/share/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions nodebuilder/state/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions nodebuilder/tests/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"testing"
"time"

"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-node/api/rpc/client"
"github.com/celestiaorg/celestia-node/libs/authtoken"
"github.com/celestiaorg/celestia-node/nodebuilder"

"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/stretchr/testify/require"
)

func getAdminClient(ctx context.Context, nd *nodebuilder.Node, t *testing.T) *client.Client {
Expand Down
3 changes: 2 additions & 1 deletion share/availability/mocks/availability.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion share/mocks/getter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion share/p2p/peers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const (
// events in libp2p
eventbusBufSize = 32

// storedPoolsAmount is the amount of pools for recent headers that will be stored in the peer manager
// storedPoolsAmount is the amount of pools for recent headers that will be stored in the peer
// manager
storedPoolsAmount = 10
)

Expand Down

0 comments on commit 5d29a7e

Please sign in to comment.