Skip to content

fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS - #5955

Open
JayT106 wants to merge 38 commits into
cometbft:mainfrom
JayT106:fix/lp2p-priority-queue-dos-backpressure
Open

JayT106 wants to merge 38 commits into
cometbft:mainfrom
JayT106:fix/lp2p-priority-queue-dos-backpressure

Conversation

@JayT106

@JayT106 JayT106 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The lp2p handleStream path closes the stream before enqueuing the decoded message. libp2p connection/stream limits therefore provide no backpressure: if a reactor's Receive is slow (e.g. mempool under load), the priority queue grows without bound until OOM.

Fix

  • Cap each reactor's priority queue via a new max_queue_size config field (default 200,000 — large enough for normal traffic, bounded enough to prevent OOM).
  • Once full, evict the oldest lower-priority item instead of rejecting the new one, so a burst of low-priority traffic can't starve out higher-priority messages.
  • Configurable globally via p2p.libp2p.scaler.max_queue_size and per-reactor via overrides[].max_queue_size. 0 = unlimited.
  • Preserve an unset override's max_queue_size across a config write/reload round-trip, so it stays "inherit the global cap" instead of collapsing to an explicit 0 (unbounded).
  • Count evicted messages in the p2p_messages_reactor_dropped metric, not just outright rejections, and log drops at Error level.

PR checklist

  • Tests written/updated
  • Changelog entry added in CHANGELOG.md
  • Updated relevant documentation (docs/ or spec/) and code comments

…n DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
@JayT106
JayT106 requested a review from a team as a code owner July 3, 2026 02:29
Comment thread lp2p/reactor_set.go Resolved
JayT106 and others added 10 commits July 7, 2026 11:40
512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.
…test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.
max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.
Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.
max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.
@dhfang

dhfang commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@greptile review

@greptile-apps

greptile-apps Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR caps each lp2p reactor's priority queue with a configurable max_queue_size (default 200 000) to prevent memory-exhaustion DoS in the handleStream path, where libp2p's stream limits provided no backpressure. When the cap is hit, a higher-priority incoming message evicts the oldest lower-priority item instead of being rejected outright, so low-priority bursts can't starve high-priority traffic; same-or-lower priority messages return ErrQueueFull.

  • internal/autopool/queue.go: Adds maxSize/size counters and an optional onEvict callback to PriorityQueue; evictLowerPriority scans from the lowest occupied level upward.
  • lp2p/reactor_set.go: Reads the per-reactor cap from config (nil override = inherit global; *0 = explicitly unbounded), wires the onEvict callback to update MessagesReactorInFlight/MessagesReactorDropped metrics, and adds a missing return that silently swallowed drop errors in the original code.
  • config/config.go + config/toml.go: Exposes max_queue_size globally and as a nullable *int override; the nullable pointer correctly distinguishes "inherit global" (nil) from "explicitly unbounded" (*0) across config write/reload round-trips.

Confidence Score: 5/5

Safe to merge. The queue cap, eviction logic, metrics wiring, and config round-trip all behave correctly, and the changes are covered by targeted unit and integration tests.

