Skip to content

Commit

Permalink
Merge branch 'master' into sigma_pool_closed
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 authored Sep 3, 2024
2 parents e699326 + bfd992e commit 5fcc3f1
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,8 @@ class CRegTestParams : public CChainParams {
consensus.stage2DevelopmentFundShare = 15;
consensus.stage2ZnodeShare = 35;

consensus.stage3StartTime = INT_MAX;
consensus.stage3StartBlock = 2000;
consensus.stage3StartTime = INT_MAX; // tests should set this value individually
consensus.stage3StartBlock = INT_MAX; // same as above
consensus.stage3DevelopmentFundShare = 15;
consensus.stage3CommunityFundShare = 10;
consensus.stage3MasternodeShare = 50;
Expand Down
12 changes: 11 additions & 1 deletion src/qt/forms/notifymnemonic.ui
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,21 @@
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="walletBirthDate">
<property name="text">
<string></string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Please write down these recovery seed phrase and keep them in a secure location.</string>
<string>Please write down these recovery seed phrase and wallet birth date and keep them in a secure location. Specifying the wallet's birth date when restoring your wallet speeds up and optimizes the scanning of your wallet.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down
60 changes: 43 additions & 17 deletions src/qt/forms/recover.ui
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ You can also choose to further encrypt your recovery seed phrase with an additio
You will need to save this passphrase as well with the recovery seed phrase. Failing to save the passphrase will lead to your funds being irrecoverable.

If you have an existing recovery seed phrase, please select "Recover existing wallet". If you have secured your recovery seed phrase with an additional passphrase, enter it too.
Also you can choose wallet birth date for more faster and optimised wallet scan.
</string>
</property>
<property name="wordWrap">
Expand Down Expand Up @@ -134,20 +135,51 @@ If you have an existing recovery seed phrase, please select "Recover existing wa
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout2">
<layout class="QVBoxLayout" name="verticalLayout2">
<item>
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Input recovery seed phrase here:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout2">
<item>
<widget class="QLabel" name="textLabel2">
<property name="text">
<string>Input recovery seed phrase here:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mnemonicWords"/>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="mnemonicWords"/>
</item>
<layout class="QHBoxLayout" name="horizontalLayoutDate">
<item>
<widget class="QLabel" name="textLabelDate">
<property name="text">
<string>Choose the wallet creation date:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="dateInput">
<property name="calendarPopup">
<bool>true</bool>
</property>
<property name="displayFormat">
<string>dd-MM-yyyy</string>
</property>
<property name="date">
</property>
</widget>
</item>
</layout>
</item>

</layout>
</item>
<item>
Expand Down Expand Up @@ -234,12 +266,6 @@ If you have an existing recovery seed phrase, please select "Recover existing wa
</item>
<item>
<widget class="QLabel" name="errorMessage">
<property name="text">
<string/>
</property>
<property name="styleSheet">
<string notr="true">color:red;</string>
</property>
<property name="text">
<string/>
</property>
Expand Down
6 changes: 6 additions & 0 deletions src/qt/notifymnemonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QSettings>
#include <QMessageBox>
#include <QAbstractButton>
#include <QDate>

NotifyMnemonic::NotifyMnemonic(QWidget *parent) :
QWizard(parent),
Expand All @@ -36,6 +37,10 @@ void NotifyMnemonic::cancelEvent()
}
}

QString getCurrentDate() {
return QDate::currentDate().toString("dd-MM-yyyy");
}

void NotifyMnemonic::notify()
{
#ifdef ENABLE_WALLET
Expand All @@ -44,6 +49,7 @@ void NotifyMnemonic::notify()
NotifyMnemonic notify;
notify.setWindowIcon(QIcon(":icons/firo"));
notify.show();
notify.ui->walletBirthDate->setText("Wallet creation date: " + getCurrentDate());
notify.ui->mnemonic->setText(mnemonic.c_str());
notify.restart();
while(true)
Expand Down
15 changes: 15 additions & 0 deletions src/qt/recover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Recover::Recover(QWidget *parent) :

connect(this, &Recover::stopThread, thread, &QThread::quit);
thread->start();

ui->dateInput->setDisplayFormat("dd-MM-yyyy");
ui->dateInput->setMinimumDate(QDate(2019, 12, 11));
}

Recover::~Recover()
Expand All @@ -47,6 +50,8 @@ void Recover::setCreateNew()
ui->textLabel2->setEnabled(false);
ui->mnemonicWords->setEnabled(false);
ui->mnemonicWords->clear();
ui->dateInput->setEnabled(false);
ui->dateInput->clear();
ui->use24->setChecked(true);
ui->usePassphrase->setChecked(false);
ui->textLabel3->setEnabled(false);
Expand All @@ -58,12 +63,18 @@ void Recover::setCreateNew()
void Recover::on_createNew_clicked()
{
setCreateNew();
ui->dateInput->setDisplayFormat("dd-MM-yyyy");
ui->dateInput->setDate(QDate(2019, 12, 11));
}

