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) { | Amount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFeeIn) { | ||||
// "Dust" is defined in terms of dustRelayFee, | // "Dust" is defined in terms of dustRelayFee, | ||||
// which has units satoshis-per-kilobyte. | // which has units satoshis-per-kilobyte. | ||||
// If you'd pay more than 1/3 in fees | // If you'd pay more than 1/3 in fees | ||||
// to spend something, then we consider it dust. | // to spend something, then we consider it dust. | ||||
// A typical spendable non-segwit txout is 34 bytes big, and will | // A typical spendable non-segwit txout is 34 bytes big, and will | ||||
// need a CTxIn of at least 148 bytes to spend: | // need a CTxIn of at least 148 bytes to spend: | ||||
// so dust is a spendable txout less than | // so dust is a spendable txout less than | ||||
// 546*dustRelayFee/1000 (in satoshis). | // 546*dustRelayFee/1000 (in satoshis). | ||||
// A typical spendable segwit txout is 31 bytes big, and will | // A typical spendable segwit txout is 31 bytes big, and will | ||||
// need a CTxIn of at least 67 bytes to spend: | // need a CTxIn of at least 67 bytes to spend: | ||||
// so dust is a spendable txout less than | // so dust is a spendable txout less than | ||||
// 294*dustRelayFee/1000 (in satoshis). | // 294*dustRelayFee/1000 (in satoshis). | ||||
if (txout.scriptPubKey.IsUnspendable()) { | if (txout.scriptPubKey.IsUnspendable()) { | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
size_t nSize = GetSerializeSize(txout, SER_DISK, 0); | size_t nSize = GetSerializeSize(txout, SER_DISK, 0); | ||||
// the 148 mentioned above | // the 148 mentioned above | ||||
nSize += (32 + 4 + 1 + 107 + 4); | nSize += (32 + 4 + 1 + 107 + 4); | ||||
return 3 * dustRelayFee.GetFee(nSize); | return 3 * dustRelayFeeIn.GetFee(nSize); | ||||
} | } | ||||
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFee) { | bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn) { | ||||
return (txout.nValue < GetDustThreshold(txout, dustRelayFee)); | return (txout.nValue < GetDustThreshold(txout, dustRelayFeeIn)); | ||||
} | } | ||||
/** | /** | ||||
* 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 | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |