Skip to content

Commit

Permalink
Export mempool errors (#2531)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Dec 21, 2023
1 parent 3e45123 commit 9a63776
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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

0 comments on commit 9a63776

Please sign in to comment.