4#include <sysio/crypto.hpp>
5#include <sysio/dispatcher.hpp>
11 using sysio::current_time_point;
15 return std::log1p(
double(annual_rate)/
double(100*inflation_precision));
20 _voters(get_self(), get_self().
value),
21 _producers(get_self(), get_self().
value),
22 _producers2(get_self(), get_self().
value),
23 _global(get_self(), get_self().
value),
24 _global2(get_self(), get_self().
value),
25 _global3(get_self(), get_self().
value),
26 _global4(get_self(), get_self().
value),
27 _rammarket(get_self(), get_self().
value),
28 _rexpool(get_self(), get_self().
value),
29 _rexretpool(get_self(), get_self().
value),
30 _rexretbuckets(get_self(), get_self().
value),
31 _rexfunds(get_self(), get_self().
value),
32 _rexbalance(get_self(), get_self().
value),
33 _rexorders(get_self(), get_self().
value)
35 _gstate = _global.exists() ? _global.get() : get_default_parameters();
38 _gstate4 = _global4.exists() ? _global4.get() : get_default_inflation_parameters();
43 get_blockchain_parameters(dp);
47 sysio_global_state4 system_contract::get_default_inflation_parameters() {
48 sysio_global_state4 gs4;
50 gs4.inflation_pay_factor = default_inflation_pay_factor;
51 gs4.votepay_factor = default_votepay_factor;
55 symbol system_contract::core_symbol()
const {
61 _global.set( _gstate, get_self() );
62 _global2.set( _gstate2, get_self() );
63 _global3.set( _gstate3, get_self() );
64 _global4.set( _gstate4, get_self() );
68 require_auth( get_self() );
70 check( _gstate.
max_ram_size < max_ram_size,
"ram may only be increased" );
71 check( max_ram_size < 1024ll*1024*1024*1024*1024,
"ram size is unrealistic" );
80 _rammarket.modify( itr, same_payer, [&](
auto& m ) {
81 m.base.balance.amount += delta;
87 void system_contract::update_ram_supply() {
88 auto cbt = sysio::current_block_time();
99 _rammarket.modify( itr, same_payer, [&](
auto& m ) {
100 m.base.balance.amount += new_ram;
106 require_auth( get_self() );
112#ifdef SYSTEM_BLOCKCHAIN_PARAMETERS
113 extern "C" [[sysio::wasm_import]]
void set_parameters_packed(
const void*,
size_t);
117 require_auth( get_self() );
118 (sysio::blockchain_parameters&)(_gstate) =
params;
119 check( 3 <= _gstate.max_authority_depth,
"max_authority_depth should be at least 3" );
120#ifndef SYSTEM_BLOCKCHAIN_PARAMETERS
121 set_blockchain_parameters(
params );
123 constexpr size_t param_count = 18;
125 char buf[1 +
sizeof(
params) + param_count];
148 if(
params.max_action_return_value_size)
150 stream <<
uint8_t(17) <<
params.max_action_return_value_size.value();
154 set_parameters_packed(
buf, stream.tellp());
158#ifdef SYSTEM_CONFIGURABLE_WASM_LIMITS
161 struct wasm_parameters
176 static constexpr wasm_parameters default_limits = {
177 .max_mutable_global_bytes = 1024,
178 .max_table_elements = 1024,
179 .max_section_elements = 8192,
180 .max_linear_memory_init = 64*1024,
181 .max_func_local_bytes = 8192,
182 .max_nested_structures = 1024,
183 .max_symbol_bytes = 8192,
184 .max_module_bytes = 20*1024*1024,
185 .max_code_bytes = 20*1024*1024,
187 .max_call_depth = 251
190 static constexpr wasm_parameters high_limits = {
191 .max_mutable_global_bytes = 8192,
192 .max_table_elements = 8192,
193 .max_section_elements = 8192,
194 .max_linear_memory_init = 16*64*1024,
195 .max_func_local_bytes = 8192,
196 .max_nested_structures = 1024,
197 .max_symbol_bytes = 8192,
198 .max_module_bytes = 20*1024*1024,
199 .max_code_bytes = 20*1024*1024,
201 .max_call_depth = 1024
204 extern "C" [[sysio::wasm_import]]
void set_wasm_parameters_packed(
const void*,
size_t );
206 void set_wasm_parameters(
const wasm_parameters&
params )
210 set_wasm_parameters_packed(
buf,
sizeof(
buf) );
213 void system_contract::wasmcfg(
const name& settings )
215 require_auth( get_self() );
216 if( settings ==
"default"_n || settings ==
"low"_n )
218 set_wasm_parameters( default_limits );
220 else if( settings ==
"high"_n )
222 set_wasm_parameters( high_limits );
226 check(
false,
"Unkown configuration");
233 require_auth( get_self() );
234 set_privileged( account, ispriv );
238 require_auth( get_self() );
241 auto ritr = userres.find( account.value );
242 check( ritr == userres.end(),
"only supports unlimited accounts" );
244 auto vitr = _voters.find( account.value );
245 if( vitr != _voters.end() ) {
249 check( !(ram_managed || net_managed || cpu_managed),
"cannot use setalimits on an account with managed resources" );
252 set_resource_limits( account, ram, net, cpu );
256 require_auth( get_self() );
258 int64_t current_ram, current_net, current_cpu;
259 get_resource_limits( account, current_ram, current_net, current_cpu );
264 auto vitr = _voters.find( account.value );
266 "RAM of account is already unmanaged" );
269 auto ritr = userres.find( account.value );
271 ram = ram_gift_bytes;
272 if( ritr != userres.end() ) {
273 ram += ritr->ram_bytes;
276 _voters.modify( vitr, same_payer, [&](
auto& v ) {
280 check( *ram_bytes >= 0,
"not allowed to set RAM limit to unlimited" );
282 auto vitr = _voters.find( account.value );
283 if ( vitr != _voters.end() ) {
284 _voters.modify( vitr, same_payer, [&](
auto& v ) {
288 _voters.emplace( account, [&](
auto& v ) {
297 set_resource_limits( account, ram, current_net, current_cpu );
301 require_auth( get_self() );
303 int64_t current_ram, current_net, current_cpu;
304 get_resource_limits( account, current_ram, current_net, current_cpu );
309 auto vitr = _voters.find( account.value );
311 "Network bandwidth of account is already unmanaged" );
314 auto ritr = userres.find( account.value );
316 if( ritr != userres.end() ) {
317 net = ritr->net_weight.amount;
320 _voters.modify( vitr, same_payer, [&](
auto& v ) {
324 check( *net_weight >= -1,
"invalid value for net_weight" );
326 auto vitr = _voters.find( account.value );
327 if ( vitr != _voters.end() ) {
328 _voters.modify( vitr, same_payer, [&](
auto& v ) {
332 _voters.emplace( account, [&](
auto& v ) {
341 set_resource_limits( account, current_ram, net, current_cpu );
345 require_auth( get_self() );
347 int64_t current_ram, current_net, current_cpu;
348 get_resource_limits( account, current_ram, current_net, current_cpu );
353 auto vitr = _voters.find( account.value );
355 "CPU bandwidth of account is already unmanaged" );
358 auto ritr = userres.find( account.value );
360 if( ritr != userres.end() ) {
361 cpu = ritr->cpu_weight.amount;
364 _voters.modify( vitr, same_payer, [&](
auto& v ) {
368 check( *cpu_weight >= -1,
"invalid value for cpu_weight" );
370 auto vitr = _voters.find( account.value );
371 if ( vitr != _voters.end() ) {
372 _voters.modify( vitr, same_payer, [&](
auto& v ) {
376 _voters.emplace( account, [&](
auto& v ) {
385 set_resource_limits( account, current_ram, current_net, cpu );
389 require_auth( get_self() );
390 preactivate_feature( feature_digest );
394 require_auth( get_self() );
395 auto prod = _producers.find( producer.value );
396 check( prod != _producers.end(),
"producer not found" );
397 _producers.modify( prod, same_payer, [&](
auto&
p) {
403 require_auth( get_self() );
404 check( _gstate2.
revision < 255,
"can not increment revision" );
405 check( revision == _gstate2.
revision + 1,
"can only increment revision by one" );
406 check( revision <= 1,
407 "specified revision is not yet supported by the code" );
412 require_auth(get_self());
413 check(annual_rate >= 0,
"annual_rate can't be negative");
414 if ( inflation_pay_factor < pay_factor_precision ) {
415 check(
false,
"inflation_pay_factor must not be less than " + std::to_string(pay_factor_precision) );
417 if ( votepay_factor < pay_factor_precision ) {
418 check(
false,
"votepay_factor must not be less than " + std::to_string(pay_factor_precision) );
423 _global4.set( _gstate4, get_self() );
436 const name& new_account_name,
437 ignore<authority> owner,
438 ignore<authority> active ) {
440 if( creator != get_self() ) {
441 uint64_t tmp = new_account_name.value >> 4;
442 bool has_dot =
false;
444 for(
uint32_t i = 0; i < 12; ++i ) {
445 has_dot |= !(tmp & 0x1f);
449 auto suffix = new_account_name.suffix();
450 if( suffix == new_account_name ) {
452 auto current = bids.find( new_account_name.value );
453 check( current != bids.end(),
"no active bid for name" );
454 check( current->high_bidder == creator,
"only highest bidder can claim" );
455 check( current->high_bid < 0,
"auction for name is not closed yet" );
456 bids.erase( current );
458 check( creator == suffix,
"only suffix may create this account" );
465 userres.emplace( new_account_name, [&](
auto& res ) {
466 res.owner = new_account_name;
471 set_resource_limits( new_account_name, 0, 0, 0 );
475 const binary_extension<std::string>& memo ) {
476 sysio::multi_index<
"abihash"_n,
abi_hash > table(get_self(), get_self().
value);
477 auto itr = table.find( acnt.value );
478 if( itr == table.end() ) {
479 table.emplace( acnt, [&](
auto& row ) {
481 row.hash =
sysio::sha256(
const_cast<char*
>(abi.data()), abi.size());
484 table.modify( itr, same_payer, [&](
auto& row ) {
485 row.hash =
sysio::sha256(
const_cast<char*
>(abi.data()), abi.size());
491 require_auth( get_self() );
492 check( version.value == 0,
"unsupported version for init action" );
495 check( itr == _rammarket.end(),
"system contract has already been initialized" );
498 check( system_token_supply.symbol == core,
"specified core symbol does not exist (precision mismatch)" );
500 check( system_token_supply.amount > 0,
"system token supply must be greater than 0" );
501 _rammarket.emplace( get_self(), [&](
auto& m ) {
502 m.supply.amount = 100000000000000ll;
506 m.quote.balance.amount = system_token_supply.amount / 1000;
507 m.quote.balance.
symbol = core;
520 auth.
keys.push_back({pub_key, 1});
524 update_auth.send(account_name,
name(
"auth.ext"),
name(
"owner"), auth,
name(
""));
contains only the public point of an elliptic curve key.
symbol(uint8_t p, const char *s)
sysio::action_wrapper<"open"_n, &token::open > open_action
static asset get_supply(const name &token_contract_account, const symbol_code &sym_code)
void setabi(const name &account, const std::vector< char > &abi, const binary_extension< std::string > &memo)
sysio::action_wrapper<"updateauth"_n, &native::updateauth > updateauth_action
void newaccount(const name &creator, const name &name, ignore< authority > owner, ignore< authority > active)
void activate(const sysio::checksum256 &feature_digest)
void setacctram(const name &account, const std::optional< int64_t > &ram_bytes)
void setparams(const blockchain_parameters_t ¶ms)
void onlinkauth(const name &user, const name &permission, const sysio::public_key &pub_key)
system_contract(name s, name code, datastream< const char * > ds)
static constexpr symbol ram_symbol
static constexpr sysio::name token_account
void setinflation(int64_t annual_rate, int64_t inflation_pay_factor, int64_t votepay_factor)
void rmvproducer(const name &producer)
void setram(uint64_t max_ram_size)
void setacctnet(const name &account, const std::optional< int64_t > &net_weight)
static constexpr sysio::name active_permission
static symbol get_core_symbol(name system_account="sysio"_n)
void setramrate(uint16_t bytes_per_block)
void init(unsigned_int version, const symbol &core)
void setacctcpu(const name &account, const std::optional< int64_t > &cpu_weight)
static constexpr symbol ramcore_symbol
void setalimits(const name &account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight)
void updtrevision(uint8_t revision)
static constexpr sysio::name rex_account
void setpriv(const name &account, uint8_t is_priv)
sysio::blockchain_parameters blockchain_parameters_t
sysio::multi_index< "namebids"_n, name_bid, indexed_by<"highbid"_n, const_mem_fun< name_bid, uint64_t, &name_bid::by_high_bid > > > name_bid_table
double get_continuous_rate(int64_t annual_rate)
sysio::multi_index< "userres"_n, user_resources > user_resources_table
unsigned __int64 uint64_t
Immutable except for fc::from_variant.
std::vector< key_weight > keys
uint16_t new_ram_per_block
uint8_t revision
used to track version updates in the future.
block_timestamp last_ram_increase
int64_t inflation_pay_factor
uint64_t free_ram() const
uint64_t total_ram_bytes_reserved
account_query_db::get_accounts_by_authorizers_params params
memcpy((char *) pInfo->slotDescription, s, l)