Skip to content

Commit cca03fc

Browse files
tac0turtletac0turtlechatton
authored
chore: revert da cleanup (#2399)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for specifying namespaces in data availability operations, enabling more granular data scoping and retrieval. * Introduced the ability to submit blobs with additional options for enhanced flexibility. * **Bug Fixes** * Improved handling of multiple submissions and height simulation in dummy data availability implementations. * **Tests** * Updated and extended test suites to cover namespace-aware operations and new submission methods. * Added new end-to-end tests for transaction submission and retrieval. * **Chores** * Enhanced test output verbosity for better debugging. * Updated dependencies for improved compatibility and stability. * **Documentation** * Clarified method behaviors and updated comments to reflect new parameters and logic. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: tac0turtle <you@example.com> Co-authored-by: chatton <github.qpeyb@simplelogin.fr>
1 parent 9bae7f4 commit cca03fc

24 files changed

Lines changed: 712 additions & 369 deletions

File tree

block/da_speed_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ func TestDASpeed(t *testing.T) {
4949
var receivedBlockCount atomic.Uint64
5050
ids := []coreda.ID{[]byte("dummy-id")}
5151
mockDAClient.
52-
On("GetIDs", mock.Anything, mock.Anything).
53-
Return(func(ctx context.Context, height uint64) (*coreda.GetIDsResult, error) {
52+
On("GetIDs", mock.Anything, mock.Anything, mock.Anything).
53+
Return(func(ctx context.Context, height uint64, namespace []byte) (*coreda.GetIDsResult, error) {
5454
return &coreda.GetIDsResult{IDs: ids, Timestamp: time.Now()}, nil
5555
})
5656

5757
mockDAClient.
58-
On("Get", mock.Anything, ids).
59-
Return(func(ctx context.Context, ids []coreda.ID) ([]coreda.Blob, error) {
58+
On("Get", mock.Anything, ids, mock.Anything).
59+
Return(func(ctx context.Context, ids []coreda.ID, namespace []byte) ([]coreda.Blob, error) {
6060
time.Sleep(spec.daDelay)
6161
// unique headers for cache misses
6262
n := receivedBlockCount.Add(1)

block/retriever.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (m *Manager) fetchBlobs(ctx context.Context, daHeight uint64) (coreda.Resul
212212
ctx, cancel := context.WithTimeout(ctx, dAefetcherTimeout)
213213
defer cancel()
214214
// TODO: we should maintain the original error instead of creating a new one as we lose context by creating a new error.
215-
blobsRes := types.RetrieveWithHelpers(ctx, m.da, m.logger, daHeight)
215+
blobsRes := types.RetrieveWithHelpers(ctx, m.da, m.logger, daHeight, []byte(m.genesis.ChainID))
216216
switch blobsRes.Code {
217217
case coreda.StatusError:
218218
err = fmt.Errorf("failed to retrieve block: %s", blobsRes.Message)

block/retriever_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ func TestProcessNextDAHeader_Success_SingleHeaderAndData(t *testing.T) {
136136
blockDataBytes, err := signedData.MarshalBinary()
137137
require.NoError(t, err)
138138
// -----------------------------------------------------------
139-
mockDAClient.On("GetIDs", mock.Anything, daHeight).Return(&coreda.GetIDsResult{
139+
mockDAClient.On("GetIDs", mock.Anything, daHeight, mock.Anything).Return(&coreda.GetIDsResult{
140140
IDs: []coreda.ID{[]byte("dummy-id")},
141141
Timestamp: time.Now(),
142142
}, nil).Once()
143-
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}).Return(
143+
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}, mock.Anything).Return(
144144
[]coreda.Blob{headerBytes, blockDataBytes}, nil,
145145
).Once()
146146

@@ -248,11 +248,11 @@ func TestProcessNextDAHeader_MultipleHeadersAndData(t *testing.T) {
248248
// Add a few more invalid blobs at the end
249249
blobs = append(blobs, invalidBlob, []byte{})
250250

251-
mockDAClient.On("GetIDs", mock.Anything, daHeight).Return(&coreda.GetIDsResult{
251+
mockDAClient.On("GetIDs", mock.Anything, daHeight, mock.Anything).Return(&coreda.GetIDsResult{
252252
IDs: []coreda.ID{[]byte("dummy-id")},
253253
Timestamp: time.Now(),
254254
}, nil).Once()
255-
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}).Return(
255+
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}, mock.Anything).Return(
256256
blobs, nil,
257257
).Once()
258258

@@ -313,7 +313,7 @@ func TestProcessNextDAHeaderAndData_NotFound(t *testing.T) {
313313

314314
// Mock GetIDs to return empty IDs to simulate "not found" scenario
315315
// Example updates needed for one instance:
316-
mockDAClient.On("GetIDs", mock.Anything, daHeight).Return(&coreda.GetIDsResult{
316+
mockDAClient.On("GetIDs", mock.Anything, daHeight, mock.Anything).Return(&coreda.GetIDsResult{
317317
IDs: []coreda.ID{},
318318
Timestamp: time.Now(),
319319
}, coreda.ErrBlobNotFound).Once()
@@ -346,13 +346,13 @@ func TestProcessNextDAHeaderAndData_UnmarshalHeaderError(t *testing.T) {
346346
invalidBytes := []byte("this is not a valid protobuf message")
347347

348348
// Mock GetIDs to return success with dummy ID
349-
mockDAClient.On("GetIDs", mock.Anything, daHeight).Return(&coreda.GetIDsResult{
349+
mockDAClient.On("GetIDs", mock.Anything, daHeight, mock.Anything).Return(&coreda.GetIDsResult{
350350
IDs: []coreda.ID{[]byte("dummy-id")},
351351
Timestamp: time.Now(),
352352
}, nil).Once()
353353

354354
// Mock Get to return invalid bytes
355-
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}).Return(
355+
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}, mock.Anything).Return(
356356
[]coreda.Blob{invalidBytes}, nil,
357357
).Once()
358358

@@ -405,13 +405,13 @@ func TestProcessNextDAHeader_UnexpectedSequencer(t *testing.T) {
405405
require.NoError(t, err)
406406

407407
// Mock GetIDs to return success with dummy ID
408-
mockDAClient.On("GetIDs", mock.Anything, daHeight).Return(&coreda.GetIDsResult{
408+
mockDAClient.On("GetIDs", mock.Anything, daHeight, mock.Anything).Return(&coreda.GetIDsResult{
409409
IDs: []coreda.ID{[]byte("dummy-id")},
410410
Timestamp: time.Now(),
411411
}, nil).Once()
412412

413413
// Mock Get to return header bytes
414-
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}).Return(
414+
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}, mock.Anything).Return(
415415
[]coreda.Blob{headerBytes}, nil,
416416
).Once()
417417

@@ -449,7 +449,7 @@ func TestProcessNextDAHeader_FetchError_RetryFailure(t *testing.T) {
449449
fetchErr := errors.New("persistent DA connection error")
450450

451451
// Mock GetIDs to return error for all retries
452-
mockDAClient.On("GetIDs", mock.Anything, daHeight).Return(
452+
mockDAClient.On("GetIDs", mock.Anything, daHeight, mock.Anything).Return(
453453
nil, fetchErr,
454454
).Times(dAFetcherRetries)
455455

@@ -539,7 +539,7 @@ func TestProcessNextDAHeader_HeaderAndDataAlreadySeen(t *testing.T) {
539539
Timestamp: time.Now(),
540540
}, nil).Once()
541541

542-
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}).Return(
542+
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}, mock.Anything).Return(
543543
[]coreda.Blob{headerBytes, blockDataBytes}, nil,
544544
).Once()
545545

@@ -577,12 +577,12 @@ func TestRetrieveLoop_ProcessError_HeightFromFuture(t *testing.T) {
577577
futureErr := fmt.Errorf("some error wrapping: %w", ErrHeightFromFutureStr)
578578

579579
// Mock GetIDs to return future error for all retries
580-
mockDAClient.On("GetIDs", mock.Anything, startDAHeight).Return(
580+
mockDAClient.On("GetIDs", mock.Anything, startDAHeight, mock.Anything).Return(
581581
nil, futureErr,
582582
).Once()
583583

584584
// Optional: Mock for the next height if needed
585-
mockDAClient.On("GetIDs", mock.Anything, startDAHeight+1).Return(
585+
mockDAClient.On("GetIDs", mock.Anything, startDAHeight+1, mock.Anything).Return(
586586
&coreda.GetIDsResult{IDs: []coreda.ID{}}, coreda.ErrBlobNotFound,
587587
).Maybe()
588588

@@ -625,7 +625,7 @@ func TestRetrieveLoop_ProcessError_Other(t *testing.T) {
625625
otherErr := errors.New("some other DA error")
626626

627627
// Mock GetIDs to return error for all retries
628-
mockDAClient.On("GetIDs", mock.Anything, startDAHeight).Return(
628+
mockDAClient.On("GetIDs", mock.Anything, startDAHeight, mock.Anything).Return(
629629
nil, otherErr,
630630
).Times(dAFetcherRetries)
631631

@@ -709,11 +709,11 @@ func TestProcessNextDAHeader_WithNoTxs(t *testing.T) {
709709
emptyDataBytes, err := emptySignedData.MarshalBinary()
710710
require.NoError(t, err)
711711

712-
mockDAClient.On("GetIDs", mock.Anything, daHeight).Return(&coreda.GetIDsResult{
712+
mockDAClient.On("GetIDs", mock.Anything, daHeight, mock.Anything).Return(&coreda.GetIDsResult{
713713
IDs: []coreda.ID{[]byte("dummy-id")},
714714
Timestamp: time.Now(),
715715
}, nil).Once()
716-
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}).Return(
716+
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}, mock.Anything).Return(
717717
[]coreda.Blob{headerBytes, emptyDataBytes}, nil,
718718
).Once()
719719

@@ -762,23 +762,23 @@ func TestRetrieveLoop_DAHeightIncrementsOnlyOnSuccess(t *testing.T) {
762762
require.NoError(t, err)
763763

764764
// 1. First call: success (header)
765-
mockDAClient.On("GetIDs", mock.Anything, startDAHeight).Return(&coreda.GetIDsResult{
765+
mockDAClient.On("GetIDs", mock.Anything, startDAHeight, mock.Anything).Return(&coreda.GetIDsResult{
766766
IDs: []coreda.ID{[]byte("dummy-id")},
767767
Timestamp: time.Now(),
768768
}, nil).Once()
769-
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}).Return(
769+
mockDAClient.On("Get", mock.Anything, []coreda.ID{[]byte("dummy-id")}, mock.Anything).Return(
770770
[]coreda.Blob{headerBytes}, nil,
771771
).Once()
772772

773773
// 2. Second call: NotFound
774-
mockDAClient.On("GetIDs", mock.Anything, startDAHeight+1).Return(&coreda.GetIDsResult{
774+
mockDAClient.On("GetIDs", mock.Anything, startDAHeight+1, mock.Anything).Return(&coreda.GetIDsResult{
775775
IDs: nil,
776776
Timestamp: time.Now(),
777777
}, nil).Once()
778778

779779
// 3. Third call: Error
780780
errDA := errors.New("some DA error")
781-
mockDAClient.On("GetIDs", mock.Anything, startDAHeight+2).Return(
781+
mockDAClient.On("GetIDs", mock.Anything, startDAHeight+2, mock.Anything).Return(
782782
&coreda.GetIDsResult{
783783
IDs: nil,
784784
Timestamp: time.Now(),

block/submitter_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestSubmitDataToDA_Success(t *testing.T) {
9898
return m.submitDataToDA(ctx, items)
9999
},
100100
mockDASetup: func(da *mocks.MockDA) {
101-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
101+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
102102
Return([]coreda.ID{getDummyID(1, []byte("commitment"))}, nil)
103103
},
104104
})
@@ -117,7 +117,7 @@ func TestSubmitHeadersToDA_Success(t *testing.T) {
117117
return m.submitHeadersToDA(ctx, items)
118118
},
119119
mockDASetup: func(da *mocks.MockDA) {
120-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
120+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
121121
Return([]coreda.ID{getDummyID(1, []byte("commitment"))}, nil)
122122
},
123123
})
@@ -187,7 +187,7 @@ func TestSubmitDataToDA_Failure(t *testing.T) {
187187
daError: tc.daError,
188188
mockDASetup: func(da *mocks.MockDA, gasPriceHistory *[]float64, daError error) {
189189
da.ExpectedCalls = nil
190-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
190+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
191191
Run(func(args mock.Arguments) { *gasPriceHistory = append(*gasPriceHistory, args.Get(2).(float64)) }).
192192
Return(nil, daError)
193193
},
@@ -222,7 +222,7 @@ func TestSubmitHeadersToDA_Failure(t *testing.T) {
222222
daError: tc.daError,
223223
mockDASetup: func(da *mocks.MockDA, gasPriceHistory *[]float64, daError error) {
224224
da.ExpectedCalls = nil
225-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
225+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
226226
Run(func(args mock.Arguments) { *gasPriceHistory = append(*gasPriceHistory, args.Get(2).(float64)) }).
227227
Return(nil, daError)
228228
},
@@ -262,15 +262,15 @@ func runRetryPartialFailuresCase[T any](t *testing.T, tc retryPartialFailuresCas
262262

263263
// Set up DA mock: three calls, each time only one item is accepted
264264
da.On("GasMultiplier", mock.Anything).Return(2.0, nil).Times(3)
265-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
265+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
266266
Run(func(args mock.Arguments) {
267267
t.Logf("DA Submit call 1: args=%#v", args)
268268
}).Once().Return([]coreda.ID{getDummyID(1, []byte("commitment2"))}, nil)
269-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
269+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
270270
Run(func(args mock.Arguments) {
271271
t.Logf("DA Submit call 2: args=%#v", args)
272272
}).Once().Return([]coreda.ID{getDummyID(1, []byte("commitment3"))}, nil)
273-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
273+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
274274
Run(func(args mock.Arguments) {
275275
t.Logf("DA Submit call 3: args=%#v", args)
276276
}).Once().Return([]coreda.ID{getDummyID(1, []byte("commitment4"))}, nil)
@@ -495,7 +495,7 @@ func TestSubmitHeadersToDA_WithMetricsRecorder(t *testing.T) {
495495
require.NotEmpty(t, headers)
496496

497497
// Simulate DA layer successfully accepting the header submission
498-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
498+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
499499
Return([]coreda.ID{[]byte("id")}, nil)
500500

501501
// Expect RecordMetrics to be called with the correct parameters
@@ -536,7 +536,7 @@ func TestSubmitDataToDA_WithMetricsRecorder(t *testing.T) {
536536

537537
// Simulate DA success
538538
da.On("GasMultiplier", mock.Anything).Return(2.0, nil)
539-
da.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
539+
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
540540
Return([]coreda.ID{[]byte("id")}, nil)
541541

542542
// Expect RecordMetrics to be called with the correct parameters

core/da/da.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@ type DA interface {
1313
//
1414
// Error should be returned if ID is not formatted properly, there is no Blob for given ID or any other client-level
1515
// error occurred (dropped connection, timeout, etc).
16-
Get(ctx context.Context, ids []ID) ([]Blob, error)
16+
Get(ctx context.Context, ids []ID, namespace []byte) ([]Blob, error)
1717

1818
// GetIDs returns IDs of all Blobs located in DA at given height.
19-
GetIDs(ctx context.Context, height uint64) (*GetIDsResult, error)
19+
GetIDs(ctx context.Context, height uint64, namespace []byte) (*GetIDsResult, error)
2020

2121
// GetProofs returns inclusion Proofs for Blobs specified by their IDs.
22-
GetProofs(ctx context.Context, ids []ID) ([]Proof, error)
22+
GetProofs(ctx context.Context, ids []ID, namespace []byte) ([]Proof, error)
2323

2424
// Commit creates a Commitment for each given Blob.
25-
Commit(ctx context.Context, blobs []Blob) ([]Commitment, error)
25+
Commit(ctx context.Context, blobs []Blob, namespace []byte) ([]Commitment, error)
2626

27-
// Submit submits the Blobs to Data Availability layer with additional options.
27+
// Submit submits the Blobs to Data Availability layer.
2828
//
2929
// This method is synchronous. Upon successful submission to Data Availability layer, it returns the IDs identifying blobs
3030
// in DA.
31-
Submit(ctx context.Context, blobs []Blob, gasPrice float64, options []byte) ([]ID, error)
31+
Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte) ([]ID, error)
32+
33+
// SubmitWithOptions submits the Blobs to Data Availability layer with additional options.
34+
SubmitWithOptions(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte, options []byte) ([]ID, error)
3235

3336
// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
34-
Validate(ctx context.Context, ids []ID, proofs []Proof) ([]bool, error)
37+
Validate(ctx context.Context, ids []ID, proofs []Proof, namespace []byte) ([]bool, error)
3538

3639
// GasPrice returns the gas price for the DA layer.
3740
GasPrice(ctx context.Context) (float64, error)

0 commit comments

Comments
 (0)