Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
chain_config.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace sysio { namespace chain {
8
17
18 //order must match parameters as ids are used in serialization
19 enum {
38 };
39
47
52
59
60 void validate()const;
61
62 inline const chain_config_v0& v0() const {
63 return *this;
64 }
65
66 template<typename Stream>
67 friend Stream& operator << ( Stream& out, const chain_config_v0& c ) {
68 return c.log(out) << "\n";
69 }
70
110
111 friend inline bool operator !=( const chain_config_v0& lhs, const chain_config_v0& rhs ) { return !(lhs == rhs); }
112
113protected:
114 template<typename Stream>
115 Stream& log(Stream& out) const{
116 return out << "Max Block Net Usage: " << max_block_net_usage << ", "
117 << "Target Block Net Usage Percent: " << ((double)target_block_net_usage_pct / (double)config::percent_1) << "%, "
118 << "Max Transaction Net Usage: " << max_transaction_net_usage << ", "
119 << "Base Per-Transaction Net Usage: " << base_per_transaction_net_usage << ", "
120 << "Net Usage Leeway: " << net_usage_leeway << ", "
121 << "Context-Free Data Net Usage Discount: " << (double)context_free_discount_net_usage_num * 100.0 / (double)context_free_discount_net_usage_den << "% , "
122
123 << "Max Block CPU Usage: " << max_block_cpu_usage << ", "
124 << "Target Block CPU Usage Percent: " << ((double)target_block_cpu_usage_pct / (double)config::percent_1) << "%, "
125 << "Max Transaction CPU Usage: " << max_transaction_cpu_usage << ", "
126 << "Min Transaction CPU Usage: " << min_transaction_cpu_usage << ", "
127
128 << "Max Transaction Lifetime: " << max_transaction_lifetime << ", "
129 << "Deferred Transaction Expiration Window: " << deferred_trx_expiration_window << ", "
130 << "Max Transaction Delay: " << max_transaction_delay << ", "
131 << "Max Inline Action Size: " << max_inline_action_size << ", "
132 << "Max Inline Action Depth: " << max_inline_action_depth << ", "
133 << "Max Authority Depth: " << max_authority_depth;
134 }
135};
136
145
146 uint32_t max_action_return_value_size = config::default_max_action_return_value_size;
147
148 //order must match parameters as ids are used in serialization
149 enum {
152 };
153
154 inline const Base& base() const {
155 return static_cast<const Base&>(*this);
156 }
157
158 void validate() const;
159
160 template<typename Stream>
161 friend Stream& operator << ( Stream& out, const chain_config_v1& c ) {
162 return c.log(out) << "\n";
163 }
164
165 friend inline bool operator == ( const chain_config_v1& lhs, const chain_config_v1& rhs ) {
166 //add v1 parameters comarison here
167 return std::tie(lhs.max_action_return_value_size) == std::tie(rhs.max_action_return_value_size)
168 && lhs.base() == rhs.base();
169 }
170
171 friend inline bool operator != ( const chain_config_v1& lhs, const chain_config_v1& rhs ) {
172 return !(lhs == rhs);
173 }
174
175 inline chain_config_v1& operator= (const Base& b) {
176 Base::operator= (b);
177 return *this;
178 }
179
180protected:
181 template<typename Stream>
182 Stream& log(Stream& out) const{
183 return base().log(out) << ", Max Action Return Value Size: " << max_action_return_value_size;
184 }
185};
186
187class controller;
188
191
192 bool operator()(uint32_t id) const;
193};
194
195//after adding 1st value to chain_config_v1 change this using to point to v1
198
199} } // namespace sysio::chain
200
202 (max_block_net_usage)(target_block_net_usage_pct)
203 (max_transaction_net_usage)(base_per_transaction_net_usage)(net_usage_leeway)
204 (context_free_discount_net_usage_num)(context_free_discount_net_usage_den)
205
206 (max_block_cpu_usage)(target_block_cpu_usage_pct)
207 (max_transaction_cpu_usage)(min_transaction_cpu_usage)
208
209 (max_transaction_lifetime)(deferred_trx_expiration_window)(max_transaction_delay)
210 (max_inline_action_size)(max_inline_action_depth)(max_authority_depth)
211
212)
213
215 (max_action_return_value_size)
216)
217
218namespace fc {
219
227template <typename DataStream>
229 using namespace sysio::chain;
230
231 //initial requirements were to skip packing field if it is not activated.
232 //this approach allows to spam this function with big buffer so changing this behavior
233 SYS_ASSERT(entry.is_allowed(), unsupported_feature, "config id ${id} is no allowed", ("id", entry.id));
234
235 switch (entry.id){
236 case chain_config_v0::max_block_net_usage_id:
237 fc::raw::pack(s, entry.config.max_block_net_usage);
238 break;
239 case chain_config_v0::target_block_net_usage_pct_id:
240 fc::raw::pack(s, entry.config.target_block_net_usage_pct);
241 break;
242 case chain_config_v0::max_transaction_net_usage_id:
243 fc::raw::pack(s, entry.config.max_transaction_net_usage);
244 break;
245 case chain_config_v0::base_per_transaction_net_usage_id:
246 fc::raw::pack(s, entry.config.base_per_transaction_net_usage);
247 break;
248 case chain_config_v0::net_usage_leeway_id:
249 fc::raw::pack(s, entry.config.net_usage_leeway);
250 break;
251 case chain_config_v0::context_free_discount_net_usage_num_id:
252 fc::raw::pack(s, entry.config.context_free_discount_net_usage_num);
253 break;
254 case chain_config_v0::context_free_discount_net_usage_den_id:
255 fc::raw::pack(s, entry.config.context_free_discount_net_usage_den);
256 break;
257 case chain_config_v0::max_block_cpu_usage_id:
258 fc::raw::pack(s, entry.config.max_block_cpu_usage);
259 break;
260 case chain_config_v0::target_block_cpu_usage_pct_id:
261 fc::raw::pack(s, entry.config.target_block_cpu_usage_pct);
262 break;
263 case chain_config_v0::max_transaction_cpu_usage_id:
264 fc::raw::pack(s, entry.config.max_transaction_cpu_usage);
265 break;
266 case chain_config_v0::min_transaction_cpu_usage_id:
267 fc::raw::pack(s, entry.config.min_transaction_cpu_usage);
268 break;
269 case chain_config_v0::max_transaction_lifetime_id:
270 fc::raw::pack(s, entry.config.max_transaction_lifetime);
271 break;
272 case chain_config_v0::deferred_trx_expiration_window_id:
273 fc::raw::pack(s, entry.config.deferred_trx_expiration_window);
274 break;
275 case chain_config_v0::max_transaction_delay_id:
276 fc::raw::pack(s, entry.config.max_transaction_delay);
277 break;
278 case chain_config_v0::max_inline_action_size_id:
279 fc::raw::pack(s, entry.config.max_inline_action_size);
280 break;
281 case chain_config_v0::max_inline_action_depth_id:
282 fc::raw::pack(s, entry.config.max_inline_action_depth);
283 break;
284 case chain_config_v0::max_authority_depth_id:
285 fc::raw::pack(s, entry.config.max_authority_depth);
286 break;
287 default:
288 FC_THROW_EXCEPTION(config_parse_error, "DataStream& operator<<: no such id: ${id}", ("id", entry.id));
289 }
290 return s;
291}
292
300template <typename DataStream>
302 using namespace sysio::chain;
303
304 //initial requirements were to skip packing field if it is not activated.
305 //this approach allows to spam this function with big buffer so changing this behavior
306 //moreover:
307 //The contract has no way to know that the value was skipped and is likely to behave incorrectly.
308 //When the protocol feature is not activated, the old version of nodeop that doesn't know about
309 //the entry MUST behave the same as the new version of nodeop that does.
310 //Skipping known but unactivated entries violates this.
311 SYS_ASSERT(entry.is_allowed(), unsupported_feature, "config id ${id} is no allowed", ("id", entry.id));
312
313 switch (entry.id){
314 case chain_config_v1::max_action_return_value_size_id:
315 fc::raw::pack(s, entry.config.max_action_return_value_size);
316 break;
317 default:
319 fc::raw::pack(s, base_entry);
320 }
321
322 return s;
323}
324
332template <typename DataStream>
334 using namespace sysio::chain;
335
336 SYS_ASSERT(entry.is_allowed(), sysio::chain::unsupported_feature, "config id ${id} is no allowed", ("id", entry.id));
337
338 switch (entry.id){
339 case chain_config_v0::max_block_net_usage_id:
340 fc::raw::unpack(s, entry.config.max_block_net_usage);
341 break;
342 case chain_config_v0::target_block_net_usage_pct_id:
343 fc::raw::unpack(s, entry.config.target_block_net_usage_pct);
344 break;
345 case chain_config_v0::max_transaction_net_usage_id:
346 fc::raw::unpack(s, entry.config.max_transaction_net_usage);
347 break;
348 case chain_config_v0::base_per_transaction_net_usage_id:
349 fc::raw::unpack(s, entry.config.base_per_transaction_net_usage);
350 break;
351 case chain_config_v0::net_usage_leeway_id:
352 fc::raw::unpack(s, entry.config.net_usage_leeway);
353 break;
354 case chain_config_v0::context_free_discount_net_usage_num_id:
355 fc::raw::unpack(s, entry.config.context_free_discount_net_usage_num);
356 break;
357 case chain_config_v0::context_free_discount_net_usage_den_id:
358 fc::raw::unpack(s, entry.config.context_free_discount_net_usage_den);
359 break;
360 case chain_config_v0::max_block_cpu_usage_id:
361 fc::raw::unpack(s, entry.config.max_block_cpu_usage);
362 break;
363 case chain_config_v0::target_block_cpu_usage_pct_id:
364 fc::raw::unpack(s, entry.config.target_block_cpu_usage_pct);
365 break;
366 case chain_config_v0::max_transaction_cpu_usage_id:
367 fc::raw::unpack(s, entry.config.max_transaction_cpu_usage);
368 break;
369 case chain_config_v0::min_transaction_cpu_usage_id:
370 fc::raw::unpack(s, entry.config.min_transaction_cpu_usage);
371 break;
372 case chain_config_v0::max_transaction_lifetime_id:
373 fc::raw::unpack(s, entry.config.max_transaction_lifetime);
374 break;
375 case chain_config_v0::deferred_trx_expiration_window_id:
376 fc::raw::unpack(s, entry.config.deferred_trx_expiration_window);
377 break;
378 case chain_config_v0::max_transaction_delay_id:
379 fc::raw::unpack(s, entry.config.max_transaction_delay);
380 break;
381 case chain_config_v0::max_inline_action_size_id:
382 fc::raw::unpack(s, entry.config.max_inline_action_size);
383 break;
384 case chain_config_v0::max_inline_action_depth_id:
385 fc::raw::unpack(s, entry.config.max_inline_action_depth);
386 break;
387 case chain_config_v0::max_authority_depth_id:
388 fc::raw::unpack(s, entry.config.max_authority_depth);
389 break;
390 default:
391 FC_THROW_EXCEPTION(sysio::chain::config_parse_error, "DataStream& operator<<: no such id: ${id}", ("id", entry.id));
392 }
393
394 return s;
395}
396
404template <typename DataStream>
406 using namespace sysio::chain;
407
408 SYS_ASSERT(entry.is_allowed(), unsupported_feature, "config id ${id} is no allowed", ("id", entry.id));
409
410 switch (entry.id){
411 case chain_config_v1::max_action_return_value_size_id:
412 fc::raw::unpack(s, entry.config.max_action_return_value_size);
413 break;
414 default:
416 fc::raw::unpack(s, base_entry);
417 }
418
419 return s;
420}
421
429template<typename DataStream, typename T>
430inline DataStream& operator<<( DataStream& s, const sysio::chain::data_range<T, sysio::chain::config_entry_validator>& selection ) {
431 using namespace sysio::chain;
432
433 fc::unsigned_int size = selection.ids.size();
434 fc::raw::pack(s, size);
435
436 //vector here serves as hash map where key is always an index
437 std::vector<bool> visited(T::PARAMS_COUNT, false);
438 for (auto uid : selection.ids){
439 uint32_t id = uid;
440 SYS_ASSERT(id < visited.size(), config_parse_error, "provided id ${id} should be less than ${size}", ("id", id)("size", visited.size()));
441 SYS_ASSERT(!visited[id], config_parse_error, "duplicate id provided: ${id}", ("id", id));
442 visited[id] = true;
443
445 fc::raw::pack(s, data_entry(selection.config, id, selection.validator));
446 }
447
448 return s;
449}
450
458template<typename DataStream, typename T>
459inline DataStream& operator>>( DataStream& s, sysio::chain::data_range<T, sysio::chain::config_entry_validator>& selection ) {
460 using namespace sysio::chain;
461
462 fc::unsigned_int length;
463 fc::raw::unpack(s, length);
464
465 //vector here serves as hash map where key is always an index
466 std::vector<bool> visited(T::PARAMS_COUNT, false);
467 for (uint32_t i = 0; i < length; ++i) {
469 fc::raw::unpack(s, id);
470
471 SYS_ASSERT(id.value < visited.size(), config_parse_error, "provided id ${id} should be less than ${size}", ("id", id)("size", visited.size()));
472 SYS_ASSERT(!visited[id], config_parse_error, "duplicate id provided: ${id}", ("id", id));
473 visited[id] = true;
474
475 data_entry<T, config_entry_validator> cfg_entry(selection.config, id, selection.validator);
476 fc::raw::unpack(s, cfg_entry);
477 }
478 return s;
479}
480
481} //namespace fc
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
Concept for reading and writing characters.
uint64_t id
Definition code_cache.cpp:0
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
datastream< ST > & operator<<(datastream< ST > &s, const sysio::chain::may_not_exist< T > &v)
Definition abi_def.hpp:146
datastream< ST > & operator>>(datastream< ST > &s, sysio::chain::may_not_exist< T > &v)
Definition abi_def.hpp:152
#define value
Definition pkcs11.h:157
#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
unsigned __int64 uint64_t
Definition stdint.h:136
Producer-voted blockchain configuration parameters.
const chain_config_v0 & v0() const
uint16_t max_inline_action_depth
recursion depth limit on sending inline actions
uint32_t max_transaction_lifetime
the maximum number of seconds that an input transaction's expiration can be ahead of the time of the ...
friend bool operator!=(const chain_config_v0 &lhs, const chain_config_v0 &rhs)
uint32_t target_block_net_usage_pct
the target percent (1% == 100, 100%= 10,000) of maximum net usage; exceeding this triggers congestion...
uint32_t context_free_discount_net_usage_num
the numerator for the discount on net usage of context-free data
uint32_t max_transaction_cpu_usage
the maximum billable cpu usage (in microseconds) that the chain will allow regardless of account limi...
uint32_t max_block_cpu_usage
the maxiumum billable cpu usage (in microseconds) for a block
uint32_t min_transaction_cpu_usage
the minimum billable cpu usage (in microseconds) that the chain requires
uint32_t deferred_trx_expiration_window
the number of seconds after the time a deferred transaction can first execute until it expires
friend bool operator==(const chain_config_v0 &lhs, const chain_config_v0 &rhs)
uint64_t max_block_net_usage
the maxiumum net usage in instructions for a block
Stream & log(Stream &out) const
friend Stream & operator<<(Stream &out, const chain_config_v0 &c)
uint32_t context_free_discount_net_usage_den
the denominator for the discount on net usage of context-free data
uint32_t max_transaction_net_usage
the maximum objectively measured net usage that the chain will allow regardless of account limits
uint16_t max_authority_depth
recursion depth limit for checking if an authority is satisfied
uint32_t base_per_transaction_net_usage
the base amount of net usage billed for a transaction to cover incidentals
uint32_t max_transaction_delay
the maximum number of seconds that can be imposed as a delay requirement by authorization checks
uint32_t target_block_cpu_usage_pct
the target percent (1% == 100, 100%= 10,000) of maximum cpu usage; exceeding this triggers congestion...
uint32_t max_inline_action_size
maximum allowed size (in bytes) of an inline action
v1 Producer-voted blockchain configuration parameters
uint32_t max_action_return_value_size
size limit for action return value
friend Stream & operator<<(Stream &out, const chain_config_v1 &c)
friend bool operator==(const chain_config_v1 &lhs, const chain_config_v1 &rhs)
friend bool operator!=(const chain_config_v1 &lhs, const chain_config_v1 &rhs)
chain_config_v1 & operator=(const Base &b)
Stream & log(Stream &out) const
bool operator()(uint32_t id) const
const controller & control
bool is_allowed() const
T & config
uint32_t id
vector< fc::unsigned_int > ids
char * s