Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::resource_limits::resource_limits_manager Class Reference

#include <resource_limits.hpp>

Public Member Functions

 resource_limits_manager (chainbase::database &db, std::function< deep_mind_handler *()> get_deep_mind_logger)
 
void add_indices ()
 
void initialize_database ()
 
void add_to_snapshot (const snapshot_writer_ptr &snapshot) const
 
void read_from_snapshot (const snapshot_reader_ptr &snapshot)
 
void initialize_account (const account_name &account)
 
void set_block_parameters (const elastic_limit_parameters &cpu_limit_parameters, const elastic_limit_parameters &net_limit_parameters)
 
void update_account_usage (const flat_set< account_name > &accounts, uint32_t ordinal)
 
void add_transaction_usage (const flat_set< account_name > &accounts, uint64_t cpu_usage, uint64_t net_usage, uint32_t ordinal)
 
void add_pending_ram_usage (const account_name account, int64_t ram_delta)
 
void verify_account_ram_usage (const account_name accunt) const
 
bool set_account_limits (const account_name &account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight)
 set_account_limits returns true if new ram_bytes limit is more restrictive than the previously set one
 
void get_account_limits (const account_name &account, int64_t &ram_bytes, int64_t &net_weight, int64_t &cpu_weight) const
 
bool is_unlimited_cpu (const account_name &account) const
 
void process_account_limit_updates ()
 
void process_block_usage (uint32_t block_num)
 
uint64_t get_total_cpu_weight () const
 
uint64_t get_total_net_weight () const
 
uint64_t get_virtual_block_cpu_limit () const
 
uint64_t get_virtual_block_net_limit () const
 
uint64_t get_block_cpu_limit () const
 
uint64_t get_block_net_limit () const
 
std::pair< int64_t, bool > get_account_cpu_limit (const account_name &name, uint32_t greylist_limit=config::maximum_elastic_resource_multiplier) const
 
std::pair< int64_t, bool > get_account_net_limit (const account_name &name, uint32_t greylist_limit=config::maximum_elastic_resource_multiplier) const
 
std::pair< account_resource_limit, bool > get_account_cpu_limit_ex (const account_name &name, uint32_t greylist_limit=config::maximum_elastic_resource_multiplier) const
 
std::pair< account_resource_limit, bool > get_account_net_limit_ex (const account_name &name, uint32_t greylist_limit=config::maximum_elastic_resource_multiplier) const
 
int64_t get_account_ram_usage (const account_name &name) const
 

Detailed Description

Definition at line 61 of file resource_limits.hpp.

Constructor & Destructor Documentation

◆ resource_limits_manager()

sysio::chain::resource_limits::resource_limits_manager::resource_limits_manager ( chainbase::database & db,
std::function< deep_mind_handler *()> get_deep_mind_logger )
inlineexplicit

Definition at line 64 of file resource_limits.hpp.

65 :_db(db),_get_deep_mind_logger(get_deep_mind_logger)
66 {
67 }

Member Function Documentation

◆ add_indices()

void sysio::chain::resource_limits::resource_limits_manager::add_indices ( )

Definition at line 51 of file resource_limits.cpp.

51 {
52 resource_index_set::add_indices(_db);
53}
Here is the caller graph for this function:

◆ add_pending_ram_usage()

void sysio::chain::resource_limits::resource_limits_manager::add_pending_ram_usage ( const account_name account,
int64_t ram_delta )

Definition at line 206 of file resource_limits.cpp.

206 {
207 if (ram_delta == 0) {
208 return;
209 }
210
211 const auto& usage = _db.get<resource_usage_object,by_owner>( account );
212
213 SYS_ASSERT( ram_delta <= 0 || UINT64_MAX - usage.ram_usage >= (uint64_t)ram_delta, transaction_exception,
214 "Ram usage delta would overflow UINT64_MAX");
215 SYS_ASSERT(ram_delta >= 0 || usage.ram_usage >= (uint64_t)(-ram_delta), transaction_exception,
216 "Ram usage delta would underflow UINT64_MAX");
217
218 _db.modify( usage, [&]( auto& u ) {
219 u.ram_usage += ram_delta;
220
221 if (auto dm_logger = _get_deep_mind_logger()) {
222 dm_logger->on_ram_event(account, u.ram_usage, ram_delta);
223 }
224 });
225}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
void modify(const ObjectType &obj, Modifier &&m)
const ObjectType & get(CompatibleKey &&key) const
key Invalid authority Invalid transaction Invalid block ID Invalid packed transaction Invalid chain ID Invalid symbol Signature type is not a currently activated type Block can not be found Unlinkable block Block does not guarantee concurrent execution without conflicts Block exhausted allowed resources Block is from the future Block is not signed by expected producer Block includes an ill formed protocol feature activation extension Block includes an ill formed additional block signature extension transaction_exception
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_to_snapshot()

