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

Cleanup platformvm mempool errs #2278

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
30 changes: 19 additions & 11 deletions vms/platformvm/txs/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
)

const (
// targetTxSize is the maximum number of bytes a transaction can use to be
// MaxTxSize is the maximum number of bytes a transaction can use to be
// allowed into the mempool.
targetTxSize = 64 * units.KiB
MaxTxSize = 64 * units.KiB

// droppedTxIDsCacheSize is the maximum number of dropped txIDs to cache
droppedTxIDsCacheSize = 64
Expand All @@ -34,7 +34,10 @@ const (
var (
_ Mempool = (*mempool)(nil)

errMempoolFull = errors.New("mempool is full")
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")
)

type BlockTimer interface {
Expand Down Expand Up @@ -158,25 +161,30 @@ func (m *mempool) Add(tx *txs.Tx) error {
// Note: a previously dropped tx can be re-added
txID := tx.ID()
if m.Has(txID) {
return fmt.Errorf("duplicate tx %s", txID)
return fmt.Errorf("%w: %s", errDuplicateTx, txID)
}

txBytes := tx.Bytes()
if len(txBytes) > targetTxSize {
return fmt.Errorf("tx %s size (%d) > target size (%d)", txID, len(txBytes), targetTxSize)
txSize := len(tx.Bytes())
if txSize > MaxTxSize {
return fmt.Errorf("%w: %s size (%d) > max size (%d)",
errTxTooLarge,
txID,
txSize,
MaxTxSize,
)
}
if len(txBytes) > m.bytesAvailable {
return fmt.Errorf("%w, tx %s size (%d) exceeds available space (%d)",
if txSize > m.bytesAvailable {
return fmt.Errorf("%w: %s size (%d) > available space (%d)",
errMempoolFull,
txID,
len(txBytes),
txSize,
m.bytesAvailable,
)
}

inputs := tx.Unsigned.InputIDs()
if m.consumedUTXOs.Overlaps(inputs) {
return fmt.Errorf("tx %s conflicts with a transaction in the mempool", txID)
return fmt.Errorf("%w: %s", errConflictsWithOtherTx, txID)
}

if err := tx.Unsigned.Visit(&issuer{
Expand Down
Loading