Skip to content

Commit

Permalink
Export P-Chain Mempool Errors (#2535)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
  • Loading branch information
joshua-kim and StephenButtolph authored Dec 22, 2023
1 parent a4cfbc0 commit 7e5d1a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
24 changes: 12 additions & 12 deletions vms/platformvm/txs/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ 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")
errCantIssueAdvanceTimeTx = errors.New("can not issue an advance time tx")
errCantIssueRewardValidatorTx = errors.New("can not issue a reward validator 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")
ErrCantIssueAdvanceTimeTx = errors.New("can not issue an advance time tx")
ErrCantIssueRewardValidatorTx = errors.New("can not issue a reward validator tx")
)

type Mempool interface {
Expand Down Expand Up @@ -122,30 +122,30 @@ func (m *mempool) Add(tx *txs.Tx) error {

switch tx.Unsigned.(type) {
case *txs.AdvanceTimeTx:
return errCantIssueAdvanceTimeTx
return ErrCantIssueAdvanceTimeTx
case *txs.RewardValidatorTx:
return errCantIssueRewardValidatorTx
return ErrCantIssueRewardValidatorTx
default:
}

// Note: a previously dropped tx can be re-added
txID := tx.ID()
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 @@ -154,7 +154,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.unissuedTxs.Put(tx.ID(), tx)
Expand Down
3 changes: 1 addition & 2 deletions vms/platformvm/txs/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package mempool

import (
"errors"
"testing"
"time"

Expand Down Expand Up @@ -39,7 +38,7 @@ func TestBlockBuilderMaxMempoolSizeHandling(t *testing.T) {
mpool.(*mempool).bytesAvailable = len(tx.Bytes()) - 1

err = mpool.Add(tx)
require.True(errors.Is(err, errMempoolFull), err, "max mempool size breached")
require.ErrorIs(err, ErrMempoolFull)

// shortcut to simulated almost filled mempool
mpool.(*mempool).bytesAvailable = len(tx.Bytes())
Expand Down

0 comments on commit 7e5d1a2

Please sign in to comment.