void sysio::chain::resource_limits::resource_limits_manager::add_to_snapshot ( const snapshot_writer_ptr & snapshot) const

Definition at line 73 of file resource_limits.cpp.

73 {
74 resource_index_set::walk_indices([this, &snapshot]( auto utils ){
75 snapshot->write_section<typename decltype(utils)::index_t::value_type>([this]( auto& section ){
76 decltype(utils)::walk(_db, [this, &section]( const auto &row ) {
77 section.add_row(row, _db);
78 });
79 });
80 });
81}
Here is the caller graph for this function:

◆ add_transaction_usage()

void sysio::chain::resource_limits::resource_limits_manager::add_transaction_usage ( const flat_set< account_name > & accounts,
uint64_t cpu_usage,
uint64_t net_usage,
uint32_t ordinal )

Definition at line 136 of file resource_limits.cpp.

136 {
137 const auto& state = _db.get<resource_limits_state_object>();
138 const auto& config = _db.get<resource_limits_config_object>();
139
140 for( const auto& a : accounts ) {
141
142 const auto& usage = _db.get<resource_usage_object,by_owner>( a );
143 int64_t unused;
144 int64_t net_weight;
145 int64_t cpu_weight;
146 get_account_limits( a, unused, net_weight, cpu_weight );
147
148 _db.modify( usage, [&]( auto& bu ){
149 bu.net_usage.add( net_usage, time_slot, config.account_net_usage_average_window );
150 bu.cpu_usage.add( cpu_usage, time_slot, config.account_cpu_usage_average_window );
151
152 if (auto dm_logger = _get_deep_mind_logger()) {
153 dm_logger->on_update_account_usage(bu);
154 }
155 });
156
157 if( cpu_weight >= 0 && state.total_cpu_weight > 0 ) {
158 uint128_t window_size = config.account_cpu_usage_average_window;
159 auto virtual_network_capacity_in_window = (uint128_t)state.virtual_cpu_limit * window_size;
160 auto cpu_used_in_window = ((uint128_t)usage.cpu_usage.value_ex * window_size) / (uint128_t)config::rate_limiting_precision;
161
162 uint128_t user_weight = (uint128_t)cpu_weight;
163 uint128_t all_user_weight = state.total_cpu_weight;
164
165 auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;
166
167 SYS_ASSERT( cpu_used_in_window <= max_user_use_in_window,
168 tx_cpu_usage_exceeded,
169 "authorizing account '${n}' has insufficient cpu resources for this transaction",
170 ("n", name(a))
171 ("cpu_used_in_window",cpu_used_in_window)
172 ("max_user_use_in_window",max_user_use_in_window) );
173 }
174
175 if( net_weight >= 0 && state.total_net_weight > 0) {
176
177 uint128_t window_size = config.account_net_usage_average_window;
178 auto virtual_network_capacity_in_window = (uint128_t)state.virtual_net_limit * window_size;
179 auto net_used_in_window = ((uint128_t)usage.net_usage.value_ex * window_size) / (uint128_t)config::rate_limiting_precision;
180
181 uint128_t user_weight = (uint128_t)net_weight;
182 uint128_t all_user_weight = state.total_net_weight;
183
184 auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;
185
186 SYS_ASSERT( net_used_in_window <= max_user_use_in_window,
187 tx_net_usage_exceeded,
188 "authorizing account '${n}' has insufficient net resources for this transaction",
189 ("n", name(a))
190 ("net_used_in_window",net_used_in_window)
191 ("max_user_use_in_window",max_user_use_in_window) );
192
193 }
194 }
195
196 // account for this transaction in the block and do not exceed those limits either
197 _db.modify(state, [&](resource_limits_state_object& rls){
198 rls.pending_cpu_usage += cpu_usage;
199 rls.pending_net_usage += net_usage;
200 });
201
202 SYS_ASSERT( state.pending_cpu_usage <= config.cpu_limit_parameters.max, block_resource_exhausted, "Block has insufficient cpu resources" );
203 SYS_ASSERT( state.pending_net_usage <= config.net_limit_parameters.max, block_resource_exhausted, "Block has insufficient net resources" );
204}
std::string name
void get_account_limits(const account_name &account, int64_t &ram_bytes, int64_t &net_weight, int64_t &cpu_weight) const
unsigned __int128 uint128_t
Definition types.hpp:242
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
signed __int64 int64_t
Definition stdint.h:135
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_cpu_limit()

