Skip to content

Commit

Permalink
[BUG] Spork signer doesn't persist new spork value to DB
Browse files Browse the repository at this point in the history
Github-Pull: #2553
Rebased-From: 5849e3e
  • Loading branch information
random-zebra authored and furszy committed Sep 19, 2021
1 parent 7f827e9 commit 09b8ec0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,9 @@ int CSporkManager::ProcessSporkMsg(CSporkMessage& spork)
LogPrintf("%s : got %s spork %d (%s) with value %d (signed at %d)\n", __func__,
strStatus, spork.nSporkID, sporkName, spork.nValue, spork.nTimeSigned);

AddOrUpdateSporkMessage(spork);
AddOrUpdateSporkMessage(spork, true);
spork.Relay();

// PIVX: add to spork database.
pSporkDB->WriteSpork(spork.nSporkID, spork);
// All good.
return 0;
}
Expand Down Expand Up @@ -201,18 +199,24 @@ bool CSporkManager::UpdateSpork(SporkId nSporkID, int64_t nValue)

if (spork.Sign(strMasterPrivKey)) {
spork.Relay();
AddOrUpdateSporkMessage(spork);
AddOrUpdateSporkMessage(spork, true);
return true;
}

return false;
}

void CSporkManager::AddOrUpdateSporkMessage(const CSporkMessage& spork)
void CSporkManager::AddOrUpdateSporkMessage(const CSporkMessage& spork, bool flush)
{
LOCK(cs);
mapSporks[spork.GetHash()] = spork;
mapSporksActive[spork.nSporkID] = spork;
{
LOCK(cs);
mapSporks[spork.GetHash()] = spork;
mapSporksActive[spork.nSporkID] = spork;
}
if (flush) {
// add to spork database.
pSporkDB->WriteSpork(spork.nSporkID, spork);
}
}

// grab the spork value, and see if it's off
Expand Down
5 changes: 3 additions & 2 deletions src/spork.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ class CSporkManager
int64_t GetSporkValue(SporkId nSporkID);
// Create/Sign/Relay the spork message, and update the maps
bool UpdateSpork(SporkId nSporkID, int64_t nValue);
// Add spork message to mapSporks and mapSporksActive
void AddOrUpdateSporkMessage(const CSporkMessage& spork);
// Add spork message to mapSporks and mapSporksActive.
// if flush=true, save to DB as well
void AddOrUpdateSporkMessage(const CSporkMessage& spork, bool flush = false);

bool IsSporkActive(SporkId nSporkID);
std::string GetSporkNameByID(SporkId id);
Expand Down

0 comments on commit 09b8ec0

Please sign in to comment.