Skip to content

Commit

Permalink
da: handle tx too large (#1620)
Browse files Browse the repository at this point in the history
## 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 -->
  • Loading branch information
tuxcanfly committed Apr 5, 2024
1 parent 775b781 commit 39afa9f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion da/da.go
Expand Up @@ -43,6 +43,9 @@ var (
// ErrTxSizeTooBig is the error message returned by the DA when tx size is too big
ErrTxSizeTooBig = errors.New("tx size is too big")

//ErrTxTooLarge is the err message returned by the DA when tx size is too large
ErrTxTooLarge = errors.New("tx too large")

// ErrContextDeadline is the error message returned by the DA when context deadline exceeds
ErrContextDeadline = errors.New("context deadline")
)
Expand Down Expand Up @@ -160,7 +163,8 @@ func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block, ma
status = StatusAlreadyInMempool
case strings.Contains(err.Error(), ErrTxIncorrectAccountSequence.Error()):
status = StatusAlreadyInMempool
case strings.Contains(err.Error(), ErrTxSizeTooBig.Error()):
case strings.Contains(err.Error(), ErrTxSizeTooBig.Error()),
strings.Contains(err.Error(), ErrTxTooLarge.Error()):
status = StatusTooBig
case strings.Contains(err.Error(), ErrContextDeadline.Error()):
status = StatusContextDeadline
Expand Down
30 changes: 30 additions & 0 deletions da/da_test.go
Expand Up @@ -91,6 +91,23 @@ func TestMockDAErrors(t *testing.T) {
mockDA.On("MaxBlobSize").Return(uint64(0), errors.New("unable to get DA max blob size"))
doTestMaxBlockSizeError(t, dalc)
})
t.Run("tx_too_large", func(t *testing.T) {
mockDA := &mock.MockDA{}
dalc := NewDAClient(mockDA, -1, -1, nil, log.TestingLogger())
blocks := []*types.Block{types.GetRandomBlock(1, 0)}
var blobs []da.Blob
for _, block := range blocks {
blockBytes, err := block.MarshalBinary()
require.NoError(t, err)
blobs = append(blobs, blockBytes)
}
// Set up the mock to throw tx too large
mockDA.On("MaxBlobSize").Return(uint64(1234), nil)
mockDA.
On("Submit", blobs, float64(-1), []byte(nil)).
Return([]da.ID{}, errors.New("tx too large"))
doTestTxTooLargeError(t, dalc, blocks)
})
}

func TestSubmitRetrieve(t *testing.T) {
Expand Down Expand Up @@ -246,6 +263,19 @@ func doTestSubmitRetrieve(t *testing.T, dalc *DAClient) {
}
}

func doTestTxTooLargeError(t *testing.T, dalc *DAClient, blocks []*types.Block) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

maxBlobSize, err := dalc.DA.MaxBlobSize(ctx)
require.NoError(t, err)

assert := assert.New(t)
resp := dalc.SubmitBlocks(ctx, blocks, maxBlobSize, -1)
assert.Contains(resp.Message, "tx too large", "should return tx too large error")
assert.Equal(resp.Code, StatusTooBig)
}

func doTestSubmitEmptyBlocks(t *testing.T, dalc *DAClient) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit 39afa9f

Please sign in to comment.