6 #ifndef KAGOME_PARACHAIN_PROCESSOR_HPP 7 #define KAGOME_PARACHAIN_PROCESSOR_HPP 12 #include <unordered_map> 14 #include <boost/asio/executor_work_guard.hpp> 15 #include <boost/asio/io_context.hpp> 16 #include <boost/asio/io_service.hpp> 17 #include <boost/asio/post.hpp> 18 #include <boost/asio/signal_set.hpp> 19 #include <libp2p/peer/peer_id.hpp> 33 struct PendingCollation;
37 class Sr25519Provider;
44 : std::enable_shared_from_this<ParachainProcessorImpl> {
46 RESPONSE_ALREADY_RECEIVED = 1,
50 static constexpr uint64_t kBackgroundWorkers = 5;
64 std::shared_ptr<network::PeerManager> pm,
65 std::shared_ptr<crypto::Sr25519Provider> crypto_provider,
66 std::shared_ptr<network::Router> router,
67 std::shared_ptr<boost::asio::io_context> this_context,
68 std::shared_ptr<crypto::Sr25519Keypair> keypair,
69 std::shared_ptr<crypto::Hasher> hasher);
76 void setAssignedParachain(std::optional<network::ParachainId> para_id);
79 std::shared_ptr<network::Statement>
const &statement);
94 : fetched_collation(
std::move(fc)),
100 using Commitments = std::shared_ptr<network::CandidateCommitments>;
101 using PeerMap = std::unordered_map<libp2p::peer::PeerId, FetchedCollation>;
104 std::unordered_map<network::ParachainId, RelayParentMap>;
107 using WorkGuard = boost::asio::executor_work_guard<
108 boost::asio::io_context::executor_type>;
128 outcome::result<void> validateCandidate(
130 outcome::result<void> validateErasureCoding(
132 template <
typename F>
156 template <StatementType kStatementType>
157 std::shared_ptr<network::Statement> createAndSignStatement(
159 std::optional<ImportStatementSummary> importStatement(
160 std::shared_ptr<network::Statement>
const &statement);
161 std::optional<network::ValidatorIndex> getOurIndex();
168 return visit_in_place(
172 return hasher_->blake2b_256(
173 scale::encode(collation_response.receipt).value());
179 return visit_in_place(
183 return collation_response.receipt.descriptor;
187 std::optional<std::reference_wrapper<network::CandidateDescriptor const>>
189 std::shared_ptr<network::Statement>
const &statement) {
190 return visit_in_place(
191 statement->candidate_state,
194 std::reference_wrapper<network::CandidateDescriptor const>> {
195 return receipt.descriptor;
199 std::reference_wrapper<network::CandidateDescriptor const>> {
211 std::shared_ptr<network::Statement>
const &statement) {
212 return visit_in_place(
213 statement->candidate_state,
215 BOOST_ASSERT(!
"Not used!");
216 return primitives::BlockHash{};
219 return hasher_->blake2b_256(
222 .commitments_hash = hasher_->blake2b_256(
223 scale::encode(data.commitments).value())})
227 return candidate_hash;
234 template <
typename F>
236 BOOST_ASSERT(context);
237 boost::asio::post(*context, std::forward<F>(func));
239 void notifyBackedCandidate(
240 std::shared_ptr<network::Statement>
const &statement);
241 void notifyAvailableData();
242 void notifyStatementDistributionSystem(
243 std::shared_ptr<network::Statement>
const &statement);
246 std::shared_ptr<network::Statement>
const &statement);
250 outcome::result<FetchedCollation> loadIntoResponseSlot(
256 outcome::result<FetchedCollation> getFromSlot(
261 template <
typename T>
262 outcome::result<network::Signature> sign(T
const &t)
const;
264 std::optional<ImportStatementSummary> importStatementToTable(
266 std::shared_ptr<network::Statement>
const &statement);
268 std::shared_ptr<network::PeerManager>
pm_;
275 std::optional<network::ParachainId> assignment;
276 std::optional<primitives::BlockHash> seconded;
277 std::optional<network::CollatorPublicKey> required_collator;
279 std::unordered_set<primitives::BlockHash> awaiting_validation;
280 std::unordered_set<primitives::BlockHash> issued_statements;
281 std::unordered_map<primitives::BlockHash, AttestingData> fallbacks;
283 std::deque<std::shared_ptr<network::Statement>>>
285 } our_current_state_;
289 std::unique_ptr<std::thread> workers_[kBackgroundWorkers];
301 #endif // KAGOME_PARACHAIN_PROCESSOR_HPP primitives::BlockHash candidateHashFrom(FetchedCollationState const &fetched_collation_state)
std::queue< network::ValidatorIndex > backing
std::shared_ptr< crypto::Sr25519Provider > crypto_provider_
primitives::BlockHash candidateHashFrom(std::shared_ptr< network::Statement > const &statement)
std::shared_ptr< crypto::Hasher > hasher_
std::shared_ptr< network::PeerManager > pm_
ReqCollationResponseData response_data
network::ValidatorIndex from_validator
std::shared_ptr< FetchedCollationState > FetchedCollation
outcome::result< void > result
crypto::Sr25519PublicKey CollatorPublicKey
CandidateDescriptor descriptor
std::shared_ptr< network::Statement > statement
std::shared_ptr< WorkersContext > this_context_
primitives::BlockHash pov_hash
network::CandidateDescriptor const & candidateDescriptorFrom(FetchedCollationState const &fetched_collation_state)
boost::asio::executor_work_guard< boost::asio::io_context::executor_type > WorkGuard
boost::asio::io_context WorkersContext
libp2p::peer::PeerId PeerId
std::shared_ptr< WorkGuard > work_guard_
void notify_internal(std::shared_ptr< WorkersContext > &context, F &&func)
SafeObject< ParachainMap > collations_
std::shared_ptr< soralog::Logger > Logger
primitives::BlockHash relay_parent
uint64_t validity_votes
How many validity votes are currently witnessed.
CollatorPublicKey collator_id
executed in the context of
std::tuple<> Dummy
NU element.
std::function< void()> BackgroundTask
network::CollatorPublicKey const & collatorIdFromDescriptor(network::CandidateDescriptor const &descriptor)
primitives::BlockHash candidate_hash
network::ParachainId group_id
The group that the candidate is in.
std::shared_ptr< network::Router > router_
std::shared_ptr< crypto::Sr25519Keypair > keypair_
CollationState collation_state
FetchedCollation fetched_collation
network::CollationFetchingResponse fetched_collation
std::shared_ptr< network::CandidateCommitments > Commitments
FetchedCollationState(network::CollationFetchingResponse &&fc, CollationState cs, PoVDataState ps)
bool attested
Attested more than threshold.
std::optional< std::reference_wrapper< network::CandidateDescriptor const > > candidateDescriptorFrom(std::shared_ptr< network::Statement > const &statement)
std::unordered_map< libp2p::peer::PeerId, FetchedCollation > PeerMap
Logger createLogger(const std::string &tag)
std::unordered_map< primitives::BlockHash, PeerMap > RelayParentMap
primitives::BlockHash candidate
The digest of the candidate.
OUTCOME_HPP_DECLARE_ERROR(kagome::parachain, ParachainProcessorImpl::Error)
std::shared_ptr< WorkersContext > context_
std::unordered_map< network::ParachainId, RelayParentMap > ParachainMap