refactor: misc instantsend refactors#7135
Conversation
…ProcessPendingInstantSendLocks Materialize CBLSLazySignature::Get() into a local CBLSSignature once instead of calling it twice (for IsValid and PushMessage). Merge the separate badSources penalization loop and badMessages check into a single pass over pending locks, using a `penalized` set to deduplicate PeerMisbehaving calls.
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
WalkthroughThis pull request refactors the InstantSend system to introduce batch verification for ISLocks and enforce deterministic cycle height validation. The primary changes include: (1) a new Sequence Diagram(s)sequenceDiagram
participant Node
participant ProcessMessage as ProcessMessage<br/>(Handler)
participant Validator as ValidateIncoming<br/>ISLock
participant CycleResolver as ResolveCycle<br/>Height
participant DeterministicCheck as ValidateDeterministic<br/>CycleHeight
participant PendingQueue as Pending Queue
Node->>ProcessMessage: Receive ISLock Message
ProcessMessage->>Validator: ValidateIncomingISLock(islock, node_id)
alt Validation Fails
Validator-->>ProcessMessage: false (invalid)
ProcessMessage->>Node: Apply misbehavior score, return
else Validation Passes
Validator-->>ProcessMessage: true
end
ProcessMessage->>CycleResolver: ResolveCycleHeight(cycle_hash)
alt Height Not Found
CycleResolver-->>ProcessMessage: std::nullopt
ProcessMessage->>Node: Apply misbehavior score, return
else Height Resolved
CycleResolver-->>ProcessMessage: optional<int> height
end
ProcessMessage->>DeterministicCheck: ValidateDeterministicCycleHeight(height, llmq_params, node_id)
alt Deterministic Check Fails
DeterministicCheck-->>ProcessMessage: false
ProcessMessage->>Node: Apply misbehavior score, return
else Check Passes
DeterministicCheck-->>ProcessMessage: true
end
ProcessMessage->>PendingQueue: Enqueue ISLock if new
PendingQueue-->>ProcessMessage: Acknowledged
sequenceDiagram
participant WorkThread as WorkThread<br/>Main
participant BatchBuilder as BuildVerification<br/>Batch
participant BatchVerifier as CBLSBatch<br/>Verifier
participant ResultApplier as ApplyVerification<br/>Results
participant RecoveredSigs as Recovered Sigs<br/>(Cache)
participant Network as Network<br/>Propagation
WorkThread->>WorkThread: Dequeue pending ISLocks (vector<PendingISLockEntry>)
WorkThread->>BatchBuilder: BuildVerificationBatch(llmq_params, signOffset, pend)
BatchBuilder->>BatchBuilder: Extract recovered sigs from pend entries
BatchBuilder->>BatchVerifier: Add recovered sigs to batch
BatchBuilder->>BatchBuilder: Increment counters
BatchBuilder-->>WorkThread: unique_ptr<BatchVerificationData>
WorkThread->>BatchVerifier: Verify batch (async/internal)
BatchVerifier-->>WorkThread: Verification complete
WorkThread->>ResultApplier: ApplyVerificationResults(llmq_params, ban, data, pend)
ResultApplier->>ResultApplier: Iterate verification results
alt Signature Verification Fails
ResultApplier->>ResultApplier: Track misbehaving peer (ban=true)
else Verification Succeeds
ResultApplier->>RecoveredSigs: Cache reconstructed recovered sig
end
ResultApplier-->>WorkThread: Uint256HashSet (verified locks)
WorkThread->>Network: Propagate verified recovered sigs
Network-->>WorkThread: Propagation complete
Estimated code review effort🎯 4 (Complex) | ⏱️ ~70 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/instantsend/net_instantsend.h (1)
1-76:⚠️ Potential issue | 🟡 MinorCI failure: clang-format differences detected.
The pipeline reports formatting issues in this file. Please run
clang-format-diffand apply the resulting patch to match the project style.src/instantsend/net_instantsend.cpp (1)
1-332:⚠️ Potential issue | 🟡 MinorCI failure: clang-format differences detected.
The pipeline reports formatting issues in this file as well. Please run
clang-format-diffand apply the resulting patch.
🧹 Nitpick comments (3)
src/instantsend/net_instantsend.cpp (3)
45-59: Consider whetherResolveCycleHeightshould handle the misbehavior penalty itself.Currently,
ResolveCycleHeightreturnsstd::nullopton failure, and the caller (ProcessMessage, line 225) applies the misbehavior penalty. This is fine for the single call site today, but ifResolveCycleHeightis reused elsewhere, the penalty logic would need to be duplicated. A minor design consideration — not blocking.
61-73: Verify the comment accuracy for non-rotation quorums.The comment on line 66 says "Deterministic islocks MUST use rotation based llmq," yet the validation only checks
cycle_height % dkgInterval == 0without verifyingllmq_params.useRotation. This works because the method is only called forllmqTypeDIP0024InstantSend(which always uses rotation), but if this helper were ever reused for a non-rotation LLMQ type, the cycle-height divisibility check would be incorrect.Consider adding an assertion for clarity:
Proposed assertion
bool NetInstantSend::ValidateDeterministicCycleHeight( int cycle_height, const Consensus::LLMQParams& llmq_params, NodeId node_id) { // Deterministic islocks MUST use rotation based llmq + assert(llmq_params.useRotation); if (cycle_height % llmq_params.dkgInterval == 0) { return true; }
75-141: Batch returnsnullptrwhen quorum selection fails — all pending locks in the batch are silently dropped.When
SelectQuorumForSigning/GetQuorumreturnsnullptr(line 123),BuildVerificationBatchreturnsnullptrandProcessPendingInstantSendLocks(line 271) returns an emptyUint256HashSet. This means all locks in the batch — including those already pushed to the batch verifier and those not yet iterated — are neither processed nor retried.The comment on line 124 says "if one fails to select, all others will also fail to select," which justifies the early return. However, locks already marked as
alreadyVerified(line 101) or added to the batch verifier (line 128) before the failure point are also lost. ThealreadyVerifiedlocks in particular had valid recovered sigs and could have been processed.This appears to be the pre-existing behavior, so it's not a regression, but worth noting.
Issue being fixed or feature implemented
Improve and modernize some instantsend code; see commits
What was done?
see commits
How Has This Been Tested?
Breaking Changes
NA
Checklist:
Go over all the following points, and put an
xin all the boxes that apply.