[logging] BCLog::ZRPC and ZRPCUNSAFE, gArgs

This commit is contained in:
Jon Layton 2018-06-04 14:53:12 -05:00
parent 8073709070
commit f113e2d4e6
5 changed files with 57 additions and 52 deletions

View File

@ -121,6 +121,8 @@ const CLogCategoryDesc LogCategories[] =
{BCLog::LEVELDB, "leveldb"},
{BCLog::EQUIHASH, "equihash"},
{BCLog::PAYMENTDISCLOSURE, "paymentdisclosure"},
{BCLog::ZRPC, "zrpc"},
{BCLog::ZRPCUNSAFE, "zrpcunsafe"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
};

View File

@ -55,6 +55,8 @@ namespace BCLog {
LEVELDB = (1 << 20),
EQUIHASH = (1 << 21),
PAYMENTDISCLOSURE = (1 << 22),
ZRPC = (1 << 23),
ZRPCUNSAFE = (1 << 24),
ALL = ~(uint32_t)0,
};

View File

@ -12,6 +12,7 @@
#include <miner.h>
#include <net.h>
#include <netbase.h>
#include <paymentdisclosuredb.h>
#include <rpc/protocol.h>
#include <rpc/server.h>
#include <script/interpreter.h>
@ -91,10 +92,10 @@ AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress(
}
// Log the context info i.e. the call parameters to z_mergetoaddress
if (LogAcceptCategory("zrpcunsafe")) {
LogPrint("zrpcunsafe", "%s: z_mergetoaddress initialized (params=%s)\n", getId(), contextInfo.write());
if (LogAcceptCategory(BCLog::ZRPCUNSAFE)) {
LogPrint(BCLog::ZRPCUNSAFE, "%s: z_mergetoaddress initialized (params=%s)\n", getId(), contextInfo.write());
} else {
LogPrint("zrpc", "%s: z_mergetoaddress initialized\n", getId());
LogPrint(BCLog::ZRPC, "%s: z_mergetoaddress initialized\n", getId());
}
// Lock UTXOs
@ -102,7 +103,7 @@ AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress(
lock_notes();
// Enable payment disclosure if requested
paymentDisclosureMode = fExperimentalMode && GetBoolArg("-paymentdisclosure", false);
paymentDisclosureMode = fExperimentalMode && gArgs.GetBoolArg("-paymentdisclosure", false);
}
AsyncRPCOperation_mergetoaddress::~AsyncRPCOperation_mergetoaddress()
@ -185,9 +186,9 @@ void AsyncRPCOperation_mergetoaddress::main()
for (PaymentDisclosureKeyInfo p : paymentDisclosureData_) {
p.first.hash = txidhash;
if (!db->Put(p.first, p.second)) {
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
} else {
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
}
}
}
@ -207,7 +208,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
size_t numInputs = utxoInputs_.size();
// Check mempooltxinputlimit to avoid creating a transaction which the local mempool rejects
size_t limit = (size_t)GetArg("-mempooltxinputlimit", 0);
size_t limit = (size_t)gArgs.GetArg("-mempooltxinputlimit", 0);
{
LOCK(cs_main);
if (NetworkUpgradeActive(chainActive.Height() + 1, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) {
@ -253,16 +254,16 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
}
tx_ = CTransaction(rawTx);
LogPrint(isPureTaddrOnlyTx ? "zrpc" : "zrpcunsafe", "%s: spending %s to send %s with fee %s\n",
LogPrint(isPureTaddrOnlyTx ? BCLog::ZRPC : BCLog::ZRPCUNSAFE, "%s: spending %s to send %s with fee %s\n",
getId(), FormatMoney(targetAmount), FormatMoney(sendAmount), FormatMoney(minersFee));
LogPrint("zrpc", "%s: transparent input: %s\n", getId(), FormatMoney(t_inputs_total));
LogPrint("zrpcunsafe", "%s: private input: %s\n", getId(), FormatMoney(z_inputs_total));
LogPrint(BCLog::ZRPC, "%s: transparent input: %s\n", getId(), FormatMoney(t_inputs_total));
LogPrint(BCLog::ZRPCUNSAFE, "%s: private input: %s\n", getId(), FormatMoney(z_inputs_total));
if (isToTaddr_) {
LogPrint("zrpc", "%s: transparent output: %s\n", getId(), FormatMoney(sendAmount));
LogPrint(BCLog::ZRPC, "%s: transparent output: %s\n", getId(), FormatMoney(sendAmount));
} else {
LogPrint("zrpcunsafe", "%s: private output: %s\n", getId(), FormatMoney(sendAmount));
LogPrint(BCLog::ZRPCUNSAFE, "%s: private output: %s\n", getId(), FormatMoney(sendAmount));
}
LogPrint("zrpc", "%s: fee: %s\n", getId(), FormatMoney(minersFee));
LogPrint(BCLog::ZRPC, "%s: fee: %s\n", getId(), FormatMoney(minersFee));
// Grab the current consensus branch ID
{
@ -469,7 +470,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
jsInputValue += plaintext.value;
LogPrint("zrpcunsafe", "%s: spending change (amount=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: spending change (amount=%s)\n",
getId(),
FormatMoney(plaintext.value));
@ -522,7 +523,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
wtxHeight = mapBlockIndex[wtx.hashBlock]->nHeight;
wtxDepth = wtx.GetDepthInMainChain();
}
LogPrint("zrpcunsafe", "%s: spending note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, height=%d, confirmations=%d)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: spending note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, height=%d, confirmations=%d)\n",
getId(),
jso.hash.ToString().substr(0, 10),
jso.js,
@ -599,7 +600,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
}
info.vjsout.push_back(jso);
LogPrint("zrpcunsafe", "%s: generating note for %s (amount=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: generating note for %s (amount=%s)\n",
getId(),
outputType,
FormatMoney(jsChange));
@ -750,7 +751,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
CMutableTransaction mtx(tx_);
LogPrint("zrpcunsafe", "%s: creating joinsplit at index %d (vpub_old=%s, vpub_new=%s, in[0]=%s, in[1]=%s, out[0]=%s, out[1]=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: creating joinsplit at index %d (vpub_old=%s, vpub_new=%s, in[0]=%s, in[1]=%s, out[0]=%s, out[1]=%s)\n",
getId(),
tx_.vjoinsplit.size(),
FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
@ -859,7 +860,7 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo));
CZCPaymentAddress address(zaddr);
LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
}
// !!! Payment disclosure END

View File

@ -10,6 +10,8 @@
#include <init.h>
#include <net.h>
#include <netbase.h>
#include <paymentdisclosure.h>
#include <paymentdisclosuredb.h>
#include <rpc/server.h>
#include <timedata.h>
#include <util.h>
@ -29,8 +31,6 @@
#include <thread>
#include <string>
#include <paymentdisclosuredb.h>
using namespace libzcash;
int find_output(UniValue obj, int n) {
@ -102,10 +102,10 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
}
// Log the context info i.e. the call parameters to z_sendmany
if (LogAcceptCategory("zrpcunsafe")) {
LogPrint("zrpcunsafe", "%s: z_sendmany initialized (params=%s)\n", getId(), contextInfo.write());
if (LogAcceptCategory(BCLog::ZRPCUNSAFE)) {
LogPrint(BCLog::ZRPCUNSAFE, "%s: z_sendmany initialized (params=%s)\n", getId(), contextInfo.write());
} else {
LogPrint("zrpc", "%s: z_sendmany initialized\n", getId());
LogPrint(BCLog::ZRPC, "%s: z_sendmany initialized\n", getId());
}
@ -185,9 +185,9 @@ void AsyncRPCOperation_sendmany::main() {
for (PaymentDisclosureKeyInfo p : paymentDisclosureData_) {
p.first.hash = txidhash;
if (!db->Put(p.first, p.second)) {
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
} else {
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
}
}
}
@ -309,7 +309,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
t_inputs_total = selectedUTXOAmount;
// Check mempooltxinputlimit to avoid creating a transaction which the local mempool rejects
size_t limit = (size_t)GetArg("-mempooltxinputlimit", 0);
size_t limit = (size_t)gArgs.GetArg("-mempooltxinputlimit", 0);
{
LOCK(cs_main);
if (NetworkUpgradeActive(chainActive.Height() + 1, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) {
@ -335,13 +335,13 @@ bool AsyncRPCOperation_sendmany::main_impl() {
tx_ = CTransaction(rawTx);
}
LogPrint((isfromtaddr_) ? "zrpc" : "zrpcunsafe", "%s: spending %s to send %s with fee %s\n",
LogPrint((isfromtaddr_) ? BCLog::ZRPC : BCLog::ZRPCUNSAFE, "%s: spending %s to send %s with fee %s\n",
getId(), FormatMoney(targetAmount), FormatMoney(sendAmount), FormatMoney(minersFee));
LogPrint("zrpc", "%s: transparent input: %s (to choose from)\n", getId(), FormatMoney(t_inputs_total));
LogPrint("zrpcunsafe", "%s: private input: %s (to choose from)\n", getId(), FormatMoney(z_inputs_total));
LogPrint("zrpc", "%s: transparent output: %s\n", getId(), FormatMoney(t_outputs_total));
LogPrint("zrpcunsafe", "%s: private output: %s\n", getId(), FormatMoney(z_outputs_total));
LogPrint("zrpc", "%s: fee: %s\n", getId(), FormatMoney(minersFee));
LogPrint(BCLog::ZRPC, "%s: transparent input: %s (to choose from)\n", getId(), FormatMoney(t_inputs_total));
LogPrint(BCLog::ZRPCUNSAFE, "%s: private input: %s (to choose from)\n", getId(), FormatMoney(z_inputs_total));
LogPrint(BCLog::ZRPC, "%s: transparent output: %s\n", getId(), FormatMoney(t_outputs_total));
LogPrint(BCLog::ZRPCUNSAFE, "%s: private output: %s\n", getId(), FormatMoney(z_outputs_total));
LogPrint(BCLog::ZRPC, "%s: fee: %s\n", getId(), FormatMoney(minersFee));
// Grab the current consensus branch ID
{
@ -366,7 +366,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
if (change > 0) {
add_taddr_change_output_to_tx(change);
LogPrint("zrpc", "%s: transparent change in transaction output (amount=%s)\n",
LogPrint(BCLog::ZRPC, "%s: transparent change in transaction output (amount=%s)\n",
getId(),
FormatMoney(change)
);
@ -446,7 +446,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
"in z_sendmany.", FormatMoney(change)));
} else {
add_taddr_change_output_to_tx(change);
LogPrint("zrpc", "%s: transparent change in transaction output (amount=%s)\n",
LogPrint(BCLog::ZRPC, "%s: transparent change in transaction output (amount=%s)\n",
getId(),
FormatMoney(change)
);
@ -583,7 +583,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
jsInputValue += plaintext.value;
LogPrint("zrpcunsafe", "%s: spending change (amount=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: spending change (amount=%s)\n",
getId(),
FormatMoney(plaintext.value)
);
@ -634,7 +634,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
wtxHeight = mapBlockIndex[wtx.hashBlock]->nHeight;
wtxDepth = wtx.GetDepthInMainChain();
}
LogPrint("zrpcunsafe", "%s: spending note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, height=%d, confirmations=%d)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: spending note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, height=%d, confirmations=%d)\n",
getId(),
jso.hash.ToString().substr(0, 10),
jso.js,
@ -738,7 +738,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
if (jsChange>0) {
info.vjsout.push_back(JSOutput(frompaymentaddress_, jsChange));
LogPrint("zrpcunsafe", "%s: generating note for change (amount=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: generating note for change (amount=%s)\n",
getId(),
FormatMoney(jsChange)
);
@ -886,7 +886,7 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() {
for (CNotePlaintextEntry & entry : entries) {
z_inputs_.push_back(SendManyInputJSOP(entry.jsop, entry.plaintext.note(frompaymentaddress_), CAmount(entry.plaintext.value)));
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
LogPrint("zrpcunsafe", "%s: found unspent note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, memo=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: found unspent note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, memo=%s)\n",
getId(),
entry.jsop.hash.ToString().substr(0, 10),
entry.jsop.js,
@ -964,7 +964,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
CMutableTransaction mtx(tx_);
LogPrint("zrpcunsafe", "%s: creating joinsplit at index %d (vpub_old=%s, vpub_new=%s, in[0]=%s, in[1]=%s, out[0]=%s, out[1]=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: creating joinsplit at index %d (vpub_old=%s, vpub_new=%s, in[0]=%s, in[1]=%s, out[0]=%s, out[1]=%s)\n",
getId(),
tx_.vjoinsplit.size(),
FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
@ -1080,7 +1080,7 @@ UniValue AsyncRPCOperation_sendmany::perform_joinsplit(
paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo));
CZCPaymentAddress address(zaddr);
LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
}
// !!! Payment disclosure END

View File

@ -10,6 +10,8 @@
#include <main.h>
#include <net.h>
#include <netbase.h>
#include <paymentdisclosure.h>
#include <paymentdisclosuredb.h>
#include <rpcserver.h>
#include <timedata.h>
#include <util.h>
@ -18,7 +20,7 @@
#include <walletdb.h>
#include <script/interpreter.h>
#include <utiltime.h>
#include <rpcprotocol.h>
#include <rpc/protocol.h>
#include <zcash/IncrementalMerkleTree.hpp>
#include <sodium.h>
#include <miner.h>
@ -30,8 +32,6 @@
#include <wallet/asyncrpcoperation_shieldcoinbase.h>
#include <wallet/paymentdisclosure.h>
#include <wallet/paymentdisclosuredb.h>
using namespace libzcash;
@ -79,10 +79,10 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
}
// Log the context info
if (LogAcceptCategory("zrpcunsafe")) {
LogPrint("zrpcunsafe", "%s: z_shieldcoinbase initialized (context=%s)\n", getId(), contextInfo.write());
if (LogAcceptCategory(BCLog::ZRPCUNSAFE)) {
LogPrint(BCLog::ZRPCUNSAFE, "%s: z_shieldcoinbase initialized (context=%s)\n", getId(), contextInfo.write());
} else {
LogPrint("zrpc", "%s: z_shieldcoinbase initialized\n", getId());
LogPrint(BCLog::ZRPC, "%s: z_shieldcoinbase initialized\n", getId());
}
// Lock UTXOs
@ -168,9 +168,9 @@ void AsyncRPCOperation_shieldcoinbase::main() {
for (PaymentDisclosureKeyInfo p : paymentDisclosureData_) {
p.first.hash = txidhash;
if (!db->Put(p.first, p.second)) {
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: Error writing entry to database for key %s\n", getId(), p.first.ToString());
} else {
LogPrint("paymentdisclosure", "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: Successfully added entry to database for key %s\n", getId(), p.first.ToString());
}
}
}
@ -185,7 +185,7 @@ bool AsyncRPCOperation_shieldcoinbase::main_impl() {
size_t numInputs = inputs_.size();
// Check mempooltxinputlimit to avoid creating a transaction which the local mempool rejects
size_t limit = (size_t)GetArg("-mempooltxinputlimit", 0);
size_t limit = (size_t)gArgs.GetArg("-mempooltxinputlimit", 0);
{
LOCK(cs_main);
if (NetworkUpgradeActive(chainActive.Height() + 1, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) {
@ -210,7 +210,7 @@ bool AsyncRPCOperation_shieldcoinbase::main_impl() {
}
CAmount sendAmount = targetAmount - minersFee;
LogPrint("zrpc", "%s: spending %s to shield %s with fee %s\n",
LogPrint(BCLog::ZRPC, "%s: spending %s to shield %s with fee %s\n",
getId(), FormatMoney(targetAmount), FormatMoney(sendAmount), FormatMoney(minersFee));
// update the transaction with these inputs
@ -337,7 +337,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
CMutableTransaction mtx(tx_);
LogPrint("zrpcunsafe", "%s: creating joinsplit at index %d (vpub_old=%s, vpub_new=%s, in[0]=%s, in[1]=%s, out[0]=%s, out[1]=%s)\n",
LogPrint(BCLog::ZRPCUNSAFE, "%s: creating joinsplit at index %d (vpub_old=%s, vpub_new=%s, in[0]=%s, in[1]=%s, out[0]=%s, out[1]=%s)\n",
getId(),
tx_.vjoinsplit.size(),
FormatMoney(info.vpub_old), FormatMoney(info.vpub_new),
@ -452,7 +452,7 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
paymentDisclosureData_.push_back(PaymentDisclosureKeyInfo(pdKey, pdInfo));
CZCPaymentAddress address(zaddr);
LogPrint("paymentdisclosure", "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
LogPrint(BCLog::PAYMENTDISCLOSURE, "%s: Payment Disclosure: js=%d, n=%d, zaddr=%s\n", getId(), js_index, int(mapped_index), address.ToString());
}
// !!! Payment disclosure END