Auto merge of #3354 - leto:absurd_fee_bug, r=bitcartel
Fix absurd fee bug reported in #3281, with tests This was ported from the Hush `absurd_fee_bug` PR: https://github.com/MyHush/hush/pull/136 Tests executed with `./qa/pull-tester/rpc-tests.sh wallet` and pass on Ubuntu 16.04. Some tests were added for previously untested behavior as well. Closes #3281.
This commit is contained in:
@@ -3703,7 +3703,9 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
|
||||
}
|
||||
|
||||
// Fee in Zatoshis, not currency format)
|
||||
CAmount nFee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE;
|
||||
CAmount nFee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE;
|
||||
CAmount nDefaultFee = nFee;
|
||||
|
||||
if (params.size() > 3) {
|
||||
if (params[3].get_real() == 0.0) {
|
||||
nFee = 0;
|
||||
@@ -3711,10 +3713,19 @@ 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)));
|
||||
}
|
||||
// Check that the user specified fee is not absurd.
|
||||
// This allows amount=0 (and all amount < nDefaultFee) transactions to use the default network fee
|
||||
// or anything less than nDefaultFee 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 not absurd.
|
||||
if (nFee > nTotalOut) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Fee %s is greater than the sum of outputs %s and also greater than the default fee", FormatMoney(nFee), FormatMoney(nTotalOut)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use input parameters as the optional context info to be returned by z_getoperationstatus and z_getoperationresult.
|
||||
|
||||
Reference in New Issue
Block a user