The bounded-queue invariants (size counter, highestNonEmptyLevel tracking, lock ordering PQ.mu → Queue.mu) are all correctly maintained through Push, Pop, and eviction. The config round-trip for the nullable *int override field is handled correctly in both the Go template (non-nil pointer is truthy, so &0 emits max_queue_size = 0) and mapstructure (absent key → nil, present 0 → &0). The previously missing return after push failure is now fixed. Test coverage is comprehensive across the queue, pool, and reactor-set layers.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
internal/autopool/queue.go Adds bounded PriorityQueue with eviction. Logic is correct: size counter and highestNonEmptyLevel are always consistent under PQ.mu, and lock ordering (PQ.mu → Queue.mu) is uniform across Push/Pop/evictLowerPriority.
lp2p/reactor_set.go Correctly reads cap from config, wires onEvict callback for metrics, and fixes the pre-existing missing return after push failure. findScalerOverride refactor unifies override lookup across scaler and queue-cap resolution.
config/config.go Adds MaxQueueSize int to LibP2PScaler and *int to LibP2PScalerOverride; ValidateBasic correctly rejects negatives; DefaultLibP2PScaler sets MEMPOOL override to explicit &200_000 so the value round-trips through TOML correctly.
config/toml.go Adds DerefIntOrZero template helper and {{- if .MaxQueueSize }} guard. Go templates evaluate *int truthiness as !IsNil(), so a non-nil *0 is truthy — correctly emitting max_queue_size = 0 for explicitly-unbounded overrides while omitting the line for nil (inherit-global) overrides.
internal/autopool/queue_test.go New tests cover the bounded queue, the eviction path, and the same-priority rejection case. Tests access the unexported size field within the same package, which is appropriate.
lp2p/reactor_set_test.go Three new integration tests validate: direct ErrQueueFull drops, nil-override inheritance of global cap, and *0-override explicit unbounded behavior. Each test sends enough messages to exceed the combined PQ + inbound-channel buffer depth.
p2p/metrics.go Adds MessagesReactorDropped counter with matching message_type and reactor labels; metrics.gen.go updated consistently.
internal/autopool/pool_test.go PushPriorityDropsWhenFull end-to-end test verifies ErrQueueFull is returned at the Pool layer when the PriorityQueue cap is exhausted and consumers are blocked.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Incoming message via handleStream] --> B[reactorSet.Receive]
    B --> C[Increment MessagesReactorInFlight]
    C --> D[Pool.PushPriority to PriorityQueue.Push]
    D --> E{maxSize > 0 AND size >= maxSize?}
    E -- No --> F[Enqueue message, size++]
    E -- Yes --> G{evictLowerPriority: any item at lower priority?}
    G -- Yes: item X evicted --> H[onEvict callback for X]
    H --> H1[Decrement InFlight for X]
    H --> H2[Increment MessagesReactorDropped for X]
    H --> F
    G -- No --> I[Return ErrQueueFull]
    I --> J[Decrement InFlight for new msg]
    J --> K[Increment MessagesReactorDropped]
    K --> L[Log Error: Reactor queue full]
    F --> M[pipePriorityQueueRoutine pops from PQ]
    M --> N[Send to inbound channel cap=512]
    N --> O[Worker calls receiveQueued]
    O --> P[reactor.Receive processes message]
    P --> Q[Decrement InFlight for msg]
Loading

Reviews (3): Last reviewed commit: "remove comments" | Re-trigger Greptile

Comment thread lp2p/reactor_set.go Resolved
Comment thread lp2p/reactor_set.go Resolved
JayT106 and others added 3 commits July 13, 2026 10:46
Match newReactorScaler's semantics: once a reactor name matches an
override, apply it wholesale instead of only when MaxQueueSize > 0.
The prior guard meant an override with an explicit max_queue_size = 0
("unlimited") was silently ignored in favor of the global default,
and there was no way to make one reactor unbounded while keeping
others capped.

This requires the default MEMPOOL override to set MaxQueueSize
explicitly (200_000) — otherwise it would silently inherit the zero
value and become unbounded, defeating the DoS fix for the reactor
most likely to be flooded.

Also downgrade the unbounded-queue log from Error to Info: it is an
intentional configuration choice, not a runtime failure, and Error
would pollute alert dashboards that key on error-level logs.
…ssure' into fix/lp2p-priority-queue-dos-backpressure
@dhfang

dhfang commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@greptile re-review

Comment thread config/toml.go Resolved
Comment thread lp2p/reactor_set.go Resolved
Comment thread lp2p/reactor_set.go Resolved
Comment thread lp2p/reactor_set_test.go Resolved
JayT106 and others added 4 commits July 14, 2026 13:13
- Drop the unbounded-queue Info log and its "0 means unbounded" comment
  in newReactorPriorityQueue — noise flagged in review, not needed since
  ValidateBasic already rejects negative values and 0/unbounded is a
  deliberate config choice.
- Simplify the config.toml max_queue_size comment to "zero means unlimited".
- Rename receive_drops_when_queue_full test to camelCase.
viper/mapstructure decodes scaler.overrides positionally against the
default Overrides slice. Any override entry beyond the default's
length (or missing the new max_queue_size field) decodes that field
to its Go zero value, silently reopening the unbounded-queue DoS this
cap exists to close.
…t from explicit-unbounded

