Skip to content

Commit

Permalink
Remove commented out for loop hack and add commenting on new lock
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Dec 3, 2023
1 parent c49b2f2 commit ef559d6
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions src/gridcoin/voting/result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,34 +864,11 @@ class VoteCounter
{
CTransaction tx;

/*
bool read_tx_success = false;
// This is very ugly. In testing for implement poll expiration reminders PR2716, there is an issue with ReadDiskTx
// on very fast machines, where upon receipt of a vote on an existing poll, the poll builder tests for the transaction
// BEFORE it is committed to disk. This retry loop is essentially zero overhead for an immediate success, but does
// up to 10 tries over up to 2.5 seconds total to "wait" for the transaction to appear in leveldb.
for (unsigned int i = 0; i < 10; ++i) {
if (m_txdb.ReadDiskTx(txid, tx)) {
read_tx_success = true;
break;
} else {
LogPrintf("WARN: %s: failed to read vote tx in try %u", __func__, i + 1);
}
if (!MilliSleep(250)) {
// Interrupt with throw if MilliSleep interrupted by op sys signal.
throw InvalidVoteError();
}
}
if (!read_tx_success) {
LogPrintf("WARN: %s: failed to read vote tx after 10 tries", __func__);
throw InvalidVoteError();
}
*/

{
// This lock is taken here to ensure that we wait on the leveldb batch write ("transaction commit") to finish
// in ReorganizeChain (which is essentially the ConnectBlock scope) and ensure that the voting transactions
// which correspond to the new vote signals sent from the contract handlers are actually present in leveldb when
// the below ReadDiskTx is called.
LOCK(cs_tx_val_commit_to_disk);
LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: cs_tx_val_commit_to_disk locked", __func__);

Expand All @@ -902,7 +879,6 @@ class VoteCounter
LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: cs_tx_val_commit_to_disk unlocked", __func__);
}


if (tx.nTime < m_poll.m_timestamp) {
LogPrintf("WARN: %s: tx earlier than poll", __func__);
throw InvalidVoteError();
Expand Down

0 comments on commit ef559d6

Please sign in to comment.