12 constexpr std::chrono::milliseconds
kDelay{1500};
21 std::shared_ptr<crypto::Hasher> hasher,
22 std::shared_ptr<ValidatorSignerFactory> signer_factory,
23 std::shared_ptr<libp2p::basic::Scheduler> scheduler,
24 std::shared_ptr<runtime::ParachainHost> parachain_api,
25 std::shared_ptr<AvailabilityStore> store,
26 std::shared_ptr<BitfieldStore> bitfield_store)
27 : hasher_{std::move(hasher)},
35 std::shared_ptr<primitives::events::ChainSubscriptionEngine>
37 chain_sub_ = std::make_shared<primitives::events::ChainEventSubscriber>(
42 [weak = weak_from_this()](
47 if (
auto self = weak.lock()) {
48 auto r =
self->onBlock(self->hasher_->blake2b_256(
50 boost::get<primitives::events::HeadsEventParams>(event))
53 SL_WARN(log(),
"onBlock error {}", r.error());
61 scale::BitVec bitfield;
62 OUTCOME_TRY(cores,
parachain_api_->availability_cores(relay_parent));
63 bitfield.bits.reserve(cores.size());
64 for (
auto &core : cores) {
65 auto occupied = boost::get<runtime::OccupiedCore>(&core);
66 bitfield.bits.push_back(occupied !=
nullptr 67 &&
store_->hasChunk(occupied->candidate_hash,
71 OUTCOME_TRY(signed_bitfield, signer.
sign(bitfield));
74 return outcome::success();
79 if (not signer.has_value()) {
80 return outcome::success();
83 [weak = weak_from_this(), relay_parent, signer{std::move(*signer)}]() {
84 if (
auto self = weak.lock()) {
85 auto r =
self->sign(signer);
87 SL_WARN(log(),
"sign error {}", r.error());
92 return outcome::success();
std::shared_ptr< runtime::ParachainHost > parachain_api_
std::shared_ptr< BitfieldStore > bitfield_store_
outcome::result< void > sign(const ValidatorSigner &signer)
Sign bitfield for given block.
ValidatorIndex validatorIndex() const
Get validator index.
std::shared_ptr< libp2p::basic::Scheduler > scheduler_
outcome::result< void > onBlock(const BlockHash &relay_parent)
std::shared_ptr< primitives::events::ChainEventSubscriber > chain_sub_
boost::variant< std::nullopt_t, HeadsEventParams, RuntimeVersionEventParams, NewRuntimeEventParams > ChainEventParams
std::shared_ptr< AvailabilityStore > store_
const primitives::BlockHash & relayParent() const
Get relay parent hash.
BitfieldSigner(std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< ValidatorSignerFactory > signer_factory, std::shared_ptr< libp2p::basic::Scheduler > scheduler, std::shared_ptr< runtime::ParachainHost > parachain_api, std::shared_ptr< AvailabilityStore > store, std::shared_ptr< BitfieldStore > bitfield_store)
constexpr std::chrono::milliseconds kDelay
Signs payload with signing context and validator keypair.
outcome::result< network::Signed< T > > sign(T payload) const
Sign payload.
uint32_t SubscriptionSetId
Logger createLogger(const std::string &tag)
std::shared_ptr< ValidatorSignerFactory > signer_factory_
void start(std::shared_ptr< primitives::events::ChainSubscriptionEngine > chain_sub_engine)
Subscribes to new heads.