#include <synchronizer_impl.hpp>
|
enum | Error {
Error::SHUTTING_DOWN = 1,
Error::EMPTY_RESPONSE,
Error::RESPONSE_WITHOUT_BLOCK_HEADER,
Error::RESPONSE_WITHOUT_BLOCK_BODY,
Error::DISCARDED_BLOCK,
Error::WRONG_ORDER,
Error::INVALID_HASH,
Error::ALREADY_IN_QUEUE,
Error::PEER_BUSY,
Error::ARRIVED_TOO_EARLY,
Error::DUPLICATE_REQUEST
} |
|
using | SyncResultHandler = std::function< void(outcome::result< primitives::BlockInfo >)> |
|
|
| SynchronizerImpl (const application::AppConfiguration &app_config, std::shared_ptr< application::AppStateManager > app_state_manager, std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< storage::changes_trie::ChangesTracker > changes_tracker, std::shared_ptr< consensus::BlockAppender > block_appender, std::shared_ptr< consensus::BlockExecutor > block_executor, std::shared_ptr< storage::trie::TrieSerializer > serializer, std::shared_ptr< storage::trie::TrieStorage > storage, std::shared_ptr< network::Router > router, std::shared_ptr< libp2p::basic::Scheduler > scheduler, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< storage::BufferStorage > buffer_storage) |
|
bool | prepare () |
|
bool | start () |
|
void | stop () |
|
bool | syncByBlockInfo (const primitives::BlockInfo &block_info, const libp2p::peer::PeerId &peer_id, SyncResultHandler &&handler, bool subscribe_to_block) override |
|
bool | syncByBlockHeader (const primitives::BlockHeader &header, const libp2p::peer::PeerId &peer_id, SyncResultHandler &&handler) override |
|
void | syncMissingJustifications (const PeerId &peer_id, primitives::BlockInfo target_block, std::optional< uint32_t > limit, SyncResultHandler &&handler) override |
|
void | syncState (const libp2p::peer::PeerId &peer_id, const primitives::BlockInfo &block, SyncResultHandler &&handler) override |
|
void | findCommonBlock (const libp2p::peer::PeerId &peer_id, primitives::BlockNumber lower, primitives::BlockNumber upper, primitives::BlockNumber hint, SyncResultHandler &&handler, std::map< primitives::BlockNumber, primitives::BlockHash > &&observed={}) |
|
void | loadBlocks (const libp2p::peer::PeerId &peer_id, primitives::BlockInfo from, SyncResultHandler &&handler) |
|
void | loadJustifications (const libp2p::peer::PeerId &peer_id, primitives::BlockInfo target_block, std::optional< uint32_t > limit, SyncResultHandler &&handler) |
|
bool | hasIncompleteRequestOfStateSync () const override |
| Check if incomplete requests of state sync exists. More...
|
|
virtual | ~Synchronizer ()=default |
|
|
std::shared_ptr< application::AppStateManager > | app_state_manager_ |
|
std::shared_ptr< blockchain::BlockTree > | block_tree_ |
|
std::shared_ptr< storage::changes_trie::ChangesTracker > | trie_changes_tracker_ |
|
std::shared_ptr< consensus::BlockAppender > | block_appender_ |
|
std::shared_ptr< consensus::BlockExecutor > | block_executor_ |
|
std::shared_ptr< storage::trie::TrieSerializer > | serializer_ |
|
std::shared_ptr< storage::trie::TrieStorage > | storage_ |
|
std::shared_ptr< network::Router > | router_ |
|
std::shared_ptr< libp2p::basic::Scheduler > | scheduler_ |
|
std::shared_ptr< crypto::Hasher > | hasher_ |
|
std::shared_ptr< storage::BufferStorage > | buffer_storage_ |
|
application::AppConfiguration::SyncMethod | sync_method_ |
|
metrics::RegistryPtr | metrics_registry_ = metrics::createRegistry() |
|
metrics::Gauge * | metric_import_queue_length_ |
|
log::Logger | log_ = log::createLogger("Synchronizer", "synchronizer") |
|
telemetry::Telemetry | telemetry_ = telemetry::createTelemetryService() |
|
std::atomic_bool | state_sync_request_in_progress_ = false |
|
std::optional< network::StateRequest > | state_sync_request_ |
|
std::optional< primitives::BlockInfo > | state_sync_on_block_ |
|
bool | node_is_shutting_down_ = false |
|
std::unordered_map< primitives::BlockHash, KnownBlock > | known_blocks_ |
|
std::optional< primitives::BlockInfo > | sync_block_ |
|
std::multimap< primitives::BlockNumber, primitives::BlockHash > | generations_ |
|
std::unordered_multimap< primitives::BlockHash, primitives::BlockHash > | ancestry_ |
|
std::queue< JustificationPair > | justifications_ |
|
std::mutex | justifications_mutex_ |
|
primitives::BlockNumber | watched_blocks_number_ {} |
|
std::unordered_multimap< primitives::BlockHash, SyncResultHandler > | watched_blocks_ |
|
std::multimap< primitives::BlockInfo, SyncResultHandler > | subscriptions_ |
|
std::atomic_bool | applying_in_progress_ = false |
|
std::atomic_bool | asking_blocks_portion_in_progress_ = false |
|
std::set< libp2p::peer::PeerId > | busy_peers_ |
|
std::set< std::tuple< libp2p::peer::PeerId, BlocksRequest::Fingerprint > > | recent_requests_ |
|
std::unordered_map< storage::trie::RootHash, std::tuple< common::Buffer, unsigned, std::shared_ptr< storage::trie::PersistentTrieBatch > > > | batches_store_ |
|
size_t | entries_ {0} |
|
Definition at line 41 of file synchronizer_impl.hpp.
struct kagome::network::SynchronizerImpl::KnownBlock |
Enumerator |
---|
SHUTTING_DOWN |
|
EMPTY_RESPONSE |
|
RESPONSE_WITHOUT_BLOCK_HEADER |
|
RESPONSE_WITHOUT_BLOCK_BODY |
|
DISCARDED_BLOCK |
|
WRONG_ORDER |
|
INVALID_HASH |
|
ALREADY_IN_QUEUE |
|
PEER_BUSY |
|
ARRIVED_TOO_EARLY |
|
DUPLICATE_REQUEST |
|
Definition at line 64 of file synchronizer_impl.hpp.
kagome::network::SynchronizerImpl::SynchronizerImpl |
( |
const application::AppConfiguration & |
app_config, |
|
|
std::shared_ptr< application::AppStateManager > |
app_state_manager, |
|
|
std::shared_ptr< blockchain::BlockTree > |
block_tree, |
|
|
std::shared_ptr< storage::changes_trie::ChangesTracker > |
changes_tracker, |
|
|
std::shared_ptr< consensus::BlockAppender > |
block_appender, |
|
|
std::shared_ptr< consensus::BlockExecutor > |
block_executor, |
|
|
std::shared_ptr< storage::trie::TrieSerializer > |
serializer, |
|
|
std::shared_ptr< storage::trie::TrieStorage > |
storage, |
|
|
std::shared_ptr< network::Router > |
router, |
|
|
std::shared_ptr< libp2p::basic::Scheduler > |
scheduler, |
|
|
std::shared_ptr< crypto::Hasher > |
hasher, |
|
|
std::shared_ptr< storage::BufferStorage > |
buffer_storage |
|
) |
| |
void kagome::network::SynchronizerImpl::applyNextBlock |
( |
| ) |
|
|
private |
void kagome::network::SynchronizerImpl::applyNextJustification |
( |
| ) |
|
|
private |
void kagome::network::SynchronizerImpl::askNextPortionOfBlocks |
( |
| ) |
|
|
private |
Removes block {
- Parameters
-
block} | and all all dependent on it from the queue |
- Returns
- number of affected blocks
Definition at line 1283 of file synchronizer_impl.cpp.
Finds best common block with peer {
- Parameters
-
peer_id} | in provided interval. It is using tail-recursive algorithm, till { |
hint} | is the needed block |
lower | is number of definitely known common block (i.e. last finalized). |
upper | is number of definitely unknown block. |
hint | is examining block for current call |
handler | callback what is called at the end of process |
Definition at line 406 of file synchronizer_impl.cpp.
bool kagome::network::SynchronizerImpl::hasIncompleteRequestOfStateSync |
( |
| ) |
const |
|
inlineoverridevirtual |
Loads blocks from peer {
- Parameters
-
peer_id} | since block { |
from} | till its best. Calls { |
handler} | when process is finished or failed |
Definition at line 583 of file synchronizer_impl.cpp.
void kagome::network::SynchronizerImpl::loadJustifications |
( |
const libp2p::peer::PeerId & |
peer_id, |
|
|
primitives::BlockInfo |
target_block, |
|
|
std::optional< uint32_t > |
limit, |
|
|
SyncResultHandler && |
handler |
|
) |
| |
Loads block justification from {
- Parameters
-
peer_id} | for { |
target_block} | or a range of blocks up to { |
upper_bound_block}. | Calls { |
handler} | when operation finishes |
Definition at line 806 of file synchronizer_impl.cpp.
void kagome::network::SynchronizerImpl::notifySubscribers |
( |
const primitives::BlockInfo & |
block_info, |
|
|
outcome::result< void > |
res |
|
) |
| |
|
private |
bool kagome::network::SynchronizerImpl::prepare |
( |
| ) |
|
Removes blocks what will never be applied because they are contained in side-branch for provided finalized block {
- Parameters
-
Definition at line 1313 of file synchronizer_impl.cpp.
void kagome::network::SynchronizerImpl::scheduleRecentRequestRemoval |
( |
const libp2p::peer::PeerId & |
peer_id, |
|
|
const BlocksRequest::Fingerprint & |
fingerprint |
|
) |
| |
|
private |
Purges internal cache of recent requests for specified {
- Parameters
-
peer_id} | and { |
fingerprint} | after kRecentnessDuration timeout |
Definition at line 1344 of file synchronizer_impl.cpp.
bool kagome::network::SynchronizerImpl::start |
( |
| ) |
|
void kagome::network::SynchronizerImpl::stop |
( |
| ) |
|
Subscribes handler for block with provided {
- Parameters
-
block_info} | { |
handler} | will be called When block is received or discarded |
- Returns
- true if subscription is successful
Definition at line 157 of file synchronizer_impl.cpp.
Enqueues loading and applying block {
- Parameters
-
block_info} | from peer { |
peer_id}. | |
- Returns
- true if sync is ran (peer is not busy) If provided block is the best after applying, {
- Parameters
-
Implements kagome::network::Synchronizer.
Definition at line 318 of file synchronizer_impl.cpp.
Enqueues loading (and applying) blocks from peer {
- Parameters
-
peer_id} | since best common block up to provided { |
block_info}. | { |
handler} | will be called when this process is finished or failed |
- Returns
- true if sync is ran (peer is not busy)
- Note
- Is used for start/continue catching up.
Implements kagome::network::Synchronizer.
Definition at line 209 of file synchronizer_impl.cpp.
std::atomic_bool kagome::network::SynchronizerImpl::applying_in_progress_ = false |
|
private |
std::atomic_bool kagome::network::SynchronizerImpl::asking_blocks_portion_in_progress_ = false |
|
private |
std::set<libp2p::peer::PeerId> kagome::network::SynchronizerImpl::busy_peers_ |
|
private |
size_t kagome::network::SynchronizerImpl::entries_ {0} |
|
private |
std::shared_ptr<crypto::Hasher> kagome::network::SynchronizerImpl::hasher_ |
|
private |
std::mutex kagome::network::SynchronizerImpl::justifications_mutex_ |
|
private |
constexpr size_t kagome::network::SynchronizerImpl::kMaxDistanceToBlockForSubscription |
|
static |
Initial value:Indicating how far the block can be subscribed to. In general we don't needed wait very far blocks. This limit to avoid extra memory consumption.
Definition at line 58 of file synchronizer_impl.hpp.
constexpr size_t kagome::network::SynchronizerImpl::kMinPreloadedBlockAmount = 256 |
|
static |
constexpr size_t kagome::network::SynchronizerImpl::kMinPreloadedBlockAmountForFastSyncing |
|
static |
Initial value:Block amount enough for applying and preloading other ones simultaneously during fast syncing
Definition at line 52 of file synchronizer_impl.hpp.
constexpr std::chrono::milliseconds kagome::network::SynchronizerImpl::kRecentnessDuration |
|
static |
metrics::Gauge* kagome::network::SynchronizerImpl::metric_import_queue_length_ |
|
private |
bool kagome::network::SynchronizerImpl::node_is_shutting_down_ = false |
|
private |
std::shared_ptr<network::Router> kagome::network::SynchronizerImpl::router_ |
|
private |
std::shared_ptr<libp2p::basic::Scheduler> kagome::network::SynchronizerImpl::scheduler_ |
|
private |
std::atomic_bool kagome::network::SynchronizerImpl::state_sync_request_in_progress_ = false |
|
private |
The documentation for this class was generated from the following files: