From 27654ac1113a967218332edf63ce228612d74408 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 19 Jun 2018 23:13:01 -0700 Subject: [PATCH] WIP Fix to absurd fee bug on small transaction amounts We inherited this bug from upstream, and most Zcash forks probably have similar behavior. Upstream issue: https://github.com/zcash/zcash/issues/3281 --- src/wallet/rpcwallet.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d9d7aec2b..a25a3ac60 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3634,8 +3634,10 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Minimum number of confirmations cannot be less than 0"); } - // Fee in Zatoshis, not currency format) - CAmount nFee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE; + // Fee in Puposhis, not currency format + CAmount nFee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE; + CAmount nDefaultFee = nFee; + if (params.size() > 3) { if (params[3].get_real() == 0.0) { nFee = 0; @@ -3643,9 +3645,17 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) nFee = AmountFromValue( params[3] ); } - // Check that the user specified fee is sane. - if (nFee > nTotalOut) { - throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Fee %s is greater than the sum of outputs %s", FormatMoney(nFee), FormatMoney(nTotalOut))); + // This allows amount=0 (and all amount < nDefaultFee) transactions to use the default network fee + // instead of being forced to use a custom fee and leak metadata + if (nTotalOut < nDefaultFee) { + if (nFee > nDefaultFee) { + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Small transaction amount %s has fee %s that is greater than the default fee %s", FormatMoney(nTotalOut), FormatMoney(nFee), FormatMoney(nDefaultFee))); + } + } else { + // Check that the user specified fee is sane. + if (nFee > nTotalOut) { + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Fee %s is greater than the sum of outputs %s", FormatMoney(nFee), FormatMoney(nTotalOut))); + } } }