From 7cfaa0197662e241d8bb0a8c7c0a6fa0e4f8de7d Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sat, 10 Feb 2024 20:13:55 -0500 Subject: [PATCH] Add try/catch around calls to GetBeaconChainletRoot The catch for std::runtime_exception in the Tally code will cause a std::abort(). The RPC code will throw a RPC_INTERNAL_ERROR. --- src/gridcoin/tally.cpp | 6 +++++- src/rpc/mining.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gridcoin/tally.cpp b/src/gridcoin/tally.cpp index 024745761f..0f92700364 100644 --- a/src/gridcoin/tally.cpp +++ b/src/gridcoin/tally.cpp @@ -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(); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index e266f624cf..be24b0b100 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -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);