Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export mempool errors #2531

Merged
merged 2 commits into from
Dec 21, 2023
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
16 changes: 8 additions & 8 deletions vms/avm/txs/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const (
var (
_ Mempool = (*mempool)(nil)

errDuplicateTx = errors.New("duplicate tx")
errTxTooLarge = errors.New("tx too large")
errMempoolFull = errors.New("mempool is full")
errConflictsWithOtherTx = errors.New("tx conflicts with other tx")
ErrDuplicateTx = errors.New("duplicate tx")
ErrTxTooLarge = errors.New("tx too large")
ErrMempoolFull = errors.New("mempool is full")
ErrConflictsWithOtherTx = errors.New("tx conflicts with other tx")
)

// Mempool contains transactions that have not yet been put into a block.
Expand Down Expand Up @@ -114,21 +114,21 @@ func (m *mempool) Add(tx *txs.Tx) error {
defer m.lock.Unlock()

if _, ok := m.unissuedTxs.Get(txID); ok {
return fmt.Errorf("%w: %s", errDuplicateTx, txID)
return fmt.Errorf("%w: %s", ErrDuplicateTx, txID)
}

txSize := len(tx.Bytes())
if txSize > MaxTxSize {
return fmt.Errorf("%w: %s size (%d) > max size (%d)",
errTxTooLarge,
ErrTxTooLarge,
txID,
txSize,
MaxTxSize,
)
}
if txSize > m.bytesAvailable {
return fmt.Errorf("%w: %s size (%d) > available space (%d)",
errMempoolFull,
ErrMempoolFull,
txID,
txSize,
m.bytesAvailable,
Expand All @@ -137,7 +137,7 @@ func (m *mempool) Add(tx *txs.Tx) error {

inputs := tx.Unsigned.InputIDs()
if m.consumedUTXOs.Overlaps(inputs) {
return fmt.Errorf("%w: %s", errConflictsWithOtherTx, txID)
return fmt.Errorf("%w: %s", ErrConflictsWithOtherTx, txID)
}

m.bytesAvailable -= txSize
Expand Down
8 changes: 4 additions & 4 deletions vms/avm/txs/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ func TestAdd(t *testing.T) {
name: "attempt adding duplicate tx",
initialTxs: []*txs.Tx{tx0},
tx: tx0,
err: errDuplicateTx,
err: ErrDuplicateTx,
},
{
name: "attempt adding too large tx",
initialTxs: nil,
tx: newTx(0, MaxTxSize+1),
err: errTxTooLarge,
err: ErrTxTooLarge,
},
{
name: "attempt adding tx when full",
initialTxs: newTxs(maxMempoolSize/MaxTxSize, MaxTxSize),
tx: newTx(maxMempoolSize/MaxTxSize, MaxTxSize),
err: errMempoolFull,
err: ErrMempoolFull,
},
{
name: "attempt adding conflicting tx",
initialTxs: []*txs.Tx{tx0},
tx: newTx(0, 32),
err: errConflictsWithOtherTx,
err: ErrConflictsWithOtherTx,
},
}
for _, test := range tests {
Expand Down
Loading