Permalink
Browse files

Merge bytespersigopstrict+sendraw_force

  • Loading branch information...
luke-jr committed Mar 7, 2017
2 parents 3db795f + 29778f7 commit aba2a0e7234e39b00023ab2d50c97ae31741c4b3
Showing with 37 additions and 1 deletion.
  1. +1 −0 src/init.cpp
  2. +1 −0 src/policy/policy.cpp
  3. +3 −0 src/policy/policy.h
  4. +32 −1 src/validation.cpp
View
@@ -488,6 +488,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to defined dust, the value of an output such that it will cost about 1/3 of its value in fees at this fee rate to spend it. (default: %s)", CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE)));
}
strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Equivalent bytes per sigop in transactions for relay and mining (default: %u)"), DEFAULT_BYTES_PER_SIGOP));
strUsage += HelpMessageOpt("-bytespersigopstrict", strprintf(_("Minimum bytes per sigop in transactions we relay and mine (default: %u)"), DEFAULT_BYTES_PER_SIGOP_STRICT));
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));
strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY));
strUsage += HelpMessageOpt("-mempoolreplacement", strprintf(_("Enable transaction replacement in the memory pool (default: %u)"), DEFAULT_ENABLE_REPLACEMENT));
View
@@ -264,6 +264,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs,
CFeeRate incrementalRelayFee = CFeeRate(DEFAULT_INCREMENTAL_RELAY_FEE);
CFeeRate dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP;
unsigned int nBytesPerSigOpStrict = DEFAULT_BYTES_PER_SIGOP_STRICT;
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
{
View
@@ -34,6 +34,8 @@ static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000;
/** Default for -bytespersigop */
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
/** Default for -bytespersigopstrict */
static const unsigned int DEFAULT_BYTES_PER_SIGOP_STRICT = 20;
/** The maximum number of witness stack items in a standard P2WSH script */
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100;
/** The maximum size of each witness stack item in a standard P2WSH script */
@@ -97,6 +99,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs,
extern CFeeRate incrementalRelayFee;
extern CFeeRate dustRelayFee;
extern unsigned int nBytesPerSigOp;
extern unsigned int nBytesPerSigOpStrict;
/** Compute the virtual transaction size (weight reinterpreted as bytes). */
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost);
View
@@ -489,6 +489,34 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
return nSigOps;
}
/** Compute accurate total signature operation cost of a transaction.
* Not consensus-critical, since legacy sigops counting is always used in the protocol.
*/
int64_t GetAccurateTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, int flags)
{
if (tx.IsCoinBase())
return 0;
unsigned int nSigOps = 0;
for (const auto& txin : tx.vin) {
nSigOps += txin.scriptSig.GetSigOpCount(false);
}
if (flags & SCRIPT_VERIFY_P2SH) {
nSigOps += GetP2SHSigOpCount(tx, inputs);
}
nSigOps *= WITNESS_SCALE_FACTOR;
if (flags & SCRIPT_VERIFY_WITNESS) {
for (unsigned int i = 0; i < tx.vin.size(); i++) {
const CTxOut &prevout = inputs.GetOutputFor(tx.vin[i]);
nSigOps += CountWitnessSigOps(tx.vin[i].scriptSig, prevout.scriptPubKey, &tx.vin[i].scriptWitness, flags);
}
}
return nSigOps;
}
@@ -808,7 +836,10 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
// MAX_BLOCK_SIGOPS; we still consider this an invalid rather than
// merely non-standard transaction.
if (setIgnoreRejects.find("bad-txns-too-many-sigops") == setIgnoreRejects.end()) {
if (nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST)
// To avoid rejecting low-sigop bare-multisig transactions, the sigops
// are counted a second time more accurately.
int64_t nAccurateSigOpsCost = GetAccurateTransactionSigOpCost(tx, view, STANDARD_SCRIPT_VERIFY_FLAGS);
if ((nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST) || (nBytesPerSigOpStrict && nAccurateSigOpsCost > nSize * WITNESS_SCALE_FACTOR / nBytesPerSigOpStrict))
return state.DoS(0, false, REJECT_NONSTANDARD, "bad-txns-too-many-sigops", false,
strprintf("%d", nSigOpsCost));
}

0 comments on commit aba2a0e

Please sign in to comment.