Skip to content

Commit

Permalink
Add missing poll and vote contract reverts from DisconnectBlocksBatch
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Jan 5, 2023
1 parent b795be1 commit fcd4efb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/gridcoin/contract/contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 11 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -913,6 +914,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list<CTransaction>& vResurrect, unsigned
{
set<string> vRereadCPIDs;
GRC::BeaconRegistry& beacons = GRC::GetBeaconRegistry();
GRC::PollRegistry& polls = GRC::GetPollRegistry();

while(pindexBest != pcommon)
{
Expand All @@ -934,7 +936,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list<CTransaction>& 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);
Expand Down Expand Up @@ -965,7 +967,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list<CTransaction>& 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:
Expand All @@ -981,6 +983,12 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list<CTransaction>& 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);
}
}
}
}
Expand All @@ -1000,7 +1008,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list<CTransaction>& 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)
Expand Down

0 comments on commit fcd4efb

Please sign in to comment.