Skip to content

Commit

Permalink
feat(mempool): add error ErrRecheckFull (backport #3654) (#3656)
Browse files Browse the repository at this point in the history
Complements #3314

This PR adds a new error with a more clear error message when checking
if the mempool is full while rechecking is in progress after a new block
was committed.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [ ] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request #3654 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Hernán Vanzetto <15466498+hvanz@users.noreply.github.com>
Co-authored-by: hvanz <hernan.vanzetto@gmail.com>
  • Loading branch information
3 people authored Aug 9, 2024
1 parent 9de925c commit f85d897
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,19 @@ func (mem *CListMempool) RemoveTxByKey(txKey types.TxKey) error {
func (mem *CListMempool) isFull(txSize int) error {
memSize := mem.Size()
txsBytes := mem.SizeBytes()
recheckFull := mem.recheck.consideredFull()

if memSize >= mem.config.Size || int64(txSize)+txsBytes > mem.config.MaxTxsBytes || recheckFull {
if memSize >= mem.config.Size || int64(txSize)+txsBytes > mem.config.MaxTxsBytes {
return ErrMempoolIsFull{
NumTxs: memSize,
MaxTxs: mem.config.Size,
TxsBytes: txsBytes,
MaxTxsBytes: mem.config.MaxTxsBytes,
RecheckFull: recheckFull,
}
}

if mem.recheck.consideredFull() {
return ErrRecheckFull
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions mempool/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var ErrTxNotFound = errors.New("transaction not found in mempool")
// ErrTxInCache is returned to the client if we saw tx earlier
var ErrTxInCache = errors.New("tx already exists in cache")

// ErrRecheckFull is returned when checking if the mempool is full and
// rechecking is still in progress after a new block was committed.
var ErrRecheckFull = errors.New("mempool is still rechecking after a new committed block, so it is considered as full")

// ErrTxTooLarge defines an error when a transaction is too big to be sent in a
// message to other peers.
type ErrTxTooLarge struct {
Expand Down

0 comments on commit f85d897

Please sign in to comment.