Skip to content

Commit d2431c0

Browse files
authored
Merge pull request #48 from btc1/2017_fixed_height_rm
[consensus] Remove flag day activation
2 parents 699d409 + ff673e9 commit d2431c0

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

qa/rpc-tests/segwit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def run_test(self):
135135
assert(tmpl['sigoplimit'] == 20000)
136136
assert(tmpl['transactions'][0]['hash'] == txid)
137137
assert(tmpl['transactions'][0]['sigops'] == 2)
138-
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']})
138+
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit','segwit2x']})
139139
assert(tmpl['sizelimit'] == 1000000)
140140
assert('weightlimit' not in tmpl)
141141
assert(tmpl['sigoplimit'] == 20000)
@@ -244,10 +244,10 @@ def run_test(self):
244244

245245
print("Verify sigops are counted in GBT with BIP141 rules after the fork")
246246
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
247-
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']})
247+
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit','segwit2x']})
248248
assert(tmpl['sizelimit'] >= 3999577) # actual maximum size is lower due to minimum mandatory non-witness data
249249
assert(tmpl['weightlimit'] == 4000000) # limit at first step
250-
assert(tmpl['sigoplimit'] == 80000)
250+
assert(tmpl['sigoplimit'] == 160000) # limit at first step
251251
assert(tmpl['transactions'][0]['txid'] == txid)
252252
assert(tmpl['transactions'][0]['sigops'] == 8)
253253

@@ -291,7 +291,7 @@ def run_test(self):
291291
assert(txid1 in template_txids)
292292

293293
# Check that running with segwit support results in all 3 being included.
294-
template = self.nodes[0].getblocktemplate({"rules": ["segwit"]})
294+
template = self.nodes[0].getblocktemplate({"rules": ["segwit","segwit2x"]})
295295
template_txids = [ t['txid'] for t in template['transactions'] ]
296296
assert(txid1 in template_txids)
297297
assert(txid2 in template_txids)

src/consensus/consensus.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,60 @@
88

99
#include <stdint.h>
1010

11-
/** BIP102 block size increase height */
12-
static const unsigned int BIP102_FORK_MIN_HEIGHT = 485218;
11+
/** BIP102 block size increase - time until HF activated */
1312
static const unsigned int BIP102_FORK_BUFFER = (144 * 90);
1413

1514
/** The maximum allowed size for a serialized block, in bytes (only for buffer size limits) */
1615
static const unsigned int MAX_BLOCK_SERIALIZED_SIZE = (8 * 1000 * 1000);
1716

1817
/** The maximum allowed size for a block excluding witness data, in bytes (network rule) */
19-
static inline bool BIP102active(int nHeight, bool fSegwitSeasoned)
18+
static inline bool BIP102active(bool fSegwitSeasoned)
2019
{
2120
if (!fSegwitSeasoned)
2221
return false;
2322

24-
if (nHeight < (int)BIP102_FORK_MIN_HEIGHT)
25-
return false;
26-
2723
return true;
2824
}
2925

3026
static const unsigned int MAX_LEGACY_BLOCK_SIZE = (1 * 1000 * 1000);
31-
inline unsigned int MaxBlockBaseSize(int nHeight, bool fSegwitSeasoned)
27+
inline unsigned int MaxBlockBaseSize(bool fSegwitSeasoned)
3228
{
33-
if (!BIP102active(nHeight, fSegwitSeasoned))
29+
if (!BIP102active(fSegwitSeasoned))
3430
return MAX_LEGACY_BLOCK_SIZE;
3531

3632
return (2 * 1000 * 1000);
3733
}
3834

3935
inline unsigned int MaxBlockBaseSize()
4036
{
41-
return MaxBlockBaseSize(99999999, true);
37+
return MaxBlockBaseSize(true);
4238
}
4339

4440

4541
/** The maximum allowed number of signature check operations in a block (network rule) */
4642
static const uint64_t MAX_BLOCK_BASE_SIGOPS = 20000;
47-
inline int64_t MaxBlockSigOpsCost(int nHeight, bool fSegwitSeasoned)
43+
inline int64_t MaxBlockSigOpsCost(bool fSegwitSeasoned)
4844
{
49-
if (!BIP102active(nHeight, fSegwitSeasoned))
45+
if (!BIP102active(fSegwitSeasoned))
5046
return (MAX_BLOCK_BASE_SIGOPS * 4 /* WITNESS_SCALE_FACTOR */);
5147

5248
return ((2 * MAX_BLOCK_BASE_SIGOPS) * 4 /* WITNESS_SCALE_FACTOR */);
5349
}
5450

5551
inline int64_t MaxBlockSigOpsCost()
5652
{
57-
return MaxBlockSigOpsCost(99999999, true);
53+
return MaxBlockSigOpsCost(true);
5854
}
5955

6056
/** The maximum allowed weight for a block, see BIP 141 (network rule) */
61-
inline unsigned int MaxBlockWeight(int nHeight, bool fSegwitSeasoned)
57+
inline unsigned int MaxBlockWeight(bool fSegwitSeasoned)
6258
{
63-
return (MaxBlockBaseSize(nHeight, fSegwitSeasoned) * 4 /* WITNESS_SCALE_FACTOR */);
59+
return (MaxBlockBaseSize(fSegwitSeasoned) * 4 /* WITNESS_SCALE_FACTOR */);
6460
}
6561

6662
inline unsigned int MaxBlockWeight()
6763
{
68-
return MaxBlockWeight(99999999, true);
64+
return MaxBlockWeight(true);
6965
}
7066