std::pair< int64_t, bool > sysio::chain::resource_limits::resource_limits_manager::get_account_cpu_limit ( const account_name & name,
uint32_t greylist_limit = config::maximum_elastic_resource_multiplier ) const

Definition at line 416 of file resource_limits.cpp.

416 {
417 auto [arl, greylisted] = get_account_cpu_limit_ex(name, greylist_limit);
418 return {arl.available, greylisted};
419}
std::pair< account_resource_limit, bool > get_account_cpu_limit_ex(const account_name &name, uint32_t greylist_limit=config::maximum_elastic_resource_multiplier) const
Here is the call graph for this function:

◆ get_account_cpu_limit_ex()

std::pair< account_resource_limit, bool > sysio::chain::resource_limits::resource_limits_manager::get_account_cpu_limit_ex ( const account_name & name,
uint32_t greylist_limit = config::maximum_elastic_resource_multiplier ) const

Definition at line 421 of file resource_limits.cpp.

421 {
422
423 const auto& state = _db.get<resource_limits_state_object>();
424 const auto& usage = _db.get<resource_usage_object, by_owner>(name);
425 const auto& config = _db.get<resource_limits_config_object>();
426
427 int64_t cpu_weight, x, y;
428 get_account_limits( name, x, y, cpu_weight );
429
430 if( cpu_weight < 0 || state.total_cpu_weight == 0 ) {
431 return {{ -1, -1, -1 }, false};
432 }
433
434 account_resource_limit arl;
435
436 uint128_t window_size = config.account_cpu_usage_average_window;
437
438 bool greylisted = false;
439 uint128_t virtual_cpu_capacity_in_window = window_size;
440 if( greylist_limit < config::maximum_elastic_resource_multiplier ) {
441 uint64_t greylisted_virtual_cpu_limit = config.cpu_limit_parameters.max * greylist_limit;
442 if( greylisted_virtual_cpu_limit < state.virtual_cpu_limit ) {
443 virtual_cpu_capacity_in_window *= greylisted_virtual_cpu_limit;
444 greylisted = true;
445 } else {
446 virtual_cpu_capacity_in_window *= state.virtual_cpu_limit;
447 }
448 } else {
449 virtual_cpu_capacity_in_window *= state.virtual_cpu_limit;
450 }
451
452 uint128_t user_weight = (uint128_t)cpu_weight;
453 uint128_t all_user_weight = (uint128_t)state.total_cpu_weight;
454
455 auto max_user_use_in_window = (virtual_cpu_capacity_in_window * user_weight) / all_user_weight;
456 auto cpu_used_in_window = impl::integer_divide_ceil((uint128_t)usage.cpu_usage.value_ex * window_size, (uint128_t)config::rate_limiting_precision);
457
458 if( max_user_use_in_window <= cpu_used_in_window )
459 arl.available = 0;
460 else
461 arl.available = impl::downgrade_cast<int64_t>(max_user_use_in_window - cpu_used_in_window);
462
463 arl.used = impl::downgrade_cast<int64_t>(cpu_used_in_window);
464 arl.max = impl::downgrade_cast<int64_t>(max_user_use_in_window);
465 return {arl, greylisted};
466}
uint64_t y
Definition sha3.cpp:34
constexpr UnsignedIntType integer_divide_ceil(UnsignedIntType num, UnsignedIntType den)
constexpr auto downgrade_cast(GreaterIntType val) -> std::enable_if_t< is_valid_downgrade_cast< LesserIntType, GreaterIntType > &&std::is_signed< LesserIntType >::value==std::is_signed< GreaterIntType >::value, LesserIntType >
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_limits()

void sysio::chain::resource_limits::resource_limits_manager::get_account_limits ( const account_name & account,
int64_t & ram_bytes,
int64_t & net_weight,
int64_t & cpu_weight ) const

Definition at line 298 of file resource_limits.cpp.

