@@ -29,10 +29,11 @@ bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidati
29
29
return state.Invalid (TxValidationResult::TX_CONSENSUS, " bad-cbtx-invalid" );
30
30
}
31
31
32
- CCbTx cbTx ;
33
- if (!GetTxPayload (tx, cbTx) ) {
32
+ const auto opt_cbTx = GetTxPayload<CCbTx>(tx) ;
33
+ if (!opt_cbTx ) {
34
34
return state.Invalid (TxValidationResult::TX_CONSENSUS, " bad-cbtx-payload" );
35
35
}
36
+ const auto & cbTx = *opt_cbTx;
36
37
37
38
if (cbTx.nVersion == CCbTx::Version::INVALID || cbTx.nVersion >= CCbTx::Version::UNKNOWN) {
38
39
return state.Invalid (TxValidationResult::TX_CONSENSUS, " bad-cbtx-version" );
@@ -68,10 +69,11 @@ bool CheckCbTxMerkleRoots(const CBlock& block, const CBlockIndex* pindex, const
68
69
69
70
int64_t nTime1 = GetTimeMicros ();
70
71
71
- CCbTx cbTx ;
72
- if (!GetTxPayload (*block. vtx [ 0 ], cbTx) ) {
72
+ const auto opt_cbTx = GetTxPayload<CCbTx>(*block. vtx [ 0 ]) ;
73
+ if (!opt_cbTx ) {
73
74
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-payload" );
74
75
}
76
+ auto cbTx = *opt_cbTx;
75
77
76
78
int64_t nTime2 = GetTimeMicros (); nTimePayload += nTime2 - nTime1;
77
79
LogPrint (BCLog::BENCHMARK, " - GetTxPayload: %.2fms [%.2fs]\n " , 0.001 * (nTime2 - nTime1), nTimePayload * 0.000001 );
@@ -255,23 +257,23 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
255
257
const auto & tx = block.vtx [i];
256
258
257
259
if (tx->nVersion == 3 && tx->nType == TRANSACTION_QUORUM_COMMITMENT) {
258
- llmq::CFinalCommitmentTxPayload qc ;
259
- if (!GetTxPayload (*tx, qc) ) {
260
+ const auto opt_qc = GetTxPayload< llmq::CFinalCommitmentTxPayload>(*tx) ;
261
+ if (!opt_qc ) {
260
262
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-qc-payload-calc-cbtx-quorummerkleroot" );
261
263
}
262
- if (qc. commitment .IsNull ()) {
264
+ if (opt_qc-> commitment .IsNull ()) {
263
265
// having null commitments is ok but we don't use them here, move to the next tx
264
266
continue ;
265
267
}
266
- const auto & llmq_params_opt = llmq::GetLLMQParams (qc. commitment .llmqType );
268
+ const auto & llmq_params_opt = llmq::GetLLMQParams (opt_qc-> commitment .llmqType );
267
269
if (!llmq_params_opt.has_value ()) {
268
270
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-qc-commitment-type-calc-cbtx-quorummerkleroot" );
269
271
}
270
272
const auto & llmq_params = llmq_params_opt.value ();
271
- auto qcHash = ::SerializeHash (qc. commitment );
273
+ auto qcHash = ::SerializeHash (opt_qc-> commitment );
272
274
if (llmq::utils::IsQuorumRotationEnabled (llmq_params, pindexPrev)) {
273
- auto & map_indexed_hashes = qcIndexedHashes[qc. commitment .llmqType ];
274
- map_indexed_hashes[qc. commitment .quorumIndex ] = qcHash;
275
+ auto & map_indexed_hashes = qcIndexedHashes[opt_qc-> commitment .llmqType ];
276
+ map_indexed_hashes[opt_qc-> commitment .quorumIndex ] = qcHash;
275
277
} else {
276
278
auto & vec_hashes = qcHashes[llmq_params.type ];
277
279
if (vec_hashes.size () == size_t (llmq_params.signingActiveQuorumCount )) {
@@ -328,17 +330,17 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex, cons
328
330
return true ;
329
331
}
330
332
331
- CCbTx cbTx ;
332
- if (!GetTxPayload (*block. vtx [ 0 ], cbTx) ) {
333
+ const auto opt_cbTx = GetTxPayload<CCbTx>(*block. vtx [ 0 ]) ;
334
+ if (!opt_cbTx ) {
333
335
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-payload" );
334
336
}
335
337
336
- if (cbTx. nVersion < CCbTx::Version::CLSIG_AND_BALANCE) {
338
+ if (opt_cbTx-> nVersion < CCbTx::Version::CLSIG_AND_BALANCE) {
337
339
return true ;
338
340
}
339
341
340
342
auto best_clsig = chainlock_handler.GetBestChainLock ();
341
- if (best_clsig.getHeight () == pindex->nHeight - 1 && cbTx. bestCLHeightDiff == 0 && cbTx. bestCLSignature == best_clsig.getSig ()) {
343
+ if (best_clsig.getHeight () == pindex->nHeight - 1 && opt_cbTx-> bestCLHeightDiff == 0 && opt_cbTx-> bestCLSignature == best_clsig.getSig ()) {
342
344
// matches our best clsig which still hold values for the previous block
343
345
return true ;
344
346
}
@@ -347,29 +349,29 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex, cons
347
349
// If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null.
348
350
if (prevBlockCoinbaseChainlock.has_value ()) {
349
351
// 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
350
- if (!cbTx. bestCLSignature .IsValid ()) {
352
+ if (!opt_cbTx-> bestCLSignature .IsValid ()) {
351
353
// IsNull() doesn't exist for CBLSSignature: we assume that a non valid BLS sig is null
352
354
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-null-clsig" );
353
355
}
354
356
int prevBlockCoinbaseCLHeight = pindex->nHeight - static_cast <int >(prevBlockCoinbaseChainlock.value ().second ) - 1 ;
355
- int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast <int >(cbTx. bestCLHeightDiff ) - 1 ;
357
+ int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast <int >(opt_cbTx-> bestCLHeightDiff ) - 1 ;
356
358
if (curBlockCoinbaseCLHeight < prevBlockCoinbaseCLHeight) {
357
359
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-older-clsig" );
358
360
}
359
361
}
360
362
361
363
// IsNull() doesn't exist for CBLSSignature: we assume that a valid BLS sig is non-null
362
- if (cbTx. bestCLSignature .IsValid ()) {
363
- int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast <int >(cbTx. bestCLHeightDiff ) - 1 ;
364
- if (best_clsig.getHeight () == curBlockCoinbaseCLHeight && best_clsig.getSig () == cbTx. bestCLSignature ) {
364
+ if (opt_cbTx-> bestCLSignature .IsValid ()) {
365
+ int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast <int >(opt_cbTx-> bestCLHeightDiff ) - 1 ;
366
+ if (best_clsig.getHeight () == curBlockCoinbaseCLHeight && best_clsig.getSig () == opt_cbTx-> bestCLSignature ) {
365
367
// matches our best (but outdated) clsig, no need to verify it again
366
368
return true ;
367
369
}
368
370
uint256 curBlockCoinbaseCLBlockHash = pindex->GetAncestor (curBlockCoinbaseCLHeight)->GetBlockHash ();
369
- if (!chainlock_handler.VerifyChainLock (llmq::CChainLockSig (curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, cbTx. bestCLSignature ))) {
371
+ if (!chainlock_handler.VerifyChainLock (llmq::CChainLockSig (curBlockCoinbaseCLHeight, curBlockCoinbaseCLBlockHash, opt_cbTx-> bestCLSignature ))) {
370
372
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-invalid-clsig" );
371
373
}
372
- } else if (cbTx. bestCLHeightDiff != 0 ) {
374
+ } else if (opt_cbTx-> bestCLHeightDiff != 0 ) {
373
375
// Null bestCLSignature is allowed only with bestCLHeightDiff = 0
374
376
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cbtx-cldiff" );
375
377
}
@@ -450,12 +452,7 @@ std::optional<CCbTx> GetCoinbaseTx(const CBlockIndex* pindex)
450
452
}
451
453
452
454
CTransactionRef cbTx = block.vtx [0 ];
453
- CCbTx cbTxPayload;
454
- if (!GetTxPayload (*cbTx, cbTxPayload)) {
455
- return std::nullopt ;
456
- }
457
-
458
- return cbTxPayload;
455
+ return GetTxPayload<CCbTx>(*cbTx);
459
456
}
460
457
461
458
std::optional<std::pair<CBLSSignature, uint32_t >> GetNonNullCoinbaseChainlock (const CBlockIndex* pindex)
0 commit comments