Skip to content

Commit

Permalink
Give time for CCoinsViewCache to update after rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Feb 2, 2022
1 parent fa8197f commit cd858b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
8 changes: 0 additions & 8 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2489,12 +2489,6 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
return balance;
}

static void PrintUTXOSet(std::vector<COutput>& vCoins) {
for (const auto& coin : vCoins) {
LogPrintf("XXX UTXOS hash %s vout %d\n", coin.tx->GetHash().ToString(), coin.i);
}
}

void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<COutput>& vCoins, bool fOnlySafe, const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount) const
{
AssertLockHeld(cs_wallet);
Expand Down Expand Up @@ -2626,12 +2620,10 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<

// Checks the maximum number of UTXO's.
if (nMaximumCount > 0 && vCoins.size() >= nMaximumCount) {
PrintUTXOSet(vCoins);
return;
}
}
}
PrintUTXOSet(vCoins);
}

/// @todo tokens: used only in listCoins by qt, so, limit with token = 0????
Expand Down
31 changes: 25 additions & 6 deletions test/functional/feature_restore_utxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal
import time

class TestRestoreUTXOs(DefiTestFramework):
def set_test_params(self):
Expand All @@ -24,6 +25,24 @@ def clearmempool(self, node: int):
return False
return True

def account_to_account(self, node: int, soure, destination):
try:
self.nodes[node].accounttoaccount(soure, {destination: "1@BTC"})
except JSONRPCException as e:
return False
return True

def account_to_account_loop(self, node: int, soure, destination):
count = 0
while not self.account_to_account(node, soure, destination):
if count == 5:
return False
else:
count += 1
time.sleep(1)
return True


def rollback(self, count):
block = self.nodes[0].getblockhash(count)
self.nodes[0].invalidateblock(block)
Expand Down Expand Up @@ -90,20 +109,20 @@ def run_test(self):
self.nodes[0].generate(1)
self.sync_blocks()
block = self.nodes[0].getblockcount() + 1
#node0_utxos = len(self.nodes[0].listunspent())
#node1_utxos = len(self.nodes[1].listunspent())
node0_utxos = len(self.nodes[0].listunspent())
node1_utxos = len(self.nodes[1].listunspent())

# Test rollbacks
for x in range(50):
self.nodes[0].accounttoaccount(node0_source, {node0_destination: "1@BTC"})
assert(self.account_to_account_loop(0, node0_source, node0_destination))
self.nodes[0].generate(1)
self.sync_blocks()
self.nodes[1].accounttoaccount(node1_source, {node1_destination: "1@BTC"})
assert(self.account_to_account_loop(1, node1_source, node1_destination))
self.nodes[1].generate(1)
self.sync_blocks()
self.rollback(block)
# assert_equal(len(self.nodes[0].listunspent()), node0_utxos) # 4 != 5
# assert_equal(len(self.nodes[1].listunspent()), node1_utxos)
assert_equal(len(self.nodes[0].listunspent()), node0_utxos)
assert_equal(len(self.nodes[1].listunspent()), node1_utxos)

if __name__ == '__main__':
TestRestoreUTXOs().main()

0 comments on commit cd858b3

Please sign in to comment.