TARAXA
Loading...
Searching...
No Matches
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/logging.hpp"
8#include "pbft/pbft_block.hpp"
9
10namespace taraxa {
11
16class DbStorage;
17class Vote;
18class DagBlock;
19struct Transaction;
20
24class PbftChain {
25 public:
26 explicit PbftChain(std::shared_ptr<DbStorage> db);
27
32 blk_hash_t getHeadHash() const;
33
39
45
51
57
63 PbftBlock getPbftBlockInChain(blk_hash_t const& pbft_block_hash);
64
69 std::string getJsonStr() const;
70
77 std::string getJsonStrForBlock(blk_hash_t const& block_hash, bool null_anchor) const;
78
84 bool findPbftBlockInChain(blk_hash_t const& pbft_block_hash);
85
91 void updatePbftChain(blk_hash_t const& pbft_block_hash, blk_hash_t const& anchor_hash);
92
98 bool checkPbftBlockValidation(const std::shared_ptr<PbftBlock>& pbft_block) const;
99
100 private:
101 mutable std::shared_mutex chain_head_access_;
102
103 blk_hash_t head_hash_; // PBFT head hash
104 PbftPeriod size_; // PBFT chain size, includes both executed and unexecuted PBFT blocks
105 PbftPeriod non_empty_size_; // PBFT chain size excluding blocks with null anchor, includes both executed and
106 // unexecuted PBFT blocks
107 blk_hash_t last_pbft_block_hash_; // last PBFT block hash in PBFT chain, may not execute yet
108 blk_hash_t last_non_null_pbft_dag_anchor_hash_; // last dag block anchor which is not null
109
110 std::shared_ptr<DbStorage> db_ = nullptr;
111
113};
114std::ostream& operator<<(std::ostream& strm, PbftChain const& pbft_chain);
115
118} // namespace taraxa
blk_hash_t last_pbft_block_hash_
Definition pbft_chain.hpp:107
bool findPbftBlockInChain(blk_hash_t const &pbft_block_hash)
Find a PBFT block in chain.
Definition pbft_chain.cpp:73
PbftPeriod non_empty_size_
Definition pbft_chain.hpp:105
bool checkPbftBlockValidation(const std::shared_ptr< PbftBlock > &pbft_block) const
Verify a PBFT block.
Definition pbft_chain.cpp:96
PbftPeriod getPbftChainSizeExcludingEmptyPbftBlocks() const
Get PBFT chain size excluding empty PBFT blocks.
Definition pbft_chain.cpp:58
logger::Logger logger_
Definition pbft_chain.hpp:112
PbftPeriod size_
Definition pbft_chain.hpp:104
std::shared_ptr< DbStorage > db_
Definition pbft_chain.hpp:110
PbftPeriod getPbftChainSize() const
Get PBFT chain size.
Definition pbft_chain.cpp:53
blk_hash_t getHeadHash() const
Get PBFT chain head hash.
Definition pbft_chain.cpp:48
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:123
std::shared_mutex chain_head_access_
Definition pbft_chain.hpp:101
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:86
blk_hash_t last_non_null_pbft_dag_anchor_hash_
Definition pbft_chain.hpp:108
blk_hash_t head_hash_
Definition pbft_chain.hpp:103
PbftBlock getPbftBlockInChain(blk_hash_t const &pbft_block_hash)
Get a PBFT block in chain.
Definition pbft_chain.cpp:77
blk_hash_t getLastPbftBlockHash() const
Get last PBFT block hash.
Definition pbft_chain.cpp:63
std::string getJsonStr() const
Get PBFT chain head block in JSON string.
Definition pbft_chain.cpp:113
blk_hash_t getLastNonNullPbftBlockAnchor() const
Get last non null PBFT block anchor.
Definition pbft_chain.cpp:68
The PbftBlock class is a PBFT block class that includes PBFT block hash, previous PBFT block hash,...
Definition pbft_block.hpp:22
PbftChain class is a single linked list that contains finalized PBFT blocks.
Definition pbft_chain.hpp:24
std::shared_ptr< spdlog::logger > Logger
Definition logging.hpp:12
Definition app.hpp:16
EthBlockNumber PbftPeriod
Definition types.hpp:25
std::ostream & operator<<(std::ostream &strm, const FullNodeConfig &conf)
Definition config.cpp:188