Skip to content

Commit 2372cfa

Browse files
committed
fix nits
1 parent 80d4873 commit 2372cfa

7 files changed

Lines changed: 86 additions & 73 deletions

File tree

api/docgen/examples.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"golang.org/x/text/language"
2424

2525
appfibre "github.com/celestiaorg/celestia-app/v8/fibre"
26+
libhead "github.com/celestiaorg/go-header"
2627
libshare "github.com/celestiaorg/go-square/v4/share"
2728
"github.com/celestiaorg/rsmt2d"
2829

@@ -200,11 +201,9 @@ func init() {
200201
add(&exampleUploadResult)
201202

202203
exampleSubmitResult := fibre2.SubmitResult{
203-
BlobID: id,
204-
ValidatorSignatures: []fibre2.ValidatorSignature{[]byte("validator_signature_bytes")},
205-
Height: 42,
206-
TxHash: "A5CF62609391B17E0340A6E07BD15860AFA4BE7F5DAF28F2E22A1C3B0CE85E64",
207-
PaymentPromise: exampleUploadResult.PaymentPromise,
204+
UploadResult: exampleUploadResult,
205+
Height: 42,
206+
TxHash: "A5CF62609391B17E0340A6E07BD15860AFA4BE7F5DAF28F2E22A1C3B0CE85E64",
208207
}
209208
add(&exampleSubmitResult)
210209

fibre/service.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ func (s *Service) Submit(
4747
ns libshare.Namespace,
4848
data []byte,
4949
options *txclient.TxConfig,
50-
) (_ *user.TxResponse, _ *appfibre.SignedPaymentPromise, _ appfibre.BlobID, err error) {
50+
) (_ *user.TxResponse, _ *appfibre.SignedPaymentPromise, err error) {
51+
if s == nil {
52+
return nil, nil, ErrClientNotAvailable
53+
}
54+
5155
start := time.Now()
5256
defer func() {
5357
s.metrics.observeSubmit(ctx, time.Since(start), len(data), err)
@@ -57,23 +61,23 @@ func (s *Service) Submit(
5761

5862
blob, err := appfibre.NewBlob(data, appfibre.DefaultBlobConfigV0())
5963
if err != nil {
60-
return nil, nil, nil, err
64+
return nil, nil, err
6165
}
6266

6367
promise, err := s.upload(ctx, ns, blob)
6468
if err != nil {
6569
log.Errorw("uploading blob", "err", err, "namespace", ns.ID())
66-
return nil, nil, nil, err
70+
return nil, nil, err
6771
}
6872

6973
protoPromise, err := promise.ToProto()
7074
if err != nil {
71-
return nil, nil, nil, err
75+
return nil, nil, err
7276
}
7377

7478
signer, err := s.txClient.GetTxAuthorAccAddress(options)
7579
if err != nil {
76-
return nil, nil, nil, fmt.Errorf("getting signer address: %w", err)
80+
return nil, nil, fmt.Errorf("getting signer address: %w", err)
7781
}
7882

7983
msg := &fibretypes.MsgPayForFibre{
@@ -84,7 +88,7 @@ func (s *Service) Submit(
8488
resp, err := s.txClient.SubmitMessage(ctx, msg, options)
8589
if err != nil {
8690
log.Errorw("submitting blob", "err", err, "namespace", promise.Namespace)
87-
return nil, nil, nil, err
91+
return nil, nil, err
8892
}
8993

9094
// go does not allow slicing a function return value directly (e.g., f()[:]).
@@ -96,7 +100,7 @@ func (s *Service) Submit(
96100
"tx-hash", resp.TxHash,
97101
"signatures", len(promise.ValidatorSignatures),
98102
)
99-
return resp, promise, blob.ID(), nil
103+
return resp, promise, nil
100104
}
101105

102106
func (s *Service) Upload(
@@ -105,6 +109,10 @@ func (s *Service) Upload(
105109
data []byte,
106110
_ *txclient.TxConfig,
107111
) (_ *appfibre.SignedPaymentPromise, _ appfibre.BlobID, err error) {
112+
if s == nil {
113+
return nil, nil, ErrClientNotAvailable
114+
}
115+
108116
start := time.Now()
109117
defer func() {
110118
s.metrics.observeUpload(ctx, time.Since(start), len(data), err)
@@ -125,15 +133,17 @@ func (s *Service) Upload(
125133
return promise, blob.ID(), nil
126134
}
127135

128-
func (s *Service) Get(ctx context.Context, blobID []byte) (*appfibre.Blob, error) {
129-
blbID := appfibre.BlobID(blobID)
130-
err := blbID.Validate()
136+
func (s *Service) Download(ctx context.Context, blobID appfibre.BlobID) (*appfibre.Blob, error) {
137+
if s == nil {
138+
return nil, ErrClientNotAvailable
139+
}
140+
141+
err := blobID.Validate()
131142
if err != nil {
132143
return nil, fmt.Errorf("invalid blob ID: %w", err)
133144
}
134-
log.Debugw("downloading fibre blob", "commitment", blbID.Commitment())
135145

136-
return s.fibreClient.Download(ctx, blbID)
146+
return s.fibreClient.Download(ctx, blobID)
137147
}
138148

139149
func (s *Service) upload(

nodebuilder/fibre/fibre.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
sdktypes "github.com/cosmos/cosmos-sdk/types"
77

8+
appfibre "github.com/celestiaorg/celestia-app/v8/fibre"
89
libshare "github.com/celestiaorg/go-square/v4/share"
910

1011
"github.com/celestiaorg/celestia-node/fibre"
@@ -20,32 +21,34 @@ var _ Module = (*API)(nil)
2021
//
2122
//go:generate mockgen -destination=mocks/api.go -package=mocks . Module
2223
type Module interface {
23-
// Submit submits a blob via the Fibre network.
24+
// Submit submits a v0 Fibre blob via the Fibre network.
2425
// It performs the full Fibre flow: uploads blob data to FSPs, aggregates validator
2526
// availability signatures, and submits MsgPayForFibre on-chain.
2627
// Returns the submission result including the on-chain height and transaction hash.
2728
// Requires the node to be connected to a core endpoint with Fibre support.
28-
Submit(_ context.Context, _ libshare.Namespace, _ []byte, _ *txclient.TxConfig) (*SubmitResult, error)
29-
// Upload performs the off-chain portion of Fibre blob submission only.
29+
// NOTE: Currently only v0 Fibre blobs are supported.
30+
Submit(context.Context, libshare.Namespace, []byte, *txclient.TxConfig) (*SubmitResult, error)
31+
// Upload performs the off-chain portion of v0 Fibre blob submission only.
3032
// It encodes the blob, constructs a payment promise, uploads encoded rows to FSPs,
3133
// and aggregates validator availability signatures. It does NOT submit MsgPayForFibre on-chain.
32-
// Use blob.SubmitFibreBlob for the full submit flow.
33-
Upload(_ context.Context, _ libshare.Namespace, _ []byte, _ *txclient.TxConfig) (*UploadResult, error)
34-
// Get retrieves a Fibre blob from FSPs by blobID.
34+
// Use fibre.Submit for the full submit flow.
35+
// NOTE: Currently only v0 Fibre blobs are supported.
36+
Upload(context.Context, libshare.Namespace, []byte, *txclient.TxConfig) (*UploadResult, error)
37+
// Download retrieves a Fibre blob from FSPs by blobID.
3538
// It reconstructs the original blob data from the encoded rows stored off-chain.
36-
Get(ctx context.Context, blobID []byte) (*GetBlobResult, error)
39+
Download(context.Context, appfibre.BlobID) (*GetBlobResult, error)
3740
// QueryEscrowAccount returns the escrow account details for the given signer address,
3841
// including total balance and available (spendable) balance.
39-
QueryEscrowAccount(ctx context.Context, signer string) (*fibre.EscrowAccount, error)
42+
QueryEscrowAccount(_ context.Context, signer string) (*fibre.EscrowAccount, error)
4043
// Deposit adds funds to the node's Fibre escrow account.
4144
// The signer is resolved from cfg (SignerAddress or KeyName) or the node's default account.
42-
Deposit(ctx context.Context, amount sdktypes.Coin, cfg *txclient.TxConfig) error
45+
Deposit(context.Context, sdktypes.Coin, *txclient.TxConfig) error
4346
// Withdraw requests a withdrawal from the node's Fibre escrow account.
4447
// The signer is resolved from cfg (SignerAddress or KeyName) or the node's default account.
4548
// The withdrawal enters an unbonding period before funds become claimable.
46-
Withdraw(ctx context.Context, amount sdktypes.Coin, cfg *txclient.TxConfig) error
49+
Withdraw(context.Context, sdktypes.Coin, *txclient.TxConfig) error
4750
// PendingWithdrawals returns all pending (not yet claimable) withdrawals for the given signer.
48-
PendingWithdrawals(ctx context.Context, signer string) ([]fibre.PendingWithdrawal, error)
51+
PendingWithdrawals(_ context.Context, signer string) ([]fibre.PendingWithdrawal, error)
4952
}
5053

5154
// API is a wrapper around Module for the RPC.
@@ -63,9 +66,9 @@ type API struct {
6366
data []byte,
6467
config *txclient.TxConfig,
6568
) (*UploadResult, error) `perm:"write"`
66-
Get func(
69+
Download func(
6770
ctx context.Context,
68-
blobID []byte,
71+
blobID appfibre.BlobID,
6972
) (*GetBlobResult, error) `perm:"read"`
7073
QueryEscrowAccount func(
7174
ctx context.Context,
@@ -106,8 +109,8 @@ func (api *API) Upload(
106109
return api.Internal.Upload(ctx, ns, data, options)
107110
}
108111

109-
func (api *API) Get(ctx context.Context, blobID []byte) (*GetBlobResult, error) {
110-
return api.Internal.Get(ctx, blobID)
112+
func (api *API) Download(ctx context.Context, blobID appfibre.BlobID) (*GetBlobResult, error) {
113+
return api.Internal.Download(ctx, blobID)
111114
}
112115

113116
func (api *API) QueryEscrowAccount(ctx context.Context, signer string) (*fibre.EscrowAccount, error) {

nodebuilder/fibre/mocks/api.go

Lines changed: 24 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodebuilder/fibre/module.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
sdktypes "github.com/cosmos/cosmos-sdk/types"
77

8+
appfibre "github.com/celestiaorg/celestia-app/v8/fibre"
89
libshare "github.com/celestiaorg/go-square/v4/share"
910

1011
"github.com/celestiaorg/celestia-node/fibre"
@@ -28,23 +29,26 @@ func (m *module) Submit(
2829
data []byte,
2930
options *txclient.TxConfig,
3031
) (*SubmitResult, error) {
31-
resp, pp, id, err := m.service.Submit(ctx, ns, data, options)
32+
resp, pp, err := m.service.Submit(ctx, ns, data, options)
3233
if err != nil {
3334
return nil, err
3435
}
3536

36-
submitRes := &SubmitResult{
37-
BlobID: id,
38-
Height: uint64(resp.Height),
39-
TxHash: resp.TxHash,
37+
blobID := appfibre.NewBlobID(uint8(pp.BlobVersion), pp.Commitment)
38+
uploadRes := UploadResult{
39+
BlobID: blobID,
4040
PaymentPromise: toNodePaymentPromise(pp.PaymentPromise),
4141
}
42-
43-
submitRes.ValidatorSignatures = make([]ValidatorSignature, len(pp.ValidatorSignatures))
42+
uploadRes.ValidatorSignatures = make([]ValidatorSignature, len(pp.ValidatorSignatures))
4443
for i, sig := range pp.ValidatorSignatures {
45-
submitRes.ValidatorSignatures[i] = sig
44+
uploadRes.ValidatorSignatures[i] = sig
4645
}
47-
return submitRes, nil
46+
47+
return &SubmitResult{
48+
UploadResult: uploadRes,
49+
Height: uint64(resp.Height),
50+
TxHash: resp.TxHash,
51+
}, nil
4852
}
4953

5054
func (m *module) Upload(
@@ -70,8 +74,8 @@ func (m *module) Upload(
7074
return uploadRes, nil
7175
}
7276

73-
func (m *module) Get(ctx context.Context, blobID []byte) (*GetBlobResult, error) {
74-
blob, err := m.service.Get(ctx, blobID)
77+
func (m *module) Download(ctx context.Context, blobID appfibre.BlobID) (*GetBlobResult, error) {
78+
blob, err := m.service.Download(ctx, blobID)
7579
if err != nil {
7680
return nil, err
7781
}

nodebuilder/fibre/stub.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
sdktypes "github.com/cosmos/cosmos-sdk/types"
88

9+
appfibre "github.com/celestiaorg/celestia-app/v8/fibre"
910
libshare "github.com/celestiaorg/go-square/v4/share"
1011

1112
"github.com/celestiaorg/celestia-node/fibre"
@@ -34,7 +35,7 @@ func (s *stubbedFibreModule) Upload(
3435
return nil, errFibreNotAvailable
3536
}
3637

37-
func (s *stubbedFibreModule) Get(context.Context, []byte) (*GetBlobResult, error) {
38+
func (s *stubbedFibreModule) Download(context.Context, appfibre.BlobID) (*GetBlobResult, error) {
3839
return nil, errFibreNotAvailable
3940
}
4041

nodebuilder/fibre/types.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ type UploadResult struct {
2525
// SubmitResult is the result of a full Fibre blob submission including on-chain MsgPayForFibre.
2626
// It extends UploadResult with chain inclusion details (height and transaction hash).
2727
type SubmitResult struct {
28-
// BlobID is the Fibre blob identifier for the submitted blob.
29-
BlobID appfibre.BlobID `json:"blob_id"`
30-
// ValidatorSignatures are attestations from validators confirming blob availability.
31-
ValidatorSignatures []ValidatorSignature `json:"validator_signatures"`
28+
UploadResult
3229
// Height is the block height at which MsgPayForFibre was included on-chain.
3330
Height uint64 `json:"height"`
3431
// TxHash is the transaction hash of the on-chain MsgPayForFibre.
3532
TxHash string `json:"tx_hash"`
36-
// PaymentPromise is the signed promise used for on-chain fee settlement.
37-
PaymentPromise *PaymentPromise `json:"payment_promise,omitempty"`
3833
}
3934

4035
// PaymentPromise represents the signed payment promise between a user and the Fibre network.

0 commit comments

Comments
 (0)