Do not automatically remove async migration operations and return txids
This commit is contained in:
parent
664b7d32a1
commit
7470ae8885
|
@ -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")
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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…
Reference in New Issue