Hold cs_main/cs_wallet in main MakeCollateralAmounts (#3197)

* Hold cs_main/cs_wallet in main MakeCollateralAmounts

Otherwise smth else can alter wallet state and we might end up creating conflicting txes.

* AssertLockHeld
This commit is contained in:
UdjinM6 2019-11-13 23:04:12 +03:00 committed by GitHub
parent 460e0f475a
commit fd50c1c715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1361,6 +1361,8 @@ bool CPrivateSendClientSession::MakeCollateralAmounts(CConnman& connman)
{
if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
LOCK2(cs_main, vpwallets[0]->cs_wallet);
// NOTE: We do not allow txes larger than 100kB, so we have to limit number of inputs here.
// We still want to consume a lot of inputs to avoid creating only smaller denoms though.
// Knowing that each CTxIn is at least 148b big, 400 inputs should take 400 x ~148b = ~60kB.
@ -1396,9 +1398,10 @@ bool CPrivateSendClientSession::MakeCollateralAmounts(CConnman& connman)
// Split up large inputs or create fee sized inputs
bool CPrivateSendClientSession::MakeCollateralAmounts(const CompactTallyItem& tallyItem, bool fTryDenominated, CConnman& connman)
{
if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
AssertLockHeld(cs_main);
AssertLockHeld(vpwallets[0]->cs_wallet);
LOCK2(cs_main, vpwallets[0]->cs_wallet);
if (!privateSendClient.fEnablePrivateSend || !privateSendClient.fPrivateSendRunning) return false;
// denominated input is always a single one, so we can check its amount directly and return early
if (!fTryDenominated && tallyItem.vecOutPoints.size() == 1 && CPrivateSend::IsDenominatedAmount(tallyItem.nAmount)) {