src/BlockChain/Validators/BlockValidator.cpp
// Validates a block is self-consistent and validates the state (eg. MMRs).
Validates a block is self-consistent and validates the state .
Validates a block is self - consistent and validates the state .
BlockSums BlockValidator::ValidateBlock(const FullBlock& block) const
{
	VerifySelfConsistent(block);
	const uint64_t maximumBlockHeight = Consensus::GetMaxCoinbaseHeight(block.GetHeight());
	for (const TransactionInput& input : block.GetTransactionBody().GetInputs())
	{
		if (input.IsCoinbase())
		{
			const std::unique_ptr<OutputLocation> pOutputLocation = m_pBlockDB->GetOutputPosition(input.GetCommitment());
			if (pOutputLocation == nullptr || pOutputLocation->GetBlockHeight() > maximumBlockHeight)
			{
				LOG_INFO_F("Coinbase not mature for block {}", block);
				throw BAD_DATA_EXCEPTION("Failed to validate coinbase maturity.");
			}
		}
	}
	if (!m_pTxHashSet->ValidateRoots(*block.GetBlockHeader()))
	{
		LOG_ERROR_F("Failed to validate TxHashSet roots for block {}", block);
		throw BAD_DATA_EXCEPTION("Failed to validate TxHashSet roots.");
	}
	const Hash previousHash = block.GetPreviousHash();
	std::unique_ptr<BlockSums> pPreviousBlockSums = m_pBlockDB->GetBlockSums(previousHash);
	if (pPreviousBlockSums == nullptr)
	{
		LOG_WARNING_F("Failed to retrieve block sums for block {}", previousHash);
		throw BLOCK_CHAIN_EXCEPTION("Failed to retrieve block sums.");
	}
	return KernelSumValidator::ValidateKernelSums(
		block.GetTransactionBody(),
		0 - Consensus::REWARD,
		block.GetTotalKernelOffset(),
		std::make_optional(*pPreviousBlockSums)
	);
}
BlockSums BlockValidator :: ValidateBlock ( const FullBlock & block ) const { VerifySelfConsistent ( block ) ; const uint64_t maximumBlockHeight = Consensus :: GetMaxCoinbaseHeight ( block . GetHeight ( ) ) ; for ( const TransactionInput & input : block . GetTransactionBody ( ) . GetInputs ( ) ) { if ( input . IsCoinbase ( ) ) { const std :: unique_ptr < OutputLocation > pOutputLocation = m_pBlockDB -> GetOutputPosition ( input . GetCommitment ( ) ) ; if ( pOutputLocation == nullptr || pOutputLocation -> GetBlockHeight ( ) > maximumBlockHeight ) { LOG_INFO_F ( " " , block ) ; throw BAD_DATA_EXCEPTION ( " " ) ; } } } if ( ! m_pTxHashSet -> ValidateRoots ( * block . GetBlockHeader ( ) ) ) { LOG_ERROR_F ( " " , block ) ; throw BAD_DATA_EXCEPTION ( " " ) ; } const Hash previousHash = block . GetPreviousHash ( ) ; std :: unique_ptr < BlockSums > pPreviousBlockSums = m_pBlockDB -> GetBlockSums ( previousHash ) ; if ( pPreviousBlockSums == nullptr ) { LOG_WARNING_F ( " " , previousHash ) ; throw BLOCK_CHAIN_EXCEPTION ( " " ) ; } return KernelSumValidator :: ValidateKernelSums ( block . GetTransactionBody ( ) , 0 - Consensus :: REWARD , block . GetTotalKernelOffset ( ) , std :: make_optional ( * pPreviousBlockSums ) ) ; }
Validates a block is self-consistent and validates the state (eg.
Validates a block is self - consistent and validates the state ( eg .
// Verify coinbase maturity