Skip to content

Commit b1f09f7

Browse files
committed
HF: Replace bip34 with simpler equivalent (coinbase.nLockTime)
1 parent 6da0ff3 commit b1f09f7

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/miner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
182182

183183
// Create coinbase transaction.
184184
CMutableTransaction coinbaseTx;
185+
coinbaseTx.nLockTime = nHeight - 1;
185186
coinbaseTx.vin.resize(1);
186187
coinbaseTx.vin[0].prevout.SetNull();
187188
coinbaseTx.vout.resize(1);
188189
coinbaseTx.vout[0].scriptPubKey = nFees ? scriptPubKeyIn : CScript() << OP_RETURN;
189190
coinbaseTx.vout[0].nValue = nFees;
190191
coinbaseTx.vout[0].nAsset = policyAsset;
191-
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
192+
coinbaseTx.vin[0].scriptSig = CScript();
192193
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
193194
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
194195
pblocktemplate->vTxFees[0] = -nFees;
@@ -633,9 +634,8 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
633634
hashPrevBlock = pblock->hashPrevBlock;
634635
}
635636
++nExtraNonce;
636-
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
637637
CMutableTransaction txCoinbase(*pblock->vtx[0]);
638-
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
638+
txCoinbase.vin[0].scriptSig = (CScript() << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
639639
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
640640

641641
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));

src/validation.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
530530
if (tx.IsCoinBase())
531531
{
532532
// Coinbase transactions may not have eccessive scriptSigs or any fee outputs
533-
if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
533+
if (tx.vin[0].scriptSig.size() > 100)
534534
return state.DoS(100, false, REJECT_INVALID, "bad-cb-length");
535535

536536
for (unsigned int i = 0; i < tx.vout.size(); i++)
@@ -3848,11 +3848,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
38483848
}
38493849

38503850
// Enforce rule that the coinbase starts with serialized block height
3851-
if (block.nVersion >= 2)
3852-
{
3853-
CScript expect = CScript() << nHeight;
3854-
if (block.vtx[0]->vin[0].scriptSig.size() < expect.size() ||
3855-
!std::equal(expect.begin(), expect.end(), block.vtx[0]->vin[0].scriptSig.begin())) {
3851+
if (nHeight > consensusParams.BIP34Height) {
3852+
if (block.vtx[0]->nLockTime != (uint32_t)nHeight - 1) {
38563853
return state.DoS(100, false, REJECT_INVALID, "bad-cb-height", false, "block height mismatch in coinbase");
38573854
}
38583855
}

0 commit comments

Comments
 (0)