Changeset View
Changeset View
Standalone View
Standalone View
src/policy/policy.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
// NOTE: This file is intended to be customised by the end user, and includes | // NOTE: This file is intended to be customised by the end user, and includes | ||||
// only local node policy logic | // only local node policy logic | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <script/interpreter.h> | #include <script/interpreter.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <utilstrencodings.h> | #include <utilstrencodings.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
Amount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFee) { | |||||
/** | |||||
* "Dust" is defined in terms of dustRelayFee, which has units | |||||
* satoshis-per-kilobyte. If you'd pay more than 1/3 in fees to spend | |||||
* something, then we consider it dust. A typical spendable txout is 34 | |||||
* bytes big, and will need a CTxIn of at least 148 bytes to spend: so dust | |||||
* is a spendable txout less than 546*dustRelayFee/1000 (in satoshis). | |||||
*/ | |||||
if (txout.scriptPubKey.IsUnspendable()) { | |||||
return Amount::zero(); | |||||
} | |||||
size_t nSize = GetSerializeSize(txout, SER_DISK, 0); | |||||
// the 148 mentioned above | |||||
nSize += (32 + 4 + 1 + 107 + 4); | |||||
return 3 * dustRelayFee.GetFee(nSize); | |||||
} | |||||
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFee) { | |||||
return (txout.nValue < GetDustThreshold(txout, dustRelayFee)); | |||||
} | |||||
/** | /** | ||||
* Check transaction inputs to mitigate two potential denial-of-service attacks: | * Check transaction inputs to mitigate two potential denial-of-service attacks: | ||||
* | * | ||||
* 1. scriptSigs with extra data stuffed into them, not consumed by scriptPubKey | * 1. scriptSigs with extra data stuffed into them, not consumed by scriptPubKey | ||||
* (or P2SH script) | * (or P2SH script) | ||||
* 2. P2SH scripts with a crazy number of expensive CHECKSIG/CHECKMULTISIG | * 2. P2SH scripts with a crazy number of expensive CHECKSIG/CHECKMULTISIG | ||||
* operations | * operations | ||||
* | * | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | for (const CTxOut &txout : tx.vout) { | ||||
return false; | return false; | ||||
} | } | ||||
if (whichType == TX_NULL_DATA) { | if (whichType == TX_NULL_DATA) { | ||||
nDataOut++; | nDataOut++; | ||||
} else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) { | } else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) { | ||||
reason = "bare-multisig"; | reason = "bare-multisig"; | ||||
return false; | return false; | ||||
} else if (txout.IsDust(dustRelayFee)) { | } else if (IsDust(txout, ::dustRelayFee)) { | ||||
reason = "dust"; | reason = "dust"; | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// only one OP_RETURN txout is permitted | // only one OP_RETURN txout is permitted | ||||
if (nDataOut > 1) { | if (nDataOut > 1) { | ||||
reason = "multi-op-return"; | reason = "multi-op-return"; | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |