Skip to content

Commit

Permalink
Checking upgradable constraints when connection block
Browse files Browse the repository at this point in the history
  • Loading branch information
mike31 committed Dec 27, 2017
1 parent d555fa2 commit fcd4f49
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/chainparams/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ int64_t COIN = 100000000;
int64_t CENT = 1000000; // amount.h
int64_t MAX_MONEY = 21000000 * COIN; // amount.h
unsigned int MAX_SCRIPT_ELEMENT_SIZE=520; // script.h
int MIN_BLOCKS_BETWEEN_UPGRADES = 100;
int MAX_OP_RETURN_SHOWN=16384;
int MAX_FORMATTED_DATA_DEPTH=100;
unsigned int MAX_OP_RETURN_OP_DROP_COUNT=100000000;
Expand Down
52 changes: 50 additions & 2 deletions src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,15 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return false;
}

if(!CheckBlockForUpgardableConstraints(block,state,"maximum-block-size",true))
{
return false;
}
if(!CheckBlockForUpgardableConstraints(block,state,"maximum-block-sigops",true))
{
return false;
}

/* MCHN START */
uint256 block_hash;
unsigned char miner_address[20];
Expand Down Expand Up @@ -4135,6 +4144,34 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool f
}

/* MCHN START */

bool CheckBlockForUpgardableConstraints(const CBlock& block, CValidationState& state, string parameter, bool in_sync)
{
if(!in_sync)
{
return true;
}

if(parameter == "maximum-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");
}
if(parameter == "maximum-block-sigops")
{
unsigned int nSigOps = 0;
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
nSigOps += GetLegacySigOpCount(tx);
}
if (nSigOps > MAX_BLOCK_SIGOPS)
return state.DoS(100, error("CheckBlock() : out-of-bounds SigOpCount"),
REJECT_INVALID, "bad-blk-sigops", true);
}
return true;
}

//bool CheckBlock(CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot)
bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot)
/* MCHN END */
Expand Down Expand Up @@ -4167,10 +4204,16 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
// because we receive the wrong transactions for it.

// Size limits
if(!CheckBlockForUpgardableConstraints(block,state,"maximum-block-size",false))
{
return false;
}
/*
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");

*/

// First transaction must be coinbase, the rest must not be
if (block.vtx.empty() || !block.vtx[0].IsCoinBase())
return state.DoS(100, error("CheckBlock() : first tx is not coinbase"),
Expand Down Expand Up @@ -4200,7 +4243,12 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
}
}

if(!CheckBlockForUpgardableConstraints(block,state,"maximum-block-sigops",false))
{
return false;
}

/*
unsigned int nSigOps = 0;
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
Expand All @@ -4209,7 +4257,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
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
2 changes: 2 additions & 0 deletions src/core/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static const unsigned int DEFAULT_MAX_SUCCESSORS_FROM_ONE_NODE = 10;
/* MCHN END */
extern int MAX_OP_RETURN_SHOWN;
extern int MAX_FORMATTED_DATA_DEPTH;
extern int MIN_BLOCKS_BETWEEN_UPGRADES;
/* MCHN END */
/** The maximum size of a blk?????.dat file (since 0.8) */
extern unsigned int MAX_BLOCKFILE_SIZE; // MCHN global
Expand Down Expand Up @@ -395,6 +396,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
/** Context-independent validity checks */
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
bool CheckBlockForUpgardableConstraints(const CBlock& block, CValidationState& state, std::string parameter, bool in_sync);

/** Context-dependent validity checks */
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex *pindexPrev, CBlockIndex *pindexChecked = NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/multichainblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int CreateUpgradeLists(int current_height,vector<mc_UpgradedParameter> *vParams,
if (it != map_last_upgrade.end())
{
take_it=false;
if((*vParams)[it->second].m_Block + 100 <= upgrade.m_AppliedBlock)
if((*vParams)[it->second].m_Block + MIN_BLOCKS_BETWEEN_UPGRADES <= upgrade.m_AppliedBlock)
{
int64_t old_value=(*vParams)[it->second].m_Value;
if(param.m_Value >= old_value)
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rpcupgrades.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ Value listupgrades(const json_spirit::Array& params, bool fHelp)
case MC_PSK_NOT_FOUND: param_err="Parameter name not recognized"; break;
case MC_PSK_WRONG_SIZE: param_err="Parameter is encoded with wrong size"; break;
case MC_PSK_OUT_OF_RANGE: param_err="Parameter value is out of range"; break;
case MC_PSK_FRESH_UPGRADE: param_err="Parameter is upgraded less than 100 blocks ago"; break;
case MC_PSK_FRESH_UPGRADE: param_err=strprintf("Parameter is upgraded less than %d blocks ago",MIN_BLOCKS_BETWEEN_UPGRADES); break;
case MC_PSK_DOUBLE_RANGE: param_err="New parameter value must be between half and double preview time"; break;
case MC_PSK_NOT_SUPPORTED: param_err="This parameter cannot be upgraded in this protocol version"; break;
case MC_PSK_NEW_NOT_DOWNGRADABLE: param_err="Cannot downgrade to this version"; break;
Expand Down

0 comments on commit fcd4f49

Please sign in to comment.