Skip to content

Commit 5aa3600

Browse files
committed
Validation: Remove CheckBlockSignature now unneeded enableP2PKH flag.
It was only needed for the activation period, now that it's fully enforced, can be removed. The activation time isn't needed, v5 enforcement checkpoint is ensuring that the chain cannot reorg to a time in which P2PKH stakes weren't enabled.
1 parent b6c873d commit 5aa3600

File tree

4 files changed

+12
-34
lines changed

4 files changed

+12
-34
lines changed

src/blocksignature.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool SignBlock(CBlock& block, const CKeyStore& keystore)
4040
return SignBlockWithKey(block, key);
4141
}
4242

43-
bool CheckBlockSignature(const CBlock& block, const bool enableP2PKH)
43+
bool CheckBlockSignature(const CBlock& block)
4444
{
4545
if (block.IsProofOfWork())
4646
return block.vchBlockSig.empty();
@@ -64,13 +64,6 @@ bool CheckBlockSignature(const CBlock& block, const bool enableP2PKH)
6464
if (!Solver(txout.scriptPubKey, whichType, vSolutions))
6565
return false;
6666

67-
if (!enableP2PKH) {
68-
// Before v5 activation, P2PKH was always failing.
69-
if (whichType == TX_PUBKEYHASH) {
70-
return false;
71-
}
72-
}
73-
7467
if (whichType == TX_PUBKEY) {
7568
valtype& vchPubKey = vSolutions[0];
7669
pubkey = CPubKey(vchPubKey);

src/blocksignature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
bool SignBlockWithKey(CBlock& block, const CKey& key);
1313
bool SignBlock(CBlock& block, const CKeyStore& keystore);
14-
bool CheckBlockSignature(const CBlock& block, const bool enableP2PKH);
14+
bool CheckBlockSignature(const CBlock& block);
1515

1616
#endif //PIVX_BLOCKSIGNATURE_H

src/test/main_tests.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,9 @@ CBlock CreateDummyBlockWithSignature(CKey stakingKey, BlockSignatureType type, b
7272
return block;
7373
}
7474

75-
bool TestBlockSignaturePreEnforcementV5(const CBlock& block)
75+
bool TestBlockSignature(const CBlock& block)
7676
{
77-
return CheckBlockSignature(block, false);
78-
}
79-
80-
bool TestBlockSignaturePostEnforcementV5(const CBlock& block)
81-
{
82-
return CheckBlockSignature(block, true);
77+
return CheckBlockSignature(block);
8378
}
8479

8580
BOOST_AUTO_TEST_CASE(block_signature_test)
@@ -89,27 +84,19 @@ BOOST_AUTO_TEST_CASE(block_signature_test)
8984
stakingKey.MakeNewKey(true);
9085
bool useInputP2PK = i % 2 == 0;
9186

92-
// Test P2PK block signature pre enforcement.
87+
// Test P2PK block signature
9388
CBlock block = CreateDummyBlockWithSignature(stakingKey, BlockSignatureType::P2PK, useInputP2PK);
94-
BOOST_CHECK(TestBlockSignaturePreEnforcementV5(block));
95-
96-
// Test P2PK block signature post enforcement
97-
block = CreateDummyBlockWithSignature(stakingKey, BlockSignatureType::P2PK, useInputP2PK);
98-
BOOST_CHECK(TestBlockSignaturePostEnforcementV5(block));
99-
100-
// Test P2PKH block signature pre enforcement ---> must fail.
101-
block = CreateDummyBlockWithSignature(stakingKey, BlockSignatureType::P2PKH, useInputP2PK);
102-
BOOST_CHECK(!TestBlockSignaturePreEnforcementV5(block));
89+
BOOST_CHECK(TestBlockSignature(block));
10390

104-
// Test P2PKH block signature post enforcement
91+
// Test P2PKH block signature
10592
block = CreateDummyBlockWithSignature(stakingKey, BlockSignatureType::P2PKH, useInputP2PK);
10693
if (useInputP2PK) {
10794
// If it's using a P2PK scriptsig as input and a P2PKH output
10895
// The block doesn't contain the public key to verify the sig anywhere.
10996
// Must fail.
110-
BOOST_CHECK(!TestBlockSignaturePostEnforcementV5(block));
97+
BOOST_CHECK(!TestBlockSignature(block));
11198
} else {
112-
BOOST_CHECK(TestBlockSignaturePostEnforcementV5(block));
99+
BOOST_CHECK(TestBlockSignature(block));
113100
}
114101
}
115102
}

src/validation.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,15 +3340,12 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, const std::shared_pt
33403340
// Preliminary checks
33413341
int64_t nStartTime = GetTimeMillis();
33423342
const Consensus::Params& consensus = Params().GetConsensus();
3343+
int newHeight = 0;
33433344

33443345
// check block
33453346
bool checked = CheckBlock(*pblock, state);
33463347

3347-
// For now, we need the tip to know whether p2pkh block signatures are accepted or not.
3348-
// After 5.0, this can be removed and replaced by the enforcement block time.
3349-
const int newHeight = chainActive.Height() + 1;
3350-
const bool enableP2PKH = consensus.NetworkUpgradeActive(newHeight, Consensus::UPGRADE_V5_0);
3351-
if (!CheckBlockSignature(*pblock, enableP2PKH))
3348+
if (!CheckBlockSignature(*pblock))
33523349
return error("%s : bad proof-of-stake block signature", __func__);
33533350

33543351
if (pblock->GetHash() != consensus.hashGenesisBlock && pfrom != NULL) {
@@ -3375,6 +3372,7 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, const std::shared_pt
33753372
if (!ret) {
33763373
return error("%s : AcceptBlock FAILED", __func__);
33773374
}
3375+
newHeight = pindex->nHeight;
33783376
}
33793377

33803378
if (!ActivateBestChain(state, pblock, checked))

0 commit comments

Comments
 (0)