TARAXA
pbft_chain.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <shared_mutex>
5 #include <string>
6 
7 #include "logger/logger.hpp"
8 #include "pbft/pbft_block.hpp"
9 
10 namespace taraxa {
11 
16 class DbStorage;
17 class FullNode;
18 class Vote;
19 class DagBlock;
20 struct Transaction;
21 
25 class PbftChain {
26  public:
27  explicit PbftChain(addr_t node_addr, std::shared_ptr<DbStorage> db);
28 
33  blk_hash_t getHeadHash() const;
34 
40 
46 
52 
58 
64  PbftBlock getPbftBlockInChain(blk_hash_t const& pbft_block_hash);
65 
70  std::string getJsonStr() const;
71 
78  std::string getJsonStrForBlock(blk_hash_t const& block_hash, bool null_anchor) const;
79 
85  bool findPbftBlockInChain(blk_hash_t const& pbft_block_hash);
86 
92  void updatePbftChain(blk_hash_t const& pbft_block_hash, blk_hash_t const& anchor_hash);
93 
99  bool checkPbftBlockValidation(const std::shared_ptr<PbftBlock>& pbft_block) const;
100 
101  private:
102  mutable std::shared_mutex chain_head_access_;
103 
104  blk_hash_t head_hash_; // PBFT head hash
105  PbftPeriod size_; // PBFT chain size, includes both executed and unexecuted PBFT blocks
106  PbftPeriod non_empty_size_; // PBFT chain size excluding blocks with null anchor, includes both executed and
107  // unexecuted PBFT blocks
108  blk_hash_t last_pbft_block_hash_; // last PBFT block hash in PBFT chain, may not execute yet
109  blk_hash_t last_non_null_pbft_dag_anchor_hash_; // last dag block anchor which is not null
110 
111  std::shared_ptr<DbStorage> db_ = nullptr;
112 
114 };
115 std::ostream& operator<<(std::ostream& strm, PbftChain const& pbft_chain);
116 
119 } // namespace taraxa
Definition: FixedHash.h:35
blk_hash_t last_pbft_block_hash_
Definition: pbft_chain.hpp:108
bool findPbftBlockInChain(blk_hash_t const &pbft_block_hash)
Find a PBFT block in chain.
Definition: pbft_chain.cpp:72
PbftPeriod non_empty_size_
Definition: pbft_chain.hpp:106
bool checkPbftBlockValidation(const std::shared_ptr< PbftBlock > &pbft_block) const
Verify a PBFT block.
Definition: pbft_chain.cpp:95
PbftPeriod getPbftChainSizeExcludingEmptyPbftBlocks() const
Get PBFT chain size excluding empty PBFT blocks.
Definition: pbft_chain.cpp:57
PbftPeriod size_
Definition: pbft_chain.hpp:105
std::shared_ptr< DbStorage > db_
Definition: pbft_chain.hpp:111
PbftPeriod getPbftChainSize() const
Get PBFT chain size.
Definition: pbft_chain.cpp:52
blk_hash_t getHeadHash() const
Get PBFT chain head hash.
Definition: pbft_chain.cpp:47
std::string getJsonStrForBlock(blk_hash_t const &block_hash, bool null_anchor) const
Get PBFT chain head block in JSON string.
Definition: pbft_chain.cpp:122
std::shared_mutex chain_head_access_
Definition: pbft_chain.hpp:102
void updatePbftChain(blk_hash_t const &pbft_block_hash, blk_hash_t const &anchor_hash)
Update PBFT chain size, non empty chain size, and last PBFT block hash.
Definition: pbft_chain.cpp:85
blk_hash_t last_non_null_pbft_dag_anchor_hash_
Definition: pbft_chain.hpp:109
PbftChain(addr_t node_addr, std::shared_ptr< DbStorage > db)
Definition: pbft_chain.cpp:11
blk_hash_t head_hash_
Definition: pbft_chain.hpp:104
PbftBlock getPbftBlockInChain(blk_hash_t const &pbft_block_hash)
Get a PBFT block in chain.
Definition: pbft_chain.cpp:76
blk_hash_t getLastPbftBlockHash() const
Get last PBFT block hash.
Definition: pbft_chain.cpp:62
std::string getJsonStr() const
Get PBFT chain head block in JSON string.
Definition: pbft_chain.cpp:112
blk_hash_t getLastNonNullPbftBlockAnchor() const
Get last non null PBFT block anchor.
Definition: pbft_chain.cpp:67
The PbftBlock class is a PBFT block class that includes PBFT block hash, previous PBFT block hash,...
Definition: pbft_block.hpp:21
PbftChain class is a single linked list that contains finalized PBFT blocks.
Definition: pbft_chain.hpp:25
#define LOG_OBJECTS_DEFINE
Definition: logger.hpp:60
Definition: config.hpp:8
EthBlockNumber PbftPeriod
Definition: types.hpp:24
std::ostream & operator<<(std::ostream &strm, NodeConfig const &conf)
Definition: config.cpp:205