Skip to content

Commit

Permalink
allow unlimited size blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
gandrewstone committed Nov 16, 2015
1 parent 4898afc commit b126b10
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/bitcoin-tx.cpp
Expand Up @@ -193,7 +193,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
// extract and validate vout
string strVout = strInput.substr(pos + 1, string::npos);
int vout = atoi(strVout);
if ((vout < 0) || (vout > (int)maxVout))
if (vout < 0) // || (vout > (int)maxVout))
throw runtime_error("invalid TX input vout");

// append to transaction input list
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.cpp
Expand Up @@ -13,7 +13,7 @@
* for both bitcoind and bitcoin-core, to make it harder for attackers to
* target servers or GUI users specifically.
*/
const std::string CLIENT_NAME("Satoshi");
const std::string CLIENT_NAME("BitcoinUnlimited");

/**
* Client version number
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/consensus.h
Expand Up @@ -7,7 +7,7 @@
#define BITCOIN_CONSENSUS_CONSENSUS_H

/** The maximum allowed size for a serialized block, in bytes (network rule) */
static const unsigned int MAX_BLOCK_SIZE = 1000000;
static const unsigned int MAX_BLOCK_SIZE = 32000000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
Expand Down
32 changes: 18 additions & 14 deletions src/main.cpp
Expand Up @@ -854,9 +854,8 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
return state.DoS(10, error("CheckTransaction(): vout empty"),
REJECT_INVALID, "bad-txns-vout-empty");
// Size limits
if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
return state.DoS(100, error("CheckTransaction(): size limits failed"),
REJECT_INVALID, "bad-txns-oversize");
//if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
// return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");

// Check for negative or overflow output values
CAmount nValueOut = 0;
Expand Down Expand Up @@ -1905,9 +1904,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin

nInputs += tx.vin.size();
nSigOps += GetLegacySigOpCount(tx);
if (nSigOps > MAX_BLOCK_SIGOPS)
return state.DoS(100, error("ConnectBlock(): too many sigops"),
REJECT_INVALID, "bad-blk-sigops");
//if (nSigOps > MAX_BLOCK_SIGOPS)
// return state.DoS(100, error("ConnectBlock(): too many sigops"),
// REJECT_INVALID, "bad-blk-sigops");

if (!tx.IsCoinBase())
{
Expand All @@ -1921,9 +1920,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// this is to prevent a "rogue miner" from creating
// an incredibly-expensive-to-validate block.
nSigOps += GetP2SHSigOpCount(tx, view);
if (nSigOps > MAX_BLOCK_SIGOPS)
return state.DoS(100, error("ConnectBlock(): too many sigops"),
REJECT_INVALID, "bad-blk-sigops");
//if (nSigOps > MAX_BLOCK_SIGOPS)
// return state.DoS(100, error("ConnectBlock(): too many sigops"),
// REJECT_INVALID, "bad-blk-sigops");
}

nFees += view.GetValueIn(tx)-tx.GetValueOut();
Expand Down Expand Up @@ -2747,7 +2746,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
// because we receive the wrong transactions for it.

// Size limits
if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
if (block.vtx.empty()) // || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
return state.DoS(100, error("CheckBlock(): size limits failed"),
REJECT_INVALID, "bad-blk-length");

Expand All @@ -2770,9 +2769,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
{
nSigOps += GetLegacySigOpCount(tx);
}
if (nSigOps > MAX_BLOCK_SIGOPS)
return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"),
REJECT_INVALID, "bad-blk-sigops", true);
// if (nSigOps > MAX_BLOCK_SIGOPS)
// return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"),
// REJECT_INVALID, "bad-blk-sigops", true);

return true;
}
Expand Down Expand Up @@ -2985,7 +2984,12 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, bool
{
// Preliminary checks
bool checked = CheckBlock(*pblock, state);

if (!checked)
{
int byteLen = ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION);
LogPrintf("Invalid block: ver:%x time:%d Tx size:%d len:%d\n", pblock->nVersion, pblock->nTime, pblock->vtx.size(),byteLen);
}