void Recover::on_recoverExisting_clicked()
{
ui->textLabel2->setEnabled(true);
ui->mnemonicWords->setEnabled(true);
ui->dateInput->setEnabled(true);
ui->dateInput->setEnabled(true);
ui->dateInput->setDisplayFormat("dd-MM-yyyy");
ui->dateInput->setDate(ui->dateInput->minimumDate());
}

void Recover::on_usePassphrase_clicked()
Expand Down Expand Up @@ -106,6 +117,10 @@ bool Recover::askRecover(bool& newWallet)
if(recover.ui->recoverExisting->isChecked()) {
newWallet = false;
std::string mnemonic = recover.ui->mnemonicWords->text().toStdString();
QDate date = recover.ui->dateInput->date();
QDate newDate = date.addDays(-1);
recover.ui->dateInput->setDate(newDate);
SoftSetArg("-wcdate", recover.ui->dateInput->text().toStdString());
const char* str = mnemonic.c_str();
bool space = true;
int n = 0;
Expand Down
43 changes: 23 additions & 20 deletions src/test/firsthalving_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ BOOST_FIXTURE_TEST_CASE(devpayout, TestChainDIP3BeforeActivationSetup)

consensusParams.nSubsidyHalvingFirst = 600;
consensusParams.stage3StartTime = INT_MAX;
consensusParams.nSubsidyHalvingSecond = 620;
consensusParams.nSubsidyHalvingSecond = consensusParams.stage4StartBlock = 620;
consensusParams.nSubsidyHalvingInterval = 10;

CScript devPayoutScript = GenerateRandomAddress();
Expand Down Expand Up @@ -225,6 +225,8 @@ BOOST_FIXTURE_TEST_CASE(devpayout, TestChainDIP3BeforeActivationSetup)

// initiate stage3
consensusParams.stage3StartTime = GetTime();
consensusParams.stage3StartBlock = chainActive.Height();

// for stage3 there is dev payout and community payout
for (int i=610; i<620; i++) {
CBlock block = CreateAndProcessBlock({}, coinbaseKey);
Expand Down Expand Up @@ -259,39 +261,39 @@ BOOST_FIXTURE_TEST_CASE(devpayout, TestChainDIP3BeforeActivationSetup)
CAmount nValue;
auto dmnPayout = FindPayoutDmn(block, nValue);

BOOST_ASSERT(dmnPayout != nullptr && nValue == 3125*COIN/1000); // 3.125 (6.25*0.5)
// stage 4: no real halving here
BOOST_ASSERT(dmnPayout != nullptr && nValue == 625*COIN/100); // 6.25

// there should be no more payment to devs fund
for (const CTxOut &txout: block.vtx[0]->vout) {
BOOST_ASSERT(txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage2DevelopmentFundAddress).Get()));
}

// miner's reward should be 6.25-3.125 = 3.125
BOOST_ASSERT(block.vtx[0]->vout[0].nValue == 3125*COIN/1000);
// should be only 2 vouts in coinbase
BOOST_ASSERT(block.vtx[0]->vout.size() == 2);
// miner's reward should be 1.25 (10%)
BOOST_ASSERT(block.vtx[0]->vout[0].nValue == 125*COIN/100);

bool paymentToDevFound = false, paymentToCommunityFound = false;
for (const CTxOut &txout: block.vtx[0]->vout) {
if (txout.scriptPubKey == GetScriptForDestination(CBitcoinAddress(consensusParams.stage3DevelopmentFundAddress).Get())) {
BOOST_ASSERT(txout.nValue == 3125*COIN/1000); // 25/2*0.25
paymentToDevFound = true;
}
if (txout.scriptPubKey == GetScriptForDestination(CBitcoinAddress(consensusParams.stage3CommunityFundAddress).Get())) {
BOOST_ASSERT(txout.nValue == 1875*COIN/1000); // 25/2*0.15
paymentToCommunityFound = true;
}
}
BOOST_ASSERT(paymentToDevFound && paymentToCommunityFound);
}

// the third halving should occur at block 630
// tail emission should occur at block 630
CBlock block = CreateAndProcessBlock({}, coinbaseKey);
deterministicMNManager->UpdatedBlockTip(chainActive.Tip());

CAmount nValue;
auto dmnPayout = FindPayoutDmn(block, nValue);

BOOST_ASSERT(dmnPayout != nullptr && nValue == 3125*COIN/1000/2); // 3.125/2 (3.125*0.5)

// there should be no more payment to devs/community funds fund
for (const CTxOut &txout: block.vtx[0]->vout) {
BOOST_ASSERT(txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage2DevelopmentFundAddress).Get()) &&
txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage3DevelopmentFundAddress).Get()) &&
txout.scriptPubKey != GetScriptForDestination(CBitcoinAddress(consensusParams.stage3CommunityFundAddress).Get()));
}

// miner's reward should be 3.125/2
BOOST_ASSERT(block.vtx[0]->vout[0].nValue == 3125*COIN/1000/2);
// should be only 2 vouts in coinbase
BOOST_ASSERT(block.vtx[0]->vout.size() == 2);
BOOST_ASSERT(dmnPayout != nullptr && nValue == COIN);

