Function isInvalidReason
Check the validity of a new pre-image information
string isInvalidReason
(
in ref const(PreImageInfo) newer,
in ref const(PreImageInfo) previous
) nothrow @safe;
Pre-image infomation is considered valid if: - The keys for enrollment in two pieces of pre-image information are same - Height for a pre-image is greater than height for a current image - A current image is same as n times hashed value of a pre-image (n = difference of two heights).
Parameters
Name | Description |
---|---|
newer | The pre-image information to check |
previous | The previous pre-image information |
Returns
null
if the pre-image is valid, otherwise a string
explaining the reason it is invalid.
Example
test for validity of pre-image
auto params = new immutable(ConsensusParams)(2000);
import agora .common .Types;
Hash[] preimages;
preimages ~= hashFull(Scalar .random());
foreach (i; 0 .. params .ValidatorCycle)
preimages ~= hashFull(preimages[i]);
reverse(preimages);
PreImageInfo prev_image = PreImageInfo(hashFull("abc"), preimages[0], Height(0));
// valid pre-image
PreImageInfo new_image = PreImageInfo(hashFull("abc"), preimages[100], Height(100));
assert(new_image .isValid(prev_image));
// invalid pre-image with wrong UTXO
new_image = PreImageInfo(hashFull("xyz"), preimages[100], Height(100));
assert(!new_image .isValid(prev_image));
// invalid pre-image with wrong height number
new_image = PreImageInfo(hashFull("abc"), preimages[1], Height(3));
assert(!new_image .isValid(prev_image));
// invalid pre-image with wrong hash value
new_image = PreImageInfo(hashFull("abc"), preimages[101], Height(100));
assert(!new_image .isValid(prev_image));