Skip to content

Commit

Permalink
Add wrappers around major sigma/lelantus/spark calls to catch exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
psolstice committed Oct 20, 2023
1 parent 4a22bd1 commit 59a52c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/lelantus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,13 @@ bool CheckLelantusTransaction(
if (allowLelantus && !isVerifyDB) {
for (const CTxOut &txout : tx.vout) {
if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsLelantusMint()) {
if (!CheckLelantusMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, lelantusTxInfo))
return false;
try {
if (!CheckLelantusMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, lelantusTxInfo))
return false;
}
catch (const std::exception &x) {
return state.Error(x.what());
}
}
}
}
Expand All @@ -762,10 +767,15 @@ bool CheckLelantusTransaction(
}

if (!isVerifyDB) {
if (!CheckLelantusJoinSplitTransaction(
tx, state, hashTx, isVerifyDB, nHeight, realHeight,
isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo, lelantusTxInfo)) {
return false;
try {
if (!CheckLelantusJoinSplitTransaction(
tx, state, hashTx, isVerifyDB, nHeight, realHeight,
isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo, lelantusTxInfo)) {
return false;
}
}
catch (const std::exception &x) {
return state.Error(x.what());
}
}
}
Expand Down
22 changes: 16 additions & 6 deletions src/sigma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,13 @@ bool CheckSigmaTransaction(
if (allowSigma) {
for (const CTxOut &txout : tx.vout) {
if (!txout.scriptPubKey.empty() && txout.scriptPubKey.IsSigmaMint()) {
if (!CheckSigmaMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, sigmaTxInfo))
return false;
try {
if (!CheckSigmaMintTransaction(txout, state, hashTx, fStatefulSigmaCheck, sigmaTxInfo))
return false;
}
catch (const std::exception &x) {
return state.Error(x.what());
}
}
}
}
Expand Down Expand Up @@ -506,10 +511,15 @@ bool CheckSigmaTransaction(
// Check vOut
// Only one loop, we checked on the format before entering this case
if (!isVerifyDB) {
if (!CheckSigmaSpendTransaction(
tx, denominations, state, hashTx, isVerifyDB, nHeight, realHeight,
isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo)) {
return false;
try {
if (!CheckSigmaSpendTransaction(
tx, denominations, state, hashTx, isVerifyDB, nHeight, realHeight,
isCheckWallet, fStatefulSigmaCheck, sigmaTxInfo)) {
return false;
}
}
catch (const std::exception &x) {
return state.Error(x.what());
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,14 @@ bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const
{
LogPrintf("AcceptToMemoryPool(), transaction: %s\n", tx->GetHash().ToString());
std::vector<COutPoint> coins_to_uncache;
bool res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache, isCheckWalletTransaction, markFiroSpendTransactionSerial);
bool res = false;
try {
res = AcceptToMemoryPoolWorker(pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee, coins_to_uncache, isCheckWalletTransaction, markFiroSpendTransactionSerial);
}
catch (const std::exception &x) {
state.Error(x.what());
res = false;
}
if (!res) {
BOOST_FOREACH(const COutPoint& hashTx, coins_to_uncache)
pcoinsTip->Uncache(hashTx);
Expand Down

0 comments on commit 59a52c1

Please sign in to comment.