Skip to content

Commit

Permalink
Add GUI changes
Browse files Browse the repository at this point in the history
Add newer checkpoint

New checkpoint

Add tests

Fix whitespace

Set correct permissions

Adjust test positon and fix num nodes
  • Loading branch information
Liquid369 committed Mar 28, 2023
1 parent cb07e1d commit 146e72b
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ static MapCheckpoints mapCheckpoints = {
{3014000, uint256S("78ad99b7225f73c42238bd7ca841ff700542b92bba75a0ef2ed351caa560f87f")}, //!< PIVX v5.3.0 enforced
{3024000, uint256S("be4bc75afcfb9136924810f7483b2695089a366cc4ee27fd6dc3ecd5396e1f0f")}, //!< Superblock
{3715200, uint256S("a676b9a598c393c82b949c37dd35013aeda55f5d18ab062349db6a8235972aaa")}, //!< Superblock for 5.5.0 mainnet rewards changeover
{3780000, uint256S("2667fa1d552999aca930ced7fd3902ae5721e5c256a607049e3c47a3137a18ee")}, //!< Fri, 10 Mar 2023 rewindblockindex testing
};

static const CCheckpointData data = {
&mapCheckpoints,
1591401645, // * UNIX timestamp of last checkpoint block
5607713, // * total number of transactions between genesis and last checkpoint
1678401150, // * UNIX timestamp of last checkpoint block
8716106, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the UpdateTip debug.log lines)
3000 // * estimated number of transactions per day after checkpoint
};
Expand Down
1 change: 1 addition & 0 deletions src/qt/pivx/qtutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const QString ZAPTXES2("-zapwallettxes=2");
const QString UPGRADEWALLET("-upgradewallet");
const QString REINDEX("-reindex");
const QString RESYNC("-resync");
const QString REWIND("-rewindblockindex");

extern Qt::Modifier SHORT_KEY;

Expand Down
83 changes: 80 additions & 3 deletions src/qt/pivx/settings/forms/settingswalletrepairwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<height>620</height>
<y>-57</y>
<width>383</width>
<height>677</height>
</rect>
</property>
<property name="autoFillBackground">
Expand Down Expand Up @@ -584,11 +584,88 @@
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalRewind" stretch="1,1">
<property name="spacing">
<number>20</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalRewind" stretch="0">
<property name="spacing">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButtonRewind">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>40</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Rewind blockchain</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelMessageRewind">
<property name="text">
<string>Rewind blockchain to last checkpoint</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
Expand Down
24 changes: 22 additions & 2 deletions src/qt/pivx/settings/settingswalletrepairwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ SettingsWalletRepairWidget::SettingsWalletRepairWidget(PIVXGUI* _window, QWidget
// Labels
setCssProperty({ui->labelMessageSalvage, ui->labelMessageRescan, ui->labelMessageRecover1,
ui->labelMessageRecover2, ui->labelMessageUpgrade, ui->labelMessageRebuild,
ui->labelMessageDelete}, "text-main-settings");
ui->labelMessageDelete, ui->labelMessageRewind}, "text-main-settings");

// Buttons
setCssProperty({ui->pushButtonSalvage, ui->pushButtonRescan, ui->pushButtonRecover1,
ui->pushButtonRecover2, ui->pushButtonUpgrade, ui->pushButtonRebuild,
ui->pushButtonDelete}, "btn-primary");
ui->pushButtonDelete, ui->pushButtonRewind}, "btn-primary");

// Wallet Repair Buttons
connect(ui->pushButtonSalvage, &QPushButton::clicked, this, &SettingsWalletRepairWidget::walletSalvage);
Expand All @@ -41,6 +41,7 @@ SettingsWalletRepairWidget::SettingsWalletRepairWidget(PIVXGUI* _window, QWidget
connect(ui->pushButtonUpgrade, &QPushButton::clicked, this, &SettingsWalletRepairWidget::walletUpgrade);
connect(ui->pushButtonRebuild, &QPushButton::clicked, this, &SettingsWalletRepairWidget::walletReindex);
connect(ui->pushButtonDelete, &QPushButton::clicked, this, &SettingsWalletRepairWidget::walletResync);
connect(ui->pushButtonRewind, &QPushButton::clicked, this, &SettingsWalletRepairWidget::walletRewind);
}

