Improved logging and error checking in consolidation and sweeping
This commit is contained in:
@@ -82,7 +82,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
|||||||
auto consensusParams = Params().GetConsensus();
|
auto consensusParams = Params().GetConsensus();
|
||||||
auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams);
|
auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams);
|
||||||
if (nextActivationHeight && targetHeight_ + CONSOLIDATION_EXPIRY_DELTA >= nextActivationHeight.get()) {
|
if (nextActivationHeight && targetHeight_ + CONSOLIDATION_EXPIRY_DELTA >= nextActivationHeight.get()) {
|
||||||
LogPrint("zrpcunsafe", "%s: Consolidation txs would be created before a NU activation but may expire after. Skipping this round.\n",opid);
|
LogPrintf("%s: Consolidation txs would be created before a NU activation but may expire after. Skipping this round.\n",opid);
|
||||||
setConsolidationResult(0, 0, std::vector<std::string>());
|
setConsolidationResult(0, 0, std::vector<std::string>());
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
|||||||
pwalletMain->GetFilteredNotes(saplingEntries, "", 11);
|
pwalletMain->GetFilteredNotes(saplingEntries, "", 11);
|
||||||
|
|
||||||
if(saplingEntries.size() == 0) {
|
if(saplingEntries.size() == 0) {
|
||||||
LogPrint("zrpcunsafe", "%s: Nothing to consolidate, done.\n",opid);
|
LogPrintf("%s: Nothing to consolidate, done.\n",opid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
|||||||
libzcash::SaplingPaymentAddress saplingAddress = boost::get<libzcash::SaplingPaymentAddress>(zAddress);
|
libzcash::SaplingPaymentAddress saplingAddress = boost::get<libzcash::SaplingPaymentAddress>(zAddress);
|
||||||
addresses.insert(saplingAddress);
|
addresses.insert(saplingAddress);
|
||||||
} else {
|
} else {
|
||||||
LogPrint("zrpcunsafe", "%s: Invalid zaddr, exiting\n", opid);
|
LogPrintf("%s: Invalid zaddr, exiting\n", opid);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,14 +176,14 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
|||||||
std::vector<boost::optional<SaplingWitness>> witnesses;
|
std::vector<boost::optional<SaplingWitness>> witnesses;
|
||||||
{
|
{
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
LogPrint("zrpcunsafe", "%s: Fetching note witnesses\n", opid);
|
// LogPrint("zrpcunsafe", "%s: Fetching note witnesses\n", opid);
|
||||||
pwalletMain->GetSaplingNoteWitnesses(ops, witnesses, anchor);
|
pwalletMain->GetSaplingNoteWitnesses(ops, witnesses, anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Sapling spends
|
// Add Sapling spends
|
||||||
for (size_t i = 0; i < notes.size(); i++) {
|
for (size_t i = 0; i < notes.size(); i++) {
|
||||||
if (!witnesses[i]) {
|
if (!witnesses[i]) {
|
||||||
LogPrint("zrpcunsafe", "%s: Missing Witnesses. Stopping.\n", opid);
|
LogPrintf("%s: Missing Witnesses! Stopping.\n", opid);
|
||||||
status=false;
|
status=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
|||||||
// actually add our sietch zoutput, the new way
|
// actually add our sietch zoutput, the new way
|
||||||
builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount);
|
builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount);
|
||||||
} else {
|
} else {
|
||||||
LogPrint("zrpcunsafe", "%s: Invalid payment address %s! Stopping.\n", opid, zdust);
|
LogPrintf("%s: Invalid payment address %s! Stopping.\n", opid, zdust);
|
||||||
status = false;
|
status = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -223,25 +223,25 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
|||||||
|
|
||||||
auto maybe_tx = builder.Build();
|
auto maybe_tx = builder.Build();
|
||||||
if (!maybe_tx) {
|
if (!maybe_tx) {
|
||||||
LogPrint("zrpcunsafe", "%s: Failed to build transaction.\n",opid);
|
LogPrintf("%s: Failed to build transaction.\n",opid);
|
||||||
status=false;
|
status=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CTransaction tx = maybe_tx.get();
|
CTransaction tx = maybe_tx.get();
|
||||||
|
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
LogPrint("zrpcunsafe", "%s: Canceled. Stopping.\n", opid);
|
LogPrintf("%s: Canceled. Stopping.\n", opid);
|
||||||
status=false;
|
status=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pwalletMain->CommitAutomatedTx(tx)) {
|
if(pwalletMain->CommitAutomatedTx(tx)) {
|
||||||
LogPrint("zrpcunsafe", "%s: Committed consolidation transaction with txid=%s\n",opid, tx.GetHash().ToString());
|
LogPrintf("%s: Committed consolidation transaction with txid=%s\n",opid, tx.GetHash().ToString());
|
||||||
amountConsolidated += actualAmountToSend;
|
amountConsolidated += actualAmountToSend;
|
||||||
consolidationTxIds.push_back(tx.GetHash().ToString());
|
consolidationTxIds.push_back(tx.GetHash().ToString());
|
||||||
numTxCreated++;
|
numTxCreated++;
|
||||||
} else {
|
} else {
|
||||||
LogPrint("zrpcunsafe", "%s: Consolidation transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString());
|
LogPrintf("%s: Consolidation transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString());
|
||||||
setConsolidationResult(numTxCreated, amountConsolidated, consolidationTxIds);
|
setConsolidationResult(numTxCreated, amountConsolidated, consolidationTxIds);
|
||||||
status = false;
|
status = false;
|
||||||
break;
|
break;
|
||||||
@@ -249,7 +249,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrint("zrpcunsafe", "%s: Created %d transactions with total Sapling output amount=%s,status=%d\n",opid , numTxCreated, FormatMoney(amountConsolidated), (int)status);
|
LogPrintf("%s: Created %d transactions with total Sapling output amount=%s,status=%d\n",opid , numTxCreated, FormatMoney(amountConsolidated), (int)status);
|
||||||
setConsolidationResult(numTxCreated, amountConsolidated, consolidationTxIds);
|
setConsolidationResult(numTxCreated, amountConsolidated, consolidationTxIds);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,13 @@ void AsyncRPCOperation_sweep::main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AsyncRPCOperation_sweep::main_impl() {
|
bool AsyncRPCOperation_sweep::main_impl() {
|
||||||
LogPrint("zrpcunsafe", "%s: Beginning asyncrpcoperation_sweep.\n", getId());
|
bool status=true;
|
||||||
|
auto opid=getId();
|
||||||
|
LogPrintf("%s: Beginning asyncrpcoperation_sweep.\n", getId());
|
||||||
auto consensusParams = Params().GetConsensus();
|
auto consensusParams = Params().GetConsensus();
|
||||||
auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams);
|
auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams);
|
||||||
if (nextActivationHeight && targetHeight_ + SWEEP_EXPIRY_DELTA >= nextActivationHeight.get()) {
|
if (nextActivationHeight && targetHeight_ + SWEEP_EXPIRY_DELTA >= nextActivationHeight.get()) {
|
||||||
LogPrint("zrpcunsafe", "%s: Sweep txs would be created before a NU activation but may expire after. Skipping this round.\n", getId());
|
LogPrintf("%s: Sweep txs would be created before a NU activation but may expire after. Skipping this round.\n", getId());
|
||||||
setSweepResult(0, 0, std::vector<std::string>());
|
setSweepResult(0, 0, std::vector<std::string>());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -201,7 +203,7 @@ bool AsyncRPCOperation_sweep::main_impl() {
|
|||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
builder.SetExpiryHeight(chainActive.Tip()->GetHeight()+ SWEEP_EXPIRY_DELTA);
|
builder.SetExpiryHeight(chainActive.Tip()->GetHeight()+ SWEEP_EXPIRY_DELTA);
|
||||||
}
|
}
|
||||||
LogPrint("zrpcunsafe", "%s: Beginning creating transaction with Sapling output amount=%s\n", getId(), FormatMoney(amountToSend - fee));
|
LogPrintf("%s: Beginning creating transaction with Sapling output amount=%s\n", getId(), FormatMoney(amountToSend - fee));
|
||||||
|
|
||||||
// Select Sapling notes
|
// Select Sapling notes
|
||||||
std::vector<SaplingOutPoint> ops;
|
std::vector<SaplingOutPoint> ops;
|
||||||
@@ -222,7 +224,7 @@ bool AsyncRPCOperation_sweep::main_impl() {
|
|||||||
// Add Sapling spends
|
// Add Sapling spends
|
||||||
for (size_t i = 0; i < notes.size(); i++) {
|
for (size_t i = 0; i < notes.size(); i++) {
|
||||||
if (!witnesses[i]) {
|
if (!witnesses[i]) {
|
||||||
LogPrint("zrpcunsafe", "%s: Missing Witnesses. Stopping.\n", getId());
|
LogPrintf("%s: Missing Witnesses! Stopping.\n", getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
builder.AddSaplingSpend(extsk.expsk, notes[i], anchor, witnesses[i].get());
|
builder.AddSaplingSpend(extsk.expsk, notes[i], anchor, witnesses[i].get());
|
||||||
@@ -244,8 +246,8 @@ bool AsyncRPCOperation_sweep::main_impl() {
|
|||||||
|
|
||||||
builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount);
|
builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount);
|
||||||
} else {
|
} else {
|
||||||
LogPrint("zrpcunsafe", "%s: Invalid payment address %s! Stopping.\n", __func__, zdust);
|
LogPrintf("%s: Invalid payment address %s! Stopping.\n", __func__, zdust);
|
||||||
// status = false;
|
status = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,22 +255,28 @@ bool AsyncRPCOperation_sweep::main_impl() {
|
|||||||
|
|
||||||
auto maybe_tx = builder.Build();
|
auto maybe_tx = builder.Build();
|
||||||
if (!maybe_tx) {
|
if (!maybe_tx) {
|
||||||
LogPrint("zrpcunsafe", "%s: Failed to build transaction %s.\n",__func__, getId());
|
LogPrintf("%s: Failed to build transaction %s.\n",__func__, getId());
|
||||||
// status=false;
|
status=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CTransaction tx = maybe_tx.get();
|
CTransaction tx = maybe_tx.get();
|
||||||
|
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
LogPrint("zrpcunsafe", "%s: Canceled. Stopping.\n", getId());
|
LogPrintf("%s: Canceled. Stopping.\n", getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pwalletMain->CommitAutomatedTx(tx);
|
if (pwalletMain->CommitAutomatedTx(tx)) {
|
||||||
LogPrint("zrpcunsafe", "%s: Committed sweep transaction with txid=%s\n", getId(), tx.GetHash().ToString());
|
LogPrintf("%s: Committed sweep transaction with txid=%s\n", getId(), tx.GetHash().ToString());
|
||||||
amountSwept += amountToSend - fee;
|
amountSwept += amountToSend - fee;
|
||||||
sweepTxIds.push_back(tx.GetHash().ToString());
|
sweepTxIds.push_back(tx.GetHash().ToString());
|
||||||
|
numTxCreated++;
|
||||||
|
} else {
|
||||||
|
LogPrintf("%s: Sweep transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString());
|
||||||
|
setSweepResult(numTxCreated, amountSwept, sweepTxIds);
|
||||||
|
status = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +290,7 @@ bool AsyncRPCOperation_sweep::main_impl() {
|
|||||||
pwalletMain->fSweepRunning = false;
|
pwalletMain->fSweepRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrint("zrpcunsafe", "%s: Created %d transactions with total Sapling output amount=%s\n", getId(), numTxCreated, FormatMoney(amountSwept));
|
LogPrintf("%s: Created %d transactions with total output amount=%s\n", getId(), numTxCreated, FormatMoney(amountSwept));
|
||||||
setSweepResult(numTxCreated, amountSwept, sweepTxIds);
|
setSweepResult(numTxCreated, amountSwept, sweepTxIds);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user