TARAXA
Loading...
Searching...
No Matches
pbft_syncing_state.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <memory>
5#include <shared_mutex>
6
7#include "common/types.hpp"
8
10
11class TaraxaPeer;
12
18 public:
19 PbftSyncingState(uint16_t deep_syncing_threshold);
20
28 bool setPbftSyncing(bool syncing, PbftPeriod current_period = 0, std::shared_ptr<TaraxaPeer> peer = nullptr);
29
33 void setSyncStatePeriod(PbftPeriod period);
34
40 bool isDeepPbftSyncing() const;
41
47 bool isPbftSyncing();
48
54 std::shared_ptr<TaraxaPeer> syncingPeer() const;
55
59 std::shared_ptr<TaraxaPeer> lastSyncingPeer() const;
60
65
71 bool isActivelySyncing() const;
72
73 private:
74 std::atomic<bool> deep_pbft_syncing_{false};
75 std::atomic<bool> pbft_syncing_{false};
76
77 const uint16_t kDeepSyncingThreshold;
78
79 // Number of seconds needed for ongoing syncing to be declared as inactive
80 static constexpr std::chrono::seconds kSyncingInactivityThreshold{60};
81
82 // What time was received last syncing packet
83 std::chrono::steady_clock::time_point last_received_sync_packet_time_{std::chrono::steady_clock::now()};
84 mutable std::shared_mutex time_mutex_;
85
86 // Peer that the node is syncing with
87 std::shared_ptr<TaraxaPeer> peer_;
88 // Last syncing peer - it is not reset to null, it is only replaced when new syncing starts
89 std::shared_ptr<TaraxaPeer> last_syncing_peer_;
90 mutable std::shared_mutex peer_mutex_;
91};
92
93} // namespace taraxa::network::tarcap
PbftSyncingState contains common members and functions related to syncing that are shared among multi...
Definition pbft_syncing_state.hpp:17
std::shared_mutex time_mutex_
Definition pbft_syncing_state.hpp:84
std::chrono::steady_clock::time_point last_received_sync_packet_time_
Definition pbft_syncing_state.hpp:83
bool isPbftSyncing()
Check if PBFT is in syncing. If not in active syncing, set PBFT syncing to false.
Definition pbft_syncing_state.cpp:72
std::shared_ptr< TaraxaPeer > syncingPeer() const
Get the peer that our node is syncing with.
Definition pbft_syncing_state.cpp:10
std::shared_ptr< TaraxaPeer > lastSyncingPeer() const
Definition pbft_syncing_state.cpp:15
bool isActivelySyncing() const
Check if syncing is active.
Definition pbft_syncing_state.cpp:63
static constexpr std::chrono::seconds kSyncingInactivityThreshold
Definition pbft_syncing_state.hpp:80
std::shared_ptr< TaraxaPeer > peer_
Definition pbft_syncing_state.hpp:87
void setLastSyncPacketTime()
Set current time as last received sync packet time.
Definition pbft_syncing_state.cpp:58
bool setPbftSyncing(bool syncing, PbftPeriod current_period=0, std::shared_ptr< TaraxaPeer > peer=nullptr)
Set pbft syncing.
Definition pbft_syncing_state.cpp:29
bool isDeepPbftSyncing() const
Check if PBFT is in deep syncing.
Definition pbft_syncing_state.cpp:70
std::shared_ptr< TaraxaPeer > last_syncing_peer_
Definition pbft_syncing_state.hpp:89
std::shared_mutex peer_mutex_
Definition pbft_syncing_state.hpp:90
std::atomic< bool > pbft_syncing_
Definition pbft_syncing_state.hpp:75
const uint16_t kDeepSyncingThreshold
Definition pbft_syncing_state.hpp:77
void setSyncStatePeriod(PbftPeriod period)
Set current pbft period.
Definition pbft_syncing_state.cpp:20
std::atomic< bool > deep_pbft_syncing_
Definition pbft_syncing_state.hpp:74
Definition vote_manager.hpp:24
EthBlockNumber PbftPeriod
Definition types.hpp:25