Skip to content
Permalink
Browse files

Restore original bytespersigop as bytespersigopstrict

Plus a bugfix to accurately count sigops for this purpose
  • Loading branch information
luke-jr committed Aug 8, 2016
1 parent 3fae116 commit a44c3b4a921cf04018a09b9f58dc3a45698c7b12
Showing with 42 additions and 1 deletion.
  1. +1 −0 src/init.cpp
  2. +1 −0 src/policy/policy.cpp
  3. +2 −0 src/policy/policy.h
  4. +1 −0 src/policy/settings.cpp
  5. +1 −0 src/policy/settings.h
  6. +36 −1 src/validation.cpp
@@ -515,6 +515,7 @@ void SetupServerArgs()
gArgs.AddArg("-incrementalrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
gArgs.AddArg("-dustrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define dust, the value of an output such that it will cost more than its value in fees at this fee rate to spend it. (default: %s)", CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
gArgs.AddArg("-bytespersigop", strprintf("Equivalent bytes per sigop in transactions for relay and mining (default: %u)", DEFAULT_BYTES_PER_SIGOP), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
gArgs.AddArg("-bytespersigopstrict", strprintf("Minimum bytes per sigop in transactions we relay and mine (default: %u)", DEFAULT_BYTES_PER_SIGOP_STRICT), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
gArgs.AddArg("-datacarrier", strprintf("Relay and mine data carrier transactions (default: %u)", DEFAULT_ACCEPT_DATACARRIER), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
gArgs.AddArg("-datacarriersize", strprintf("Maximum size of data in data carrier transactions we relay and mine (default: %u)", MAX_OP_RETURN_RELAY), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
gArgs.AddArg("-mempoolreplacement", strprintf("Enable transaction replacement in the memory pool (default: %u)", DEFAULT_ENABLE_REPLACEMENT), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
@@ -7,6 +7,7 @@

#include <policy/policy.h>

#include <consensus/tx_verify.h>
#include <consensus/validation.h>
#include <coins.h>

@@ -35,6 +35,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;
/** Default for -mempoolreplacement */
static const bool DEFAULT_ENABLE_REPLACEMENT = true;
static const bool DEFAULT_REPLACEMENT_HONOUR_OPTOUT = true;
@@ -14,3 +14,4 @@ bool fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
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;
@@ -15,6 +15,7 @@ class CTransaction;
extern CFeeRate incrementalRelayFee;
extern CFeeRate dustRelayFee;
extern unsigned int nBytesPerSigOp;
extern unsigned int nBytesPerSigOpStrict;
extern bool fIsBareMultisigStd;
extern bool fEnableReplacement;
extern bool fReplacementHonourOptOut;
@@ -315,6 +315,38 @@ bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flag
// Returns the script flags which should be checked for a given block
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& chainparams);

/** 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 (const auto& txin : tx.vin) {
const Coin& coin = inputs.AccessCoin(txin.prevout);
assert(!coin.IsSpent());
const CTxOut &prevout = coin.out;
nSigOps += CountWitnessSigOps(txin.scriptSig, prevout.scriptPubKey, &txin.scriptWitness, flags);
}
}

return nSigOps;
}

static void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age)
EXCLUSIVE_LOCKS_REQUIRED(pool.cs, ::cs_main)
{
@@ -738,9 +770,12 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
fSpendsCoinbase, nSigOpsCost, lp));
unsigned int nSize = entry->GetTxSize();

if (nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST)
// To avoid rejecting low-sigop bare-multisig transactions, the sigops
// are counted a second time more accurately.
if ((nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST) || (nBytesPerSigOpStrict && GetAccurateTransactionSigOpCost(tx, m_view, STANDARD_SCRIPT_VERIFY_FLAGS) > nSize * WITNESS_SCALE_FACTOR / nBytesPerSigOpStrict)) {
MaybeRejectDbg(ValidationInvalidReason::TX_NOT_STANDARD, REJECT_NONSTANDARD, "bad-txns-too-many-sigops",
strprintf("%d", nSigOpsCost));
}

// No transactions are allowed below minRelayTxFee except from disconnected
// blocks

0 comments on commit a44c3b4

Please sign in to comment.
You can’t perform that action at this time.