Browse Source

Do not automatically remove async migration operations and return txids

pull/245/head
Eirik0 5 years ago
parent
commit
7470ae8885
  1. 2
      qa/rpc-tests/sprout_sapling_migration.py
  2. 15
      src/wallet/asyncrpcoperation_saplingmigration.cpp
  3. 2
      src/wallet/asyncrpcoperation_saplingmigration.h
  4. 4
      src/wallet/wallet.cpp

2
qa/rpc-tests/sprout_sapling_migration.py

@ -87,6 +87,8 @@ class SproutSaplingMigration(BitcoinTestFramework):
assert_equal('saplingmigration', result['method'])
assert_equal(target_height, result['target_height'])
assert_equal(1, result['result']['num_tx_created'])
assert_equal(1, len(result['result']['migration_txids']))
assert_true(result['result']['amount_migrated'] > Decimal('0'))
assert_equal(0, len(node.getrawmempool()), "mempool size at 495 % 500")

15
src/wallet/asyncrpcoperation_saplingmigration.cpp

@ -83,7 +83,7 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
}
// If the remaining amount to be migrated is less than 0.01 ZEC, end the migration.
if (availableFunds < CENT) {
setMigrationResult(0, 0);
setMigrationResult(0, 0, std::vector<std::string>());
return true;
}
@ -95,6 +95,7 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
// Up to the limit of 5, as many transactions are sent as are needed to migrate the remaining funds
int numTxCreated = 0;
CAmount amountMigrated = 0;
std::vector<std::string> migrationTxIds;
int noteIndex = 0;
CCoinsViewCache coinsView(pcoinsTip);
do {
@ -132,17 +133,23 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
}
pwalletMain->AddPendingSaplingMigrationTx(tx);
++numTxCreated;
amountMigrated += amountToSend;
amountMigrated += amountToSend - FEE;
migrationTxIds.push_back(tx.GetHash().ToString());
} while (numTxCreated < 5 && availableFunds > CENT);
setMigrationResult(numTxCreated, amountMigrated);
setMigrationResult(numTxCreated, amountMigrated, migrationTxIds);
return true;
}
void AsyncRPCOperation_saplingmigration::setMigrationResult(int numTxCreated, CAmount amountMigrated) {
void AsyncRPCOperation_saplingmigration::setMigrationResult(int numTxCreated, const CAmount& amountMigrated, const std::vector<std::string>& migrationTxIds) {
UniValue res(UniValue::VOBJ);
res.push_back(Pair("num_tx_created", numTxCreated));
res.push_back(Pair("amount_migrated", FormatMoney(amountMigrated)));
UniValue txIds(UniValue::VARR);
for (const std::string& txId : migrationTxIds) {
txIds.push_back(txId);
}
res.push_back(Pair("migration_txids", txIds));
set_result(res);
}

2
src/wallet/asyncrpcoperation_saplingmigration.h

@ -29,7 +29,7 @@ private:
bool main_impl();
void setMigrationResult(int numTxCreated, CAmount amountMigrated);
void setMigrationResult(int numTxCreated, const CAmount& amountMigrated, const std::vector<std::string>& migrationTxIds);
CAmount chooseAmount(const CAmount& availableFunds);
};

4
src/wallet/wallet.cpp

@ -610,7 +610,7 @@ void CWallet::RunSaplingMigration(int blockHeight) {
// height N-5
if (blockHeight % 500 == 495) {
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> lastOperation = q->popOperationForId(saplingMigrationOperationId);
std::shared_ptr<AsyncRPCOperation> lastOperation = q->getOperationForId(saplingMigrationOperationId);
if (lastOperation != nullptr) {
lastOperation->cancel();
}
@ -620,7 +620,7 @@ void CWallet::RunSaplingMigration(int blockHeight) {
q->addOperation(operation);
} else if (blockHeight % 500 == 499) {
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> lastOperation = q->popOperationForId(saplingMigrationOperationId);
std::shared_ptr<AsyncRPCOperation> lastOperation = q->getOperationForId(saplingMigrationOperationId);
if (lastOperation != nullptr) {
lastOperation->cancel();
}

Loading…
Cancel
Save