Skip to content

LLMQ: Bound InstantSend lock intake - #1939

Open
navidR wants to merge 1 commit into
firoorg:masterfrom
navidR:dev/navidr/bounded-instantsend-intake
Open

LLMQ: Bound InstantSend lock intake#1939
navidR wants to merge 1 commit into
firoorg:masterfrom
navidR:dev/navidr/bounded-instantsend-intake

Conversation

@navidR

@navidR navidR commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Bound InstantSend input vectors and the pending-lock queue, and process at most 32 locks per pass. Add boundary coverage for each admission and processing limit.

Upstream: Dash PR #7397 and Dash PR #3399.

Limit lock input vectors, bound the pending queue, and process at most 32 locks per pass. Add boundary regression tests.
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 59 minutes.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d671dbd-22d2-4422-83ef-9ad2470f2e89

📥 Commits

Reviewing files that changed from the base of the PR and between 4f0c771 and 9a5bdf1.

📒 Files selected for processing (4)
  • src/llmq/quorums_instantsend.cpp
  • src/llmq/quorums_instantsend.h
  • src/test/CMakeLists.txt
  • src/test/quorums_instantsend_tests.cpp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-30T15:02:14.640910Z 9a5bdf1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codeant-ai

codeant-ai Bot commented Aug 30, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 9a5bdf1 Aug 30, 2026 · 14:56 15:00

@codeant-ai

codeant-ai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Aug 30, 2026
@codeant-ai

codeant-ai Bot commented Aug 30, 2026

Copy link
Copy Markdown

User description

Bound InstantSend input vectors and the pending-lock queue, and process at most 32 locks per pass. Add boundary coverage for each admission and processing limit.


CodeAnt-AI Description

Bound InstantSend lock intake and processing

What Changed

  • Rejects InstantSend locks with more inputs than can fit in a valid block and penalizes the sending peer
  • Limits the pending InstantSend lock queue to 1,024 entries, dropping new locks when it is full
  • Processes at most 32 pending locks per pass instead of draining the entire queue
  • Reuses a recovered signature only when both the transaction and signature match the incoming lock
  • Adds regression coverage for input, queue, processing, and signature-matching limits

Impact

✅ Protection against oversized InstantSend messages
✅ Bounded InstantSend memory usage during lock bursts
✅ Fewer duplicate signature verifications

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Comment on lines +707 to +711
if (islock.inputs.size() > CInstantSendLock::MAX_INPUTS) {
LOCK(cs_main);
Misbehaving(pfrom->id, 100);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The limit is checked only after deserialization, so a peer can still make the parser allocate and process a network-sized input vector before rejection. [resource leak]

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/llmq/quorums_instantsend.cpp
**Line:** 707:711
**Comment:**
	*Resource Leak: The limit is checked only after deserialization, so a peer can still make the parser allocate and process a network-sized input vector before rejection.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +780 to +784
while (pend.size() < maxCount) {
auto it = pendingInstantSendLocks.begin();
pend.emplace(it->first, std::move(it->second));
pendingInstantSendLocks.erase(it);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Extracted locks are lost when InstantSend is disabled or quorum selection fails, because this partial drain never reinserts pend into pendingInstantSendLocks. [incomplete implementation]

Assessment: 🟠 Major · 🔁 Occurrence: Sometimes

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/llmq/quorums_instantsend.cpp
**Line:** 780:784
**Comment:**
	*Incomplete Implementation: Extracted locks are lost when InstantSend is disabled or quorum selection fails, because this partial drain never reinserts `pend` into `pendingInstantSendLocks`.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai

codeant-ai Bot commented Aug 30, 2026

Copy link
Copy Markdown

CodeAnt Nitpicks

1 code suggestion

1. pendingInstantSendLocks.size() is size_t, but %d expects int; this mismatched variadic argument type causes undefined behavior while logging a full queue.

Type error · src/llmq/quorums_instantsend.cpp:737-739

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a5bdf138b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +736 to +739
if (pendingInstantSendLocks.size() >= MAX_PENDING_INSTANTSEND_LOCKS) {
LogPrint("instantsend", "CInstantSendManager::%s -- pending islock queue full (%d), dropping islock=%s, peer=%d\n",
__func__, pendingInstantSendLocks.size(), hash.ToString(), pfrom->id);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reserve pending capacity across peers

A connected peer can fill this global first-come queue with distinct one-input locks because PreVerifyInstantSendLock does not authenticate the BLS signature; once it reaches 1024, valid locks from every other peer are dropped before verification. By continuously submitting BLS-valid but quorum-invalid signatures faster than the 32-item worker batches, an attacker can keep the queue full and suppress InstantSend lock intake, so the bound needs per-peer admission limits, fair eviction, or reserved capacity rather than an unconditional global drop.

AGENTS.md reference: AGENTS.md:L238-L245

Useful? React with 👍 / 👎.

Comment on lines +707 to +710
if (islock.inputs.size() > CInstantSendLock::MAX_INPUTS) {
LOCK(cs_main);
Misbehaving(pfrom->id, 100);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the input limit during deserialization

When an unauthenticated peer sends an ISLOCK whose CompactSize input count exceeds MAX_INPUTS, vRecv >> islock has already allocated and parsed the entire vector before this check runs. The generic vector deserializer accepts counts up to MAX_SIZE, so a maximum-sized network message can force allocation and parsing of hundreds of thousands of COutPoints before the peer is banned, leaving the intended intake bound ineffective; read and validate the count before resizing the vector.

AGENTS.md reference: AGENTS.md:L238-L245

Useful? React with 👍 / 👎.

Comment on lines +774 to +776
// Only process 32 locks at a time to avoid duplicate verification of recovered signatures which have been
// verified by CSigningManager in parallel.
const size_t maxCount = 32;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid scoring the same peer once per 32-lock batch

When one peer has more than 128 locks that fail verification because they are old enough not to match either active quorum set, this cap splits them across at least five invocations. The existing verification path applies Misbehaving(nodeId, 20) once per bad source per invocation, so the default score reaches 100 and disconnects the peer; before this change the entire pending set produced only one 20-point penalty. This contradicts the nearby intent to be lenient toward peers relaying old locks, so penalties need to be deduplicated across a queue drain or entries need to be batched by source.

AGENTS.md reference: AGENTS.md:L238-L245

Useful? React with 👍 / 👎.

@reubenyap reubenyap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the intake limit, queue boundary and draining behavior, recovered-signature shortcut, callers, and boundary coverage. The 32-item passes continue draining safely and the exact-signature check preserves verification semantics. CI is green; I found no additional actionable defects beyond the logging-format mismatch already raised in the discussion.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants