From 1ccdc19134955736cba3b661b8951d5742224bfc Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Mon, 30 Oct 2023 00:54:06 -0400 Subject: [PATCH] corrections (TBS) --- src/qt/voting/polltablemodel.cpp | 8 ++++---- src/qt/voting/votingmodel.cpp | 20 +++++++++++++------- src/qt/voting/votingmodel.h | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/qt/voting/polltablemodel.cpp b/src/qt/voting/polltablemodel.cpp index cf1fb9cb30..d5c28e3ffe 100644 --- a/src/qt/voting/polltablemodel.cpp +++ b/src/qt/voting/polltablemodel.cpp @@ -203,10 +203,6 @@ PollTableModel::PollTableModel(QObject* parent) setFilterKeyColumn(ColumnIndex::Title); setSortCaseSensitivity(Qt::CaseInsensitive); setSortRole(SortRole); - - // Connect poll stale handler to newVoteReceived signal from voting model, which propagates - // from the core. - connect(m_model, &VotingModel::newVoteReceived, this, &PollTableModel::handlePollStaleFlag); } PollTableModel::~PollTableModel() @@ -217,6 +213,10 @@ PollTableModel::~PollTableModel() void PollTableModel::setModel(VotingModel* model) { m_model = model; + + // Connect poll stale handler to newVoteReceived signal from voting model, which propagates + // from the core. + connect(m_model, &VotingModel::newVoteReceived, this, &PollTableModel::handlePollStaleFlag); } void PollTableModel::setPollFilterFlags(PollFilterFlag flags) diff --git a/src/qt/voting/votingmodel.cpp b/src/qt/voting/votingmodel.cpp index e1b440c1de..603e194191 100644 --- a/src/qt/voting/votingmodel.cpp +++ b/src/qt/voting/votingmodel.cpp @@ -124,6 +124,9 @@ std::optional BuildPollItem(const PollRegistry::Sequence::Iterator& it item.m_top_answer = QString::fromStdString(result->WinnerLabel()).replace("_", " "); } + // Mark stale flag false since we just rebuilt the item. + item.m_stale = false; + g_timer.GetTimes(std::string{"End "} + std::string{__func__}, "buildPollTable"); return item; } @@ -267,6 +270,7 @@ std::vector VotingModel::buildPollTable(const PollFilterFlag flags) // been received for that poll). If it is stale, it will need rebuilding. If not, we insert the cached // poll item into the results and move on. + bool pollitem_needs_rebuild = true; auto pollitems_iter = m_pollitems.find(iter->Ref().Txid()); // Note that the NewVoteReceived core signal will also be fired during reorgs where votes are reverted, @@ -276,7 +280,7 @@ std::vector VotingModel::buildPollTable(const PollFilterFlag flags) if (!pollitems_iter->second.m_stale) { // Not stale... the cache entry is good. Insert into items to return and go to the next one. items.push_back(pollitems_iter->second); - continue; + pollitem_needs_rebuild = false; } else { // If stale remove the entry from the cache and allow it to be rebuilt below. m_pollitems.erase(pollitems_iter); @@ -297,13 +301,15 @@ std::vector VotingModel::buildPollTable(const PollFilterFlag flags) // Transactions that have not been rolled back by a reorg can be safely accessed for reading // by another thread as we are doing here. - try { - if (std::optional item = BuildPollItem(iter)) { - items.push_back(std::move(*item)); + if (pollitem_needs_rebuild) { + try { + if (std::optional item = BuildPollItem(iter)) { + items.push_back(std::move(*item)); + } + } catch (InvalidDuetoReorgFork& e) { + LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: Invalidated due to reorg/fork. Starting over.", + __func__); } - } catch (InvalidDuetoReorgFork& e) { - LogPrint(BCLog::LogFlags::VOTE, "INFO: %s: Invalidated due to reorg/fork. Starting over.", - __func__); } // This must be AFTER BuildPollItem. If a reorg occurred during reg traversal that could invalidate diff --git a/src/qt/voting/votingmodel.h b/src/qt/voting/votingmodel.h index 2691e3c3c9..348cd9edbc 100644 --- a/src/qt/voting/votingmodel.h +++ b/src/qt/voting/votingmodel.h @@ -87,7 +87,7 @@ class PollItem bool m_self_voted; GRC::PollResult::VoteDetail m_self_vote_detail; - bool m_stale = false; + bool m_stale = true; }; //!