@@ -1384,267 +1384,6 @@ void CObfuscationPool::ClearLastMessage()
13841384bool CObfuscationPool::DoAutomaticDenominating (bool fDryRun )
13851385{
13861386 return false ; // Disabled until Obfuscation is completely removed
1387-
1388- if (!fEnableZeromint ) return false ;
1389- if (fMasterNode ) return false ;
1390- if (state == POOL_STATUS_ERROR || state == POOL_STATUS_SUCCESS) return false ;
1391- if (GetEntriesCount () > 0 ) {
1392- strAutoDenomResult = _ (" Mixing in progress..." );
1393- return false ;
1394- }
1395-
1396- TRY_LOCK (cs_obfuscation, lockDS);
1397- if (!lockDS) {
1398- strAutoDenomResult = _ (" Lock is already in place." );
1399- return false ;
1400- }
1401-
1402- if (!masternodeSync.IsBlockchainSynced ()) {
1403- strAutoDenomResult = _ (" Can't mix while sync in progress." );
1404- return false ;
1405- }
1406-
1407- if (!fDryRun && pwalletMain->IsLocked ()) {
1408- strAutoDenomResult = _ (" Wallet is locked." );
1409- return false ;
1410- }
1411-
1412- if (chainActive.Tip ()->nHeight - cachedLastSuccess < minBlockSpacing) {
1413- LogPrintf (" CObfuscationPool::DoAutomaticDenominating - Last successful Obfuscation action was too recent\n " );
1414- strAutoDenomResult = _ (" Last successful Obfuscation action was too recent." );
1415- return false ;
1416- }
1417-
1418- if (mnodeman.size () == 0 ) {
1419- LogPrint (" obfuscation" , " CObfuscationPool::DoAutomaticDenominating - No Masternodes detected\n " );
1420- strAutoDenomResult = _ (" No Masternodes detected." );
1421- return false ;
1422- }
1423-
1424- // ** find the coins we'll use
1425- std::vector<CTxIn> vCoins;
1426- CAmount nValueMin = CENT;
1427- CAmount nValueIn = 0 ;
1428-
1429- CAmount nOnlyDenominatedBalance;
1430- CAmount nBalanceNeedsDenominated;
1431-
1432- // should not be less than fees in OBFUSCATION_COLLATERAL + few (lets say 5) smallest denoms
1433- CAmount nLowestDenom = OBFUSCATION_COLLATERAL + obfuScationDenominations[obfuScationDenominations.size () - 1 ] * 5 ;
1434-
1435- // if there are no OBF collateral inputs yet
1436- if (!pwalletMain->HasCollateralInputs ())
1437- // should have some additional amount for them
1438- nLowestDenom += OBFUSCATION_COLLATERAL * 4 ;
1439-
1440- CAmount nBalanceNeedsAnonymized = nAnonymizePivxAmount * COIN - pwalletMain->GetAnonymizedBalance ();
1441-
1442- // if balanceNeedsAnonymized is more than pool max, take the pool max
1443- if (nBalanceNeedsAnonymized > OBFUSCATION_POOL_MAX) nBalanceNeedsAnonymized = OBFUSCATION_POOL_MAX;
1444-
1445- // if balanceNeedsAnonymized is more than non-anonymized, take non-anonymized
1446- CAmount nAnonymizableBalance = pwalletMain->GetAnonymizableBalance ();
1447- if (nBalanceNeedsAnonymized > nAnonymizableBalance) nBalanceNeedsAnonymized = nAnonymizableBalance;
1448-
1449- if (nBalanceNeedsAnonymized < nLowestDenom) {
1450- LogPrintf (" DoAutomaticDenominating : No funds detected in need of denominating \n " );
1451- strAutoDenomResult = _ (" No funds detected in need of denominating." );
1452- return false ;
1453- }
1454-
1455- LogPrint (" obfuscation" , " DoAutomaticDenominating : nLowestDenom=%d, nBalanceNeedsAnonymized=%d\n " , nLowestDenom, nBalanceNeedsAnonymized);
1456-
1457- // select coins that should be given to the pool
1458- if (!pwalletMain->SelectCoinsDark (nValueMin, nBalanceNeedsAnonymized, vCoins, nValueIn, 0 , nZeromintPercentage)) {
1459- nValueIn = 0 ;
1460- vCoins.clear ();
1461-
1462- if (pwalletMain->SelectCoinsDark (nValueMin, 9999999 * COIN, vCoins, nValueIn, -2 , 0 )) {
1463- nOnlyDenominatedBalance = pwalletMain->GetDenominatedBalance (true ) + pwalletMain->GetDenominatedBalance () - pwalletMain->GetAnonymizedBalance ();
1464- nBalanceNeedsDenominated = nBalanceNeedsAnonymized - nOnlyDenominatedBalance;
1465-
1466- if (nBalanceNeedsDenominated > nValueIn) nBalanceNeedsDenominated = nValueIn;
1467-
1468- if (nBalanceNeedsDenominated < nLowestDenom) return false ; // most likely we just waiting for denoms to confirm
1469- if (!fDryRun ) return CreateDenominated (nBalanceNeedsDenominated);
1470-
1471- return true ;
1472- } else {
1473- LogPrintf (" DoAutomaticDenominating : Can't denominate - no compatible inputs left\n " );
1474- strAutoDenomResult = _ (" Can't denominate: no compatible inputs left." );
1475- return false ;
1476- }
1477- }
1478-
1479- if (fDryRun ) return true ;
1480-
1481- nOnlyDenominatedBalance = pwalletMain->GetDenominatedBalance (true ) + pwalletMain->GetDenominatedBalance () - pwalletMain->GetAnonymizedBalance ();
1482- nBalanceNeedsDenominated = nBalanceNeedsAnonymized - nOnlyDenominatedBalance;
1483-
1484- // check if we have should create more denominated inputs
1485- if (nBalanceNeedsDenominated > nOnlyDenominatedBalance) return CreateDenominated (nBalanceNeedsDenominated);
1486-
1487- // check if we have the collateral sized inputs
1488- if (!pwalletMain->HasCollateralInputs ()) return !pwalletMain->HasCollateralInputs (false ) && MakeCollateralAmounts ();
1489-
1490- std::vector<CTxOut> vOut;
1491-
1492- // initial phase, find a Masternode
1493- if (!sessionFoundMasternode) {
1494- // Clean if there is anything left from previous session
1495- UnlockCoins ();
1496- SetNull ();
1497-
1498- int nUseQueue = rand () % 100 ;
1499- UpdateState (POOL_STATUS_ACCEPTING_ENTRIES);
1500-
1501- if (pwalletMain->GetDenominatedBalance (true ) > 0 ) { // get denominated unconfirmed inputs
1502- LogPrintf (" DoAutomaticDenominating -- Found unconfirmed denominated outputs, will wait till they confirm to continue.\n " );
1503- strAutoDenomResult = _ (" Found unconfirmed denominated outputs, will wait till they confirm to continue." );
1504- return false ;
1505- }
1506-
1507- // check our collateral nad create new if needed
1508- std::string strReason;
1509- CValidationState state;
1510- if (txCollateral == CMutableTransaction ()) {
1511- if (!pwalletMain->CreateCollateralTransaction (txCollateral, strReason)) {
1512- LogPrintf (" % -- create collateral error:%s\n " , __func__, strReason);
1513- return false ;
1514- }
1515- } else {
1516- if (!IsCollateralValid (txCollateral)) {
1517- LogPrintf (" %s -- invalid collateral, recreating...\n " , __func__);
1518- if (!pwalletMain->CreateCollateralTransaction (txCollateral, strReason)) {
1519- LogPrintf (" %s -- create collateral error: %s\n " , __func__, strReason);
1520- return false ;
1521- }
1522- }
1523- }
1524-
1525- // if we've used 90% of the Masternode list then drop all the oldest first
1526- int nThreshold = (int )(mnodeman.CountEnabled (ActiveProtocol ()) * 0.9 );
1527- LogPrint (" obfuscation" , " Checking vecMasternodesUsed size %d threshold %d\n " , (int )vecMasternodesUsed.size (), nThreshold);
1528- while ((int )vecMasternodesUsed.size () > nThreshold) {
1529- vecMasternodesUsed.erase (vecMasternodesUsed.begin ());
1530- LogPrint (" obfuscation" , " vecMasternodesUsed size %d threshold %d\n " , (int )vecMasternodesUsed.size (), nThreshold);
1531- }
1532-
1533- // don't use the queues all of the time for mixing
1534- if (nUseQueue > 33 ) {
1535- // Look through the queues and see if anything matches
1536- for (CObfuscationQueue& dsq : vecObfuscationQueue) {
1537- CService addr;
1538- if (dsq.time == 0 ) continue ;
1539-
1540- if (!dsq.GetAddress (addr)) continue ;
1541- if (dsq.IsExpired ()) continue ;
1542-
1543- int protocolVersion;
1544- if (!dsq.GetProtocolVersion (protocolVersion)) continue ;
1545- if (protocolVersion < ActiveProtocol ()) continue ;
1546-
1547- // non-denom's are incompatible
1548- if ((dsq.nDenom & (1 << 4 ))) continue ;
1549-
1550- bool fUsed = false ;
1551- // don't reuse Masternodes
1552- for (CTxIn usedVin : vecMasternodesUsed) {
1553- if (dsq.vin == usedVin) {
1554- fUsed = true ;
1555- break ;
1556- }
1557- }
1558- if (fUsed ) continue ;
1559-
1560- std::vector<CTxIn> vTempCoins;
1561- std::vector<COutput> vTempCoins2;
1562- // Try to match their denominations if possible
1563- if (!pwalletMain->SelectCoinsByDenominations (dsq.nDenom , nValueMin, nBalanceNeedsAnonymized, vTempCoins, vTempCoins2, nValueIn, 0 , nZeromintPercentage)) {
1564- LogPrintf (" DoAutomaticDenominating --- Couldn't match denominations %d\n " , dsq.nDenom );
1565- continue ;
1566- }
1567-
1568- CMasternode* pmn = mnodeman.Find (dsq.vin );
1569- if (pmn == NULL ) {
1570- LogPrintf (" DoAutomaticDenominating --- dsq vin %s is not in masternode list!" , dsq.vin .ToString ());
1571- continue ;
1572- }
1573-
1574- LogPrintf (" DoAutomaticDenominating --- attempt to connect to masternode from queue %s\n " , pmn->addr .ToString ());
1575- lastTimeChanged = GetTimeMillis ();
1576-
1577- // connect to Masternode and submit the queue request
1578- CNode* pnode = ConnectNode ((CAddress)addr, NULL , true );
1579- if (pnode != NULL ) {
1580- pSubmittedToMasternode = pmn;
1581- vecMasternodesUsed.push_back (dsq.vin );
1582- sessionDenom = dsq.nDenom ;
1583-
1584- pnode->PushMessage (" dsa" , sessionDenom, txCollateral);
1585- LogPrintf (" DoAutomaticDenominating --- connected (from queue), sending dsa for %d - %s\n " , sessionDenom, pnode->addr .ToString ());
1586- strAutoDenomResult = _ (" Mixing in progress..." );
1587- dsq.time = 0 ; // remove node
1588- return true ;
1589- } else {
1590- LogPrintf (" DoAutomaticDenominating --- error connecting \n " );
1591- strAutoDenomResult = _ (" Error connecting to Masternode." );
1592- dsq.time = 0 ; // remove node
1593- continue ;
1594- }
1595- }
1596- }
1597-
1598- // do not initiate queue if we are a liquidity proveder to avoid useless inter-mixing
1599- if (nLiquidityProvider) return false ;
1600-
1601- int i = 0 ;
1602-
1603- // otherwise, try one randomly
1604- while (i < 10 ) {
1605- CMasternode* pmn = mnodeman.FindRandomNotInVec (vecMasternodesUsed, ActiveProtocol ());
1606- if (pmn == NULL ) {
1607- LogPrintf (" DoAutomaticDenominating --- Can't find random masternode!\n " );
1608- strAutoDenomResult = _ (" Can't find random Masternode." );
1609- return false ;
1610- }
1611-
1612- if (pmn->nLastDsq != 0 &&
1613- pmn->nLastDsq + mnodeman.CountEnabled (ActiveProtocol ()) / 5 > mnodeman.nDsqCount ) {
1614- i++;
1615- continue ;
1616- }
1617-
1618- lastTimeChanged = GetTimeMillis ();
1619- LogPrintf (" DoAutomaticDenominating --- attempt %d connection to Masternode %s\n " , i, pmn->addr .ToString ());
1620- CNode* pnode = ConnectNode ((CAddress)pmn->addr , NULL , true );
1621- if (pnode != NULL ) {
1622- pSubmittedToMasternode = pmn;
1623- vecMasternodesUsed.push_back (pmn->vin );
1624-
1625- std::vector<CAmount> vecAmounts;
1626- pwalletMain->ConvertList (vCoins, vecAmounts);
1627- // try to get a single random denom out of vecAmounts
1628- while (sessionDenom == 0 )
1629- sessionDenom = GetDenominationsByAmounts (vecAmounts);
1630-
1631- pnode->PushMessage (" dsa" , sessionDenom, txCollateral);
1632- LogPrintf (" DoAutomaticDenominating --- connected, sending dsa for %d\n " , sessionDenom);
1633- strAutoDenomResult = _ (" Mixing in progress..." );
1634- return true ;
1635- } else {
1636- vecMasternodesUsed.push_back (pmn->vin ); // postpone MN we wasn't able to connect to
1637- i++;
1638- continue ;
1639- }
1640- }
1641-
1642- strAutoDenomResult = _ (" No compatible Masternode found." );
1643- return false ;
1644- }
1645-
1646- strAutoDenomResult = _ (" Mixing in progress..." );
1647- return false ;
16481387}
16491388
16501389
0 commit comments