consensusParams = consensusParamsBackup;
}
Expand All @@ -303,6 +305,7 @@ BOOST_FIXTURE_TEST_CASE(devpayoutverification, TestChainDIP3BeforeActivationSetu

consensusParams.nSubsidyHalvingFirst = 600;
consensusParams.nSubsidyHalvingSecond = 610;
consensusParams.stage3StartTime = INT_MAX;
consensusParams.nSubsidyHalvingInterval = 10;

// skip to block 600
Expand Down
15 changes: 14 additions & 1 deletion src/test/mtp_halving_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ CScript scriptPubKeyMtpHalving;


struct MtpHalvingTestingSetup : public TestingSetup {
MtpHalvingTestingSetup() : TestingSetup(CBaseChainParams::REGTEST)
Consensus::Params &mutableParams;
Consensus::Params oldParams;

MtpHalvingTestingSetup() : TestingSetup(CBaseChainParams::REGTEST), mutableParams(const_cast<Consensus::Params&>(Params().GetConsensus()))
{
oldParams = mutableParams;

// disable stage 3 stuff for now
mutableParams.stage3StartTime = INT_MAX;
mutableParams.stage3StartBlock = INT_MAX;

CPubKey newKey;
BOOST_CHECK(pwalletMain->GetKeyFromPool(newKey));

Expand All @@ -66,6 +75,10 @@ struct MtpHalvingTestingSetup : public TestingSetup {
}
}

~MtpHalvingTestingSetup() {
mutableParams = oldParams;
}

CBlock CreateBlock(const CScript& scriptPubKeyMtpHalving, bool mtp = false) {
const CChainParams& chainparams = Params();
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKeyMtpHalving);
Expand Down
65 changes: 52 additions & 13 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,30 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,

}

static std::time_t parseDate(const std::string& dateStr) {
std::tm tm = {};
std::istringstream ss(dateStr);
ss >> std::get_time(&tm, "%d-%m-%Y");
if (ss.fail()) {
throw std::invalid_argument("Invalid date format: " + dateStr);
}
return std::mktime(&tm);
}

CBlockIndex* CWallet::GetBlockByDate(CBlockIndex* pindexStart, const std::string& dateStr) {
std::time_t targetTimestamp = parseDate(dateStr);

CBlockIndex* pindex = pindexStart;

while (pindex) {
if (pindex->GetBlockTime() > targetTimestamp) {
return chainActive[pindex->nHeight - 200];
}
pindex = chainActive.Next(pindex);
}
return chainActive[chainActive.Tip()->nHeight];
}

/**
* Scan the block chain (starting in pindexStart) for transactions
* from or to us. If fUpdate is true, found transactions that already
Expand All @@ -2383,18 +2407,34 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex *pindexStart, bool f
CBlockIndex* pindex = pindexStart;
{
LOCK2(cs_main, cs_wallet);

// no need to read and scan block, if block was created before
// our wallet birthday (as adjusted for block time variability)
// if you are recovering wallet with mnemonics start rescan from block when mnemonics implemented in Firo
if (fRecoverMnemonic) {
pindex = chainActive[chainParams.GetConsensus().nMnemonicBlock];
if (pindex == NULL)
pindex = chainActive.Tip();
} else
while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200)))
pindex = chainActive.Next(pindex);

// No need to read and scan block if block was created before our wallet birthday (as adjusted for block time variability).
// If you are recovering wallet with mnemonics, start rescan from the block when mnemonics were implemented in Firo.
// If the user provides a date, start scanning from the block that corresponds to that date.
// If no date is provided, start scanning from the mnemonic start block.

std::string wcdate = GetArg("-wcdate", "");
CBlockIndex* mnemonicStartBlock = chainActive[chainParams.GetConsensus().nMnemonicBlock];
if (mnemonicStartBlock == NULL)
mnemonicStartBlock = chainActive.Tip();

if (!wcdate.empty()) {
pindex = GetBlockByDate(mnemonicStartBlock, wcdate);
if (pindex->nHeight < chainParams.GetConsensus().nMnemonicBlock) {
pindex = mnemonicStartBlock;
}
} else {
bool fRescan = GetBoolArg("-rescan", false);
if (fRescan || fRecoverMnemonic) {
if (mnemonicContainer.IsNull())
pindex = chainActive.Genesis();
else
pindex = mnemonicStartBlock;
}
else
while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200)))
pindex = chainActive.Next(pindex);
}
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height(), pindex->nHeight);
ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex);
double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip());
Expand Down Expand Up @@ -7285,7 +7325,6 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
}

uiInterface.InitMessage(_("Rescanning..."));
LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height() - pindexRescan->nHeight, pindexRescan->nHeight);
nStart = GetTimeMillis();
walletInstance->ScanForWalletTransactions(pindexRescan, true, fRecoverMnemonic);
LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart);
Expand Down
Loading

0 comments on commit 5fcc3f1

Please sign in to comment.