TARAXA
period_data_queue.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <libp2p/Host.h>
4 
5 #include <deque>
6 
7 #include "pbft/period_data.hpp"
8 
9 namespace taraxa {
10 
15 class PeriodData;
16 
21  public:
22  PeriodDataQueue() = default;
23 
32  bool push(PeriodData &&period_data, const dev::p2p::NodeID &node_id, uint64_t max_pbft_size,
33  std::vector<std::shared_ptr<PbftVote>> &&cert_votes);
34 
39  std::tuple<PeriodData, std::vector<std::shared_ptr<PbftVote>>, dev::p2p::NodeID> pop();
40 
44  void clear();
45 
50  size_t size() const;
51 
56  bool empty() const;
57 
62  uint64_t getPeriod() const;
63 
68  std::shared_ptr<PbftBlock> lastPbftBlock() const;
69 
74  void cleanOldData(uint64_t period);
75 
76  private:
77  std::deque<std::pair<PeriodData, dev::p2p::NodeID>> queue_;
78  // We need this variable as for small amount of time block is not part of queue but still being processed
79  uint64_t period_{0};
80  mutable std::shared_mutex queue_access_;
81  // Once fully synced, this will keep the cert votes for the last block in the chain
82  std::vector<std::shared_ptr<PbftVote>> last_block_cert_votes_;
83 };
84 
87 } // namespace taraxa
std::vector< std::shared_ptr< PbftVote > > last_block_cert_votes_
Definition: period_data_queue.hpp:82
void clear()
Clear the syncing queue and reset period to 0.
Definition: period_data_queue.cpp:29
std::deque< std::pair< PeriodData, dev::p2p::NodeID > > queue_
Definition: period_data_queue.hpp:77
bool empty() const
Return true if the queue is empty.
Definition: period_data_queue.cpp:24
bool push(PeriodData &&period_data, const dev::p2p::NodeID &node_id, uint64_t max_pbft_size, std::vector< std::shared_ptr< PbftVote >> &&cert_votes)
Push a synced block in queue.
Definition: period_data_queue.cpp:36
std::tuple< PeriodData, std::vector< std::shared_ptr< PbftVote > >, dev::p2p::NodeID > pop()
Pop the first block from syncing queue.
Definition: period_data_queue.cpp:53
std::shared_mutex queue_access_
Definition: period_data_queue.hpp:80
uint64_t period_
Definition: period_data_queue.hpp:79
void cleanOldData(uint64_t period)
Clean any old blocks below current period.
Definition: period_data_queue.cpp:76
size_t size() const
Get the syncing queue size.
Definition: period_data_queue.cpp:14
std::shared_ptr< PbftBlock > lastPbftBlock() const
Get last pbft block from queue.
Definition: period_data_queue.cpp:68
uint64_t getPeriod() const
Get period number of the last synced block in queue.
Definition: period_data_queue.cpp:9
PeriodData class is for block execution, that includes PBFT block, certify votes, DAG blocks,...
Definition: period_data.hpp:25
PeriodDataQueue class is a syncing queue, the queue stores blocks synced from peers.
Definition: period_data_queue.hpp:20
Definition: config.hpp:8