Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed number of confirmations for spending a mint to 1 #1077

Merged
merged 4 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion qa/pull-tester/rpc-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
127 changes: 0 additions & 127 deletions qa/rpc-tests/sigma_listsigmapubcoins_validation.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/firo_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoinstrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand Down
6 changes: 0 additions & 6 deletions src/test/lelantus_mintspend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 6 additions & 2 deletions src/test/sigma_lelantus_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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");
Expand All @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/test/sigma_manymintspend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/test/sigma_mintspend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/wallet/lelantusjoinsplitbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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<lelantus::PublicCoin> set;
set.reserve(group.size());
for(auto& coin : group) {
Expand Down
16 changes: 8 additions & 8 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/sigmaspendbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ static std::unique_ptr<SigmaSpendSigner> 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;
Expand Down
54 changes: 0 additions & 54 deletions src/wallet/test/sigma_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<sigma::CoinDenomination, int>> 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<CSigmaEntry> coins;
std::vector<sigma::CoinDenomination> coinsToMint;
std::list<CSigmaEntry> 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<std::pair<sigma::CoinDenomination, int>> newCoins;
Expand Down Expand Up @@ -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<CSigmaEntry> selected;
std::vector<CHDMint> changes;
std::vector<CRecipient> 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;
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2882,7 +2882,7 @@ std::list<CSigmaEntry> CWallet::GetAvailableCoins(const CCoinControl *coinContro
std::vector<sigma::PublicCoin> 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,
Expand Down Expand Up @@ -2960,7 +2960,7 @@ std::list<CLelantusEntry> CWallet::GetAvailableLelantusCoins(const CCoinControl
std::vector<unsigned char> 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,
Expand Down