AppLayerLabs / bdk-cpp

MIT License
7 stars 12 forks source link

Failing testcase: "rdPoS validateBlock(), ten block from genesis" #123

Open fcecin opened 2 months ago

fcecin commented 2 months ago

Every ~500 runs, the rdPoS validateBlock(), ten block from genesis SECTION of an rdPoS testcase fails the following assert, after the blockchainWrapper is destructed and then reloaded from disk.

REQUIRE(blockchainWrapper.state.rdposGetBestRandomSeed() == expectedRandomnessFromBestBlock);

Upon inspecting both seeds, the seed on the left is from block 9, and the seed from the right is from block 10.

This issue can still be reproduced by e.g. putting a sleep of 1 second before the scope-close that calls the destructor of the first blockchainWrapper.

fcecin commented 2 months ago

This issue was root-caused to the "latest" key in the DB being raced by the threads that do block saving. If block 10 is written then block 9 is written out of order, the "latest" key gets assigned to block 9.