int zero value couldn't tell "config predates this field" (mapstructure
decodes a positionally-missing override to zero) apart from an operator
deliberately setting max_queue_size = 0 for one reactor. The former
must inherit the global cap; the latter must stay unbounded, per the
intent of 3379b9c (apply override unconditionally). *int lets nil
mean "inherit" and *0 mean "explicitly unbounded", so both cases now
behave correctly.
JayT106 added a commit to JayT106/cometbft that referenced this pull request Jul 14, 2026
…t from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.
thomas-nguy pushed a commit to crypto-org-chain/cometbft that referenced this pull request Jul 16, 2026
…n DoS (#53)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
(cherry picked from commit 4894956)

* chore: add CHANGELOG entry for cometbft#5955

(cherry picked from commit f14ca91)

* chore: fix CHANGELOG entry wording for cometbft#5955

(cherry picked from commit 8494170)

* fix(lp2p): raise priority queue cap to 200k and make it configurable

512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.

(cherry picked from commit d7d0c4e)

* refactor(lp2p): simplify scaler config access and fix flood count in test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.

(cherry picked from commit 51f7dea)

* fix(config): expose max_queue_size in config.toml template

max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.

(cherry picked from commit 1e85cb6)

* chore(config): move MaxQueueSize field comments to toml.go

Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.

(cherry picked from commit 86115a2)

* chore(lp2p): restore original concurrentPoolCapacity comment

(cherry picked from commit c897ca8)

* chore(config): mention default max_queue_size in toml comment

(cherry picked from commit 04707e9)

* fix(lp2p): log error when priority queue is unbounded

max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.

(cherry picked from commit db36a5b)

* chore(config): use 200000 as example max_queue_size in toml comment

(cherry picked from commit e231e50)

* fix(config): make override MaxQueueSize a pointer to distinguish unset from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.

* docs(config): trim LibP2PScalerOverride comment

* fix(autopool): evict lower-priority item instead of rejecting on full priority queue

PriorityQueue.Push capped total depth across all priority levels and
rejected any push once full, regardless of the incoming message's
priority. A burst of low-priority traffic could fill the queue and
then starve out higher-priority admissions.

Push now evicts the oldest strictly-lower-priority item to make room
for a higher-priority one. ErrQueueFull is only returned when no
lower-priority item is queued to evict.

* chore(autopool): trim eviction comments to one line each

* fix(config): preserve unset override max_queue_size across toml write and reload

Rendering an unset override MaxQueueSize as literal 0 in config.toml made it
indistinguishable from an explicit unbounded override. Regenerating the file
(e.g. via `cometbft testnet --config`) silently turned "inherit the global
cap" into "no cap", reopening the queue-exhaustion DoS.

Also move the lp2p changelog entry to the top of BUG FIXES per convention.

* fix(lp2p): count evicted messages in reactor metrics

Push() evicting a lower-priority item to make room silently dropped it:
MessagesReactorInFlight was never decremented and MessagesReactorDropped
never counted it, so eviction-based drops were invisible to metrics. Add
an onEvict callback to PriorityQueue and wire it up in the reactor pool so
evicted messages update both metrics with the evicted message's own
labels.

Also extract the duplicated case-insensitive reactor-override lookup into
a shared helper.

* remove comments

---------

Signed-off-by: JayT106 <[email protected]>
@dhfang

dhfang commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@greptile re-review

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days-before-close if no further activity occurs.

…loads inherit the global cap

Add tests for max_queue_size validation, toml round-trip and WithOnEvict.
Consolidate queue-full subtests into a deterministic table; drop the
DerefIntOrZero template helper and document override/onEvict semantics.
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Oct 19, 2026
max_queue_size counts messages, so reactors carrying multi-MB payloads can
exhaust memory long before the count trips. Add max_queue_bytes (default
200MB) next to it; Push evicts lower-priority items until both bounds fit.

Ported from 2dc0508. Its override-default fix and unbounded-queue log are
dropped: upstream cometbft#5955 already has the first and removed the second in review.
…ue-dos-backpressure

# Conflicts:
#	CHANGELOG.md
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Oct 30, 2026
…n DoS (#53)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
(cherry picked from commit 4894956)

* chore: add CHANGELOG entry for cometbft#5955

(cherry picked from commit f14ca91)

* chore: fix CHANGELOG entry wording for cometbft#5955

(cherry picked from commit 8494170)

* fix(lp2p): raise priority queue cap to 200k and make it configurable

512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.

(cherry picked from commit d7d0c4e)

* refactor(lp2p): simplify scaler config access and fix flood count in test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.

(cherry picked from commit 51f7dea)

* fix(config): expose max_queue_size in config.toml template

max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.

(cherry picked from commit 1e85cb6)

* chore(config): move MaxQueueSize field comments to toml.go

Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.

(cherry picked from commit 86115a2)

* chore(lp2p): restore original concurrentPoolCapacity comment

(cherry picked from commit c897ca8)

* chore(config): mention default max_queue_size in toml comment

(cherry picked from commit 04707e9)

* fix(lp2p): log error when priority queue is unbounded

max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.

(cherry picked from commit db36a5b)

* chore(config): use 200000 as example max_queue_size in toml comment

(cherry picked from commit e231e50)

* fix(config): make override MaxQueueSize a pointer to distinguish unset from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.

* docs(config): trim LibP2PScalerOverride comment

* fix(autopool): evict lower-priority item instead of rejecting on full priority queue

PriorityQueue.Push capped total depth across all priority levels and
rejected any push once full, regardless of the incoming message's
priority. A burst of low-priority traffic could fill the queue and
then starve out higher-priority admissions.

Push now evicts the oldest strictly-lower-priority item to make room
for a higher-priority one. ErrQueueFull is only returned when no
lower-priority item is queued to evict.

* chore(autopool): trim eviction comments to one line each

* fix(config): preserve unset override max_queue_size across toml write and reload

Rendering an unset override MaxQueueSize as literal 0 in config.toml made it
indistinguishable from an explicit unbounded override. Regenerating the file
(e.g. via `cometbft testnet --config`) silently turned "inherit the global
cap" into "no cap", reopening the queue-exhaustion DoS.

Also move the lp2p changelog entry to the top of BUG FIXES per convention.

* fix(lp2p): count evicted messages in reactor metrics

Push() evicting a lower-priority item to make room silently dropped it:
MessagesReactorInFlight was never decremented and MessagesReactorDropped
never counted it, so eviction-based drops were invisible to metrics. Add
an onEvict callback to PriorityQueue and wire it up in the reactor pool so
evicted messages update both metrics with the evicted message's own
labels.

Also extract the duplicated case-insensitive reactor-override lookup into
a shared helper.

* remove comments

---------

Signed-off-by: JayT106 <[email protected]>
(cherry picked from commit 76b16e0)
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Oct 30, 2026
Aligns the #53 port with upstream PR head b525c51: the default MEMPOOL
override inherits the global max_queue_size, plus upstream's config and
lp2p tests.
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Oct 30, 2026
…n DoS (#53)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
(cherry picked from commit 4894956)

* chore: add CHANGELOG entry for cometbft#5955

(cherry picked from commit f14ca91)

* chore: fix CHANGELOG entry wording for cometbft#5955

(cherry picked from commit 8494170)

* fix(lp2p): raise priority queue cap to 200k and make it configurable

512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.

(cherry picked from commit d7d0c4e)

* refactor(lp2p): simplify scaler config access and fix flood count in test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.

(cherry picked from commit 51f7dea)

* fix(config): expose max_queue_size in config.toml template

max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.

(cherry picked from commit 1e85cb6)

* chore(config): move MaxQueueSize field comments to toml.go

Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.

(cherry picked from commit 86115a2)

* chore(lp2p): restore original concurrentPoolCapacity comment

(cherry picked from commit c897ca8)

* chore(config): mention default max_queue_size in toml comment

(cherry picked from commit 04707e9)

* fix(lp2p): log error when priority queue is unbounded

max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.

(cherry picked from commit db36a5b)

* chore(config): use 200000 as example max_queue_size in toml comment

(cherry picked from commit e231e50)

* fix(config): make override MaxQueueSize a pointer to distinguish unset from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.

* docs(config): trim LibP2PScalerOverride comment

* fix(autopool): evict lower-priority item instead of rejecting on full priority queue

PriorityQueue.Push capped total depth across all priority levels and
rejected any push once full, regardless of the incoming message's
priority. A burst of low-priority traffic could fill the queue and
then starve out higher-priority admissions.

Push now evicts the oldest strictly-lower-priority item to make room
for a higher-priority one. ErrQueueFull is only returned when no
lower-priority item is queued to evict.

* chore(autopool): trim eviction comments to one line each

* fix(config): preserve unset override max_queue_size across toml write and reload

Rendering an unset override MaxQueueSize as literal 0 in config.toml made it
indistinguishable from an explicit unbounded override. Regenerating the file
(e.g. via `cometbft testnet --config`) silently turned "inherit the global
cap" into "no cap", reopening the queue-exhaustion DoS.

Also move the lp2p changelog entry to the top of BUG FIXES per convention.

* fix(lp2p): count evicted messages in reactor metrics

Push() evicting a lower-priority item to make room silently dropped it:
MessagesReactorInFlight was never decremented and MessagesReactorDropped
never counted it, so eviction-based drops were invisible to metrics. Add
an onEvict callback to PriorityQueue and wire it up in the reactor pool so
evicted messages update both metrics with the evicted message's own
labels.

Also extract the duplicated case-insensitive reactor-override lookup into
a shared helper.

* remove comments

---------

Signed-off-by: JayT106 <[email protected]>
(cherry picked from commit 76b16e0)
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Oct 30, 2026
Aligns the #53 port with upstream PR head b525c51: the default MEMPOOL
override inherits the global max_queue_size, plus upstream's config and
lp2p tests.
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Nov 2, 2026
…n DoS (#53)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
(cherry picked from commit 4894956)

* chore: add CHANGELOG entry for cometbft#5955

(cherry picked from commit f14ca91)

* chore: fix CHANGELOG entry wording for cometbft#5955

(cherry picked from commit 8494170)

* fix(lp2p): raise priority queue cap to 200k and make it configurable

512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.

(cherry picked from commit d7d0c4e)

* refactor(lp2p): simplify scaler config access and fix flood count in test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.

(cherry picked from commit 51f7dea)

* fix(config): expose max_queue_size in config.toml template

max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.

(cherry picked from commit 1e85cb6)

* chore(config): move MaxQueueSize field comments to toml.go

Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.

(cherry picked from commit 86115a2)

* chore(lp2p): restore original concurrentPoolCapacity comment

(cherry picked from commit c897ca8)

* chore(config): mention default max_queue_size in toml comment

(cherry picked from commit 04707e9)

* fix(lp2p): log error when priority queue is unbounded

max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.

(cherry picked from commit db36a5b)

* chore(config): use 200000 as example max_queue_size in toml comment

(cherry picked from commit e231e50)

* fix(config): make override MaxQueueSize a pointer to distinguish unset from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.

* docs(config): trim LibP2PScalerOverride comment

* fix(autopool): evict lower-priority item instead of rejecting on full priority queue

PriorityQueue.Push capped total depth across all priority levels and
rejected any push once full, regardless of the incoming message's
priority. A burst of low-priority traffic could fill the queue and
then starve out higher-priority admissions.

Push now evicts the oldest strictly-lower-priority item to make room
for a higher-priority one. ErrQueueFull is only returned when no
lower-priority item is queued to evict.

* chore(autopool): trim eviction comments to one line each

* fix(config): preserve unset override max_queue_size across toml write and reload

Rendering an unset override MaxQueueSize as literal 0 in config.toml made it
indistinguishable from an explicit unbounded override. Regenerating the file
(e.g. via `cometbft testnet --config`) silently turned "inherit the global
cap" into "no cap", reopening the queue-exhaustion DoS.

Also move the lp2p changelog entry to the top of BUG FIXES per convention.

* fix(lp2p): count evicted messages in reactor metrics

Push() evicting a lower-priority item to make room silently dropped it:
MessagesReactorInFlight was never decremented and MessagesReactorDropped
never counted it, so eviction-based drops were invisible to metrics. Add
an onEvict callback to PriorityQueue and wire it up in the reactor pool so
evicted messages update both metrics with the evicted message's own
labels.

Also extract the duplicated case-insensitive reactor-override lookup into
a shared helper.

* remove comments

---------

Signed-off-by: JayT106 <[email protected]>

Port note (v0.40.0): synced to upstream cometbft#5955 head
(override inheritance, negative-value validation, eviction). Also folds in
the v0.40 review follow-ups: queue-full drops logged at Debug since peers
can trigger them, shared drop-metric helpers, tests pinning the default cap
and its inheritance, and an unbounded queue for the maxed-out lp2p bench.

(cherry picked from commit 76b16e0)
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Nov 4, 2026
…n DoS (#53)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
(cherry picked from commit 4894956)

* chore: add CHANGELOG entry for cometbft#5955

(cherry picked from commit f14ca91)

* chore: fix CHANGELOG entry wording for cometbft#5955

(cherry picked from commit 8494170)

* fix(lp2p): raise priority queue cap to 200k and make it configurable

512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.

(cherry picked from commit d7d0c4e)

* refactor(lp2p): simplify scaler config access and fix flood count in test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.

(cherry picked from commit 51f7dea)

* fix(config): expose max_queue_size in config.toml template

max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.

(cherry picked from commit 1e85cb6)

* chore(config): move MaxQueueSize field comments to toml.go

Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.

(cherry picked from commit 86115a2)

* chore(lp2p): restore original concurrentPoolCapacity comment

(cherry picked from commit c897ca8)

* chore(config): mention default max_queue_size in toml comment

(cherry picked from commit 04707e9)

* fix(lp2p): log error when priority queue is unbounded

max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.

(cherry picked from commit db36a5b)

* chore(config): use 200000 as example max_queue_size in toml comment

(cherry picked from commit e231e50)

* fix(config): make override MaxQueueSize a pointer to distinguish unset from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.

* docs(config): trim LibP2PScalerOverride comment

* fix(autopool): evict lower-priority item instead of rejecting on full priority queue

PriorityQueue.Push capped total depth across all priority levels and
rejected any push once full, regardless of the incoming message's
priority. A burst of low-priority traffic could fill the queue and
then starve out higher-priority admissions.

Push now evicts the oldest strictly-lower-priority item to make room
for a higher-priority one. ErrQueueFull is only returned when no
lower-priority item is queued to evict.

* chore(autopool): trim eviction comments to one line each

* fix(config): preserve unset override max_queue_size across toml write and reload

Rendering an unset override MaxQueueSize as literal 0 in config.toml made it
indistinguishable from an explicit unbounded override. Regenerating the file
(e.g. via `cometbft testnet --config`) silently turned "inherit the global
cap" into "no cap", reopening the queue-exhaustion DoS.

Also move the lp2p changelog entry to the top of BUG FIXES per convention.

* fix(lp2p): count evicted messages in reactor metrics

Push() evicting a lower-priority item to make room silently dropped it:
MessagesReactorInFlight was never decremented and MessagesReactorDropped
never counted it, so eviction-based drops were invisible to metrics. Add
an onEvict callback to PriorityQueue and wire it up in the reactor pool so
evicted messages update both metrics with the evicted message's own
labels.

Also extract the duplicated case-insensitive reactor-override lookup into
a shared helper.

* remove comments

---------

Signed-off-by: JayT106 <[email protected]>

Port note (v0.40.0): synced to upstream cometbft#5955 head
(override inheritance, negative-value validation, eviction). Also folds in
the v0.40 review follow-ups: queue-full drops logged at Debug since peers
can trigger them, shared drop-metric helpers, tests pinning the default cap
and its inheritance, and an unbounded queue for the maxed-out lp2p bench.

(cherry picked from commit 76b16e0)
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Nov 5, 2026
…n DoS (#53)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
(cherry picked from commit 4894956)

* chore: add CHANGELOG entry for cometbft#5955

(cherry picked from commit f14ca91)

* chore: fix CHANGELOG entry wording for cometbft#5955

(cherry picked from commit 8494170)

* fix(lp2p): raise priority queue cap to 200k and make it configurable

512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.

(cherry picked from commit d7d0c4e)

* refactor(lp2p): simplify scaler config access and fix flood count in test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.

(cherry picked from commit 51f7dea)

* fix(config): expose max_queue_size in config.toml template

max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.

(cherry picked from commit 1e85cb6)

* chore(config): move MaxQueueSize field comments to toml.go

Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.

(cherry picked from commit 86115a2)

* chore(lp2p): restore original concurrentPoolCapacity comment

(cherry picked from commit c897ca8)

* chore(config): mention default max_queue_size in toml comment

(cherry picked from commit 04707e9)

* fix(lp2p): log error when priority queue is unbounded

max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.

(cherry picked from commit db36a5b)

* chore(config): use 200000 as example max_queue_size in toml comment

(cherry picked from commit e231e50)

* fix(config): make override MaxQueueSize a pointer to distinguish unset from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.

* docs(config): trim LibP2PScalerOverride comment

* fix(autopool): evict lower-priority item instead of rejecting on full priority queue

PriorityQueue.Push capped total depth across all priority levels and
rejected any push once full, regardless of the incoming message's
priority. A burst of low-priority traffic could fill the queue and
then starve out higher-priority admissions.

Push now evicts the oldest strictly-lower-priority item to make room
for a higher-priority one. ErrQueueFull is only returned when no
lower-priority item is queued to evict.

* chore(autopool): trim eviction comments to one line each

* fix(config): preserve unset override max_queue_size across toml write and reload

Rendering an unset override MaxQueueSize as literal 0 in config.toml made it
indistinguishable from an explicit unbounded override. Regenerating the file
(e.g. via `cometbft testnet --config`) silently turned "inherit the global
cap" into "no cap", reopening the queue-exhaustion DoS.

Also move the lp2p changelog entry to the top of BUG FIXES per convention.

* fix(lp2p): count evicted messages in reactor metrics

Push() evicting a lower-priority item to make room silently dropped it:
MessagesReactorInFlight was never decremented and MessagesReactorDropped
never counted it, so eviction-based drops were invisible to metrics. Add
an onEvict callback to PriorityQueue and wire it up in the reactor pool so
evicted messages update both metrics with the evicted message's own
labels.

Also extract the duplicated case-insensitive reactor-override lookup into
a shared helper.

* remove comments

---------

Signed-off-by: JayT106 <[email protected]>

Port note (v0.40.0): synced to upstream cometbft#5955 head
(override inheritance, negative-value validation, eviction). Also folds in
the v0.40 review follow-ups: queue-full drops logged at Debug since peers
can trigger them, shared drop-metric helpers, tests pinning the default cap
and its inheritance, and an unbounded queue for the maxed-out lp2p bench.

(cherry picked from commit 76b16e0)
JayT106 added a commit to crypto-org-chain/cometbft that referenced this pull request Nov 5, 2026
* fix(mempool): AppMempool ABCI response handling, callback/cleanup, and lifecycle (#51)

* fix(mempool): AppMempool ABCI response handling, callback/cleanup, and lifecycle

* fix(mempool): don't clear seen cache on nil CheckTx response

* update ResponseCheckTx code

Port note (v0.40.0): also folds in the v0.40 review follow-ups: CHANGELOG
entry for upstream cometbft#5942, nil CheckTx response handled through the
client-error path, tests for nil ReapTxs, CheckTx internal code and the
seen cache, and stale comment fixes. The node, which owns the mempool, now
closes the AppMempool seen-cache guard in its OnStop instead of the reactor.

(cherry picked from commit 524b896)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS (#53)

* fix(lp2p): cap per-reactor priority queue to prevent memory-exhaustion DoS

The lp2p handleStream path reads and closes the libp2p stream before
enqueueing the decoded message. Stream and connection limits therefore
provide no backpressure against a fast peer: a slow reactor (e.g.
mempool under load) lets the priority queue grow without bound until
OOM.

Fix: add an optional maxSize cap to PriorityQueue. When the limit is
reached, Push returns ErrQueueFull and the message is dropped.
newReactorPriorityQueue now passes concurrentPoolCapacity (512) as
the cap, matching the downstream inbound channel — total per-reactor
buffer stays bounded at 1024 items before drops begin.

Drops are counted in a new p2p_messages_reactor_dropped metric and
logged at Error level so operators can detect a saturated reactor.

The autoscaler's queue-pressure signal still reads only len(inbound),
which remains correct; the priority queue is upstream pre-staging.

Fixes: unbounded per-reactor priority queue (lp2p memory-exhaustion DoS)
(cherry picked from commit 4894956)

* chore: add CHANGELOG entry for cometbft#5955

(cherry picked from commit f14ca91)

* chore: fix CHANGELOG entry wording for cometbft#5955

(cherry picked from commit 8494170)

* fix(lp2p): raise priority queue cap to 200k and make it configurable

512 was too small: normal mempool traffic from two peers (each sending
hundreds of txs) would fill the queue and drop messages before the
mempool's own deduplication cache could filter them.

Decouple the priority queue max from the pool inbound channel capacity
(which stays at 512). Add MaxQueueSize to LibP2PScaler and
LibP2PScalerOverride so operators can tune per-reactor; default is
200_000 (~200 MB at 1 KB/msg average), matching the budget noted in
review feedback.

0 means unbounded and is reserved for tests.

(cherry picked from commit d7d0c4e)

* refactor(lp2p): simplify scaler config access and fix flood count in test

Use a local scalerCfg alias in newReactorPriorityQueue to avoid
repeating the long access chain — consistent with newReactorScaler.

Raise the queue-full test flood count from 64 to 1000 so it reliably
exceeds the total buffer depth (~inbound cap 512 + workers + pq cap 16)
regardless of goroutine scheduling when run alongside other subtests.

(cherry picked from commit 51f7dea)

* fix(config): expose max_queue_size in config.toml template

max_queue_size was added to LibP2PScaler but missing from the TOML
template, so operators couldn't set it via config.toml.

(cherry picked from commit 1e85cb6)

* chore(config): move MaxQueueSize field comments to toml.go

Config struct fields don't need inline comments; the TOML template
is the right place for operator-facing documentation.

(cherry picked from commit 86115a2)

* chore(lp2p): restore original concurrentPoolCapacity comment

(cherry picked from commit c897ca8)

* chore(config): mention default max_queue_size in toml comment

(cherry picked from commit 04707e9)

* fix(lp2p): log error when priority queue is unbounded

max_queue_size = 0 disables the DoS cap silently. Emit an Error-level
log at reactor startup so operators are warned when the node is
vulnerable to memory-exhaustion from a fast peer.

(cherry picked from commit db36a5b)

* chore(config): use 200000 as example max_queue_size in toml comment

(cherry picked from commit e231e50)

* fix(config): make override MaxQueueSize a pointer to distinguish unset from explicit-unbounded

Backport of the fix from cometbft#5955's follow-up commits.
An override's MaxQueueSize as a plain int can't tell "not set in this
config" apart from "explicitly set to 0 for an unbounded reactor" -
both decode to the same zero value. Switching to *int lets nil mean
"inherit the global cap" while an explicit 0 stays a real choice.

* docs(config): trim LibP2PScalerOverride comment

* fix(autopool): evict lower-priority item instead of rejecting on full priority queue

PriorityQueue.Push capped total depth across all priority levels and
rejected any push once full, regardless of the incoming message's
priority. A burst of low-priority traffic could fill the queue and
then starve out higher-priority admissions.

Push now evicts the oldest strictly-lower-priority item to make room
for a higher-priority one. ErrQueueFull is only returned when no
lower-priority item is queued to evict.

* chore(autopool): trim eviction comments to one line each

* fix(config): preserve unset override max_queue_size across toml write and reload

Rendering an unset override MaxQueueSize as literal 0 in config.toml made it
indistinguishable from an explicit unbounded override. Regenerating the file
(e.g. via `cometbft testnet --config`) silently turned "inherit the global
cap" into "no cap", reopening the queue-exhaustion DoS.

Also move the lp2p changelog entry to the top of BUG FIXES per convention.

* fix(lp2p): count evicted messages in reactor metrics

Push() evicting a lower-priority item to make room silently dropped it:
MessagesReactorInFlight was never decremented and MessagesReactorDropped
never counted it, so eviction-based drops were invisible to metrics. Add
an onEvict callback to PriorityQueue and wire it up in the reactor pool so
evicted messages update both metrics with the evicted message's own
labels.

Also extract the duplicated case-insensitive reactor-override lookup into
a shared helper.

* remove comments

---------

Signed-off-by: JayT106 <[email protected]>

Port note (v0.40.0): synced to upstream cometbft#5955 head
(override inheritance, negative-value validation, eviction). Also folds in
the v0.40 review follow-ups: queue-full drops logged at Debug since peers
can trigger them, shared drop-metric helpers, tests pinning the default cap
and its inheritance, and an unbounded queue for the maxed-out lp2p bench.

(cherry picked from commit 76b16e0)

* ci: run e2e on ubuntu-latest and fix flaky PEX seed test (#64)

Ports the part of fork #64 ("chore: cherry-pick missing upstream v0.39.4
commits") that v0.40.0 still needs. Its upstream backports (cometbft#5813, cometbft#5668,
cometbft#5959) are already in v0.40.0.

- Run e2e-test on ubuntu-latest: the fork has no Depot runner, so
  depot-ubuntu-24.04-4 jobs queue until the 24h timeout.
- Tolerate an already-stopped peer in TestPEXReactorSeedModeFlushStop, since
  the seed may disconnect it first (v0.40 follow-up, not in fork #64).

(cherry picked from commit 14b7b93)

---------

Co-authored-by: songgaoye <[email protected]>
@JayT106

JayT106 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi team, any update! @dhfang @swift1337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants