Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
producer_schedule.hpp
Go to the documentation of this file.
1#pragma once
7
8namespace sysio { namespace chain {
9
10 namespace legacy {
14 struct producer_key {
17
18 friend bool operator == ( const producer_key& lhs, const producer_key& rhs ) {
19 return tie( lhs.producer_name, lhs.block_signing_key ) == tie( rhs.producer_name, rhs.block_signing_key );
20 }
21 friend bool operator != ( const producer_key& lhs, const producer_key& rhs ) {
22 return tie( lhs.producer_name, lhs.block_signing_key ) != tie( rhs.producer_name, rhs.block_signing_key );
23 }
24 };
25
32
34 {
35 if( a.version != b.version ) return false;
36 if ( a.producers.size() != b.producers.size() ) return false;
37 for( uint32_t i = 0; i < a.producers.size(); ++i )
38 if( a.producers[i] != b.producers[i] ) return false;
39 return true;
40 }
41
43 {
44 return !(a==b);
45 }
46 };
47 }
48
62
63 using shared_block_signing_authority = std::variant<shared_block_signing_authority_v0>;
64
80
95
101 static constexpr std::string_view abi_type_name() { return "block_signing_authority_v0"; }
102
105
106 template<typename Op>
107 void for_each_key( Op&& op ) const {
108 for (const auto& kw : keys ) {
109 op(kw.key);
110 }
111 }
112
113 std::pair<bool, size_t> keys_satisfy_and_relevant( const std::set<public_key_type>& presented_keys ) const {
114 size_t num_relevant_keys = 0;
115 uint32_t total_weight = 0;
116 for (const auto& kw : keys ) {
117 const auto& iter = presented_keys.find(kw.key);
118 if (iter != presented_keys.end()) {
119 ++num_relevant_keys;
120
121 if( total_weight < threshold ) {
122 total_weight += std::min<uint32_t>(std::numeric_limits<uint32_t>::max() - total_weight, kw.weight);
123 }
124 }
125 }
126
127 return {total_weight >= threshold, num_relevant_keys};
128 }
129
132 result.threshold = threshold;
133 result.keys.clear();
134 result.keys.reserve(keys.size());
135 for (const auto& k: keys) {
136 result.keys.emplace_back(shared_key_weight::convert(alloc, k));
137 }
138
139 return result;
140 }
141
144 result.threshold = src.threshold;
145 result.keys.reserve(src.keys.size());
146 for (const auto& k: src.keys) {
147 result.keys.push_back(k);
148 }
149
150 return result;
151 }
152
154 return tie( lhs.threshold, lhs.keys ) == tie( rhs.threshold, rhs.keys );
155 }
157 return tie( lhs.threshold, lhs.keys ) != tie( rhs.threshold, rhs.keys );
158 }
159 };
160
161 using block_signing_authority = std::variant<block_signing_authority_v0>;
162
166
167 template<typename Op>
168 static void for_each_key( const block_signing_authority& authority, Op&& op ) {
169 std::visit([&op](const auto &a){
170 a.for_each_key(std::forward<Op>(op));
171 }, authority);
172 }
173
174 template<typename Op>
175 void for_each_key( Op&& op ) const {
176 for_each_key(authority, std::forward<Op>(op));
177 }
178
179 static std::pair<bool, size_t> keys_satisfy_and_relevant( const std::set<public_key_type>& keys, const block_signing_authority& authority ) {
180 return std::visit([&keys](const auto &a){
181 return a.keys_satisfy_and_relevant(keys);
182 }, authority);
183 }
184
185 std::pair<bool, size_t> keys_satisfy_and_relevant( const std::set<public_key_type>& presented_keys ) const {
186 return keys_satisfy_and_relevant(presented_keys, authority);
187 }
188
190 auto shared_auth = std::visit([&alloc](const auto& a) {
191 return a.to_shared(alloc);
192 }, authority);
193
194 return shared_producer_authority(producer_name, std::move(shared_auth));
195 }
196
197 static auto from_shared( const shared_producer_authority& src ) {
198 producer_authority result;
199 result.producer_name = src.producer_name;
200 result.authority = std::visit(overloaded {
203 }
204 }, src.authority);
205
206 return result;
207 }
208
222
223 friend bool operator == ( const producer_authority& lhs, const producer_authority& rhs ) {
224 return tie( lhs.producer_name, lhs.authority ) == tie( rhs.producer_name, rhs.authority );
225 }
226 friend bool operator != ( const producer_authority& lhs, const producer_authority& rhs ) {
227 return tie( lhs.producer_name, lhs.authority ) != tie( rhs.producer_name, rhs.authority );
228 }
229 };
230
233
238 :version(old.version)
239 {
240 producers.reserve( old.producers.size() );
241 for( const auto& p : old.producers )
242 producers.emplace_back(producer_authority{ p.producer_name, block_signing_authority_v0{ 1, {{p.block_signing_key, 1}} } });
243 }
244
245 producer_authority_schedule( uint32_t version, std::initializer_list<producer_authority> producers )
246 :version(version)
248 {}
249
251 auto result = shared_producer_authority_schedule(alloc);
252 result.version = version;
253 result.producers.clear();
254 result.producers.reserve( producers.size() );
255 for( const auto& p : producers ) {
256 result.producers.emplace_back(p.to_shared(alloc));
257 }
258 return result;
259 }
260
263 result.version = src.version;
264 result.producers.reserve(src.producers.size());
265 for( const auto& p : src.producers ) {
266 result.producers.emplace_back(producer_authority::from_shared(p));
267 }
268
269 return result;
270 }
271
272 uint32_t version = 0;
274
276 {
277 if( a.version != b.version ) return false;
278 if ( a.producers.size() != b.producers.size() ) return false;
279 for( uint32_t i = 0; i < a.producers.size(); ++i )
280 if( ! (a.producers[i] == b.producers[i]) ) return false;
281 return true;
282 }
283
285 {
286 return !(a==b);
287 }
288 };
289
308
309
311 {
312 if(pa.producer_name != pb.producer_name) return false;
313 if(pa.authority.index() != pb.authority.index()) return false;
314
315 bool authority_matches = std::visit([&pb]( const auto& lhs ){
316 return std::visit( [&lhs](const auto& rhs ) {
317 if (lhs.threshold != rhs.threshold) return false;
318 return std::equal(lhs.keys.cbegin(), lhs.keys.cend(), rhs.keys.cbegin(), rhs.keys.cend());
319 }, pb.authority);
320 }, pa.authority);
321
322 if (!authority_matches) return false;
323 return true;
324 }
325
326} }
327
334
335FC_REFLECT( sysio::chain::shared_block_signing_authority_v0, (threshold)(keys))
336FC_REFLECT( sysio::chain::shared_producer_authority, (producer_name)(authority) )
337FC_REFLECT( sysio::chain::shared_producer_authority_schedule, (version)(producers) )
338
const mie::Vuint & p
Definition bn.cpp:27
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
bip::allocator< T, pinnable_mapped_file::segment_manager > allocator
Definition chainbase.hpp:56
Definition name.hpp:106
bool operator==(const permission_level &lhs, const permission_level &rhs)
Definition action.hpp:13
std::variant< shared_block_signing_authority_v0 > shared_block_signing_authority
bool operator!=(const permission_level &lhs, const permission_level &rhs)
Definition action.hpp:17
std::variant< block_signing_authority_v0 > block_signing_authority
boost::interprocess::vector< T, allocator< T > > shared_vector
Definition types.hpp:85
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers producers(dont_start)) FC_REFLECT(testnet_def
producer_name(block_signing_key)) FC_REFLECT(producer_set_def
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition reflect.hpp:298
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
auto to_shared(chainbase::allocator< char > alloc) const
static constexpr std::string_view abi_type_name()
friend bool operator!=(const block_signing_authority_v0 &lhs, const block_signing_authority_v0 &rhs)
static auto from_shared(const shared_block_signing_authority_v0 &src)
friend bool operator==(const block_signing_authority_v0 &lhs, const block_signing_authority_v0 &rhs)
std::pair< bool, size_t > keys_satisfy_and_relevant(const std::set< public_key_type > &presented_keys) const
friend bool operator!=(const producer_key &lhs, const producer_key &rhs)
friend bool operator==(const producer_key &lhs, const producer_key &rhs)
friend bool operator==(const producer_schedule_type &a, const producer_schedule_type &b)
uint32_t version
sequentially incrementing version number
friend bool operator!=(const producer_schedule_type &a, const producer_schedule_type &b)
Immutable except for fc::from_variant.
Definition name.hpp:43
producer_authority_schedule(const legacy::producer_schedule_type &old)
uint32_t version
sequentially incrementing version number
static auto from_shared(const shared_producer_authority_schedule &src)
producer_authority_schedule(uint32_t version, std::initializer_list< producer_authority > producers)
auto to_shared(chainbase::allocator< char > alloc) const
static auto from_shared(const shared_producer_authority &src)
friend bool operator==(const producer_authority &lhs, const producer_authority &rhs)
auto to_shared(chainbase::allocator< char > alloc) const
friend bool operator!=(const producer_authority &lhs, const producer_authority &rhs)
static std::pair< bool, size_t > keys_satisfy_and_relevant(const std::set< public_key_type > &keys, const block_signing_authority &authority)
static void for_each_key(const block_signing_authority &authority, Op &&op)
std::pair< bool, size_t > keys_satisfy_and_relevant(const std::set< public_key_type > &presented_keys) const
producer_schedule_change_extension(const producer_authority_schedule &sched)
producer_schedule_change_extension & operator=(const producer_schedule_change_extension &)=default
producer_schedule_change_extension(producer_schedule_change_extension &&)=default
producer_schedule_change_extension & operator=(producer_schedule_change_extension &&)=default
producer_schedule_change_extension(const producer_schedule_change_extension &)=default
shared_block_signing_authority_v0(const shared_block_signing_authority_v0 &)=default
shared_block_signing_authority_v0(chainbase::allocator< char > alloc)
shared_block_signing_authority_v0 & operator=(shared_block_signing_authority_v0 &&)=default
shared_block_signing_authority_v0(shared_block_signing_authority_v0 &&)=default
static shared_key_weight convert(chainbase::allocator< char > allocator, const key_weight &k)
shared_producer_authority_schedule(shared_producer_authority_schedule &&)=default
shared_vector< shared_producer_authority > producers
shared_producer_authority_schedule(const shared_producer_authority_schedule &)=default
shared_producer_authority_schedule & operator=(shared_producer_authority_schedule &&)=default
uint32_t version
sequentially incrementing version number
shared_producer_authority_schedule(chainbase::allocator< char > alloc)
shared_block_signing_authority authority
shared_producer_authority & operator=(shared_producer_authority &&)=default
shared_producer_authority(shared_producer_authority &&)=default
shared_producer_authority(const name &producer_name, shared_block_signing_authority &&authority)
shared_producer_authority(const shared_producer_authority &)=default