{
LOCK(cs_main);
bool fRequested = MarkBlockAsReceived(pblock->GetHash());
Expand Down
4 changes: 2 additions & 2 deletions src/merkleblock.cpp
Expand Up @@ -153,8 +153,8 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector<uint256> &vMatch) {
if (nTransactions == 0)
return uint256();
// check for excessively high numbers of transactions
if (nTransactions > MAX_BLOCK_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction
return uint256();
//if (nTransactions > MAX_BLOCK_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction
// return uint256();
// there can never be more hashes provided than one for every txid
if (vHash.size() > nTransactions)
return uint256();
Expand Down
59 changes: 59 additions & 0 deletions src/policy/policy.h
@@ -0,0 +1,59 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_POLICY_H
#define BITCOIN_POLICY_H

#include "consensus/consensus.h"
#include "script/interpreter.h"
#include "script/standard.h"

#include <string>

class CCoinsViewCache;

/** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000;
static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0;
/** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
/** The maximum size for transactions we're willing to relay/mine */
static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
/** Maximum number of signature check operations in an IsStandard() P2SH script */
static const unsigned int MAX_P2SH_SIGOPS = 15;
/** The maximum number of sigops we're willing to relay/mine in a single tx */
static const unsigned int MAX_STANDARD_TX_SIGOPS = 100*MAX_BLOCK_SIGOPS/5;
/**
* Standard script verification flags that standard transactions will comply
* with. However scripts violating these flags may still be present in valid
* blocks and we must accept those blocks.
*/
static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
SCRIPT_VERIFY_DERSIG |
SCRIPT_VERIFY_STRICTENC |
SCRIPT_VERIFY_MINIMALDATA |
SCRIPT_VERIFY_NULLDUMMY |
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
SCRIPT_VERIFY_CLEANSTACK |
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
SCRIPT_VERIFY_LOW_S;

/** For convenience, standard but not mandatory verify flags. */
static const unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;

bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
/**
* Check for standard transaction types
* @return True if all outputs (scriptPubKeys) use only standard transaction forms
*/
bool IsStandardTx(const CTransaction& tx, std::string& reason);
/**
* Check for standard transaction types
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
* @return True if all inputs (scriptSigs) use only standard transaction forms
*/
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);

#endif // BITCOIN_POLICY_H
8 changes: 4 additions & 4 deletions src/qt/unlimitedmodel.cpp
Expand Up @@ -101,7 +101,7 @@ QVariant UnlimitedModel::data(const QModelIndex& index, int role) const
switch (index.row())
{
case MaxGeneratedBlock:
return maxGeneratedBlock;
return QVariant((qulonglong)maxGeneratedBlock);
case UseReceiveShaping:
return settings.value("fUseReceiveShaping");
case UseSendShaping:
Expand Down Expand Up @@ -133,8 +133,8 @@ bool UnlimitedModel::setData(const QModelIndex& index, const QVariant& value, in
switch (index.row())
{
case MaxGeneratedBlock:
maxGeneratedBlock = value.toInt();
settings.setValue("maxGeneratedBlock", maxGeneratedBlock);
maxGeneratedBlock = value.toULongLong();
settings.setValue("maxGeneratedBlock", (qlonglong) maxGeneratedBlock);
break;
case UseReceiveShaping:
if (settings.value("fUseReceiveShaping") != value)
Expand Down Expand Up @@ -217,7 +217,7 @@ void UnlimitedModel::setMaxGeneratedBlock(const QVariant& value)
{
QSettings settings;
maxGeneratedBlock = value.toInt();
settings.setValue("maxGeneratedBlock",maxGeneratedBlock);
settings.setValue("maxGeneratedBlock",(qulonglong) maxGeneratedBlock);
// Q_EMIT your signal if you need one
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/unlimited.cpp
Expand Up @@ -6,6 +6,7 @@

#include "util.h"
#include "unlimited.h"
#include "rpcserver.h"

uint64_t maxGeneratedBlock = DEFAULT_MAX_GENERATED_BLOCK_SIZE;

Expand All @@ -14,3 +15,6 @@ void UnlimitedSetup(void)
{
maxGeneratedBlock = GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE);
}



0 comments on commit b126b10

Please sign in to comment.