Skip to content

Commit 9546a97

Browse files
committed
Merge pull request #6335
9238ecb Policy: MOVEONLY: 3 functions to policy.o: (Luke Dashjr) 627b9de Policy: MOVEONLY: Create policy/policy.h with some constants (Jorge Timón)
2 parents d0a10c1 + 9238ecb commit 9546a97

16 files changed

+250
-214
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ BITCOIN_CORE_H = \
111111
netbase.h \
112112
noui.h \
113113
policy/fees.h \
114+
policy/policy.h \
114115
pow.h \
115116
primitives/block.h \
116117
primitives/transaction.h \
@@ -176,6 +177,7 @@ libbitcoin_server_a_SOURCES = \
176177
net.cpp \
177178
noui.cpp \
178179
policy/fees.cpp \
180+
policy/policy.cpp \
179181
pow.cpp \
180182
rest.cpp \
181183
rpcblockchain.cpp \

src/bitcoin-tx.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "consensus/consensus.h"
99
#include "core_io.h"
1010
#include "keystore.h"
11+
#include "policy/policy.h"
1112
#include "primitives/transaction.h"
1213
#include "script/script.h"
1314
#include "script/sign.h"

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "main.h"
1919
#include "miner.h"
2020
#include "net.h"
21+
#include "policy/policy.h"
2122
#include "rpcserver.h"
2223
#include "script/standard.h"
2324
#include "scheduler.h"

src/main.cpp

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
#include "chainparams.h"
1212
#include "checkpoints.h"
1313
#include "checkqueue.h"
14+
#include "consensus/consensus.h"
1415
#include "consensus/validation.h"
1516
#include "init.h"
1617
#include "merkleblock.h"
1718
#include "net.h"
19+
#include "policy/policy.h"
1820
#include "pow.h"
1921
#include "txdb.h"
2022
#include "txmempool.h"
@@ -605,76 +607,6 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
605607
return nEvicted;
606608
}
607609

608-
609-
610-
611-
612-
613-
614-
bool IsStandardTx(const CTransaction& tx, string& reason)
615-
{
616-
if (tx.nVersion > CTransaction::CURRENT_VERSION || tx.nVersion < 1) {
617-
reason = "version";
618-
return false;
619-
}
620-
621-
// Extremely large transactions with lots of inputs can cost the network
622-
// almost as much to process as they cost the sender in fees, because
623-
// computing signature hashes is O(ninputs*txsize). Limiting transactions
624-
// to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks.
625-
unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION);
626-
if (sz >= MAX_STANDARD_TX_SIZE) {
627-
reason = "tx-size";
628-
return false;
629-
}
630-
631-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
632-
{
633-
// Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed
634-
// keys. (remember the 520 byte limit on redeemScript size) That works
635-
// out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627
636-
// bytes of scriptSig, which we round off to 1650 bytes for some minor
637-
// future-proofing. That's also enough to spend a 20-of-20
638-
// CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not
639-
// considered standard)
640-
if (txin.scriptSig.size() > 1650) {
641-
reason = "scriptsig-size";
642-
return false;
643-
}
644-
if (!txin.scriptSig.IsPushOnly()) {
645-
reason = "scriptsig-not-pushonly";
646-
return false;
647-
}
648-
}
649-
650-
unsigned int nDataOut = 0;
651-
txnouttype whichType;
652-
BOOST_FOREACH(const CTxOut& txout, tx.vout) {
653-
if (!::IsStandard(txout.scriptPubKey, whichType)) {
654-
reason = "scriptpubkey";
655-
return false;
656-
}
657-
658-
if (whichType == TX_NULL_DATA)
659-
nDataOut++;
660-
else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
661-
reason = "bare-multisig";
662-
return false;
663-
} else if (txout.IsDust(::minRelayTxFee)) {
664-
reason = "dust";
665-
return false;
666-
}
667-
}
668-
669-
// only one OP_RETURN txout is permitted
670-
if (nDataOut > 1) {
671-
reason = "multi-op-return";
672-
return false;
673-
}
674-
675-
return true;
676-
}
677-
678610
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
679611
{
680612
if (tx.nLockTime == 0)
@@ -693,74 +625,6 @@ bool CheckFinalTx(const CTransaction &tx)
693625
return IsFinalTx(tx, chainActive.Height() + 1, GetAdjustedTime());
694626
}
695627

