Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase1(t *testing.T) {

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

block1 := types.GetRandomBlock(uint64(0), 5)
block2 := types.GetRandomBlock(uint64(1), 5)
block3 := types.GetRandomBlock(uint64(2), 5)
block1 := types.GetRandomBlock(uint64(1), 5)
block2 := types.GetRandomBlock(uint64(2), 5)
block3 := types.GetRandomBlock(uint64(3), 5)

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

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

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

block1 := types.GetRandomBlock(uint64(0), 5)
block2 := types.GetRandomBlock(uint64(1), 5)
block3 := types.GetRandomBlock(uint64(2), 5)
block1 := types.GetRandomBlock(uint64(1), 5)
block2 := types.GetRandomBlock(uint64(2), 5)
block3 := types.GetRandomBlock(uint64(3), 5)

store := mocks.NewStore(t)
invalidateBlockHeader(block3)
store.On("SetMetadata", ctx, LastSubmittedHeightKey, []byte(strconv.FormatUint(2, 10))).Return(nil)
store.On("GetMetadata", ctx, LastSubmittedHeightKey).Return(nil, ds.ErrNotFound)
store.On("GetBlock", ctx, uint64(1)).Return(block1, nil)
store.On("GetBlock", ctx, uint64(2)).Return(block2, nil)
Expand All @@ -379,12 +381,11 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase2(t *testing.T) {
var err error
m.pendingBlocks, err = NewPendingBlocks(store, m.logger)
require.NoError(err)

err = m.submitBlocksToDA(ctx)
assert.ErrorContains(err, "failed to submit all blocks to DA layer")
blocks, err := m.pendingBlocks.getPendingBlocks(ctx)
assert.NoError(err)
assert.Equal(3, len(blocks))
assert.Equal(1, len(blocks))
}

// invalidateBlockHeader results in a block header that produces a marshalling error
Expand Down
28 changes: 14 additions & 14 deletions da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,35 @@ func NewDAClient(da goDA.DA, gasPrice, gasMultiplier float64, ns goDA.Namespace,

// SubmitBlocks submits blocks to DA.
func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block, maxBlobSize uint64, gasPrice float64) ResultSubmitBlocks {
var blobs [][]byte
var blobSize uint64
var submitted uint64
var (
blobs [][]byte
blobSize uint64
message string
)
for i := range blocks {
blob, err := blocks[i].MarshalBinary()
if err != nil {
return ResultSubmitBlocks{
BaseResult: BaseResult{
Code: StatusError,
Message: "failed to serialize block",
},
}
message = fmt.Sprint("failed to serialize block", err)
dac.Logger.Info(message)
break
Comment thread
MSevey marked this conversation as resolved.
}
if blobSize+uint64(len(blob)) > maxBlobSize {
dac.Logger.Info("blob size limit reached", "maxBlobSize", maxBlobSize, "index", i, "blobSize", blobSize, "len(blob)", len(blob))
message = fmt.Sprint(ErrBlobSizeOverLimit.Error(), "blob size limit reached", "maxBlobSize", maxBlobSize, "index", i, "blobSize", blobSize, "len(blob)", len(blob))
dac.Logger.Info(message)
break
}
blobSize += uint64(len(blob))
submitted += 1
blobs = append(blobs, blob)
}
if submitted == 0 {
if len(blobs) == 0 {
return ResultSubmitBlocks{
BaseResult: BaseResult{
Code: StatusError,
Message: "failed to submit blocks: oversized block: " + ErrBlobSizeOverLimit.Error(),
Message: "failed to submit blocks: no blobs generated " + message,
},
}
}
Comment thread
ThanhNhann marked this conversation as resolved.

ctx, cancel := context.WithTimeout(ctx, dac.SubmitTimeout)
defer cancel()
ids, err := dac.DA.Submit(ctx, blobs, gasPrice, dac.Namespace)
Expand Down Expand Up @@ -186,7 +186,7 @@ func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block, ma
BaseResult: BaseResult{
Code: StatusSuccess,
DAHeight: binary.LittleEndian.Uint64(ids[0]),
SubmittedCount: submitted,
SubmittedCount: uint64(len(ids)),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion da/da_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func doTestSubmitOversizedBlock(t *testing.T, dalc *DAClient) {
oversizedBlock := types.GetRandomBlock(1, int(limit))
resp := dalc.SubmitBlocks(ctx, []*types.Block{oversizedBlock}, limit, -1)
assert.Equal(StatusError, resp.Code, "oversized block should throw error")
assert.Contains(resp.Message, "failed to submit blocks: oversized block: blob: over size limit")
assert.Contains(resp.Message, "failed to submit blocks: no blobs generated blob: over size limit")
}

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