298 {
299 const auto* pending_buo = _db.find<resource_limits_object,by_owner>( boost::make_tuple(true, account) );
300 if (pending_buo) {
301 ram_bytes = pending_buo->ram_bytes;
302 net_weight = pending_buo->net_weight;
303 cpu_weight = pending_buo->cpu_weight;
304 } else {
305 const auto& buo = _db.get<resource_limits_object,by_owner>( boost::make_tuple( false, account ) );
306 ram_bytes = buo.ram_bytes;
307 net_weight = buo.net_weight;
308 cpu_weight = buo.cpu_weight;
309 }
310}
const ObjectType * find(CompatibleKey &&key) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_net_limit()

std::pair< int64_t, bool > sysio::chain::resource_limits::resource_limits_manager::get_account_net_limit ( const account_name & name,
uint32_t greylist_limit = config::maximum_elastic_resource_multiplier ) const

Definition at line 468 of file resource_limits.cpp.

468 {
469 auto [arl, greylisted] = get_account_net_limit_ex(name, greylist_limit);
470 return {arl.available, greylisted};
471}
std::pair< account_resource_limit, bool > get_account_net_limit_ex(const account_name &name, uint32_t greylist_limit=config::maximum_elastic_resource_multiplier) const
Here is the call graph for this function:

◆ get_account_net_limit_ex()

std::pair< account_resource_limit, bool > sysio::chain::resource_limits::resource_limits_manager::get_account_net_limit_ex ( const account_name & name,
uint32_t greylist_limit = config::maximum_elastic_resource_multiplier ) const

Definition at line 473 of file resource_limits.cpp.

473 {
474 const auto& config = _db.get<resource_limits_config_object>();
475 const auto& state = _db.get<resource_limits_state_object>();
476 const auto& usage = _db.get<resource_usage_object, by_owner>(name);
477
478 int64_t net_weight, x, y;
479 get_account_limits( name, x, net_weight, y );
480
481 if( net_weight < 0 || state.total_net_weight == 0) {
482 return {{ -1, -1, -1 }, false};
483 }
484
485 account_resource_limit arl;
486
487 uint128_t window_size = config.account_net_usage_average_window;
488
489 bool greylisted = false;
490 uint128_t virtual_network_capacity_in_window = window_size;
491 if( greylist_limit < config::maximum_elastic_resource_multiplier ) {
492 uint64_t greylisted_virtual_net_limit = config.net_limit_parameters.max * greylist_limit;
493 if( greylisted_virtual_net_limit < state.virtual_net_limit ) {
494 virtual_network_capacity_in_window *= greylisted_virtual_net_limit;
495 greylisted = true;
496 } else {
497 virtual_network_capacity_in_window *= state.virtual_net_limit;
498 }
499 } else {
500 virtual_network_capacity_in_window *= state.virtual_net_limit;
501 }
502
503 uint128_t user_weight = (uint128_t)net_weight;
504 uint128_t all_user_weight = (uint128_t)state.total_net_weight;
505
506 auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;
507 auto net_used_in_window = impl::integer_divide_ceil((uint128_t)usage.net_usage.value_ex * window_size, (uint128_t)config::rate_limiting_precision);
508
509 if( max_user_use_in_window <= net_used_in_window )
510 arl.available = 0;
511 else
512 arl.available = impl::downgrade_cast<int64_t>(max_user_use_in_window - net_used_in_window);
513
514 arl.used = impl::downgrade_cast<int64_t>(net_used_in_window);
515 arl.max = impl::downgrade_cast<int64_t>(max_user_use_in_window);
516 return {arl, greylisted};
517}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_ram_usage()

int64_t sysio::chain::resource_limits::resource_limits_manager::get_account_ram_usage ( const account_name & name) const

Definition at line 239 of file resource_limits.cpp.

239 {
240 return _db.get<resource_usage_object,by_owner>( name ).ram_usage;
241}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_cpu_limit()

uint64_t sysio::chain::resource_limits::resource_limits_manager::get_block_cpu_limit ( ) const

Definition at line 404 of file resource_limits.cpp.

404 {
405 const auto& state = _db.get<resource_limits_state_object>();
406 const auto& config = _db.get<resource_limits_config_object>();
407 return config.cpu_limit_parameters.max - state.pending_cpu_usage;
408}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_net_limit()

uint64_t sysio::chain::resource_limits::resource_limits_manager::get_block_net_limit ( ) const

Definition at line 410 of file resource_limits.cpp.

