Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
fix wallet corruption on rescan and zapwallettxes (#189)
Browse files Browse the repository at this point in the history
* reenable zapwallettxes.py test

* add additional flush in shutdown, clean up threadgroup with join_all

* compare min version to wallet version not client version

* remove account tests (dont support accounts), enable rescan,reindex,zap,salvage tests

* make cs_utxo a shared mutex and rework the coin logic accordingly

* rework validation code, fix rescan failures caused by disconnect failure

* fix formatting

* change getchainips to explicitly reconnect the network
  • Loading branch information
Greg-Griffith authored May 22, 2019
1 parent 7b5cbf2 commit 88be346
Show file tree
Hide file tree
Showing 23 changed files with 570 additions and 415 deletions.
2 changes: 1 addition & 1 deletion qa/pull-tester/rpc-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def option_passed(option_without_dashes):
'txpropagate',
'wallet',
'walletbackup',
'zapwallettxes',
#
Disabled('mempool_limit', "FAILS"),
Disabled('mempool_reorg', "FAILS"),
Expand All @@ -208,7 +209,6 @@ def option_passed(option_without_dashes):
Disabled('invalidtxrequest', "FAILS"),
Disabled('merkle_blocks', "FAILS"),
Disabled('miningtest', "FAILS"),
Disabled('zapwallettxes', "FAILS"),
Disabled('sendheaders', "FAILS"),
Disabled('signrawtransactions', "FAILS"),
#
Expand Down
16 changes: 13 additions & 3 deletions qa/rpc-tests/getchaintips.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.util import *

class GetChainTipsTest (BitcoinTestFramework):

Expand Down Expand Up @@ -42,9 +43,18 @@ def run_test (self):
assert_equal (longTip['height'], 220)
assert_equal (tips[0]['status'], 'active')

# Join the network halves and check that we now have two tips
# (at least at the nodes that previously had the short chain).
self.join_network ()
stop_nodes(self.nodes)
wait_bitcoinds()
self.is_network_split = False
self.nodes = self.setup_nodes()
connect_nodes_bi(self.nodes, 0, 1)
connect_nodes_bi(self.nodes, 0, 2)
connect_nodes_bi(self.nodes, 0, 3)
connect_nodes_bi(self.nodes, 1, 2)
connect_nodes_bi(self.nodes, 1, 3)
connect_nodes_bi(self.nodes, 2, 3)
self.sync_blocks()
self.sync_all()

tips = self.nodes[0].getchaintips ()
assert_equal (len (tips), 2)
Expand Down
21 changes: 6 additions & 15 deletions qa/rpc-tests/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,27 +422,13 @@ def run_test (self):
{"address": self.nodes[2].getaddressforms(p2shAddress2)["bitcoincash"]},
{"label": ""})
'''
#check if wallet or blochchain maintenance changes the balance
self.sync_all()
blocks = self.nodes[0].generate(2)
self.sync_all()
balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
block_count = self.nodes[0].getblockcount()
'''

# Check modes:
# - True: unicode escaped as \u....
# - False: unicode directly as UTF-8
'''
for mode in [True, False]:
self.nodes[0].ensure_ascii = mode
# unicode check: Basic Multilingual Plane, Supplementary Plane respectively
for s in [u'рыба', u'𝅘𝅥𝅯']:
addr = self.nodes[0].getaccountaddress(s)
label = self.nodes[0].getaccount(addr)
assert_equal(label, s)
assert(s in self.nodes[0].listaccounts().keys())
self.nodes[0].ensure_ascii = True # restore to default


# maintenance tests
Expand All @@ -464,12 +450,17 @@ def run_test (self):
time.sleep(0.1)
assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)])

'''
# Exercise listsinceblock with the last two blocks
coinbase_tx_1 = self.nodes[0].listsinceblock(blocks[0])
assert_equal(coinbase_tx_1["lastblock"], blocks[1])
assert_equal(len(coinbase_tx_1["transactions"]), 1)
assert_equal(len(coinbase_tx_1["transactions"]), 2)
print(coinbase_tx_1["transactions"][0])
assert_equal(coinbase_tx_1["transactions"][0]["blockhash"], blocks[1])
assert_equal(coinbase_tx_1["transactions"][0]["satoshi"], Decimal('2500000000'))
assert_equal(coinbase_tx_1["transactions"][0]["amount"], Decimal('50.000000'))
print(self.nodes[0].listsinceblock(blocks[1])["transactions"])
assert_equal(len(self.nodes[0].listsinceblock(blocks[1])["transactions"]), 0)
'''

Expand Down
2 changes: 2 additions & 0 deletions src/blockgeneration/blockgeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void ThreadMiner(void *parg, bool shutdownOnly)
if (minerThreads != nullptr)
{
minerThreads->interrupt_all();
minerThreads->join_all();
delete minerThreads;
minerThreads = nullptr;
return;
Expand Down Expand Up @@ -108,6 +109,7 @@ void ThreadMinter(void *parg, bool shutdownOnly)
if (minterThreads != nullptr)
{
minterThreads->interrupt_all();
minterThreads->join_all();
delete minterThreads;
minterThreads = nullptr;
return;
Expand Down
12 changes: 5 additions & 7 deletions src/chain/tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
std::string CTransaction::ToString() const
{
std::string str;
str += strprintf(
"CTransaction(hash=%s, ver=%d, nTime=%u, vin.size=%u, vout.size=%u, nLockTime=%u, serviceReferenceHash=%s)\n",
GetHash().ToString().substr(0, 10), nVersion, nTime, vin.size(), vout.size(), nLockTime,
serviceReferenceHash.GetHex().c_str());
str += strprintf("CTransaction(hash=%s, ver=%d, nTime=%u, vin.size=%u, vout.size=%u, nLockTime=%u)\n",
GetHash().ToString().substr(0, 10), nVersion, nTime, vin.size(), vout.size(), nLockTime);
for (unsigned int i = 0; i < vin.size(); i++)
str += " " + vin[i].ToString() + "\n";
for (unsigned int i = 0; i < vout.size(); i++)
Expand Down Expand Up @@ -387,10 +385,10 @@ bool GetTransaction(const uint256 &hash,

if (fAllowSlow) // use coin database to locate block that contains transaction, and scan it
{
const Coin &coin = AccessByTxid(*(pnetMan->getChainActive()->pcoinsTip), hash);
if (!coin.IsSpent())
CoinAccessor coin(*(pnetMan->getChainActive()->pcoinsTip), hash);
if (!coin->IsSpent())
{
pindexSlow = pnetMan->getChainActive()->chainActive[coin.nHeight];
pindexSlow = pnetMan->getChainActive()->chainActive[coin->nHeight];
}
}

Expand Down
Loading

0 comments on commit 88be346

Please sign in to comment.