Repository navigation
A head we could not re-read is not a head that changed #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khalidsaidi
wants to merge
1
commit into
main
Choose a base branch
from
fix/canonical-outage-buries-finding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """Failing to RE-READ the head is not the same as the head having CHANGED. | ||
|
|
||
| Both once left `canonical` false, and main() returned 2 on that before it had | ||
| even compared the observed transfers against the ledger. So a confirmed | ||
| unledgered movement could sit in a complete, successfully scanned history and | ||
| be reported as a CI deferral -- a green build over real evidence. That is | ||
| issue #10's defect at a different gate: the run goes quiet because a later | ||
| read failed. | ||
|
|
||
| The two causes are now distinguished: | ||
|
|
||
| * the head HASH CHANGED -- positive proof the snapshot's basis is gone, so | ||
| observations tied to it are not evidence about the current chain. Still 2. | ||
| * the head could NOT BE READ -- an outage, which says nothing about what was | ||
| already observed. An unaccounted movement survives it, as it survives a | ||
| failed page (test_history_scan) and a failed state read (test_allowance_outage). | ||
| """ | ||
| import unittest | ||
|
|
||
| from test_history_scan import ALICE, CHARLIE, Node, event, run | ||
|
|
||
| import verify_ledger as v | ||
|
|
||
|
|
||
| class HeadOutage(Node): | ||
| """A complete scan observes an unledgered transfer; the mandatory head | ||
| re-read then fails as an outage rather than a disagreement.""" | ||
|
|
||
| def __init__(self, **kw): | ||
| super().__init__(**kw) | ||
| self.events += [event(200, ALICE, CHARLIE, 40 * 10**18)] | ||
| self.scanned = False | ||
|
|
||
| def __call__(self, payload, endpoint=None): | ||
| if payload["method"] == "eth_getLogs": | ||
| self.scanned = True | ||
| if payload["method"] == "eth_getBlockByNumber" and self.scanned: | ||
| raise v.SourceUnavailable("RPC request budget exhausted") | ||
| return super().__call__(payload, endpoint) | ||
|
|
||
|
|
||
| class HeadReorg(Node): | ||
| """The same observation, but the head genuinely changed under us.""" | ||
|
|
||
| def __init__(self, **kw): | ||
| super().__init__(**kw) | ||
| self.events += [event(200, ALICE, CHARLIE, 40 * 10**18)] | ||
| self.changed_head = True | ||
|
|
||
|
|
||
| class CanonicalOutage(unittest.TestCase): | ||
| def test_unreadable_head_does_not_bury_an_observed_violation(self): | ||
| code, output = run(HeadOutage()) | ||
| self.assertEqual(code, 1, output) | ||
| self.assertIn("UNACCOUNTED", output) | ||
| self.assertIn(CHARLIE, output) | ||
|
|
||
| def test_a_changed_head_still_invalidates_the_observation(self): | ||
| code, output = run(HeadReorg()) | ||
| self.assertEqual(code, 2, output) | ||
| self.assertIn("no longer canonical", output) | ||
| self.assertNotIn("RESULT: FAIL", output) | ||
|
|
||
| def test_an_unreadable_head_without_a_violation_stays_inconclusive(self): | ||
| class Clean(HeadOutage): | ||
| def __init__(self, **kw): | ||
| Node.__init__(self, **kw) | ||
| self.scanned = False | ||
| code, output = run(Clean()) | ||
| self.assertEqual(code, 2, output) | ||
| self.assertNotIn("RESULT: FAIL", output) | ||
|
|
||
| def test_the_cause_is_named_in_the_output(self): | ||
| _, outage = run(HeadOutage()) | ||
| _, reorg = run(HeadReorg()) | ||
| self.assertIn("outage", outage) | ||
| self.assertIn("replaced", reorg) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an earlier page contains an unledgered movement and a later page raises
HistoryConflict,derive_transfers()returns immediately withcanonical=Falseandhead_changed=False, retaining the earlier transfers. This branch now reports an accounting violation even though the history was explicitly invalidated, rather than returning 2 as before. This includes a log at the fixed head having a different block hash, not just duplicate-record conflicts. I reproduced exit 1 using an unledgered transfer in the first page and conflicting copies of one log in a later page. Preserve a distinct invalid-history outcome and exclude it from the outage-only failure path.Useful? React with 👍 / 👎.