@@ -342,13 +342,14 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
342342 if (!opt_cbTx) {
343343 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-payload" );
344344 }
345+ const auto & cbTx = *opt_cbTx;
345346
346- if (opt_cbTx-> nVersion < CCbTx::Version::CLSIG_AND_BALANCE) {
347+ if (cbTx. nVersion < CCbTx::Version::CLSIG_AND_BALANCE) {
347348 return true ;
348349 }
349350
350351 auto best_clsig = chainlock_handler.GetBestChainLock ();
351- if (best_clsig.getHeight () == pindex->nHeight - 1 && opt_cbTx-> bestCLHeightDiff == 0 && opt_cbTx-> bestCLSignature == best_clsig.getSig ()) {
352+ if (best_clsig.getHeight () == pindex->nHeight - 1 && cbTx. bestCLHeightDiff == 0 && cbTx. bestCLSignature == best_clsig.getSig ()) {
352353 // matches our best clsig which still hold values for the previous block
353354 return true ;
354355 }
@@ -357,27 +358,27 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
357358 // If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null.
358359 if (prevBlockCoinbaseChainlock.has_value ()) {
359360 // 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+ if (!cbTx. bestCLSignature .IsValid ()) {
361362 // IsNull() doesn't exist for CBLSSignature: we assume that a non valid BLS sig is null
362363 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-null-clsig" );
363364 }
364- if (opt_cbTx-> bestCLHeightDiff > prevBlockCoinbaseChainlock.value ().second + 1 ) {
365+ if (cbTx. bestCLHeightDiff > prevBlockCoinbaseChainlock.value ().second + 1 ) {
365366 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-older-clsig" );
366367 }
367368 }
368369
369370 // IsNull() doesn't exist for CBLSSignature: we assume that a valid BLS sig is non-null
370- if (opt_cbTx-> bestCLSignature .IsValid ()) {
371- int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast <int >(opt_cbTx-> bestCLHeightDiff ) - 1 ;
372- if (best_clsig.getHeight () == curBlockCoinbaseCLHeight && best_clsig.getSig () == opt_cbTx-> bestCLSignature ) {
371+ if (cbTx. bestCLSignature .IsValid ()) {
372+ int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast <int >(cbTx. bestCLHeightDiff ) - 1 ;
373+ if (best_clsig.getHeight () == curBlockCoinbaseCLHeight && best_clsig.getSig () == cbTx. bestCLSignature ) {
373374 // matches our best (but outdated) clsig, no need to verify it again
374375 return true ;
375376 }
376377 uint256 curBlockCoinbaseCLBlockHash = pindex->GetAncestor (curBlockCoinbaseCLHeight)->GetBlockHash ();
377- if (chainlock_handler.VerifyChainLock (llmq::CChainLockSig (curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, opt_cbTx-> bestCLSignature )) != llmq::VerifyRecSigStatus::Valid) {
378+ if (chainlock_handler.VerifyChainLock (llmq::CChainLockSig (curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, cbTx. bestCLSignature )) != llmq::VerifyRecSigStatus::Valid) {
378379 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-invalid-clsig" );
379380 }
380- } else if (opt_cbTx-> bestCLHeightDiff != 0 ) {
381+ } else if (cbTx. bestCLHeightDiff != 0 ) {
381382 // Null bestCLSignature is allowed only with bestCLHeightDiff = 0
382383 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-cldiff" );
383384 }
0 commit comments