7167
/** The maximum allowed number of transactions per block */

src/miner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ BlockAssembler::BlockAssembler(const CChainParams& _chainparams)
102102
}
103103

104104
// Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
105-
nBlockMaxWeight = std::max((unsigned int)4000, std::min((unsigned int)(MaxBlockWeight(0, false)-4000), nBlockMaxWeight));
105+
nBlockMaxWeight = std::max((unsigned int)4000, std::min((unsigned int)(MaxBlockWeight(false)-4000), nBlockMaxWeight));
106106
// Limit size to between 1K and MAX_BLOCK_SERIALIZED_SIZE-1K for sanity:
107107
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SERIALIZED_SIZE-1000), nBlockMaxSize));
108108
// Whether we need to account for byte usage (in addition to weight usage)
@@ -242,7 +242,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
242242
// TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
243243
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight)
244244
return false;
245-
if (nBlockSigOpsCost + packageSigOpsCost >= (uint64_t)MaxBlockSigOpsCost(nHeight, fIncludeWitness)) // note - excludes bip102 buffer
245+
if (nBlockSigOpsCost + packageSigOpsCost >= (uint64_t)MaxBlockSigOpsCost(fIncludeWitness)) // note - excludes bip102 buffer
246246
return false;
247247
return true;
248248
}
@@ -302,7 +302,7 @@ bool BlockAssembler::TestForBlock(CTxMemPool::txiter iter)
302302
}
303303
}
304304

305-
uint64_t sigOpMax = MaxBlockSigOpsCost(nHeight, fIncludeWitness);
305+
uint64_t sigOpMax = MaxBlockSigOpsCost(fIncludeWitness); // excludes bip102 buffer
306306
if (nBlockSigOpsCost + iter->GetSigOpCost() >= sigOpMax) {
307307
// If the block has room for no more sig ops then
308308
// flag that the block is finished

src/rpc/mining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
681681
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
682682
result.push_back(Pair("mutable", aMutable));
683683
result.push_back(Pair("noncerange", "00000000ffffffff"));
684-
int64_t nSigOpLimit = MaxBlockSigOpsCost(pindexPrev->nHeight+1, fPreSegWit?false:true);
684+
int64_t nSigOpLimit = MaxBlockSigOpsCost(fPreSegWit?false:true); // excl bip102 buffer
685685
if (fPreSegWit) {
686686
assert(nSigOpLimit % WITNESS_SCALE_FACTOR == 0);
687687
nSigOpLimit /= WITNESS_SCALE_FACTOR;
@@ -691,7 +691,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
691691
result.push_back(Pair("sizelimit", (int64_t)MAX_LEGACY_BLOCK_SIZE));
692692
} else {
693693
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SERIALIZED_SIZE));
694-
result.push_back(Pair("weightlimit", (int64_t)MaxBlockWeight(0, false)));
694+
result.push_back(Pair("weightlimit", (int64_t)MaxBlockWeight(false)));
695695
}
696696
result.push_back(Pair("curtime", pblock->GetBlockTime()));
697697
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
19121912
// * p2sh (when P2SH enabled in flags and excludes coinbase)
19131913
// * witness (when witness enabled in flags and excludes coinbase)
19141914
nSigOpsCost += GetTransactionSigOpCost(tx, view, flags);
1915-
if (nSigOpsCost > MaxBlockSigOpsCost(pindex->nHeight, fSegwitSeasoned))
1915+
if (nSigOpsCost > MaxBlockSigOpsCost(fSegwitSeasoned))
19161916
return state.DoS(100, error("ConnectBlock(): too many sigops"),
19171917
REJECT_INVALID, "bad-blk-sigops");
19181918

@@ -3091,7 +3091,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
30913091
fSegwitSeasoned = IsWitnessSeasoned(pindexPrev, consensusParams);
30923092
}
30933093

3094-
if (::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MaxBlockBaseSize(nHeight, fSegwitSeasoned))
3094+
if (::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MaxBlockBaseSize(fSegwitSeasoned))
30953095
return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, "size limits failed");
30963096

30973097
// No witness data is allowed in blocks that don't commit to witness data, as this would otherwise leave room for spam
@@ -3108,7 +3108,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
31083108
{
31093109
nSigOps += GetLegacySigOpCount(*tx);
31103110
}
3111-
if (nSigOps * WITNESS_SCALE_FACTOR > MaxBlockSigOpsCost(nHeight, fSegwitSeasoned))
3111+
if (nSigOps * WITNESS_SCALE_FACTOR > MaxBlockSigOpsCost(fSegwitSeasoned))
31123112
return state.DoS(100, false, REJECT_INVALID, "bad-blk-sigops", false, "out-of-bounds SigOpCount");
31133113

31143114
// After the coinbase witness nonce and commitment are verified,
@@ -3117,7 +3117,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
31173117
// large by filling up the coinbase witness, which doesn't change
31183118
// the block hash, so we couldn't mark the block as permanently
31193119
// failed).
3120-
if (GetBlockWeight(block) > MaxBlockWeight(nHeight, fSegwitSeasoned)) {
3120+
if (GetBlockWeight(block) > MaxBlockWeight(fSegwitSeasoned)) {
31213121
return state.DoS(100, false, REJECT_INVALID, "bad-blk-weight", false, strprintf("%s : weight limit failed", __func__));
31223122
}
31233123

0 commit comments

Comments
 (0)