696-
/**
697-
* Check transaction inputs to mitigate two
698-
* potential denial-of-service attacks:
699-
*
700-
* 1. scriptSigs with extra data stuffed into them,
701-
* not consumed by scriptPubKey (or P2SH script)
702-
* 2. P2SH scripts with a crazy number of expensive
703-
* CHECKSIG/CHECKMULTISIG operations
704-
*/
705-
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
706-
{
707-
if (tx.IsCoinBase())
708-
return true; // Coinbases don't use vin normally
709-
710-
for (unsigned int i = 0; i < tx.vin.size(); i++)
711-
{
712-
const CTxOut& prev = mapInputs.GetOutputFor(tx.vin[i]);
713-
714-
vector<vector<unsigned char> > vSolutions;
715-
txnouttype whichType;
716-
// get the scriptPubKey corresponding to this input:
717-
const CScript& prevScript = prev.scriptPubKey;
718-
if (!Solver(prevScript, whichType, vSolutions))
719-
return false;
720-
int nArgsExpected = ScriptSigArgsExpected(whichType, vSolutions);
721-
if (nArgsExpected < 0)
722-
return false;
723-
724-
// Transactions with extra stuff in their scriptSigs are
725-
// non-standard. Note that this EvalScript() call will
726-
// be quick, because if there are any operations
727-
// beside "push data" in the scriptSig
728-
// IsStandardTx() will have already returned false
729-
// and this method isn't called.
730-
vector<vector<unsigned char> > stack;
731-
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker()))
732-
return false;
733-
734-
if (whichType == TX_SCRIPTHASH)
735-
{
736-
if (stack.empty())
737-
return false;
738-
CScript subscript(stack.back().begin(), stack.back().end());
739-
vector<vector<unsigned char> > vSolutions2;
740-
txnouttype whichType2;
741-
if (Solver(subscript, whichType2, vSolutions2))
742-
{
743-
int tmpExpected = ScriptSigArgsExpected(whichType2, vSolutions2);
744-
if (tmpExpected < 0)
745-
return false;
746-
nArgsExpected += tmpExpected;
747-
}
748-
else
749-
{
750-
// Any other Script with less than 15 sigops OK:
751-
unsigned int sigops = subscript.GetSigOpCount(true);
752-
// ... extra data left on the stack after execution is OK, too:
753-
return (sigops <= MAX_P2SH_SIGOPS);
754-
}
755-
}
756-
757-
if (stack.size() != (unsigned int)nArgsExpected)
758-
return false;
759-
}
760-
761-
return true;
762-
}
763-
764628
unsigned int GetLegacySigOpCount(const CTransaction& tx)
765629
{
766630
unsigned int nSigOps = 0;

src/main.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "chain.h"
1515
#include "chainparams.h"
1616
#include "coins.h"
17-
#include "consensus/consensus.h"
1817
#include "net.h"
1918
#include "primitives/block.h"
2019
#include "primitives/transaction.h"
@@ -47,19 +46,8 @@ class CValidationState;
4746

4847
struct CNodeStateStats;
4948

50-
/** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/
51-
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000;
52-
static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0;
53-
/** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
54-
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
5549
/** Default for accepting alerts from the P2P network. */
5650
static const bool DEFAULT_ALERTS = true;
57-
/** The maximum size for transactions we're willing to relay/mine */
58-
static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
59-
/** Maximum number of signature check operations in an IsStandard() P2SH script */
60-
static const unsigned int MAX_P2SH_SIGOPS = 15;
61-
/** The maximum number of sigops we're willing to relay/mine in a single tx */
62-
static const unsigned int MAX_STANDARD_TX_SIGOPS = MAX_BLOCK_SIGOPS/5;
6351
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
6452
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
6553
/** The maximum size of a blk?????.dat file (since 0.8) */
@@ -274,25 +262,6 @@ struct CDiskTxPos : public CDiskBlockPos
274262

275263
CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree);
276264

277-
/**
278-
* Check transaction inputs, and make sure any
279-
* pay-to-script-hash transactions are evaluating IsStandard scripts
280-
*
281-
* Why bother? To avoid denial-of-service attacks; an attacker
282-
* can submit a standard HASH... OP_EQUAL transaction,
283-
* which will get accepted into blocks. The redemption
284-
* script can be anything; an attacker could use a very
285-
* expensive-to-check-upon-redemption script like:
286-
* DUP CHECKSIG DROP ... repeated 100 times... OP_1
287-
*/
288-
289-
/**
290-
* Check for standard transaction types
291-
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
292-
* @return True if all inputs (scriptSigs) use only standard transaction forms
293-
*/
294-
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
295-
296265
/**
297266
* Count ECDSA signature operations the old-fashioned (pre-0.6) way
298267
* @return number of sigops this transaction's outputs will produce when spent
@@ -324,11 +293,6 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
324293
/** Context-independent validity checks */
325294
bool CheckTransaction(const CTransaction& tx, CValidationState& state);
326295

327-
/** Check for standard transaction types
328-
* @return True if all outputs (scriptPubKeys) use only standard transaction forms
329-
*/
330-
bool IsStandardTx(const CTransaction& tx, std::string& reason);
331-
332296
/**
333297
* Check if transaction is final and can be included in a block with the
334298
* specified height and time. Consensus critical.

src/miner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "hash.h"
1313
#include "main.h"
1414
#include "net.h"
15+
#include "policy/policy.h"
1516
#include "pow.h"
1617
#include "primitives/transaction.h"
1718
#include "timedata.h"

0 commit comments

Comments
 (0)