diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py index 9e77256702..835c613671 100755 --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -185,7 +185,6 @@ 'sigma_listsigmamints_validation.py', 'sigma_listsigmaspends_validation.py', 'sigma_listunspentmints_sigma_validation.py', - 'sigma_listsigmapubcoins_validation.py', 'sigma_resetsigmamint_validation.py', 'sigma_setsigmamintstatus_validation.py', 'sigma_spend_gettransaction.py', diff --git a/qa/rpc-tests/sigma_listsigmapubcoins_validation.py b/qa/rpc-tests/sigma_listsigmapubcoins_validation.py deleted file mode 100755 index f5e1916f63..0000000000 --- a/qa/rpc-tests/sigma_listsigmapubcoins_validation.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python3 -from decimal import * - -from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import * - -denoms = { - '0.05': 0.05, - '0.1': 0.1, - '0.5': 0.5, - '1': 1, - '10': 10, - '25': 25, - '100': 100 -} - -# Should be unused pair of each denomination, due two mints -expected_pubcoins_before_spend = \ - [ - ('0.05', False), ('0.05', False), - ('0.1', False), ('0.1', False), - ('0.5', False), ('0.5', False), - ('1', False), ('1', False), - ('10', False), ('10', False), - ('25', False), ('25', False), - ('100', False), ('100', False), - ] - -expected_pubcoins_after_denom_spend = { - '0.05': [('0.05', False), ('0.05', False), ('0.1', False), ('0.1', True), - ('0.5', False), ('0.5', False), ('1', False), ('1', False), - ('10', False), ('10', False), ('100', False), ('100', False), ('25', False), ('25', False)], - - '0.1': [('0.05', False), ('0.05', True), ('0.1', True), ('0.1', True), - ('0.5', False), ('0.5', False), ('1', False), ('1', False), ('10', False), - ('10', False), ('100', False), ('100', False), ('25', False), ('25', False)], - - '0.5': [('0.05', True), ('0.05', True), ('0.1', True), ('0.1', True), ('0.5', False), - ('0.5', True), ('1', False), ('1', False), ('10', False), ('10', False), ('100', False), - ('100', False), ('25', False), ('25', False)], - - '1': [('0.05', False), ('0.05', True), ('0.05', True), ('0.1', False), ('0.1', False), ('0.1', False), - ('0.1', False), ('0.1', True), ('0.1', True), ('0.5', True), ('0.5', True), ('1', False), ('1', True), - ('10', False), ('10', False), ('100', False), ('100', False), ('25', False), ('25', False)], - - '10': [('0.05', False), ('0.05', False), ('0.05', True), ('0.05', True), ('0.1', False), ('0.1', False), - ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), - ('0.1', True), ('0.1', True), ('0.5', False), ('0.5', True), ('0.5', True), ('1', True), ('1', True), - ('10', False), ('10', True), ('100', False), ('100', False), ('25', False), ('25', False)], - - '25': [('0.05', False), ('0.05', True), ('0.05', True), ('0.05', True), ('0.1', False), ('0.1', False), - ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), - ('0.1', True), ('0.1', True), ('0.5', False), ('0.5', True), ('0.5', True), ('1', True), ('1', True), - ('10', False), ('10', True), ('100', False), ('100', False), ('25', False), ('25', True)], - - '100': [('0.05', True), ('0.05', True), ('0.05', True), ('0.05', True), ('0.1', False), ('0.1', False), - ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), ('0.1', False), - ('0.1', True), ('0.1', True), ('0.5', False), ('0.5', True), ('0.5', True), ('1', True), ('1', True), - ('10', False), ('10', True), ('100', False), ('100', True), ('25', False), ('25', True)] -} - - -class ListSigmaPubCoinsValidationWithFundsTest(BitcoinTestFramework): - def __init__(self): - super().__init__() - self.num_nodes = 4 - self.setup_clean_chain = False - - def setup_nodes(self): - # This test requires mocktime - enable_mocktime() - return start_nodes(self.num_nodes, self.options.tmpdir) - - def run_test(self): - getcontext().prec = 6 - self.sync_all() - - for denom in denoms.values(): - assert not self.nodes[0].listsigmapubcoins(str(denom)), 'List sigma pubcoins should be empty.' - - assert_raises(JSONRPCException, self.nodes[0].listsigmapubcoins, "0.15") - assert_raises(JSONRPCException, self.nodes[0].listsigmapubcoins, 0.1) - assert_raises(JSONRPCException, self.nodes[0].listsigmapubcoins, ["0.1", 1]) - - for denom in denoms.values(): - self.nodes[0].mint(denom) - self.nodes[0].mint(denom) - self.nodes[0].generate(2) - self.sync_all() - - pubcoins = [(pubcoin['denomination'], pubcoin['IsUsed']) - for pubcoin in self.nodes[0].listsigmapubcoins()] - - assert sorted(pubcoins) == sorted(expected_pubcoins_before_spend), \ - 'Unexpected pubcoins list returned. Should be: {}, but was: {}.' \ - .format(expected_pubcoins_before_spend, pubcoins) - - for denom_value in sorted(denoms.items(),key=lambda x:x[1]): - denom_name = denom_value[0] - denom = denom_value[1] - print("denom: " + denom_name) - args = {'THAYjKnnCsN5xspnEcb1Ztvw4mSPBuwxzU': denom} - self.nodes[0].spendmany("", args) - self.nodes[0].generate(1) - self.sync_all() - - pubcoins = [(pubcoin['denomination'], pubcoin['IsUsed']) - for pubcoin in self.nodes[0].listsigmapubcoins()] - - assert sorted(pubcoins) == sorted(expected_pubcoins_after_denom_spend[denom_name]), \ - 'Unexpected pubcoins list returned after spend: {}. Should be: {}, but was: {}.' \ - .format(denom, sorted(expected_pubcoins_after_denom_spend[denom_name]), sorted(pubcoins)) - - - - unused_pubcoins_sum = sum([Decimal(pubcoin['denomination']) - for pubcoin in self.nodes[0].listsigmapubcoins() if pubcoin['IsUsed'] == False]) - expected_unused_pubcoins_sum = sum(denoms.values()) - len(denoms) * 0.05 - - diff = int(unused_pubcoins_sum)-int(expected_unused_pubcoins_sum) - assert diff == 0, \ - 'Unexpected diff between unused coins sum expected and actual.' - - -if __name__ == '__main__': - ListSigmaPubCoinsValidationWithFundsTest().main() - diff --git a/src/firo_params.h b/src/firo_params.h index 1f8c6518ab..e8b8d26e72 100644 --- a/src/firo_params.h +++ b/src/firo_params.h @@ -108,7 +108,7 @@ static const int64_t DUST_HARD_LIMIT = 1000; // 0.00001 FIRO mininput #define EVOSPORK_MIN_VERSION 140200 // number of mint confirmations needed to spend coin -#define ZC_MINT_CONFIRMATIONS 2 +#define ZC_MINT_CONFIRMATIONS 1 // Genesis block timestamp #define ZC_GENESIS_BLOCK_TIME 1414776286 diff --git a/src/qt/bitcoinstrings.cpp b/src/qt/bitcoinstrings.cpp index 7226601aec..5a63e65806 100644 --- a/src/qt/bitcoinstrings.cpp +++ b/src/qt/bitcoinstrings.cpp @@ -117,7 +117,7 @@ QT_TRANSLATE_NOOP("firo-core", "" "Found unconfirmed denominated outputs, will wait till they confirm to " "continue."), QT_TRANSLATE_NOOP("firo-core", "" -"Has to have at least two mint coins with at least 2 confirmation in order to " +"Has to have at least two mint coins with at least 1 confirmation in order to " "spend a coin"), QT_TRANSLATE_NOOP("firo-core", "" "How thorough the block verification of -checkblocks is (0-4, default: %u)"), diff --git a/src/test/lelantus_mintspend_test.cpp b/src/test/lelantus_mintspend_test.cpp index fb01fbbe6c..727d169065 100644 --- a/src/test/lelantus_mintspend_test.cpp +++ b/src/test/lelantus_mintspend_test.cpp @@ -56,12 +56,6 @@ BOOST_AUTO_TEST_CASE(lelantus_mintspend_test) {GetScriptForDestination(randomAddr.Get()), 30 * COIN, true}, }; - // Add 1 more blocks and verify that Mint can not be spent until 2blocks verification - { - CWalletTx wtx; - BOOST_CHECK_THROW(pwalletMain->JoinSplitLelantus(recipients, {}, wtx), WalletError); //this must throw as it has to have at least two mint coins with at least 2 confirmation - } - GenerateBlock({}); BOOST_CHECK_MESSAGE(previousHeight + 1 == chainActive.Height(), "Block not added to chain"); diff --git a/src/test/sigma_lelantus_transition.cpp b/src/test/sigma_lelantus_transition.cpp index 87afaa31ff..69ee40e2ad 100644 --- a/src/test/sigma_lelantus_transition.cpp +++ b/src/test/sigma_lelantus_transition.cpp @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(sigma_lelantus_transition_test) BOOST_CHECK_MESSAGE(mempool.size() == 0, "Mints were not removed from mempool"); GenerateBlocks(6); recipients = { - {GetScriptForDestination(randomAddr.Get()), 100 * COIN, true}, + {GetScriptForDestination(randomAddr.Get()), 105 * COIN, true}, }; wtx.Init(NULL); BOOST_CHECK_NO_THROW(pwalletMain->JoinSplitLelantus(recipients, {}, wtx)); @@ -121,6 +121,7 @@ BOOST_AUTO_TEST_CASE(sigma_lelantus_transition_test) GenerateBlock({CMutableTransaction(*wtx.tx)}); BOOST_CHECK_MESSAGE(previousHeight + 1 == chainActive.Height(), "Block not added to chain"); BOOST_CHECK_MESSAGE(mempool.size() == 0, "JoinSplit is not removed from mempool"); + int joinSplitHeight = chainActive.Height(); coins = pwalletMain->GetAvailableCoins(nullptr, false); BOOST_CHECK_MESSAGE(coins.size() == 0, "All sigma coins should be marked used, but something went wrong"); @@ -132,7 +133,10 @@ BOOST_AUTO_TEST_CASE(sigma_lelantus_transition_test) GenerateBlocks(6); auto currentLelantusCoins = pwalletMain->GetAvailableLelantusCoins(nullptr, false); - BOOST_CHECK_MESSAGE(currentLelantusCoins.size() > lelantusCoins.size(), "Newly created jmint should be marked as spendable, but something went wrong"); + // There should be a mint with height equal to join split height in list of available lelantus coins + BOOST_CHECK_MESSAGE(std::find_if(currentLelantusCoins.begin(), currentLelantusCoins.end(), + [=](const CLelantusEntry &coin) { return coin.nHeight == joinSplitHeight; }) != currentLelantusCoins.end(), + "Newly created jmint should be marked as spendable, but something went wrong"); mempool.clear(); sigma::CSigmaState::GetState()->Reset(); diff --git a/src/test/sigma_manymintspend_test.cpp b/src/test/sigma_manymintspend_test.cpp index 8bbac1071c..440830277e 100644 --- a/src/test/sigma_manymintspend_test.cpp +++ b/src/test/sigma_manymintspend_test.cpp @@ -125,9 +125,6 @@ BOOST_AUTO_TEST_CASE(sigma_mintspend_many) previousHeight = chainActive.Height(); - //Add 1 more blocks and verify that Mint can not be spent until 2 blocks verification - wtx.Init(NULL); - BOOST_CHECK_THROW(pwalletMain->SpendSigma(recipients, wtx), WalletError); //this must throw as 2 blocks have not passed yet, b = CreateAndProcessBlock(scriptPubKey); wtx.Init(NULL); diff --git a/src/test/sigma_mintspend_test.cpp b/src/test/sigma_mintspend_test.cpp index 6d75d2f6e9..dd6f7da0d8 100644 --- a/src/test/sigma_mintspend_test.cpp +++ b/src/test/sigma_mintspend_test.cpp @@ -116,11 +116,6 @@ BOOST_AUTO_TEST_CASE(sigma_mintspend_test) previousHeight = chainActive.Height(); - //Add 1 more blocks and verify that Mint can not be spent until 2 blocks verification - { - CWalletTx wtx; - BOOST_CHECK_THROW(pwalletMain->SpendSigma(recipients, wtx), WalletError); //this must throw as 2 blocks have not passed yet, - } b = CreateAndProcessBlock(scriptPubKey); BOOST_CHECK_MESSAGE(previousHeight + 1 == chainActive.Height(), "Block not added to chain"); diff --git a/src/wallet/lelantusjoinsplitbuilder.cpp b/src/wallet/lelantusjoinsplitbuilder.cpp index 9f26870bb0..d04d5ec226 100644 --- a/src/wallet/lelantusjoinsplitbuilder.cpp +++ b/src/wallet/lelantusjoinsplitbuilder.cpp @@ -469,13 +469,13 @@ void LelantusJoinSplitBuilder::CreateJoinSplit( uint256 blockHash; if (state->GetCoinSetForSpend( &chainActive, - chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 2 confirmation for mint to spend + chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 1 confirmation for mint to spend groupId, blockHash, set, setHash) < 2) throw std::runtime_error( - _("Has to have at least two mint coins with at least 2 confirmation in order to spend a coin")); + _("Has to have at least two mint coins with at least 1 confirmation in order to spend a coin")); groupBlockHashes[groupId] = blockHash; anonymity_sets[groupId] = set; if (!setHash.empty()) @@ -518,13 +518,13 @@ void LelantusJoinSplitBuilder::CreateJoinSplit( uint256 blockHash; if (sigmaState->GetCoinSetForSpend( &chainActive, - chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 2 confirmation for mint to spend + chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 1 confirmation for mint to spend spend.get_denomination(), groupId, blockHash, group) < 2) throw std::runtime_error( - _("Has to have at least two mint coins with at least 2 confirmation in order to spend a coin")); + _("Has to have at least two mint coins with at least 1 confirmation in order to spend a coin")); std::vector set; set.reserve(group.size()); for(auto& coin : group) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index be9bc081ac..55b2102bef 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -696,9 +696,9 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request) "\nThe amount including unconfirmed transactions, zero confirmations\n" + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 0") + "\nThe amount with at least 2 confirmation, very safe\n" - + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 6") + + + HelpExampleCli("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" 2") + "\nAs a json rpc call\n" - + HelpExampleRpc("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 6") + + HelpExampleRpc("getreceivedbyaddress", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", 2") ); LOCK2(cs_main, pwallet->cs_wallet); @@ -758,9 +758,9 @@ UniValue getreceivedbyaccount(const JSONRPCRequest& request) "\nAmount received at the tabby account including unconfirmed amounts with zero confirmations\n" + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 0") + "\nThe amount with at least 2 confirmation, very safe\n" - + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 6") + + + HelpExampleCli("getreceivedbyaccount", "\"tabby\" 2") + "\nAs a json rpc call\n" - + HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 6") + + HelpExampleRpc("getreceivedbyaccount", "\"tabby\", 2") ); LOCK2(cs_main, pwallet->cs_wallet); @@ -1010,9 +1010,9 @@ UniValue sendfrom(const JSONRPCRequest& request) "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n" + HelpExampleCli("sendfrom", "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") + "\nSend 0.01 from the tabby account to the given address, funds must have at least 2 confirmations\n" - + HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") + + + HelpExampleCli("sendfrom", "\"tabby\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 2 \"donation\" \"seans outpost\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("sendfrom", "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 6, \"donation\", \"seans outpost\"") + + HelpExampleRpc("sendfrom", "\"tabby\", \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 2, \"donation\", \"seans outpost\"") ); LOCK2(cs_main, pwallet->cs_wallet); @@ -1826,9 +1826,9 @@ UniValue listaccounts(const JSONRPCRequest& request) "\nList account balances including zero confirmation transactions\n" + HelpExampleCli("listaccounts", "0") + "\nList account balances for 2 or more confirmations\n" - + HelpExampleCli("listaccounts", "6") + + + HelpExampleCli("listaccounts", "2") + "\nAs json rpc call\n" - + HelpExampleRpc("listaccounts", "6") + + HelpExampleRpc("listaccounts", "2") ); LOCK2(cs_main, pwallet->cs_wallet); diff --git a/src/wallet/sigmaspendbuilder.cpp b/src/wallet/sigmaspendbuilder.cpp index 1ea4a20518..c86a1cb0f1 100644 --- a/src/wallet/sigmaspendbuilder.cpp +++ b/src/wallet/sigmaspendbuilder.cpp @@ -96,12 +96,12 @@ static std::unique_ptr CreateSigner(const CSigmaEntry& coin) if (state->GetCoinSetForSpend( &chainActive, - chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 2 confirmation for mint to spend + chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 1 confirmation for mint to spend denom, groupId, signer->lastBlockOfGroup, signer->group) < 2) { - throw std::runtime_error(_("Has to have at least two mint coins with at least 2 confirmation in order to spend a coin")); + throw std::runtime_error(_("Has to have at least two mint coins with at least 1 confirmation in order to spend a coin")); } return signer; diff --git a/src/wallet/test/sigma_tests.cpp b/src/wallet/test/sigma_tests.cpp index 966ae6cc95..fe372d8758 100644 --- a/src/wallet/test/sigma_tests.cpp +++ b/src/wallet/test/sigma_tests.cpp @@ -324,25 +324,6 @@ BOOST_AUTO_TEST_CASE(get_coin_not_enough) sigmaState->Reset(); } -BOOST_AUTO_TEST_CASE(get_coin_cannot_spend_unconfirmed_coins) -{ - AddOneCoinForEachGroup(); - std::vector> newCoins; - GetCoinSetByDenominationAmount(newCoins, 1, 1, 1, 1, 1, 1, 1); - GenerateBlockWithCoins(newCoins); - // Intentionally do not create 5 more blocks after this one, so coins can not be spent. - // GenerateEmptyBlocks(5); - - CAmount require(11150 * CENT); // 111.5 - - std::vector coins; - std::vector coinsToMint; - std::list availableCoins = pwalletMain->GetAvailableCoins(); - - BOOST_CHECK_THROW(pwalletMain->GetCoinsToSpend(require, coins, coinsToMint, availableCoins), InsufficientFunds); - sigmaState->Reset(); -} - BOOST_AUTO_TEST_CASE(get_coin_minimize_coins_spend_fit_amount) { std::vector> newCoins; @@ -477,41 +458,6 @@ BOOST_AUTO_TEST_CASE(create_spend_with_insufficient_coins) sigmaState->Reset(); } -BOOST_AUTO_TEST_CASE(create_spend_with_confirmation_less_than_6) -{ - CAmount fee; - std::vector selected; - std::vector changes; - std::vector recipients; - - GenerateBlockWithCoins({ std::make_pair(sigma::CoinDenomination::SIGMA_DENOM_10, 2) }); - - recipients.push_back(CRecipient{ - .scriptPubKey = GetScriptForDestination(randomAddr1.Get()), - .nAmount = 5 * COIN, - .fSubtractFeeFromAmount = false - }); - - recipients.push_back(CRecipient{ - .scriptPubKey = GetScriptForDestination(randomAddr2.Get()), - .nAmount = 5 * COIN, - .fSubtractFeeFromAmount = false - }); - - recipients.push_back(CRecipient{ - .scriptPubKey = GetScriptForDestination(randomAddr3.Get()), - .nAmount = 1 * COIN, - .fSubtractFeeFromAmount = false - }); - - bool fChangeAddedToFee; - BOOST_CHECK_EXCEPTION( - pwalletMain->CreateSigmaSpendTransaction(recipients, fee, selected, changes, fChangeAddedToFee), - InsufficientFunds, - [](const InsufficientFunds& e) { return e.what() == std::string("Insufficient funds"); }); - sigmaState->Reset(); -} - BOOST_AUTO_TEST_CASE(create_spend_with_coins_less_than_2) { CAmount fee; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c9b8da0738..45878e463f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2882,7 +2882,7 @@ std::list CWallet::GetAvailableCoins(const CCoinControl *coinContro std::vector coinOuts; sigmaState->GetCoinSetForSpend( &chainActive, - chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 2 confirmation for mint to spend + chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 1 confirmation for mint to spend coin.get_denomination(), coinId, hashOut, @@ -2960,7 +2960,7 @@ std::list CWallet::GetAvailableLelantusCoins(const CCoinControl std::vector setHash; state->GetCoinSetForSpend( &chainActive, - chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 2 confirmation for mint to spend + chainActive.Height() - (ZC_MINT_CONFIRMATIONS - 1), // required 1 confirmation for mint to spend coinId, hashOut, coinOuts,