Skip to content

Commit 775b781

Browse files
authored
[Feature]: Submit all blocks possible (#1607)
<!-- 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. --> ## Overview closes #1590 <!-- 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. --> - This pr updates the logic of `DAClient.SubmitBlocks` so now it can submit all blocks possible ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved error handling and messaging for block submission failures due to serialization issues or size limits in the `SubmitBlocks` method. - **Tests** - Updated test cases `Test_submitBlocksToDA_BlockMarshalErrorCase1` and `Test_submitBlocksToDA_BlockMarshalErrorCase2` to reflect changes in block submission and error messaging. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ffc446b commit 775b781

3 files changed

Lines changed: 25 additions & 24 deletions

File tree

block/manager_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase1(t *testing.T) {
329329

330330
m := getManager(t, goDATest.NewDummyDA())
331331

332-
block1 := types.GetRandomBlock(uint64(0), 5)
333-
block2 := types.GetRandomBlock(uint64(1), 5)
334-
block3 := types.GetRandomBlock(uint64(2), 5)
332+
block1 := types.GetRandomBlock(uint64(1), 5)
333+
block2 := types.GetRandomBlock(uint64(2), 5)
334+
block3 := types.GetRandomBlock(uint64(3), 5)
335335

336336
store := mocks.NewStore(t)
337337
invalidateBlockHeader(block1)
@@ -354,20 +354,22 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase1(t *testing.T) {
354354
assert.Equal(3, len(blocks))
355355
}
356356

357-
// Test_submitBlocksToDA_BlockMarshalErrorCase2: A and B are fair blocks, but C has a marshalling error. None of the blocks get submitted to DA layer.
357+
// Test_submitBlocksToDA_BlockMarshalErrorCase2: A and B are fair blocks, but C has a marshalling error
358+
// - Block A and B get submitted to DA layer not block C
358359
func Test_submitBlocksToDA_BlockMarshalErrorCase2(t *testing.T) {
359360
assert := assert.New(t)
360361
require := require.New(t)
361362
ctx := context.Background()
362363

363364
m := getManager(t, goDATest.NewDummyDA())
364365

365-
block1 := types.GetRandomBlock(uint64(0), 5)
366-
block2 := types.GetRandomBlock(uint64(1), 5)
367-
block3 := types.GetRandomBlock(uint64(2), 5)
366+
block1 := types.GetRandomBlock(uint64(1), 5)
367+
block2 := types.GetRandomBlock(uint64(2), 5)
368+
block3 := types.GetRandomBlock(uint64(3), 5)
368369

369370
store := mocks.NewStore(t)
370371
invalidateBlockHeader(block3)
372+
store.On("SetMetadata", ctx, LastSubmittedHeightKey, []byte(strconv.FormatUint(2, 10))).Return(nil)
371373
store.On("GetMetadata", ctx, LastSubmittedHeightKey).Return(nil, ds.ErrNotFound)
372374
store.On("GetBlock", ctx, uint64(1)).Return(block1, nil)
373375
store.On("GetBlock", ctx, uint64(2)).Return(block2, nil)
@@ -379,12 +381,11 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase2(t *testing.T) {
379381
var err error
380382
m.pendingBlocks, err = NewPendingBlocks(store, m.logger)
381383
require.NoError(err)
382-
383384
err = m.submitBlocksToDA(ctx)
384385
assert.ErrorContains(err, "failed to submit all blocks to DA layer")
385386
blocks, err := m.pendingBlocks.getPendingBlocks(ctx)
386387
assert.NoError(err)
387-
assert.Equal(3, len(blocks))
388+
assert.Equal(1, len(blocks))
388389
}
389390

390391
// invalidateBlockHeader results in a block header that produces a marshalling error

da/da.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,35 +119,35 @@ func NewDAClient(da goDA.DA, gasPrice, gasMultiplier float64, ns goDA.Namespace,
119119

120120
// SubmitBlocks submits blocks to DA.
121121
func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block, maxBlobSize uint64, gasPrice float64) ResultSubmitBlocks {
122-
var blobs [][]byte
123-
var blobSize uint64
124-
var submitted uint64
122+
var (
123+
blobs [][]byte
124+
blobSize uint64
125+
message string
126+
)
125127
for i := range blocks {
126128
blob, err := blocks[i].MarshalBinary()
127129
if err != nil {
128-
return ResultSubmitBlocks{
129-
BaseResult: BaseResult{
130-
Code: StatusError,
131-
Message: "failed to serialize block",
132-
},
133-
}
130+
message = fmt.Sprint("failed to serialize block", err)
131+
dac.Logger.Info(message)
132+
break
134133
}
135134
if blobSize+uint64(len(blob)) > maxBlobSize {
136-
dac.Logger.Info("blob size limit reached", "maxBlobSize", maxBlobSize, "index", i, "blobSize", blobSize, "len(blob)", len(blob))
135+
message = fmt.Sprint(ErrBlobSizeOverLimit.Error(), "blob size limit reached", "maxBlobSize", maxBlobSize, "index", i, "blobSize", blobSize, "len(blob)", len(blob))
136+
dac.Logger.Info(message)
137137
break
138138
}
139139
blobSize += uint64(len(blob))
140-
submitted += 1
141140
blobs = append(blobs, blob)
142141
}
143-
if submitted == 0 {
142+
if len(blobs) == 0 {
144143
return ResultSubmitBlocks{
145144
BaseResult: BaseResult{
146145
Code: StatusError,
147-
Message: "failed to submit blocks: oversized block: " + ErrBlobSizeOverLimit.Error(),
146+
Message: "failed to submit blocks: no blobs generated " + message,
148147
},
149148
}
150149
}
150+
151151
ctx, cancel := context.WithTimeout(ctx, dac.SubmitTimeout)
152152
defer cancel()
153153
ids, err := dac.DA.Submit(ctx, blobs, gasPrice, dac.Namespace)
@@ -186,7 +186,7 @@ func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block, ma
186186
BaseResult: BaseResult{
187187
Code: StatusSuccess,
188188
DAHeight: binary.LittleEndian.Uint64(ids[0]),
189-
SubmittedCount: submitted,
189+
SubmittedCount: uint64(len(ids)),
190190
},
191191
}
192192
}

da/da_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func doTestSubmitOversizedBlock(t *testing.T, dalc *DAClient) {
274274
oversizedBlock := types.GetRandomBlock(1, int(limit))
275275
resp := dalc.SubmitBlocks(ctx, []*types.Block{oversizedBlock}, limit, -1)
276276
assert.Equal(StatusError, resp.Code, "oversized block should throw error")
277-
assert.Contains(resp.Message, "failed to submit blocks: oversized block: blob: over size limit")
277+
assert.Contains(resp.Message, "failed to submit blocks: no blobs generated blob: over size limit")
278278
}
279279

280280
func doTestSubmitSmallBlocksBatch(t *testing.T, dalc *DAClient) {

0 commit comments

Comments
 (0)