Skip to content

Commit

Permalink
Minimal consensus/miner changes for 2mb block size bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinandresen committed Feb 5, 2016
1 parent 53580de commit 7b60bb2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
10 changes: 6 additions & 4 deletions src/consensus/consensus.h
Expand Up @@ -6,10 +6,12 @@
#ifndef BITCOIN_CONSENSUS_CONSENSUS_H #ifndef BITCOIN_CONSENSUS_CONSENSUS_H
#define BITCOIN_CONSENSUS_CONSENSUS_H #define BITCOIN_CONSENSUS_CONSENSUS_H


/** The maximum allowed size for a serialized block, in bytes (network rule) */ /** Block size limit, post-2MB fork */
static const unsigned int MAX_BLOCK_SIZE = 1000000; static const unsigned int MAX_BLOCK_SIZE = 2000000;
/** The maximum allowed number of signature check operations in a block (network rule) */ /** The old block size limit */
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50; static const unsigned int OLD_MAX_BLOCK_SIZE = 1000000;
/** pre-2MB-fork limit on signature operations in a block */
static const unsigned int MAX_BLOCK_SIGOPS = OLD_MAX_BLOCK_SIZE/50;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */ /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
static const int COINBASE_MATURITY = 100; static const int COINBASE_MATURITY = 100;


Expand Down
20 changes: 15 additions & 5 deletions src/main.cpp
Expand Up @@ -2742,15 +2742,17 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
REJECT_INVALID, "bad-txns-duplicate", true); REJECT_INVALID, "bad-txns-duplicate", true);
} }


// All potential-corruption validation must be done before we do any
// transaction validation, as otherwise we may mark the header as invalid
// because we receive the wrong transactions for it.

// Size limits // Size limits
if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE) unsigned int nSizeLimit = MaxBlockSize(block.nTime);

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


// All potential-corruption validation must be done before we do any
// transaction validation, as otherwise we may mark the header as invalid
// because we receive the wrong transactions for it.

// First transaction must be coinbase, the rest must not be // First transaction must be coinbase, the rest must not be
if (block.vtx.empty() || !block.vtx[0].IsCoinBase()) if (block.vtx.empty() || !block.vtx[0].IsCoinBase())
return state.DoS(100, error("CheckBlock(): first tx is not coinbase"), return state.DoS(100, error("CheckBlock(): first tx is not coinbase"),
Expand Down Expand Up @@ -5217,6 +5219,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst), DateTimeStrFormat("%Y-%m-%d", nTimeLast)); return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst), DateTimeStrFormat("%Y-%m-%d", nTimeLast));
} }


/** Maximum size of a block */
unsigned int MaxBlockSize(uint32_t nBLockTime)
{
if (true) // TODO: activation condition
return MAX_BLOCK_SIZE;
return OLD_MAX_BLOCK_SIZE;
}





class CMainCleanup class CMainCleanup
Expand Down
3 changes: 3 additions & 0 deletions src/main.h
Expand Up @@ -492,4 +492,7 @@ extern CCoinsViewCache *pcoinsTip;
/** Global variable that points to the active block tree (protected by cs_main) */ /** Global variable that points to the active block tree (protected by cs_main) */
extern CBlockTreeDB *pblocktree; extern CBlockTreeDB *pblocktree;


/** Maximum size of a block */
unsigned int MaxBlockSize(uint32_t nBlockTime);

#endif // BITCOIN_MAIN_H #endif // BITCOIN_MAIN_H
32 changes: 17 additions & 15 deletions src/miner.cpp
Expand Up @@ -116,21 +116,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxFees.push_back(-1); // updated at end
pblocktemplate->vTxSigOps.push_back(-1); // updated at end pblocktemplate->vTxSigOps.push_back(-1); // updated at end


// Largest block you're willing to create:
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
// Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize));

// How much of the block should be dedicated to high-priority transactions,
// included regardless of the fees they pay
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);

// Minimum block size you want to create; block will be filled with free transactions
// until there are no more or the block reaches this size:
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);

// Collect memory pool transactions into the block // Collect memory pool transactions into the block
CAmount nFees = 0; CAmount nFees = 0;


Expand All @@ -142,6 +127,23 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
CCoinsViewCache view(pcoinsTip); CCoinsViewCache view(pcoinsTip);


unsigned int nSizeLimit = MaxBlockSize(nMedianTimePast);

// Largest block you're willing to create:
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
// Limit to betweeen 1K and max size-1K for sanity:
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(nSizeLimit-1000), nBlockMaxSize));

// How much of the block should be dedicated to high-priority transactions,
// included regardless of the fees they pay
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);

// Minimum block size you want to create; block will be filled with free transactions
// until there are no more or the block reaches this size:
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);

// Priority order to process transactions // Priority order to process transactions
list<COrphan> vOrphan; // list memory doesn't move list<COrphan> vOrphan; // list memory doesn't move
map<uint256, vector<COrphan*> > mapDependers; map<uint256, vector<COrphan*> > mapDependers;
Expand Down

0 comments on commit 7b60bb2

Please sign in to comment.