mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
[raw] reject insanely high fees by default in sendrawtransaction
There have been several incidents where mainnet experimentation with raw transactions resulted in insane fees. This is hard to prevent in the raw transaction api because the inputs may not be known. Since sending doesn't work if the inputs aren't known, we can catch it there. This rejects fees > than 10000 * nMinRelayTxFee or 1 BTC with the defaults and can be overridden with a bool at the rpc.
This commit is contained in:
@@ -527,9 +527,9 @@ Value signrawtransaction(const Array& params, bool fHelp)
|
||||
|
||||
Value sendrawtransaction(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 1)
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"sendrawtransaction <hex string>\n"
|
||||
"sendrawtransaction <hex string> [allowhighfees=false]\n"
|
||||
"Submits raw transaction (serialized, hex-encoded) to local node and network.");
|
||||
|
||||
// parse hex string from parameter
|
||||
@@ -537,6 +537,10 @@ Value sendrawtransaction(const Array& params, bool fHelp)
|
||||
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
|
||||
CTransaction tx;
|
||||
|
||||
bool fOverrideFees = false;
|
||||
if (params.size() > 1)
|
||||
fOverrideFees = params[1].get_bool();
|
||||
|
||||
// deserialize binary data stream
|
||||
try {
|
||||
ssData >> tx;
|
||||
@@ -554,7 +558,7 @@ Value sendrawtransaction(const Array& params, bool fHelp)
|
||||
if (!fHave) {
|
||||
// push to local node
|
||||
CValidationState state;
|
||||
if (!mempool.accept(state, tx, false, NULL))
|
||||
if (!mempool.accept(state, tx, false, NULL, !fOverrideFees))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX rejected"); // TODO: report validation state
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user