410 {
411 const auto& state = _db.get<resource_limits_state_object>();
412 const auto& config = _db.get<resource_limits_config_object>();
413 return config.net_limit_parameters.max - state.pending_net_usage;
414}
Here is the call graph for this function:

◆ get_total_cpu_weight()

uint64_t sysio::chain::resource_limits::resource_limits_manager::get_total_cpu_weight ( ) const

Definition at line 384 of file resource_limits.cpp.

384 {
385 const auto& state = _db.get<resource_limits_state_object>();
386 return state.total_cpu_weight;
387}
Here is the call graph for this function:

◆ get_total_net_weight()

uint64_t sysio::chain::resource_limits::resource_limits_manager::get_total_net_weight ( ) const

Definition at line 389 of file resource_limits.cpp.

389 {
390 const auto& state = _db.get<resource_limits_state_object>();
391 return state.total_net_weight;
392}
Here is the call graph for this function:

◆ get_virtual_block_cpu_limit()

uint64_t sysio::chain::resource_limits::resource_limits_manager::get_virtual_block_cpu_limit ( ) const

Definition at line 394 of file resource_limits.cpp.

394 {
395 const auto& state = _db.get<resource_limits_state_object>();
396 return state.virtual_cpu_limit;
397}
Here is the call graph for this function:

◆ get_virtual_block_net_limit()

uint64_t sysio::chain::resource_limits::resource_limits_manager::get_virtual_block_net_limit ( ) const

Definition at line 399 of file resource_limits.cpp.

399 {
400 const auto& state = _db.get<resource_limits_state_object>();
401 return state.virtual_net_limit;
402}
Here is the call graph for this function:

◆ initialize_account()

void sysio::chain::resource_limits::resource_limits_manager::initialize_account ( const account_name & account)

Definition at line 96 of file resource_limits.cpp.