/** Restart wallet with "-salvagewallet" */
Expand Down Expand Up @@ -100,6 +101,25 @@ void SettingsWalletRepairWidget::walletResync()
buildParameterlist(RESYNC);
}

/** Restart wallet with "-rewindblockindex" */
void SettingsWalletRepairWidget::walletRewind()
{
QString rewindWarning = tr("This will rewind your blocks to the most recent checkpoint.<br /><br />");
rewindWarning += tr("Do you want to continue?.<br />");
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm resync Blockchain"),
rewindWarning,
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);

if (retval != QMessageBox::Yes) {
// Rewind canceled
return;
}

// Restart and rewind
buildParameterlist(REWIND);
}

/** Build command-line parameter list for restart */
void SettingsWalletRepairWidget::buildParameterlist(QString arg)
{
Expand Down
1 change: 1 addition & 0 deletions src/qt/pivx/settings/settingswalletrepairwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public Q_SLOTS:
void walletUpgrade();
void walletReindex();
void walletResync();
void walletRewind();

private:
Ui::SettingsWalletRepairWidget *ui;
Expand Down
65 changes: 65 additions & 0 deletions test/functional/feature_rewind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
# Copyright (c) 2019 The Bitcoin Core developers
# Copyright (c) 2023 The PIVX Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php.

"""Test running pivxd with -rewindblockindex option.
- Start 2 Nodes
- Sync both nodes to different chains
- Stop and then start both nodes with -rewindblockindex
"""

from test_framework.test_framework import PivxTestFramework
from test_framework.util import (
assert_equal,
connect_nodes,
)

class RewindBlockIndexCheckpointTest(PivxTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args = [
['-nuparams=PoS:201', '-nuparams=PoS_v2:201', "-whitelist=127.0.0.1", '-debug=0'], #right chain
['-nuparams=PoS:301', '-nuparams=PoS_v2:301', "-whitelist=127.0.0.1", '-debug=0'] #wrong chain
]

def run_test(self):
self.log.info("Starting nodes")

res0 = self.nodes[0].getblockchaininfo()
res1 = self.nodes[1].getblockchaininfo()

self.nodes[0].generate(1)
self.nodes[1].generate(1)

res0 = self.nodes[0].getblockchaininfo()
res1 = self.nodes[1].getblockchaininfo()

rightChain = res0["bestblockhash"]
wrongChain = res1["bestblockhash"]

assert not rightChain==wrongChain

self.log.info("Restart Node1 (after upgrade window) with forced rewindblockindex")
# restart node1 with right nuparams and rewindblockindex
# on regtest only forced rewinds possible because there are no checkpoints
self.restart_node(1, extra_args=['-nuparams=PoS:201', '-nuparams=PoS_v2:201', '-rewindblockindex', '-debug=0'])

res0 = self.nodes[0].getblockchaininfo()
res1 = self.nodes[1].getblockchaininfo()

connect_nodes(self.nodes[0], 1)
self.sync_blocks([self.nodes[i] for i in [0, 1]], timeout=120)

res0 = self.nodes[0].getblockchaininfo()
res1 = self.nodes[1].getblockchaininfo()

assert_equal(res1["bestblockhash"], rightChain)

self.log.info("Node1 on right chain")

if __name__ == '__main__':
RewindBlockIndexCheckpointTest().main()
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
# Longest test should go first, to favor running tests in parallel
# vv Tests less than 20m vv
'feature_dbcrash.py',
'feature_rewind.py', # ~ 353 sec
'sapling_fillblock.py', # ~ 780 sec
'feature_fee_estimation.py', # ~ 360 sec
# vv Tests less than 5m vv
Expand Down

0 comments on commit 146e72b

Please sign in to comment.