Skip to content

Commit

Permalink
Merge #2233: [test] fix miner_tests block generation race condition.
Browse files Browse the repository at this point in the history
f12bd4c test: fix miner_tests block generation race condition. (furszy)

Pull request description:

  Took a while to understand the UB.. but this should fix it. Based on the results thrown by #2220.

  As we are "faking" the block creation based on the same `CBlock` shared_ptr and the pointer is shared across multiple threads, there is a possible race condition with the scheduler thread when we clear the transactions vector to add the new coinbase transaction for the next "new" block. If the secondary thread is not fast enough, as we are doing all in the same loop non-stop, the scheduler thread could try to access to the block ptr vtx a millisecond later when there is no transactions, causing the UB due the vector brackets operator access on an empty container.

ACKs for top commit:
  Fuzzbawls:
    utACK f12bd4c
  random-zebra:
    utACK f12bd4c and merging...

Tree-SHA512: 7124534e07226337a7c8a9198a3b199f7c5305b1ec0f203bfe66394d1c341f41f53ed53abf2abfca7d71fa452b044e7ac91c0a29e0bf431bbc60ca1c5730fb9f
  • Loading branch information
random-zebra committed Mar 10, 2021
2 parents ea91ace + f12bd4c commit e9461b3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/test/miner_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
CValidationState state;
BOOST_CHECK(ProcessNewBlock(state, nullptr, pblock, nullptr));
BOOST_CHECK(state.IsValid());
SyncWithValidationInterfaceQueue();
pblock->hashPrevBlock = pblock->GetHash();
}

Expand Down

0 comments on commit e9461b3

Please sign in to comment.