@@ -199,7 +199,7 @@ void CBudgetManager::SubmitFinalBudget()
199199 }
200200
201201 // See if collateral tx exists
202- if (!mapCollateralTxids .count (budgetHash)) {
202+ if (!mapUnconfirmedFeeTx .count (budgetHash)) {
203203 // create the collateral tx, send it to the network and return
204204 CWalletTx wtx;
205205 // Get our change address
@@ -210,20 +210,21 @@ void CBudgetManager::SubmitFinalBudget()
210210 }
211211 // Send the tx to the network. Do NOT use SwiftTx, locking might need too much time to propagate, especially for testnet
212212 const CWallet::CommitResult& res = pwalletMain->CommitTransaction (wtx, keyChange, g_connman.get (), " NO-ix" );
213- if (res.status == CWallet::CommitStatus::OK)
214- mapCollateralTxids.emplace (budgetHash, wtx.GetHash ());
213+ if (res.status == CWallet::CommitStatus::OK) {
214+ const uint256& collateraltxid = wtx.GetHash ();
215+ mapUnconfirmedFeeTx.emplace (budgetHash, collateraltxid);
216+ LogPrint (BCLog::MNBUDGET," %s: Collateral sent. txid: %s\n " , __func__, collateraltxid.ToString ());
217+ }
215218 return ;
216219 }
217220
218221 // Collateral tx already exists, see if it's mature enough.
219- CFinalizedBudget fb (strBudgetName, nBlockStart, vecTxBudgetPayments, mapCollateralTxids .at (budgetHash));
222+ CFinalizedBudget fb (strBudgetName, nBlockStart, vecTxBudgetPayments, mapUnconfirmedFeeTx .at (budgetHash));
220223 if (!AddFinalizedBudget (fb)) {
221224 return ;
222225 }
223226 fb.Relay ();
224227 nSubmittedHeight = nCurrentHeight;
225- // Remove collateral tx from map
226- mapCollateralTxids.erase (budgetHash);
227228 LogPrint (BCLog::MNBUDGET," %s: Done! %s\n " , __func__, budgetHash.ToString ());
228229}
229230
@@ -445,9 +446,10 @@ bool CBudgetManager::AddFinalizedBudget(CFinalizedBudget& finalizedBudget)
445446
446447 std::string strError;
447448 int nCurrentHeight = GetBestHeight ();
448- if (!CheckCollateral (finalizedBudget.GetFeeTXHash (), nHash, strError, finalizedBudget.nTime , nCurrentHeight, true )) {
449- LogPrint (BCLog::MNBUDGET," %s: invalid finalized budget (%s) collateral - %s\n " ,
450- __func__, nHash.ToString (), strError);
449+ const uint256& feeTxId = finalizedBudget.GetFeeTXHash ();
450+ if (!CheckCollateral (feeTxId, nHash, strError, finalizedBudget.nTime , nCurrentHeight, true )) {
451+ LogPrint (BCLog::MNBUDGET," %s: invalid finalized budget (%s) collateral id=%s - %s\n " ,
452+ __func__, nHash.ToString (), feeTxId.ToString (), strError);
451453 return false ;
452454 }
453455
@@ -458,7 +460,15 @@ bool CBudgetManager::AddFinalizedBudget(CFinalizedBudget& finalizedBudget)
458460 }
459461
460462 SetBudgetProposalsStr (finalizedBudget);
461- WITH_LOCK (cs_budgets, mapFinalizedBudgets.emplace (nHash, finalizedBudget); );
463+ {
464+ LOCK (cs_budgets);
465+ mapFinalizedBudgets.emplace (nHash, finalizedBudget);
466+ // Add to feeTx index
467+ mapFeeTxToBudget.emplace (feeTxId, nHash);
468+ // Remove the budget from the unconfirmed map, if it was there
469+ if (mapUnconfirmedFeeTx.count (nHash))
470+ mapUnconfirmedFeeTx.erase (nHash);
471+ }
462472 LogPrint (BCLog::MNBUDGET," %s: finalized budget %s [%s (%s)] added\n " ,
463473 __func__, nHash.ToString (), finalizedBudget.GetName (), finalizedBudget.GetProposalsStr ());
464474 return true ;
@@ -481,9 +491,10 @@ bool CBudgetManager::AddProposal(CBudgetProposal& budgetProposal)
481491
482492 std::string strError;
483493 int nCurrentHeight = GetBestHeight ();
484- if (!CheckCollateral (budgetProposal.GetFeeTXHash (), nHash, strError, budgetProposal.nTime , nCurrentHeight, false )) {
485- LogPrint (BCLog::MNBUDGET," %s: invalid budget proposal (%s) collateral - %s\n " ,
486- __func__, nHash.ToString (), strError);
494+ const uint256& feeTxId = budgetProposal.GetFeeTXHash ();
495+ if (!CheckCollateral (feeTxId, nHash, strError, budgetProposal.nTime , nCurrentHeight, false )) {
496+ LogPrint (BCLog::MNBUDGET," %s: invalid budget proposal (%s) collateral id=%s - %s\n " ,
497+ __func__, nHash.ToString (), feeTxId.ToString (), strError);
487498 return false ;
488499 }
489500
@@ -493,8 +504,14 @@ bool CBudgetManager::AddProposal(CBudgetProposal& budgetProposal)
493504 return false ;
494505 }
495506
496- WITH_LOCK (cs_proposals, mapProposals.emplace (nHash, budgetProposal); );
497- LogPrint (BCLog::MNBUDGET," %s: proposal %s [%s] added\n " , __func__, nHash.ToString (), budgetProposal.GetName ());
507+ {
508+ LOCK (cs_proposals);
509+ mapProposals.emplace (nHash, budgetProposal);
510+ // Add to feeTx index
511+ mapFeeTxToProposal.emplace (feeTxId, nHash);
512+ }
513+ LogPrint (BCLog::MNBUDGET," %s: budget proposal %s [%s] added\n " , __func__, nHash.ToString (), budgetProposal.GetName ());
514+
498515 return true ;
499516}
500517
@@ -511,6 +528,7 @@ void CBudgetManager::CheckAndRemove()
511528 CFinalizedBudget* pfinalizedBudget = &(it.second );
512529 if (!pfinalizedBudget->UpdateValid (nCurrentHeight)) {
513530 LogPrint (BCLog::MNBUDGET," %s: Invalid finalized budget %s %s\n " , __func__, (it.first ).ToString (), pfinalizedBudget->IsInvalidLogStr ());
531+ mapFeeTxToBudget.erase (pfinalizedBudget->GetFeeTXHash ());
514532 } else {
515533 LogPrint (BCLog::MNBUDGET," %s: Found valid finalized budget: %s %s\n " , __func__,
516534 pfinalizedBudget->GetName (), pfinalizedBudget->GetFeeTXHash ().ToString ());
@@ -530,6 +548,7 @@ void CBudgetManager::CheckAndRemove()
530548 CBudgetProposal* pbudgetProposal = &(it.second );
531549 if (!pbudgetProposal->UpdateValid (nCurrentHeight)) {
532550 LogPrint (BCLog::MNBUDGET," %s: Invalid budget proposal %s %s\n " , __func__, (it.first ).ToString (), pbudgetProposal->IsInvalidLogStr ());
551+ mapFeeTxToProposal.erase (pbudgetProposal->GetFeeTXHash ());
533552 } else {
534553 LogPrint (BCLog::MNBUDGET," %s: Found valid budget proposal: %s %s\n " , __func__,
535554 pbudgetProposal->GetName (), pbudgetProposal->GetFeeTXHash ().ToString ());
0 commit comments