From 09941f6f1388db7fd3a6eed922bab5b88a089e54 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Tue, 3 Jan 2023 17:31:10 -0500 Subject: [PATCH] Add missing poll and vote contract reverts from DisconnectBlocksBatch --- src/gridcoin/contract/contract.cpp | 6 ++++-- src/main.cpp | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gridcoin/contract/contract.cpp b/src/gridcoin/contract/contract.cpp index 108c768d0c..3501e1119c 100644 --- a/src/gridcoin/contract/contract.cpp +++ b/src/gridcoin/contract/contract.cpp @@ -256,7 +256,9 @@ class Dispatcher { // Don't reset the beacon registry as it is now backed by a database. // GetBeaconRegistry().Reset(); - GetPollRegistry().Reset(); + + // Don't reset the poll registry as reorgs are properly handled. + // GetPollRegistry().Reset(); GetWhitelist().Reset(); m_appcache_handler.Reset(); } @@ -458,7 +460,7 @@ void GRC::ReplayContracts(CBlockIndex* pindex_end, CBlockIndex* pindex_start) LogPrint(BCLog::LogFlags::CONTRACT, "Replaying contracts from block %" PRId64 "...", pindex->nHeight); - // This no longer includes beacons. + // This no longer includes beacons or polls. g_dispatcher.ResetHandlers(); BeaconRegistry& beacons = GetBeaconRegistry(); diff --git a/src/main.cpp b/src/main.cpp index abfdac9d13..ecfe950e8f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ #include "amount.h" #include "chainparams.h" #include "consensus/merkle.h" +#include "gridcoin/voting/registry.h" #include "util.h" #include "net.h" #include "streams.h" @@ -913,6 +914,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list& vResurrect, unsigned { set vRereadCPIDs; GRC::BeaconRegistry& beacons = GRC::GetBeaconRegistry(); + GRC::PollRegistry& polls = GRC::GetPollRegistry(); while(pindexBest != pcommon) { @@ -934,7 +936,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list& vResurrect, unsigned // Queue memory transactions to resurrect. // We only do this for blocks after the last checkpoint (reorganisation before that - // point should only happen with -reindex/-loadblock, or a misbehaving peer. + // point should only happen with -reindex/-loadblock, or a misbehaving peer). for (auto const& tx : boost::adaptors::reverse(block.vtx)) if (!(tx.IsCoinBase() || tx.IsCoinStake()) && pindexBest->nHeight > Params().Checkpoints().GetHeight()) vResurrect.push_front(tx); @@ -965,7 +967,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list& vResurrect, unsigned GRC::Quorum::ForgetVote(pindexBest); } - // Delete beacons from contracts in disconnected blocks. + // Delete beacons, polls and votes from contracts in disconnected blocks. if (pindexBest->IsContract()) { // Skip coinbase and coinstake transactions: @@ -981,6 +983,12 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list& vResurrect, unsigned beacons.Revert(contract_context); } + + if (contract.m_type == GRC::ContractType::POLL || contract.m_type == GRC::ContractType::VOTE) { + const GRC::ContractContext contract_context(contract, *tx, pindexBest); + + polls.Revert(contract_context); + } } } } @@ -1000,7 +1008,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list& vResurrect, unsigned } /* fix up after disconnecting, prepare for new blocks */ - if(cnt_dis>0) + if (cnt_dis > 0) { // Resurrect memory transactions that were in the disconnected branch for( CTransaction& tx : vResurrect)