Browse Source

Correctly account for migration transactions in the mempool

Co-authored-by: LarryRuane <larry@z.cash>
pull/245/head
Eirik0 5 years ago
parent
commit
7cf4749d0d
  1. 3
      qa/rpc-tests/sprout_sapling_migration.py
  2. 9
      src/wallet/rpcwallet.cpp

3
qa/rpc-tests/sprout_sapling_migration.py

@ -106,6 +106,9 @@ class SproutSaplingMigration(BitcoinTestFramework):
assert_equal(node.z_getbalance(sproutAddr), Decimal('0'))
assert_equal(node.z_getbalance(saplingAddr), Decimal('0'))
assert_true(node.z_getbalance(saplingAddr, 0) > Decimal('0'), "Unconfirmed sapling balance at 499 % 500")
# Check that unmigrated amount + unfinalized = starting balance - fee
status = node.z_getmigrationstatus()
assert_equal(Decimal('9.9999'), Decimal(status['unmigrated_amount']) + Decimal(status['unfinalized_migrated_amount']))
node.generate(1)
self.sync_all()

9
src/wallet/rpcwallet.cpp

@ -3967,7 +3967,8 @@ UniValue z_getmigrationstatus(const UniValue& params, bool fHelp) {
{
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, "", 1);
std::set<PaymentAddress> zaddrs;
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs, 0, INT_MAX, true, true, false);
CAmount unmigratedAmount = 0;
for (const auto& sproutEntry : sproutEntries) {
unmigratedAmount += sproutEntry.plaintext.value();
@ -4000,7 +4001,6 @@ UniValue z_getmigrationstatus(const UniValue& params, bool fHelp) {
continue;
}
migrationTxids.push_back(txPair.first.ToString());
CBlockIndex* blockIndex = mapBlockIndex[tx.hashBlock];
// A transaction is "finalized" iff it has at least 10 confirmations.
// TODO: subject to change, if the recommended number of confirmations changes.
if (tx.GetDepthInMainChain() >= 10) {
@ -4009,6 +4009,11 @@ UniValue z_getmigrationstatus(const UniValue& params, bool fHelp) {
} else {
unfinalizedMigratedAmount -= tx.valueBalance;
}
// If the transaction is in the mempool it will not be associated with a block yet
if (tx.hashBlock.IsNull() || mapBlockIndex[tx.hashBlock] == nullptr) {
continue;
}
CBlockIndex* blockIndex = mapBlockIndex[tx.hashBlock];
// The value of "time_started" is the earliest Unix timestamp of any known
// migration transaction involving this wallet; if there is no such transaction,
// then the field is absent.

Loading…
Cancel
Save