Skip to content

Commit

Permalink
HARDFORK: implement block resources limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
jl2012 committed Dec 3, 2016
1 parent 8d587ac commit 69e613b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2992,6 +2992,16 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
}
}

if (nHeight >= HARDFORK_HEIGHT) {
if ((GetBlockWeight(block) > (MAX_BLOCK_WEIGHT * 2) || GetBlockWeight(block) > block.nTxsWeight))

This comment has been minimized.

Copy link
@luke-jr

luke-jr Dec 4, 2016

The comparisons to the committed values need to be exact.

This comment has been minimized.

Copy link
@jl2012

jl2012 Dec 4, 2016

Author Owner

@luke-jr A future softfork may define another witness field and add more weight through a softfork. If the comparison is exact, the nTxsWeight field will become nothing but just a placebo for legacy nodes.

Similarly, a future script softfork may define new CHECKSIG operation, and is counted as SigOp

This comment has been minimized.

Copy link
@luke-jr

luke-jr Dec 4, 2016

Hmm, perhaps the check should be strict until unknown deployments activate? Of course, this would impair the ability of BIPs [affecting these rules] to specify their own deployment conditions somewhat...

OTOH, maybe using it as a minimum is okay. I have to think more on this.

This comment has been minimized.

Copy link
@jl2012

jl2012 Dec 4, 2016

Author Owner

Actually I don't see how these committed values are useful. For full nodes, they will validate everything so these values are not useful. For SPV nodes, these values won't help them to judge if a block is oversize. They still need to download the whole block to verify the size, and even all previous txs to verify the nSigOp. The only way to generate compact proof is using a merkle-sum-tree (but merkle-sum-tree has the same problem mentioned: after a softfork the counting rules maybe changed)

return state.DoS(100, false, REJECT_INVALID, "bad-blk-weight", false, strprintf("%s : weight limit failed", __func__));
if (::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > block.nTxsBytes)
return state.DoS(100, false, REJECT_INVALID, "bad-blk-size", false, strprintf("%s : size limit failed", __func__));
if (block.vtx.size() > block.nTxsCount)
return state.DoS(100, false, REJECT_INVALID, "bad-txs-count", false, strprintf("%s : txs count failed", __func__));
return true;
}

// After the coinbase witness nonce and commitment are verified,
// we can check if the block weight passes (before we've checked the
// coinbase witness, it would be possible for the weight to be too
Expand Down

0 comments on commit 69e613b

Please sign in to comment.