Skip to content

Commit 39afa9f

Browse files
authored
da: handle tx too large (#1620)
## Overview This PR updates the block submission loop to additionally handle `tx too large` error. ## Checklist - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [x] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced handling for transactions exceeding the maximum size limit. - **Bug Fixes** - Updated logic to correctly handle oversized transactions. - **Tests** - Added new test cases to verify the handling of transactions that are too large. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 775b781 commit 39afa9f

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

da/da.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var (
4343
// ErrTxSizeTooBig is the error message returned by the DA when tx size is too big
4444
ErrTxSizeTooBig = errors.New("tx size is too big")
4545

46+
//ErrTxTooLarge is the err message returned by the DA when tx size is too large
47+
ErrTxTooLarge = errors.New("tx too large")
48+
4649
// ErrContextDeadline is the error message returned by the DA when context deadline exceeds
4750
ErrContextDeadline = errors.New("context deadline")
4851
)
@@ -160,7 +163,8 @@ func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block, ma
160163
status = StatusAlreadyInMempool
161164
case strings.Contains(err.Error(), ErrTxIncorrectAccountSequence.Error()):
162165
status = StatusAlreadyInMempool
163-
case strings.Contains(err.Error(), ErrTxSizeTooBig.Error()):
166+
case strings.Contains(err.Error(), ErrTxSizeTooBig.Error()),
167+
strings.Contains(err.Error(), ErrTxTooLarge.Error()):
164168
status = StatusTooBig
165169
case strings.Contains(err.Error(), ErrContextDeadline.Error()):
166170
status = StatusContextDeadline

da/da_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ func TestMockDAErrors(t *testing.T) {
9191
mockDA.On("MaxBlobSize").Return(uint64(0), errors.New("unable to get DA max blob size"))
9292
doTestMaxBlockSizeError(t, dalc)
9393
})
94+
t.Run("tx_too_large", func(t *testing.T) {
95+
mockDA := &mock.MockDA{}
96+
dalc := NewDAClient(mockDA, -1, -1, nil, log.TestingLogger())
97+
blocks := []*types.Block{types.GetRandomBlock(1, 0)}
98+
var blobs []da.Blob
99+
for _, block := range blocks {
100+
blockBytes, err := block.MarshalBinary()
101+
require.NoError(t, err)
102+
blobs = append(blobs, blockBytes)
103+
}
104+
// Set up the mock to throw tx too large
105+
mockDA.On("MaxBlobSize").Return(uint64(1234), nil)
106+
mockDA.
107+
On("Submit", blobs, float64(-1), []byte(nil)).
108+
Return([]da.ID{}, errors.New("tx too large"))
109+
doTestTxTooLargeError(t, dalc, blocks)
110+
})
94111
}
95112

96113
func TestSubmitRetrieve(t *testing.T) {
@@ -246,6 +263,19 @@ func doTestSubmitRetrieve(t *testing.T, dalc *DAClient) {
246263
}
247264
}
248265

266+
func doTestTxTooLargeError(t *testing.T, dalc *DAClient, blocks []*types.Block) {
267+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
268+
defer cancel()
269+
270+
maxBlobSize, err := dalc.DA.MaxBlobSize(ctx)
271+
require.NoError(t, err)
272+
273+
assert := assert.New(t)
274+
resp := dalc.SubmitBlocks(ctx, blocks, maxBlobSize, -1)
275+
assert.Contains(resp.Message, "tx too large", "should return tx too large error")
276+
assert.Equal(resp.Code, StatusTooBig)
277+
}
278+
249279
func doTestSubmitEmptyBlocks(t *testing.T, dalc *DAClient) {
250280
ctx, cancel := context.WithCancel(context.Background())
251281
defer cancel()

0 commit comments

Comments
 (0)