Skip to content

Commit

Permalink
Add try/catch around calls to GetBeaconChainletRoot
Browse files Browse the repository at this point in the history
The catch for std::runtime_exception will assert, ensuring
Gridcoin stops after resetting the beacon registry.
  • Loading branch information
jamescowens committed Feb 11, 2024
1 parent 6616bcb commit 964be89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/gridcoin/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,11 @@ CAmount Tally::GetNewbieSuperblockAccrualCorrection(const Cpid& cpid, const Supe
// Walk back the entries in the historical beacon map linked by renewal prev tx hash until the first
// beacon in the renewal chain is found (the original advertisement). The accrual starts no earlier
// than here.
beacon_ptr = beacons.GetBeaconChainletRoot(beacon);
try {
beacon_ptr = beacons.GetBeaconChainletRoot(beacon);
} catch (std::runtime_error& e) {
std::abort;
}

const CBlockIndex* pindex_baseline = GRC::Tally::GetBaseline();

Expand Down
6 changes: 5 additions & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ UniValue auditsnapshotaccrual(const UniValue& params, bool fHelp)

UniValue beacon_chain(UniValue::VARR);

beacon_ptr = beacons.GetBeaconChainletRoot(beacon_ptr, beacon_chain_out_ptr);
try {
beacon_ptr = beacons.GetBeaconChainletRoot(beacon_ptr, beacon_chain_out_ptr);
} catch (std::runtime_error& e) {
throw JSONRPCError(RPC_INTERNAL_ERROR, e.what());
}

for (const auto& iter : *beacon_chain_out_ptr) {
UniValue beacon_chain_entry(UniValue::VOBJ);
Expand Down

0 comments on commit 964be89

Please sign in to comment.