9 #include <boost/assert.hpp> 16 #include "scale/scale.hpp" 19 BabeBlockValidator::ValidationError,
23 case E::NO_AUTHORITIES:
24 return "no authorities are provided for the validation";
25 case E::INVALID_SIGNATURE:
26 return "SR25519 signature, which is in BABE header, is invalid";
28 return "VRF value and output are invalid";
29 case E::TWO_BLOCKS_IN_SLOT:
30 return "peer tried to distribute several blocks in one slot";
31 case E::SECONDARY_SLOT_ASSIGNMENTS_DISABLED:
32 return "Secondary slot assignments are disabled for the current epoch.";
34 return "unknown error";
42 std::shared_ptr<blockchain::BlockTree> block_tree,
43 std::shared_ptr<runtime::TaggedTransactionQueue> tx_queue,
44 std::shared_ptr<crypto::Hasher> hasher,
45 std::shared_ptr<crypto::VRFProvider> vrf_provider,
46 std::shared_ptr<crypto::Sr25519Provider> sr25519_provider)
47 : block_tree_{std::move(block_tree)},
66 SL_DEBUG(
log_,
"Validated block signed by authority: {}", authority_id.
id);
70 const auto &[seal, babe_header] = babe_digests;
75 if (babe_header.isProducedInSecondarySlot()) {
76 bool plainAndAllowed =
77 babe_config.
allowed_slots == AllowedSlots::PrimaryAndSecondaryPlain
80 babe_config.
allowed_slots == AllowedSlots::PrimaryAndSecondaryVRF
82 if (not plainAndAllowed and not vrfAndAllowed) {
85 auto slot_type = babe_header.slotType();
88 "Block {} produced in {} slot, but current " 89 "configuration allows only {}",
91 auto encoded = scale::encode(header).value();
92 auto hash =
hasher_->blake2b_256(encoded);
110 if (babe_header.needVRFCheck()
116 babe_header.needVRFWithThresholdCheck())) {
120 return outcome::success();
130 auto unsealed_header = header;
131 unsealed_header.
digest.pop_back();
133 auto unsealed_header_encoded = scale::encode(unsealed_header).value();
135 auto block_hash =
hasher_->blake2b_256(unsealed_header_encoded);
140 return res && res.value();
149 const bool checkThreshold)
const {
152 transcript, randomness, babe_header.
slot_number, epoch_number);
154 "prepareTranscript (verifyVRF): randomness {}, slot {}, epoch {}",
160 transcript, babe_header.
vrf_output, public_key, threshold);
161 if (not verify_res.is_valid) {
162 log_->error(
"VRF proof in block is not valid");
167 if (checkThreshold && not verify_res.is_less) {
168 log_->error(
"VRF value is not less than the threshold");
crypto::Sr25519PublicKey BabeSessionKey
Randomness randomness
The randomness for the genesis epoch.
outcome::result< std::pair< Seal, BabeBlockHeader > > getBabeDigests(const primitives::BlockHeader &block_header)
A secondary deterministic slot assignment.
std::shared_ptr< blockchain::BlockTree > block_tree_
std::string_view to_string(SlotType s)
A secondary deterministic slot assignment with VRF outputs.
std::shared_ptr< crypto::Sr25519Provider > sr25519_provider_
Configuration data used by the BABE consensus engine.
outcome::result< void > validateHeader(const primitives::BlockHeader &header, const EpochNumber epoch_number, const primitives::AuthorityId &authority_id, const Threshold &threshold, const primitives::BabeConfiguration &babe_config) const override
std::shared_ptr< runtime::TaggedTransactionQueue > tx_queue_
crypto::Sr25519Signature signature
Sig_sr25519(Blake2s(block_header))
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
AllowedSlots allowed_slots
Type of allowed slots.
OUTCOME_CPP_DEFINE_CATEGORY(kagome::consensus, BabeBlockValidator::ValidationError, e)
BabeBlockValidator(std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< runtime::TaggedTransactionQueue > tx_queue, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< crypto::VRFProvider > vrf_provider, std::shared_ptr< crypto::Sr25519Provider > sr25519_provider)
bool verifySignature(const primitives::BlockHeader &header, const BabeBlockHeader &babe_header, const Seal &seal, const primitives::BabeSessionKey &public_key) const
detail::BlockInfoT< struct BlockInfoTag > BlockInfo
Logger createLogger(const std::string &tag)
bool verifyVRF(const BabeBlockHeader &babe_header, const EpochNumber epoch_number, const primitives::BabeSessionKey &public_key, const Threshold &threshold, const Randomness &randomness, const bool checkThreshold) const
uint64_t EpochNumber
number of the epoch in the Babe production
crypto::VRFThreshold Threshold
threshold, which must not be exceeded for the party to be a slot leader
std::shared_ptr< crypto::Hasher > hasher_
primitives::Transcript & prepareTranscript(primitives::Transcript &transcript, const Randomness &randomness, BabeSlotNumber slot_number, EpochNumber epoch)
std::shared_ptr< crypto::VRFProvider > vrf_provider_