Skip to content

Commit af93e87

Browse files
committed
refactor: removed pre-MN_RR logic of validation of CL
The fork MN_RR is active awhile on testnet and mainnet and no more need legacy check
1 parent 018d80a commit af93e87

File tree

4 files changed

+20
-33
lines changed

4 files changed

+20
-33
lines changed

src/evo/cbtx.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
332332
}
333333

334334
bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
335-
const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state, const bool check_clhdiff)
335+
const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state)
336336
{
337337
if (block.vtx[0]->nType != TRANSACTION_COINBASE) {
338338
return true;
@@ -353,18 +353,16 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
353353
return true;
354354
}
355355

356-
if (check_clhdiff) {
357-
auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex->pprev);
358-
// If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null.
359-
if (prevBlockCoinbaseChainlock.has_value()) {
360-
// Previous block Coinbase has a non-null Chainlock: current block's Chainlock must be non-null and at least as new as the previous one
361-
if (!opt_cbTx->bestCLSignature.IsValid()) {
362-
// IsNull() doesn't exist for CBLSSignature: we assume that a non valid BLS sig is null
363-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-null-clsig");
364-
}
365-
if (opt_cbTx->bestCLHeightDiff > prevBlockCoinbaseChainlock.value().second + 1) {
366-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig");
367-
}
356+
const auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex->pprev);
357+
// If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null.
358+
if (prevBlockCoinbaseChainlock.has_value()) {
359+
// Previous block Coinbase has a non-null Chainlock: current block's Chainlock must be non-null and at least as new as the previous one
360+
if (!opt_cbTx->bestCLSignature.IsValid()) {
361+
// IsNull() doesn't exist for CBLSSignature: we assume that a non valid BLS sig is null
362+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-null-clsig");
363+
}
364+
if (opt_cbTx->bestCLHeightDiff > prevBlockCoinbaseChainlock.value().second + 1) {
365+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig");
368366
}
369367
}
370368

src/evo/cbtx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
9696
BlockValidationState& state);
9797

9898
bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindexPrev,
99-
const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state, const bool check_clhdiff);
99+
const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state);
100100
bool CalcCbTxBestChainlock(const llmq::CChainLocksHandler& chainlock_handler, const CBlockIndex* pindexPrev,
101101
uint32_t& bestCLHeightDiff, CBLSSignature& bestCLSignature);
102102

src/evo/specialtxman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
188188
nTimeMerkle += nTime5 - nTime4;
189189
LogPrint(BCLog::BENCHMARK, " - CheckCbTxMerkleRoots: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeMerkle * 0.000001);
190190

191-
if (fCheckCbTxMerkleRoots && !CheckCbTxBestChainlock(block, pindex, m_clhandler, state, DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_MN_RR))) {
191+
if (fCheckCbTxMerkleRoots && !CheckCbTxBestChainlock(block, pindex, m_clhandler, state)) {
192192
// pass the state returned by the function above
193193
return false;
194194
}

test/functional/feature_llmq_chainlocks.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class LLMQChainLocksTest(DashTestFramework):
2222
def set_test_params(self):
23-
self.set_dash_test_params(5, 4, [["-testactivationheight=mn_rr@1100"]] * 5)
23+
self.set_dash_test_params(5, 4)
2424

2525
def run_test(self):
2626
# Connect all nodes to node1 so that we always have the whole network connected
@@ -243,14 +243,8 @@ def run_test(self):
243243
assert_equal(tip_1['cbTx']['bestCLSignature'], tip_0['cbTx']['bestCLSignature'])
244244
assert_equal(tip_1['cbTx']['bestCLHeightDiff'], tip_0['cbTx']['bestCLHeightDiff'] + 1)
245245

246-
self.log.info("Test that bestCLHeightDiff conditions are relaxed before mn_rr")
247-
self.test_bestCLHeightDiff(False)
248-
249-
self.activate_mn_rr(expected_activation_height=1100)
250-
self.log.info("Activated mn_rr at height:" + str(self.nodes[0].getblockcount()))
251-
252-
self.log.info("Test that bestCLHeightDiff conditions are stricter after mn_rr")
253-
self.test_bestCLHeightDiff(True)
246+
self.log.info("Test bestCLHeightDiff restrictions")
247+
self.test_bestCLHeightDiff()
254248

255249
def create_chained_txs(self, node, amount):
256250
txid = node.sendtoaddress(node.getnewaddress(), amount)
@@ -293,11 +287,10 @@ def test_coinbase_best_cl(self, node, expected_cl_in_cb=True, expected_null_cl=F
293287
else:
294288
assert "bestCLHeightDiff" not in cbtx and "bestCLSignature" not in cbtx
295289

296-
def test_bestCLHeightDiff(self, mn_rr_active):
290+
def test_bestCLHeightDiff(self):
297291
# We need 2 blocks we can grab clsigs from
298292
for _ in range(2):
299293
self.wait_for_chainlocked_block_all_nodes(self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0])
300-
assert_equal(softfork_active(self.nodes[1], "mn_rr"), mn_rr_active)
301294
tip1_hash = self.nodes[1].getbestblockhash()
302295

303296
self.isolate_node(1)
@@ -339,7 +332,7 @@ def test_bestCLHeightDiff(self, mn_rr_active):
339332
mal_block.hashMerkleRoot = mal_block.calc_merkle_root()
340333
mal_block.solve()
341334
result = self.nodes[1].submitblock(mal_block.serialize().hex())
342-
assert_equal(result, "bad-cbtx-older-clsig" if mn_rr_active else "bad-cbtx-invalid-clsig")
335+
assert_equal(result, "bad-cbtx-older-clsig")
343336
assert_equal(self.nodes[1].getbestblockhash(), tip1_hash)
344337

345338
# Update the sig too and it should pass now when mn_rr is not active and fail otherwise
@@ -350,12 +343,8 @@ def test_bestCLHeightDiff(self, mn_rr_active):
350343
mal_block.hashMerkleRoot = mal_block.calc_merkle_root()
351344
mal_block.solve()
352345
result = self.nodes[1].submitblock(mal_block.serialize().hex())
353-
if mn_rr_active:
354-
assert_equal(result, "bad-cbtx-older-clsig")
355-
assert_equal(self.nodes[1].getbestblockhash(), tip1_hash)
356-
else:
357-
assert_equal(result, None)
358-
assert not self.nodes[1].getbestblockhash() == tip1_hash
346+
assert_equal(result, "bad-cbtx-older-clsig")
347+
assert_equal(self.nodes[1].getbestblockhash(), tip1_hash)
359348

360349
self.reconnect_isolated_node(1, 0)
361350
self.sync_all()

0 commit comments

Comments
 (0)