Skip to content

Commit fe7fcb6

Browse files
committed
rework input param from commitment to blob id
1 parent ab049b4 commit fe7fcb6

8 files changed

Lines changed: 68 additions & 75 deletions

File tree

api/docgen/examples.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,19 @@ func init() {
193193
add(network.DirUnknown)
194194
add(bytes.HexBytes(hash))
195195

196-
// Fibre types
197-
fibreCommitment := appfibre.Commitment{}
198-
copy(fibreCommitment[:], commitment)
199-
add(fibreCommitment)
196+
id := make(appfibre.BlobID, appfibre.BlobIDSize)
197+
id[0] = 2
198+
copy(id[1:], commitment)
199+
add(id)
200200

201201
exampleUploadResult := fibre2.UploadResult{
202-
Commitment: fibreCommitment,
202+
BlobID: id,
203203
ValidatorSignatures: []fibre2.ValidatorSignature{[]byte("validator_signature_bytes")},
204204
PaymentPromise: &fibre2.PaymentPromise{
205205
ChainID: "celestia",
206206
Namespace: namespace,
207207
BlobSize: 1024,
208-
Commitment: fibreCommitment,
208+
Commitment: id.Commitment(),
209209
RowVersion: 2,
210210
ValsetHeight: 100,
211211
CreationTimestamp: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
@@ -215,7 +215,7 @@ func init() {
215215
add(&exampleUploadResult)
216216

217217
exampleSubmitResult := fibre2.SubmitResult{
218-
Commitment: fibreCommitment,
218+
BlobID: id,
219219
ValidatorSignatures: []fibre2.ValidatorSignature{[]byte("validator_signature_bytes")},
220220
Height: 42,
221221
TxHash: "A5CF62609391B17E0340A6E07BD15860AFA4BE7F5DAF28F2E22A1C3B0CE85E64",
@@ -244,7 +244,7 @@ func init() {
244244
ChainID: "celestia",
245245
Namespace: namespace,
246246
BlobSize: 1024,
247-
Commitment: fibreCommitment,
247+
Commitment: id.Commitment(),
248248
RowVersion: 2,
249249
ValsetHeight: 100,
250250
CreationTimestamp: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),

fibre/account.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,39 @@ func (a *AccountClient) QueryEscrowAccount(ctx context.Context, signer string) (
7373

7474
log.Infow("querying escrow account", "signer", signer)
7575

76-
var resp *fibretypes.QueryEscrowAccountResponse
76+
var successfulResp *fibretypes.QueryEscrowAccountResponse
7777
for _, conn := range a.conns {
7878
queryClient := fibretypes.NewQueryClient(conn)
79-
resp, err = queryClient.EscrowAccount(ctx, &fibretypes.QueryEscrowAccountRequest{
79+
resp, err := queryClient.EscrowAccount(ctx, &fibretypes.QueryEscrowAccountRequest{
8080
Signer: signer,
8181
})
8282
if err != nil {
8383
log.Warnw("querying escrow account", "error", err)
8484
continue
8585
}
86-
86+
successfulResp = resp
8787
if resp.Found {
8888
break
8989
}
9090
log.Warnw("escrow account not found for signer", "signer", signer)
9191
}
9292

93-
if resp == nil {
93+
if successfulResp == nil {
9494
return nil, fmt.Errorf("querying escrow account: %w", err)
9595
}
96-
if !resp.Found {
96+
if !successfulResp.Found {
9797
return nil, fmt.Errorf("escrow account not found for signer:%s", signer)
9898
}
9999

100100
log.Debugw("escrow account found",
101-
"signer", resp.EscrowAccount.Signer,
102-
"balance", resp.EscrowAccount.Balance,
103-
"available-balance", resp.EscrowAccount.AvailableBalance,
101+
"signer", successfulResp.EscrowAccount.Signer,
102+
"balance", successfulResp.EscrowAccount.Balance,
103+
"available-balance", successfulResp.EscrowAccount.AvailableBalance,
104104
)
105105
return &EscrowAccount{
106-
Signer: resp.EscrowAccount.Signer,
107-
Balance: resp.EscrowAccount.Balance,
108-
AvailableBalance: resp.EscrowAccount.AvailableBalance,
106+
Signer: successfulResp.EscrowAccount.Signer,
107+
Balance: successfulResp.EscrowAccount.Balance,
108+
AvailableBalance: successfulResp.EscrowAccount.AvailableBalance,
109109
}, nil
110110
}
111111

@@ -190,7 +190,6 @@ func (a *AccountClient) PendingWithdrawals(ctx context.Context, signer string) (
190190
log.Infow("querying pending withdrawals", "signer", signer)
191191

192192
var resp *fibretypes.QueryWithdrawalsResponse
193-
194193
for _, conn := range a.conns {
195194
queryClient := fibretypes.NewQueryClient(conn)
196195
resp, err = queryClient.Withdrawals(ctx, &fibretypes.QueryWithdrawalsRequest{

fibre/service.go

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
logging "github.com/ipfs/go-log/v2"
1111

1212
appfibre "github.com/celestiaorg/celestia-app/v8/fibre"
13+
"github.com/celestiaorg/celestia-app/v8/pkg/user"
1314
fibretypes "github.com/celestiaorg/celestia-app/v8/x/fibre/types"
1415
libshare "github.com/celestiaorg/go-square/v4/share"
1516

@@ -46,7 +47,7 @@ func (s *Service) Submit(
4647
ns libshare.Namespace,
4748
data []byte,
4849
options *txclient.TxConfig,
49-
) (_ *appfibre.PutResult, _ *appfibre.PaymentPromise, err error) {
50+
) (_ *user.TxResponse, _ *appfibre.SignedPaymentPromise, _ appfibre.BlobID, err error) {
5051
start := time.Now()
5152
defer func() {
5253
s.metrics.observeSubmit(ctx, time.Since(start), len(data), err)
@@ -56,23 +57,23 @@ func (s *Service) Submit(
5657

5758
blob, err := appfibre.NewBlob(data, appfibre.DefaultBlobConfigV0())
5859
if err != nil {
59-
return nil, nil, err
60+
return nil, nil, nil, err
6061
}
6162

6263
promise, err := s.upload(ctx, ns, blob)
6364
if err != nil {
6465
log.Errorw("uploading blob", "err", err, "namespace", ns.ID())
65-
return nil, nil, err
66+
return nil, nil, nil, err
6667
}
6768

6869
protoPromise, err := promise.ToProto()
6970
if err != nil {
70-
return nil, nil, err
71+
return nil, nil, nil, err
7172
}
7273

7374
signer, err := s.txClient.GetTxAuthorAccAddress(options)
7475
if err != nil {
75-
return nil, nil, fmt.Errorf("getting signer address: %w", err)
76+
return nil, nil, nil, fmt.Errorf("getting signer address: %w", err)
7677
}
7778

7879
msg := &fibretypes.MsgPayForFibre{
@@ -83,34 +84,27 @@ func (s *Service) Submit(
8384
resp, err := s.txClient.SubmitMessage(ctx, msg, options)
8485
if err != nil {
8586
log.Errorw("submitting blob", "err", err, "namespace", promise.Namespace)
86-
return nil, nil, err
87-
}
88-
89-
putRes := &appfibre.PutResult{
90-
BlobID: blob.ID(),
91-
ValidatorSignatures: promise.ValidatorSignatures,
92-
TxHash: resp.TxHash,
93-
Height: uint64(resp.Height),
87+
return nil, nil, nil, err
9488
}
9589

9690
// go does not allow slicing a function return value directly (e.g., f()[:]).
97-
commitment := putRes.BlobID.Commitment()
91+
commitment := blob.ID().Commitment()
9892
log.Debugw("blob submitted",
9993
"namespace", promise.Namespace,
10094
"commitment", hex.EncodeToString(commitment[:]),
101-
"height", putRes.Height,
102-
"tx-hash", putRes.TxHash,
103-
"signatures", len(putRes.ValidatorSignatures),
95+
"height", resp.Height,
96+
"tx-hash", resp.TxHash,
97+
"signatures", len(promise.ValidatorSignatures),
10498
)
105-
return putRes, promise.PaymentPromise, nil
99+
return resp, promise, blob.ID(), nil
106100
}
107101

108102
func (s *Service) Upload(
109103
ctx context.Context,
110104
ns libshare.Namespace,
111105
data []byte,
112106
_ *txclient.TxConfig,
113-
) (_ *appfibre.SignedPaymentPromise, err error) {
107+
) (_ *appfibre.SignedPaymentPromise, _ appfibre.BlobID, err error) {
114108
start := time.Now()
115109
defer func() {
116110
s.metrics.observeUpload(ctx, time.Since(start), len(data), err)
@@ -120,25 +114,26 @@ func (s *Service) Upload(
120114

121115
blob, err := appfibre.NewBlob(data, appfibre.DefaultBlobConfigV0())
122116
if err != nil {
123-
return nil, err
117+
return nil, nil, err
124118
}
125119
promise, err := s.upload(ctx, ns, blob)
126120
if err != nil {
127121
log.Errorw("uploading blob", "err", err, "namespace", ns.ID())
128-
return nil, err
122+
return nil, nil, err
129123
}
130124
// TODO: add async fibre submit
131-
return promise, nil
125+
return promise, blob.ID(), nil
132126
}
133127

134-
func (s *Service) Get(ctx context.Context, ns libshare.Namespace, commitment []byte) (*appfibre.Blob, error) {
135-
log.Debugw("getting blob", "namespace", ns.ID(), "commitment", hex.EncodeToString(commitment))
136-
if len(commitment) != appfibre.CommitmentSize {
137-
return nil, fmt.Errorf("commitment size does not match. want:%d got:%d", appfibre.CommitmentSize, len(commitment))
128+
func (s *Service) Get(ctx context.Context, blobID []byte) (*appfibre.Blob, error) {
129+
blbID := appfibre.BlobID(blobID)
130+
err := blbID.Validate()
131+
if err != nil {
132+
return nil, fmt.Errorf("invalid blob ID: %w", err)
138133
}
134+
log.Debugw("downloading fibre blob", "commitment", blbID.Commitment())
139135

140-
blobID := appfibre.NewBlobID(ns.Version(), appfibre.Commitment(commitment))
141-
return s.fibreClient.Download(ctx, blobID)
136+
return s.fibreClient.Download(ctx, blbID)
142137
}
143138

144139
func (s *Service) upload(

nodebuilder/fibre/fibre.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type Module interface {
3131
// and aggregates validator availability signatures. It does NOT submit MsgPayForFibre on-chain.
3232
// Use blob.SubmitFibreBlob for the full submit flow.
3333
Upload(_ context.Context, _ libshare.Namespace, _ []byte, _ *txclient.TxConfig) (*UploadResult, error)
34-
// Get retrieves a Fibre blob from FSPs by namespace and commitment.
34+
// Get retrieves a Fibre blob from FSPs by blobID.
3535
// It reconstructs the original blob data from the encoded rows stored off-chain.
36-
Get(ctx context.Context, ns libshare.Namespace, commitment []byte) (*GetBlobResult, error)
36+
Get(ctx context.Context, blobID []byte) (*GetBlobResult, error)
3737
// QueryEscrowAccount returns the escrow account details for the given signer address,
3838
// including total balance and available (spendable) balance.
3939
QueryEscrowAccount(ctx context.Context, signer string) (*fibre.EscrowAccount, error)
@@ -65,8 +65,7 @@ type API struct {
6565
) (*UploadResult, error) `perm:"write"`
6666
Get func(
6767
ctx context.Context,
68-
ns libshare.Namespace,
69-
commitment []byte,
68+
blobID []byte,
7069
) (*GetBlobResult, error) `perm:"read"`
7170
QueryEscrowAccount func(
7271
ctx context.Context,
@@ -107,8 +106,8 @@ func (api *API) Upload(
107106
return api.Internal.Upload(ctx, ns, data, options)
108107
}
109108

110-
func (api *API) Get(ctx context.Context, ns libshare.Namespace, commitment []byte) (*GetBlobResult, error) {
111-
return api.Internal.Get(ctx, ns, commitment)
109+
func (api *API) Get(ctx context.Context, blobID []byte) (*GetBlobResult, error) {
110+
return api.Internal.Get(ctx, blobID)
112111
}
113112

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

nodebuilder/fibre/mocks/api.go

Lines changed: 4 additions & 4 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: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ func (m *module) Submit(
2828
data []byte,
2929
options *txclient.TxConfig,
3030
) (*SubmitResult, error) {
31-
putRes, pp, err := m.service.Submit(ctx, ns, data, options)
31+
resp, pp, id, err := m.service.Submit(ctx, ns, data, options)
3232
if err != nil {
3333
return nil, err
3434
}
3535

3636
submitRes := &SubmitResult{
37-
Commitment: putRes.BlobID.Commitment(),
38-
Height: putRes.Height,
39-
TxHash: putRes.TxHash,
40-
PaymentPromise: toNodePaymentPromise(pp),
37+
BlobID: id,
38+
Height: uint64(resp.Height),
39+
TxHash: resp.TxHash,
40+
PaymentPromise: toNodePaymentPromise(pp.PaymentPromise),
4141
}
4242

43-
submitRes.ValidatorSignatures = make([]ValidatorSignature, len(putRes.ValidatorSignatures))
44-
for i, sig := range putRes.ValidatorSignatures {
43+
submitRes.ValidatorSignatures = make([]ValidatorSignature, len(pp.ValidatorSignatures))
44+
for i, sig := range pp.ValidatorSignatures {
4545
submitRes.ValidatorSignatures[i] = sig
4646
}
4747
return submitRes, nil
@@ -53,13 +53,13 @@ func (m *module) Upload(
5353
data []byte,
5454
options *txclient.TxConfig,
5555
) (*UploadResult, error) {
56-
promise, err := m.service.Upload(ctx, ns, data, options)
56+
promise, blobID, err := m.service.Upload(ctx, ns, data, options)
5757
if err != nil {
5858
return nil, err
5959
}
6060

6161
uploadRes := &UploadResult{
62-
Commitment: promise.Commitment,
62+
BlobID: blobID,
6363
PaymentPromise: toNodePaymentPromise(promise.PaymentPromise),
6464
}
6565

@@ -70,8 +70,8 @@ func (m *module) Upload(
7070
return uploadRes, nil
7171
}
7272

73-
func (m *module) Get(ctx context.Context, ns libshare.Namespace, commitment []byte) (*GetBlobResult, error) {
74-
blob, err := m.service.Get(ctx, ns, commitment)
73+
func (m *module) Get(ctx context.Context, blobID []byte) (*GetBlobResult, error) {
74+
blob, err := m.service.Get(ctx, blobID)
7575
if err != nil {
7676
return nil, err
7777
}

nodebuilder/fibre/stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (s *stubbedFibreModule) Upload(
3434
return nil, errFibreNotAvailable
3535
}
3636

37-
func (s *stubbedFibreModule) Get(context.Context, libshare.Namespace, []byte) (*GetBlobResult, error) {
37+
func (s *stubbedFibreModule) Get(context.Context, []byte) (*GetBlobResult, error) {
3838
return nil, errFibreNotAvailable
3939
}
4040

nodebuilder/fibre/types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
type ValidatorSignature []byte
1212

1313
// UploadResult is the result of uploading a blob to FSPs without on-chain submission.
14-
// It contains the blob commitment, aggregated validator signatures, and the payment promise
14+
// It contains the blob ID, aggregated validator signatures, and the payment promise
1515
// that can be used for a later on-chain MsgPayForFibre submission.
1616
type UploadResult struct {
17-
// Commitment is the Fibre commitment for the uploaded blob.
18-
Commitment appfibre.Commitment `json:"commitment"`
17+
// BlobID is the Fibre blob identifier for the uploaded blob.
18+
BlobID appfibre.BlobID `json:"blob_id"`
1919
// ValidatorSignatures are attestations from validators confirming blob availability.
2020
ValidatorSignatures []ValidatorSignature `json:"validator_signatures"`
2121
// PaymentPromise is the signed promise used for on-chain fee settlement.
@@ -25,8 +25,8 @@ 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-
// Commitment is the Fibre commitment for the submitted blob.
29-
Commitment appfibre.Commitment `json:"commitment"`
28+
// BlobID is the Fibre blob identifier for the submitted blob.
29+
BlobID appfibre.BlobID `json:"blob_id"`
3030
// ValidatorSignatures are attestations from validators confirming blob availability.
3131
ValidatorSignatures []ValidatorSignature `json:"validator_signatures"`
3232
// Height is the block height at which MsgPayForFibre was included on-chain.

0 commit comments

Comments
 (0)