96 {
97 const auto& limits = _db.create<resource_limits_object>([&]( resource_limits_object& bl ) {
98 bl.owner = account;
99 });
100
101 const auto& usage = _db.create<resource_usage_object>([&]( resource_usage_object& bu ) {
102 bu.owner = account;
103 });
104 if (auto dm_logger = _get_deep_mind_logger()) {
105 dm_logger->on_newaccount_resource_limits(limits, usage);
106 }
107}
const ObjectType & create(Constructor &&con)
static const Reg8 bl(Operand::BL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_database()

void sysio::chain::resource_limits::resource_limits_manager::initialize_database ( )

Definition at line 55 of file resource_limits.cpp.

55 {
56 const auto& config = _db.create<resource_limits_config_object>([](resource_limits_config_object& config){
57 // see default settings in the declaration
58 });
59
60 const auto& state = _db.create<resource_limits_state_object>([&config](resource_limits_state_object& state){
61 // see default settings in the declaration
62
63 // start the chain off in a way that it is "congested" aka slow-start
64 state.virtual_cpu_limit = config.cpu_limit_parameters.max;
65 state.virtual_net_limit = config.net_limit_parameters.max;
66 });
67
68 if (auto dm_logger = _get_deep_mind_logger()) {
69 dm_logger->on_init_resource_limits(config, state);
70 }
71}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_unlimited_cpu()

bool sysio::chain::resource_limits::resource_limits_manager::is_unlimited_cpu ( const account_name & account) const

Definition at line 312 of file resource_limits.cpp.

312 {
313 const auto* buo = _db.find<resource_limits_object,by_owner>( boost::make_tuple(false, account) );
314 if (buo) {
315 return buo->cpu_weight == -1;
316 }
317 return false;
318}
Here is the call graph for this function:

◆ process_account_limit_updates()

void sysio::chain::resource_limits::resource_limits_manager::process_account_limit_updates ( )

Definition at line 320 of file resource_limits.cpp.

320 {
321 auto& multi_index = _db.get_mutable_index<resource_limits_index>();
322 auto& by_owner_index = multi_index.indices().get<by_owner>();
323
324 // convenience local lambda to reduce clutter
325 auto update_state_and_value = [](uint64_t &total, int64_t &value, int64_t pending_value, const char* debug_which) -> void {
326 if (value > 0) {
327 SYS_ASSERT(total >= static_cast<uint64_t>(value), rate_limiting_state_inconsistent, "underflow when reverting old value to ${which}", ("which", debug_which));
328 total -= value;
329 }
330
331 if (pending_value > 0) {
332 SYS_ASSERT(UINT64_MAX - total >= static_cast<uint64_t>(pending_value), rate_limiting_state_inconsistent, "overflow when applying new value to ${which}", ("which", debug_which));
333 total += pending_value;
334 }
335
336 value = pending_value;
337 };
338
339 const auto& state = _db.get<resource_limits_state_object>();
340 _db.modify(state, [&](resource_limits_state_object& rso){
341 while(!by_owner_index.empty()) {
342 const auto& itr = by_owner_index.lower_bound(boost::make_tuple(true));
343 if (itr == by_owner_index.end() || itr->pending!= true) {
344 break;
345 }
346
347 const auto& actual_entry = _db.get<resource_limits_object, by_owner>(boost::make_tuple(false, itr->owner));
348 _db.modify(actual_entry, [&](resource_limits_object& rlo){
349 update_state_and_value(rso.total_ram_bytes, rlo.ram_bytes, itr->ram_bytes, "ram_bytes");
350 update_state_and_value(rso.total_cpu_weight, rlo.cpu_weight, itr->cpu_weight, "cpu_weight");
351 update_state_and_value(rso.total_net_weight, rlo.net_weight, itr->net_weight, "net_weight");
352 });
353
354 multi_index.remove(*itr);
355 }
356
357 if (auto dm_logger = _get_deep_mind_logger()) {
358 dm_logger->on_update_resource_limits_state(state);
359 }
360 });
361}
generic_index< MultiIndexType > & get_mutable_index()
chainbase::shared_multi_index_container< resource_limits_object, indexed_by< ordered_unique< tag< by_id >, member< resource_limits_object, resource_limits_object::id_type, &resource_limits_object::id > >, ordered_unique< tag< by_owner >, composite_key< resource_limits_object, BOOST_MULTI_INDEX_MEMBER(resource_limits_object, bool, pending), > > > > resource_limits_index
#define value
Definition pkcs11.h:157
#define UINT64_MAX
Definition stdint.h:189
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_block_usage()

void sysio::chain::resource_limits::resource_limits_manager::process_block_usage ( uint32_t block_num)

Definition at line 363 of file resource_limits.cpp.

363 {
364 const auto& s = _db.get<resource_limits_state_object>();
365 const auto& config = _db.get<resource_limits_config_object>();
366 _db.modify(s, [&](resource_limits_state_object& state){
367 // apply pending usage, update virtual limits and reset the pending
368
369 state.average_block_cpu_usage.add(state.pending_cpu_usage, block_num, config.cpu_limit_parameters.periods);
370 state.update_virtual_cpu_limit(config);
371 state.pending_cpu_usage = 0;
372
373 state.average_block_net_usage.add(state.pending_net_usage, block_num, config.net_limit_parameters.periods);
374 state.update_virtual_net_limit(config);
375 state.pending_net_usage = 0;
376
377 if (auto dm_logger = _get_deep_mind_logger()) {
378 dm_logger->on_update_resource_limits_state(state);
379 }
380 });
381
382}
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_from_snapshot()

void sysio::chain::resource_limits::resource_limits_manager::read_from_snapshot ( const snapshot_reader_ptr & snapshot)

Definition at line 83 of file resource_limits.cpp.

83 {
84 resource_index_set::walk_indices([this, &snapshot]( auto utils ){
85 snapshot->read_section<typename decltype(utils)::index_t::value_type>([this]( auto& section ) {
86 bool more = !section.empty();
87 while(more) {
88 decltype(utils)::create(_db, [this, &section, &more]( auto &row ) {
89 more = section.read_row(row, _db);
90 });
91 }
92 });
93 });
94}
Here is the caller graph for this function:

◆ set_account_limits()

bool sysio::chain::resource_limits::resource_limits_manager::set_account_limits ( const account_name & account,
int64_t ram_bytes,
int64_t net_weight,
int64_t cpu_weight )

Definition at line 244 of file resource_limits.cpp.

244 {
245 //const auto& usage = _db.get<resource_usage_object,by_owner>( account );
246 /*
247 * Since we need to delay these until the next resource limiting boundary, these are created in a "pending"
248 * state or adjusted in an existing "pending" state. The chain controller will collapse "pending" state into
249 * the actual state at the next appropriate boundary.
250 */
251 auto find_or_create_pending_limits = [&]() -> const resource_limits_object& {
252 const auto* pending_limits = _db.find<resource_limits_object, by_owner>( boost::make_tuple(true, account) );
253 if (pending_limits == nullptr) {
254 const auto& limits = _db.get<resource_limits_object, by_owner>( boost::make_tuple(false, account));
255 return _db.create<resource_limits_object>([&](resource_limits_object& pending_limits){
256 pending_limits.owner = limits.owner;
257 pending_limits.ram_bytes = limits.ram_bytes;
258 pending_limits.net_weight = limits.net_weight;
259 pending_limits.cpu_weight = limits.cpu_weight;
260 pending_limits.pending = true;
261 });
262 } else {
263 return *pending_limits;
264 }
265 };
266
267 // update the users weights directly
268 auto& limits = find_or_create_pending_limits();
269
270 bool decreased_limit = false;
271
272 if( ram_bytes >= 0 ) {
273
274 decreased_limit = ( (limits.ram_bytes < 0) || (ram_bytes < limits.ram_bytes) );
275
276 /*
277 if( limits.ram_bytes < 0 ) {
278 SYS_ASSERT(ram_bytes >= usage.ram_usage, wasm_execution_error, "converting unlimited account would result in overcommitment [commit=${c}, desired limit=${l}]", ("c", usage.ram_usage)("l", ram_bytes));
279 } else {
280 SYS_ASSERT(ram_bytes >= usage.ram_usage, wasm_execution_error, "attempting to release committed ram resources [commit=${c}, desired limit=${l}]", ("c", usage.ram_usage)("l", ram_bytes));
281 }
282 */
283 }
284
285 _db.modify( limits, [&]( resource_limits_object& pending_limits ){
286 pending_limits.ram_bytes = ram_bytes;
287 pending_limits.net_weight = net_weight;
288 pending_limits.cpu_weight = cpu_weight;
289
290 if (auto dm_logger = _get_deep_mind_logger()) {
291 dm_logger->on_set_account_limits(pending_limits);
292 }
293 });
294
295 return decreased_limit;
296}
Here is the call graph for this function:

◆ set_block_parameters()

void sysio::chain::resource_limits::resource_limits_manager::set_block_parameters ( const elastic_limit_parameters & cpu_limit_parameters,
const elastic_limit_parameters & net_limit_parameters )

Definition at line 109 of file resource_limits.cpp.

109 {
110 cpu_limit_parameters.validate();
111 net_limit_parameters.validate();
112 const auto& config = _db.get<resource_limits_config_object>();
113 if( config.cpu_limit_parameters == cpu_limit_parameters && config.net_limit_parameters == net_limit_parameters )
114 return;
115 _db.modify(config, [&](resource_limits_config_object& c){
116 c.cpu_limit_parameters = cpu_limit_parameters;
117 c.net_limit_parameters = net_limit_parameters;
118
119 if (auto dm_logger = _get_deep_mind_logger()) {
120 dm_logger->on_update_resource_limits_config(c);
121 }
122 });
123}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_account_usage()

void sysio::chain::resource_limits::resource_limits_manager::update_account_usage ( const flat_set< account_name > & accounts,
uint32_t ordinal )

Definition at line 125 of file resource_limits.cpp.

125 {
126 const auto& config = _db.get<resource_limits_config_object>();
127 for( const auto& a : accounts ) {
128 const auto& usage = _db.get<resource_usage_object,by_owner>( a );
129 _db.modify( usage, [&]( auto& bu ){
130 bu.net_usage.add( 0, time_slot, config.account_net_usage_average_window );
131 bu.cpu_usage.add( 0, time_slot, config.account_cpu_usage_average_window );
132 });
133 }
134}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_account_ram_usage()

void sysio::chain::resource_limits::resource_limits_manager::verify_account_ram_usage ( const account_name accunt) const

Definition at line 227 of file resource_limits.cpp.

227 {
228 int64_t ram_bytes; int64_t net_weight; int64_t cpu_weight;
229 get_account_limits( account, ram_bytes, net_weight, cpu_weight );
230 const auto& usage = _db.get<resource_usage_object,by_owner>( account );
231
232 if( ram_bytes >= 0 ) {
233 SYS_ASSERT( usage.ram_usage <= static_cast<uint64_t>(ram_bytes), ram_usage_exceeded,
234 "account ${account} has insufficient ram; needs ${needs} bytes has ${available} bytes",
235 ("account", account)("needs",usage.ram_usage)("available",ram_bytes) );
236 }
237}
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: