Skip to content
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

test: fix test "test_prepare_uncles"; it could failed with a very small chance #2478

Merged

Conversation

yangby-cryptape
Copy link
Collaborator

@yangby-cryptape yangby-cryptape commented Dec 29, 2020

Issue

  • ChainController::process_block(..) is synchronized, it will wait for the response.

    ckb/chain/src/chain.rs

    Lines 200 to 208 in 6e34d89

    recv(process_block_receiver) -> msg => match msg {
    Ok(Request { responder, arguments: (block, verify) }) => {
    let _ = responder.send(self.process_block(block, verify));
    },
    _ => {
    error!("process_block_receiver closed");
    break;
    },
    },

  • But when ChainService::process_block(..), it will send NewUncle(..) to TxPoolController without waiting for the response.

    ckb/chain/src/chain.rs

    Lines 491 to 497 in 6e34d89

    if let Err(e) = self
    .shared
    .tx_pool_controller()
    .notify_new_uncle(block_ref.as_uncle())
    {
    error!("notify new_uncle error {}", e);
    }

  • 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.

    assert_eq!(block_template.uncles[0].hash, block0_0.hash().unpack());

Reproduce

Append ::std::thread::sleep(::std::time::Duration::from_millis(500)); to line 629 in the follow code section to delay TxPool update NewUncle can reproduce this issue.

ckb/tx-pool/src/service.rs

Lines 629 to 637 in 6e34d89

Message::NewUncle(Notify { arguments: uncle }) => {
if service.block_assembler.is_some() {
let block_assembler = service.block_assembler.clone().unwrap();
block_assembler.candidate_uncles.lock().await.insert(uncle);
block_assembler
.last_uncles_updated_at
.store(unix_time_as_millis(), Ordering::SeqCst);
}
}

Copy link
Contributor

@keroro520 keroro520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

@yangby-cryptape
Copy link
Collaborator Author

bors r=zhangsoledad,keroro520

@bors
Copy link
Contributor

bors bot commented Dec 30, 2020

Build succeeded:

  • continuous-integration/travis-ci/push

@bors bors bot merged commit 4a5e8a2 into nervosnetwork:develop Dec 30, 2020
bors bot added a commit that referenced this pull request Dec 30, 2020
2483: test: fix potential failure in integration tests, such as DifferentTxsWithSameInput r=zhangsoledad,driftluo a=yangby-cryptape

#### Issue

- `ChainController::process_block(..)` is synchronized, it will wait for the response.

  https://github.com/nervosnetwork/ckb/blob/6e34d89a44aaeba3ffbfbf62c173e6a0a6547273/chain/src/chain.rs#L200-L208

- But when `ChainService::process_block(..)`, it will send `ChainReorg(..)` to `TxPoolController` without waiting for the response.
 
  https://github.com/nervosnetwork/ckb/blob/6e34d89a44aaeba3ffbfbf62c173e6a0a6547273/chain/src/chain.rs#L454-L461
  https://github.com/nervosnetwork/ckb/blob/6e34d89a44aaeba3ffbfbf62c173e6a0a6547273/tx-pool/src/service.rs#L195-L198

- So, with a very small probability, the `ChainReorg(..)` may not have been processed by `TxPoolService` before we use transactions in the new tip block.

  Then the error `TransactionFailedToResolve: Resolve failed Unknown([OutPoint(0x..)])` could be thrown.

  Similar to #2478.

#### Reproduce

Append `::std::thread::sleep(::std::time::Duration::from_millis(100));` to line 619 in the follow code section to delay `TxPool` update `ChainReorg(..)` can reproduce this issue.
https://github.com/nervosnetwork/ckb/blob/6e34d89a44aaeba3ffbfbf62c173e6a0a6547273/tx-pool/src/service.rs#L617-L628

#### Affected

This issue causes a lot of integration tests failures, for example:

- `DifferentTxsWithSameInput`

  https://github.com/nervosnetwork/ckb/blob/6e34d89a44aaeba3ffbfbf62c173e6a0a6547273/test/src/specs/tx_pool/different_txs_with_same_input.rs#L16-L17

- `ConflictInGap`

  https://github.com/nervosnetwork/ckb/blob/6e34d89a44aaeba3ffbfbf62c173e6a0a6547273/test/src/specs/tx_pool/collision.rs#L92-L94

Co-authored-by: Boyu Yang <[email protected]>
@yangby-cryptape yangby-cryptape deleted the pr/fix-test_prepare_uncles branch December 30, 2020 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants