Function isInvalidReason
Check the validity of a block.
string isInvalidReason
(
in ref const(Block) block,
Engine engine,
Height prev_height,
in ref const(geod24 .bitblob .BitBlob!(64L)) prev_hash,
scope nothrow @safe bool delegate(in ref geod24 .bitblob .BitBlob!(64L), out UTXO) findUTXO,
scope nothrow @safe string delegate(in ref Transaction, Amount) checkFee,
scope nothrow @trusted bool delegate(in ref geod24 .bitblob .BitBlob!(64L), out EnrollmentState) findEnrollment,
scope nothrow @safe Amount delegate(geod24 .bitblob .BitBlob!(64L)) getPenaltyDeposit,
ulong active_validators_next_block
) nothrow @safe;
A block is considered valid if: - its height is the previous block height + 1 - its prev_hash is the previous block header's hash - the number of transactions in the block is at least 1 - the merkle root in the header matches the re-built merkle tree root based on the included transactions in the block - Transactions are ordered by their hash value - all the transactions pass validation, which implies: - signatures are authentic - the inputs spend an output which must be found with the findUTXO() delegate
Note that checking for transactions which double-spend is the responsibility
of the findUTXO() delegate. During validation, whenever this delegate is
called it should also keep track of the used UTXOs, thereby marking
it as a spent output. See the findNonSpent
function in the
unittest for an example.
As a special case, the genesis block is rejected by this function.
Validation of a genesis block should be done through the
isGenesisBlockInvalidReason
function.
Parameters
Name | Description |
---|---|
block | the block to check |
engine | script execution engine |
prev_height | the height of the direct ancestor of this block |
prev_hash | the hash of the direct ancestor of this block |
findUTXO | delegate to find the referenced unspent UTXOs with |
checkPayload | delegate for checking data payload |
active_validators_next_block | the number of validators that will be active at the block the follows the one currently being validated, provided none of them gets slashed this block. |
Returns
null
if the block is valid, a string explaining the reason it
is invalid otherwise.