Skip to content

Commit

Permalink
a dirty to recreate bitcoin#29767, dace race in my local machine iwit…
Browse files Browse the repository at this point in the history
…h a probability of around 10%.
  • Loading branch information
nanlour committed Apr 2, 2024
1 parent bbe82c1 commit 5931fb8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ void BaseIndex::Sync()
const CBlockIndex* pindex_next = WITH_LOCK(cs_main, return NextSyncBlock(pindex, m_chainstate->m_chain));
if (!pindex_next) {
SetBestBlockIndex(pindex);
m_synced = true;
m_syned_ = true;
// No need to handle errors in Commit. See rationale above.
Commit();
m_synced = true;
break;
}
if (pindex_next->pprev != pindex && !Rewind(pindex, pindex_next->pprev)) {
Expand Down
4 changes: 4 additions & 0 deletions src/index/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class BaseIndex : public CValidationInterface
void WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator);
};

// Use this variable to make only thread basic block filter index pause, and only pause once
// As scheduler may also call Commit(), if pause every call, it will not make race window bigger
std::atomic<bool> m_syned_{false};

private:
/// Whether the index has been initialized or not.
std::atomic<bool> m_init{false};
Expand Down
6 changes: 6 additions & 0 deletions src/index/blockfilterindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ bool BlockFilterIndex::CustomCommit(CDBBatch& batch)
{
const FlatFilePos& pos = m_next_filter_pos;

if (m_syned_) {
// Set it to false, as i only want it to pause once
m_syned_ = false;
std::this_thread::sleep_for(std::chrono::seconds(5));
}

// Flush current filter file to disk.
AutoFile file{m_filter_fileseq->Open(pos)};
if (file.IsNull()) {
Expand Down

0 comments on commit 5931fb8

Please sign in to comment.