-
Notifications
You must be signed in to change notification settings - Fork 86
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
Fix reorg race condition that can cause rare crashes #409
Conversation
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.
utACK
91fae0d
to
7afa136
Compare
Force-pushed to improve comment as a result of review comment (thanks, @daira), and also thanks for your review, @defuse |
7afa136
to
94a135e
Compare
Force-pushed to fix a comment typo |
common/common_test.go
Outdated
} | ||
// Simulate that we're synced (caught up); | ||
// Simulate that we're synced (caught up, latest block 380641); | ||
// this should cause one 10s sleep (then retry). |
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.
// this should cause one 10s sleep (then retry). | |
// this should cause one sleep (then retry). |
The sleep interval isn't 10s.
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.
Good catch, and actually there isn't any sleep-retry in this case (I single-stepped in the debugger to make sure), so I removed that comment line. I think that comment was copy-pasted from elsewhere.
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.
utACK with minor suggestion.
Fixes issue 408. This bug was introduced by PR 393, which changed how txids are determined. That PR changed each call to the zcash getblock call into a pair of calls, the first to get the raw block data, the second to retrieve the txids in the block. (Unfortunately, you can't get both in a single getblock RPC.) But this ordering introduced a timing window in which the block at the given height can change, if a reorg occurred between the two calls. This PR reorders the getblock calls, so that the first call gets the transaction IDs, which also happens to return the block hash, so then the second getblock call can specify the block hash, rather than the height. This ensures that the two RPC calls return consistent data, definitely the same block.
94a135e
to
1a556c3
Compare
Force-pushed to address @daira's review comments. |
Fixes issue #408.
This bug was introduced by PR #393, which changed how txids are
determined. That PR changed each call to the zcash getblock call into a
pair of calls, the first to get the raw block data, the second to
retrieve the txids in the block. (Unfortunately, you can't get both in a
single getblock RPC.) But this ordering introduced a timing window in
which the block at the given height can change, if a reorg occurred
between the two calls.
This PR reorders the getblock calls, so that the first call gets the
transaction IDs, which also happens to return the block hash, so then
the second getblock call can specify the block hash, rather than the
height. This ensures that the two RPC calls return consistent data,
definitely the same block.