TARAXA
Loading...
Searching...
No Matches
pillar_block.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <json/value.h>
4#include <libdevcore/RLP.h>
5
6#include <shared_mutex>
7
9#include "common/types.hpp"
11
12namespace taraxa {
13class PillarVote;
14}
15
16namespace taraxa::pillar_chain {
17
26 public:
27 // Validator votes count change
45
46 public:
47 PillarBlock() = default;
48 PillarBlock(const dev::RLP& rlp);
49 PillarBlock(PbftPeriod period, h256 state_root, blk_hash_t previous_pillar_block_hash, h256 bridge_root, u256 epoch,
50 std::vector<ValidatorVoteCountChange>&& validator_votes_count_changes);
51
52 PillarBlock(const PillarBlock& pillar_block);
53
57 blk_hash_t getHash() const;
58
62 PbftPeriod getPeriod() const;
63
68
72 const std::vector<ValidatorVoteCountChange>& getValidatorsVoteCountsChanges() const;
73
77 const h256& getStateRoot() const;
78
82 const h256& getBridgeRoot() const;
83
87 const uint64_t& getEpoch() const;
88
92 dev::bytes getRlp() const;
93
97 Json::Value getJson() const;
98
99 // this is needed for solidity encoding. So should be changed if fields are changed
100 static constexpr uint8_t kFieldsSize = 5;
101 static constexpr uint8_t kArrayPosAndSize = 2;
102 static constexpr uint8_t kFieldsInVoteCount = 2;
109
116 static PillarBlock decodeSolidity(const bytes& enc);
117
119
120 private:
121 // Pillar block pbft period
123
124 // Pbft block(for period_) state root
126
127 // Hash of the previous pillar block as pillar blocks forms a chain
129
130 // Bridge root
132
133 // Bridge epoch
134 uint64_t epoch_{};
135
136 // Delta change of validators votes count between current and latest pillar block
137 std::vector<ValidatorVoteCountChange> validators_votes_count_changes_{};
138
139 mutable std::optional<blk_hash_t> hash_;
140 mutable std::shared_mutex hash_mutex_;
141};
142
144 std::shared_ptr<PillarBlock> block_;
145 std::vector<std::shared_ptr<PillarVote>> pillar_votes_;
146
147 PillarBlockData(std::shared_ptr<PillarBlock> block, const std::vector<std::shared_ptr<PillarVote>>& pillar_votes);
148 PillarBlockData(const dev::RLP& rlp);
149 dev::bytes getRlp() const;
150 Json::Value getJson(bool include_signatures) const;
151
152 const static size_t kRlpItemCount = 2;
153};
154
156 std::shared_ptr<pillar_chain::PillarBlock> pillar_block;
157 std::vector<state_api::ValidatorVoteCount> vote_counts;
158
160};
161
164} // namespace taraxa::pillar_chain
Definition FixedHash.h:35
Definition RLP.h:56
#define HAS_RLP_FIELDS
Definition encoding_rlp.hpp:208
std::vector< state_api::ValidatorVoteCount > vote_counts
Definition pillar_block.hpp:157
h256 bridge_root_
Definition pillar_block.hpp:131
PillarBlockData(std::shared_ptr< PillarBlock > block, const std::vector< std::shared_ptr< PillarVote > > &pillar_votes)
const uint64_t & getEpoch() const
Definition pillar_block.cpp:55
static constexpr uint8_t kFieldsInVoteCount
Definition pillar_block.hpp:102
static PillarBlock decodeSolidity(const bytes &enc)
Decodes solidity encoded representation of pillar block.
Definition pillar_block.cpp:116
const h256 & getBridgeRoot() const
Definition pillar_block.cpp:53
std::shared_ptr< pillar_chain::PillarBlock > pillar_block
Definition pillar_block.hpp:156
blk_hash_t getPreviousBlockHash() const
Definition pillar_block.cpp:45
dev::bytes encodeSolidity() const
Definition pillar_block.cpp:90
Json::Value getJson(bool include_signatures) const
Definition pillar_block.cpp:164
std::optional< blk_hash_t > hash_
Definition pillar_block.hpp:139
static constexpr uint8_t kFieldsSize
Definition pillar_block.hpp:100
static const size_t kRlpItemCount
Definition pillar_block.hpp:152
uint64_t epoch_
Definition pillar_block.hpp:134
blk_hash_t previous_pillar_block_hash_
Definition pillar_block.hpp:128
std::shared_ptr< PillarBlock > block_
Definition pillar_block.hpp:144
PbftPeriod pbft_period_
Definition pillar_block.hpp:122
std::vector< ValidatorVoteCountChange > validators_votes_count_changes_
Definition pillar_block.hpp:137
dev::bytes getRlp() const
Definition pillar_block.cpp:41
dev::bytes getRlp() const
Definition pillar_block.cpp:156
PbftPeriod getPeriod() const
Definition pillar_block.cpp:43
h256 state_root_
Definition pillar_block.hpp:125
Json::Value getJson() const
Definition pillar_block.cpp:70
std::shared_mutex hash_mutex_
Definition pillar_block.hpp:140
blk_hash_t getHash() const
Definition pillar_block.cpp:57
const std::vector< ValidatorVoteCountChange > & getValidatorsVoteCountsChanges() const
Definition pillar_block.cpp:47
const h256 & getStateRoot() const
Definition pillar_block.cpp:51
std::vector< std::shared_ptr< PillarVote > > pillar_votes_
Definition pillar_block.hpp:145
static constexpr uint8_t kArrayPosAndSize
Definition pillar_block.hpp:101
PillarBlock contains merkle root of all finalized blocks created in the last epoch.
Definition pillar_block.hpp:25
Definition pillar_block.hpp:155
Definition pillar_block.hpp:143
std::vector<::byte > bytes
Definition Common.h:46
Definition app_base.hpp:25
Definition app.hpp:16
std::vector< byte > bytes
Definition types.hpp:53
EthBlockNumber PbftPeriod
Definition types.hpp:25
ValidatorVoteCountChange(ValidatorVoteCountChange &&)=default
ValidatorVoteCountChange(const ValidatorVoteCountChange &)=default
ValidatorVoteCountChange & operator=(const ValidatorVoteCountChange &)=default
ValidatorVoteCountChange & operator=(ValidatorVoteCountChange &&)=default
int32_t vote_count_change_
Definition pillar_block.hpp:30