Repository navigation
fix: validator VM crash should vote DISAGREE, not AGREE - #1448
Conversation
The _set_vote logic was comparing raw result bytes between leader and validator receipts. When both crashed with the same VM error (e.g. exit_code, OOM), they'd match byte-for-byte and vote AGREE — even though neither actually validated anything. New logic: - RETURN/USER_ERROR → check deterministic properties (state, pending_txs, execution_result) for DETERMINISTIC_VIOLATION, otherwise AGREE - VM_ERROR + timeout/internal → TIMEOUT - VM_ERROR + anything else (exit_code, OOM) → DISAGREE - nondet_disagree signal from GenVM → DISAGREE Result bytes are no longer compared for vote determination. Only execution outcome category and contract state matter.
📝 WalkthroughWalkthroughThe changes refine the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ 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.
🧹 Nitpick comments (2)
backend/node/base.py (1)
700-702: Defensive check:receipt.resultmust be non-empty.
receipt.result[0]will raiseIndexErrorifresultis an emptybytesobject. While current callers always produce a result with at least one byte (viaencode_result_to_bytes), a defensive guard would make this more robust against future changes.🛡️ Optional defensive check
def _set_vote(self, receipt: Receipt) -> Receipt: + if not receipt.result: + receipt.vote = Vote.DISAGREE + return receipt result_code = receipt.result[0]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/node/base.py` around lines 700 - 702, The _set_vote method accesses receipt.result[0] without verifying receipt.result is non-empty; add a defensive check at the start of _set_vote (method name: _set_vote, type: Receipt, property: Receipt.result) that verifies receipt.result is not empty (e.g., if not receipt.result: raise ValueError(...) or return an explicit error), and include a clear error message referencing the Receipt (or its id) so callers can diagnose unexpected empty results; ensure the rest of the function uses the validated result[0] after this guard.tests/unit/test_set_vote.py (1)
301-319: Add explicit test forpending_transactionsdivergence in the AGREE path.The
_set_votelogic comparespending_transactionsas part of the deterministic violation check (line 727 ofbackend/node/base.py). However, the_make_receipthelper does not support settingpending_transactions, so all current tests implicitly rely on the default empty tuple(). This means the comparison branch is never explicitly exercised. Add a test wherepending_transactionsdiffers between leader and validator to ensure it triggersVote.DETERMINISTIC_VIOLATION.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/test_set_vote.py` around lines 301 - 319, Add a new unit test variant that exercises the deterministic-violation branch by creating a leader receipt and a validator receipt via _make_receipt where you explicitly set differing pending_transactions values (e.g., leader uses default or () and validator uses a non-empty tuple) and then call node._set_vote(validator_receipt) to assert the returned vote is Vote.DETERMINISTIC_VIOLATION; update or extend test_user_error_matching_state_votes_agree (or create a new test function) so _make_receipt is called with a pending_transactions argument to force the divergence and validate the deterministic-violation path in the _set_vote logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/node/base.py`:
- Around line 700-702: The _set_vote method accesses receipt.result[0] without
verifying receipt.result is non-empty; add a defensive check at the start of
_set_vote (method name: _set_vote, type: Receipt, property: Receipt.result) that
verifies receipt.result is not empty (e.g., if not receipt.result: raise
ValueError(...) or return an explicit error), and include a clear error message
referencing the Receipt (or its id) so callers can diagnose unexpected empty
results; ensure the rest of the function uses the validated result[0] after this
guard.
In `@tests/unit/test_set_vote.py`:
- Around line 301-319: Add a new unit test variant that exercises the
deterministic-violation branch by creating a leader receipt and a validator
receipt via _make_receipt where you explicitly set differing
pending_transactions values (e.g., leader uses default or () and validator uses
a non-empty tuple) and then call node._set_vote(validator_receipt) to assert the
returned vote is Vote.DETERMINISTIC_VIOLATION; update or extend
test_user_error_matching_state_votes_agree (or create a new test function) so
_make_receipt is called with a pending_transactions argument to force the
divergence and validate the deterministic-violation path in the _set_vote logic.
|
🎉 This PR is included in version 0.101.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
_set_votecompared raw result bytes between leader and validator. When both crashed with the same VM error (e.g.exit_code 1), they matched and voted AGREE — even though neither validated anything.RETURNandUSER_ERRORwith matching deterministic properties (execution_result, contract_state, pending_transactions) vote AGREE.Vote determination logic (new)
VM_ERROR+ timeout / internal errornondet_disagreesetVM_ERROR+ exit_code / OOM / otherRETURN/USER_ERROR+ state mismatchRETURN/USER_ERROR+ state matchesProduction incident
On Rally testnet, a contract's leader crashed with
exit_code 1(LLM returned malformed response). Validators also crashed (couldn't unpack leader's error). All voted AGREE because raw error bytes matched. Transaction finalized as "agreed" with no actual validation.Test plan
test_set_vote.pytests pass (8 existing + 5 new)Summary by CodeRabbit
Release Notes