test: fix test "test_prepare_uncles"; it could failed with a very small chance #2478
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.
Issue
ChainController::process_block(..)
is synchronized, it will wait for the response.ckb/chain/src/chain.rs
Lines 200 to 208 in 6e34d89
But when
ChainService::process_block(..)
, it will sendNewUncle(..)
toTxPoolController
without waiting for the response.ckb/chain/src/chain.rs
Lines 491 to 497 in 6e34d89
So, with a very small probability, the uncle block may not have been processed by
TxPoolService
.So the follow line will throw the error:
panicked at 'index out of bounds: the len is 0 but the index is 0
.ckb/chain/src/tests/block_assembler.rs
Line 210 in 6e34d89
Reproduce
Append
::std::thread::sleep(::std::time::Duration::from_millis(500));
to line 629 in the follow code section to delayTxPool
updateNewUncle
can reproduce this issue.ckb/tx-pool/src/service.rs
Lines 629 to 637 in 6e34d89