diff --git a/contracts/eosio.system/delegate_bandwidth.cpp b/contracts/eosio.system/delegate_bandwidth.cpp index 95cc6c61d027ca250de71c357c997e7b1da5f0da..bc22840f06f436b0968a28593a06cb257a177047 100644 --- a/contracts/eosio.system/delegate_bandwidth.cpp +++ b/contracts/eosio.system/delegate_bandwidth.cpp @@ -77,14 +77,16 @@ namespace eosiosystem { typedef eosio::multi_index< N(refunds), refund_request> refunds_table; void system_contract::delegatebw( const account_name from, const account_name receiver, - const asset stake_net_quantity, const asset stake_cpu_quantity, - const asset stake_storage_quantity ) + const asset& stake_net_quantity, const asset& stake_cpu_quantity, + const asset& stake_storage_quantity ) { eosio_assert( stake_cpu_quantity.amount >= 0, "must stake a positive amount" ); eosio_assert( stake_net_quantity.amount >= 0, "must stake a positive amount" ); eosio_assert( stake_storage_quantity.amount >= 0, "must stake a positive amount" ); + print( "adding stake...", stake_net_quantity, " ", stake_cpu_quantity, " ", stake_storage_quantity ); asset total_stake = stake_cpu_quantity + stake_net_quantity + stake_storage_quantity; + print( "\ntotal stake: ", total_stake ); eosio_assert( total_stake.amount > 0, "must stake a positive amount" ); require_auth( from ); @@ -95,6 +97,11 @@ namespace eosiosystem { global_state_singleton gs( _self, _self ); auto parameters = gs.exists() ? gs.get() : get_default_parameters(); const eosio::asset token_supply = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()); + + print( " token supply: ", token_supply, " \n" ); + print( " max storage size: ", parameters.max_storage_size, "\n"); + print( " total reserved: ", parameters.total_storage_bytes_reserved, "\n"); + //make sure that there is no posibility of overflow here int64_t storage_bytes_estimated = int64_t( parameters.max_storage_size - parameters.total_storage_bytes_reserved ) * int64_t(parameters.storage_reserve_ratio) * stake_storage_quantity @@ -107,6 +114,7 @@ namespace eosiosystem { eosio_assert( 0 < storage_bytes, "stake is too small to increase storage even by 1 byte" ); parameters.total_storage_bytes_reserved += uint64_t(storage_bytes); + print( "\ntotal storage stake: ", parameters.total_storage_stake, "\n" ); parameters.total_storage_stake += stake_storage_quantity; gs.set( parameters, _self ); } @@ -151,7 +159,7 @@ namespace eosiosystem { }); } - //set_resource_limits( tot_itr->owner, tot_itr->storage_bytes, tot_itr->net_weight.quantity, tot_itr->cpu_weight.quantity ); + set_resource_limits( tot_itr->owner, tot_itr->storage_bytes, tot_itr->net_weight.amount, tot_itr->cpu_weight.amount ); INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {from,N(active)}, { from, N(eosio), total_stake, std::string("stake bandwidth") } ); @@ -162,6 +170,20 @@ namespace eosiosystem { } // delegatebw + void system_contract::setparams( uint64_t max_storage_size, uint32_t storage_reserve_ratio ) { + require_auth( _self ); + + eosio_assert( storage_reserve_ratio > 0, "invalid reserve ratio" ); + + global_state_singleton gs( _self, _self ); + auto parameters = gs.exists() ? gs.get() : get_default_parameters(); + + eosio_assert( max_storage_size > parameters.total_storage_bytes_reserved, "attempt to set max below reserved" ); + + parameters.max_storage_size = max_storage_size; + parameters.storage_reserve_ratio = storage_reserve_ratio; + gs.set( parameters, _self ); + } void system_contract::undelegatebw( const account_name from, const account_name receiver, const asset unstake_net_quantity, const asset unstake_cpu_quantity, @@ -212,7 +234,7 @@ namespace eosiosystem { tot.storage_bytes -= unstake_storage_bytes; }); - //set_resource_limits( totals.owner, totals.storage_bytes, totals.net_weight.quantity, totals.cpu_weight.quantity ); + set_resource_limits( totals.owner, totals.storage_bytes, totals.net_weight.amount, totals.cpu_weight.amount ); refunds_table refunds_tbl( _self, from ); //create refund request diff --git a/contracts/eosio.system/eosio.system.abi b/contracts/eosio.system/eosio.system.abi index f7aebf4c4fb26d219cc3d5bef5b19feed0ee02e5..aa964db3ebff682e0bb1612c0bafa9b311e9108a 100644 --- a/contracts/eosio.system/eosio.system.abi +++ b/contracts/eosio.system/eosio.system.abi @@ -140,18 +140,17 @@ "fields": [ {"name":"owner", "type":"account_name"}, {"name":"total_votes", "type":"uint128"}, - {"name":"prefs", "type":"eosio_parameters"}, - {"name":"packed_key", "type":"uint8[]"}, + {"name":"packed_key", "type":"public_key"}, {"name":"per_block_payments", "type":"uint64"}, - {"name":"last_claim_time", "type":"uint32"} + {"name":"last_claim_time", "type":"time"} ] },{ "name": "regproducer", "base": "", "fields": [ {"name":"producer", "type":"account_name"}, - {"name":"producer_key", "type":"bytes"}, - {"name":"prefs", "type":"eosio_parameters"} + {"name":"producer_key", "type":"public_key"}, + {"name":"url", "type":"string"} ] },{ "name": "unregprod", @@ -159,6 +158,13 @@ "fields": [ {"name":"producer", "type":"account_name"} ] + },{ + "name": "setparams", + "base": "", + "fields": [ + {"name":"max_ram_size", "type":"uint64"} + {"name":"ram_reserve_ratio", "type":"uint32"} + ] },{ "name": "regproxy", "base": "", @@ -185,7 +191,7 @@ "fields": [ {"name":"owner", "type":"account_name"}, {"name":"proxy", "type":"account_name"}, - {"name":"last_update", "type":"uint32"}, + {"name":"last_update", "type":"time"}, {"name":"is_proxy", "type":"uint32"}, {"name":"staked", "type":"asset"}, {"name":"unstaking", "type":"asset"}, @@ -227,6 +233,10 @@ "name": "regproducer", "type": "regproducer", "ricardian_contract": "" + },{ + "name": "setparams", + "type": "setparams", + "ricardian_contract": "" },{ "name": "unregprod", "type": "unregprod", @@ -259,6 +269,12 @@ "index_type": "i64", "key_names" : ["owner"], "key_types" : ["uint64"] + },{ + "name": "voters", + "type": "voter_info", + "index_type": "i64", + "key_names" : ["owner"], + "key_types" : ["account_name"] },{ "name": "totalband", "type": "total_resources", diff --git a/contracts/eosio.system/eosio.system.cpp b/contracts/eosio.system/eosio.system.cpp index 6dfcd8699a97a930e0e23ede245e65f57802ba4e..08074ea6021e43116c544902275aadcb282d18e2 100644 --- a/contracts/eosio.system/eosio.system.cpp +++ b/contracts/eosio.system/eosio.system.cpp @@ -6,11 +6,13 @@ #include "voting.cpp" EOSIO_ABI( eosiosystem::system_contract, + (setparams) // delegate_bandwith.cpp (delegatebw)(undelegatebw)(refund) (regproxy) // voting.cpp - (unregproxy)(regproducer)(unregprod)(voteproducer)(onblock) + (unregproxy)(regproducer)(unregprod)(voteproducer) + (onblock) // producer_pay.cpp (claimrewards) // native.hpp diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index c994b5c0acecb106198fc8f4574fc6f8719023b6..50e8ab7f0da709009445e3c2c412f41258ba0885 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -25,20 +25,19 @@ namespace eosiosystem { time timestamp; checksum256 transaction_mroot; checksum256 action_mroot; - checksum256 block_mroot; account_name producer; uint32_t schedule_version; eosio::optional new_producers; // explicit serialization macro is not necessary, used here only to improve compilation time - EOSLIB_SERIALIZE(block_header, (previous)(timestamp)(transaction_mroot)(action_mroot)(block_mroot) + EOSLIB_SERIALIZE(block_header, (previous)(timestamp)(transaction_mroot)(action_mroot) (producer)(schedule_version)(new_producers)) }; struct eosio_parameters : eosio::blockchain_parameters { - uint64_t max_storage_size = 10 * 1024 * 1024; + uint64_t max_storage_size = 1024 * 1024 * 1024; uint32_t percent_of_max_inflation_rate = 0; - uint32_t storage_reserve_ratio = 1000; // ratio * 1000 + uint32_t storage_reserve_ratio = 2000; // ratio * 1000 // explicit serialization macro is not necessary, used here only to improve compilation time EOSLIB_SERIALIZE_DERIVED( eosio_parameters, eosio::blockchain_parameters, (max_storage_size)(percent_of_max_inflation_rate)(storage_reserve_ratio) ) @@ -63,8 +62,7 @@ namespace eosiosystem { struct producer_info { account_name owner; uint128_t total_votes = 0; - eosio_parameters prefs; - eosio::bytes packed_key; /// a packed public key object + eosio::public_key producer_key; /// a packed public key object eosio::asset per_block_payments; time last_rewards_claim = 0; time time_became_active = 0; @@ -72,10 +70,10 @@ namespace eosiosystem { uint64_t primary_key()const { return owner; } uint128_t by_votes()const { return total_votes; } - bool active() const { return 0 < packed_key.size(); } + bool active() const { return producer_key != public_key(); } // explicit serialization macro is not necessary, used here only to improve compilation time - EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(prefs)(packed_key) + EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(producer_key) (per_block_payments)(last_rewards_claim) (time_became_active)(last_produced_block_time) ) }; @@ -99,8 +97,8 @@ namespace eosiosystem { // functions defined in delegate_bandwidth.cpp void delegatebw( const account_name from, const account_name receiver, - const asset stake_net_quantity, const asset stake_cpu_quantity, - const asset stake_storage_quantity ); + const asset& stake_net_quantity, const asset& stake_cpu_quantity, + const asset& stake_storage_quantity ); void undelegatebw( const account_name from, const account_name receiver, const asset unstake_net_quantity, const asset unstake_cpu_quantity, @@ -110,13 +108,12 @@ namespace eosiosystem { // functions defined in voting.cpp - void regproducer( const account_name producer, const bytes& producer_key, const eosio_parameters& prefs ); + void regproducer( const account_name producer, const public_key& producer_key, const std::string& url ); void unregprod( const account_name producer ); - eosio::asset payment_per_block(uint32_t percent_of_max_inflation_rate); + void setparams( uint64_t max_storage_size, uint32_t storage_reserve_ratio ); - void update_elected_producers(time cycle_time); void voteproducer( const account_name voter, const account_name proxy, const std::vector& producers ); @@ -133,6 +130,10 @@ namespace eosiosystem { void claimrewards( const account_name& owner ); private: + eosio::asset payment_per_block(uint32_t percent_of_max_inflation_rate); + + void update_elected_producers(time cycle_time); + // Implementation details: //defined in voting.hpp diff --git a/contracts/eosio.system/native.hpp b/contracts/eosio.system/native.hpp index 872ae49bde7d65e3d5ebca4e85a511608aa49874..1c09567aa18cf8c9a1f8979d337b3ddd4de203bf 100644 --- a/contracts/eosio.system/native.hpp +++ b/contracts/eosio.system/native.hpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include namespace eosiosystem { using eosio::permission_level; @@ -47,11 +49,15 @@ namespace eosiosystem { class native { public: - void newaccount( /*account_name creator, - account_name name, + void newaccount( account_name creator, + account_name newact + /* const authority& owner, const authority& active, - const authority& recovery*/ ) {} + const authority& recovery*/ ) { + eosio::print( eosio::name{creator}, " created ", eosio::name{newact}); + set_resource_limits( newact, 1000, 0, 0 ); + } void updateauth( /*account_name account, permission_name permission, diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index c1a66c043e9be24304b7a488b4fdda65f7b00dda..1779cb74d47d026290fad837563c0131ff52f62a 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -59,27 +59,25 @@ namespace eosiosystem { * @pre authority of producer to register * */ - void system_contract::regproducer( const account_name producer, const bytes& packed_producer_key, const eosio_parameters& prefs ) { + void system_contract::regproducer( const account_name producer, const public_key& producer_key, const std::string& url ) { //, const eosio_parameters& prefs ) { + eosio_assert( url.size() < 512, "url too long" ); //eosio::print("produce_key: ", producer_key.size(), ", sizeof(public_key): ", sizeof(public_key), "\n"); require_auth( producer ); producers_table producers_tbl( _self, _self ); auto prod = producers_tbl.find( producer ); - //check that we can unpack producer key - public_key producer_key = eosio::unpack( packed_producer_key ); - if ( prod != producers_tbl.end() ) { - producers_tbl.modify( prod, producer, [&]( producer_info& info ){ - info.prefs = prefs; - info.packed_key = eosio::pack( producer_key ); - }); + if( producer_key != prod->producer_key ) { + producers_tbl.modify( prod, producer, [&]( producer_info& info ){ + info.producer_key = producer_key; + }); + } } else { producers_tbl.emplace( producer, [&]( producer_info& info ){ info.owner = producer; info.total_votes = 0; - info.prefs = prefs; - info.packed_key = eosio::pack( producer_key ); + info.producer_key = producer_key; }); } } @@ -92,7 +90,7 @@ namespace eosiosystem { eosio_assert( prod != producers_tbl.end(), "producer not found" ); producers_tbl.modify( prod, 0, [&]( producer_info& info ){ - info.packed_key.clear(); + info.producer_key = public_key(); }); } @@ -205,6 +203,7 @@ namespace eosiosystem { producers_table producers_tbl( _self, _self ); auto idx = producers_tbl.template get_index(); + /* std::array max_block_net_usage; std::array target_block_net_usage_pct; std::array base_per_transaction_net_usage; @@ -233,6 +232,7 @@ namespace eosiosystem { std::array max_storage_size; std::array percent_of_max_inflation_rate; std::array storage_reserve_ratio; + */ eosio::producer_schedule schedule; schedule.producers.reserve(21); @@ -242,9 +242,10 @@ namespace eosiosystem { schedule.producers.emplace_back(); schedule.producers.back().producer_name = it->owner; //eosio_assert( sizeof(schedule.producers.back().block_signing_key) == it->packed_key.size(), "size mismatch" ); - schedule.producers.back().block_signing_key = eosio::unpack( it->packed_key ); + schedule.producers.back().block_signing_key = it->producer_key; //std::copy( it->packed_key.begin(), it->packed_key.end(), schedule.producers.back().block_signing_key.data.data() ); + /* max_block_net_usage[n] = it->prefs.max_block_net_usage; target_block_net_usage_pct[n] = it->prefs.target_block_net_usage_pct; max_transaction_net_usage[n] = it->prefs.max_transaction_net_usage; @@ -273,51 +274,23 @@ namespace eosiosystem { max_storage_size[n] = it->prefs.max_storage_size; storage_reserve_ratio[n] = it->prefs.storage_reserve_ratio; percent_of_max_inflation_rate[n] = it->prefs.percent_of_max_inflation_rate; + */ ++n; } } if ( n == 0 ) { //no active producers with votes > 0 return; } - if ( 1 < n ) { - std::sort( max_block_net_usage.begin(), max_block_net_usage.begin()+n ); - std::sort( target_block_net_usage_pct.begin(), target_block_net_usage_pct.begin()+n ); - std::sort( max_transaction_net_usage.begin(), max_transaction_net_usage.begin()+n ); - std::sort( base_per_transaction_net_usage.begin(), base_per_transaction_net_usage.begin()+n ); - std::sort( context_free_discount_net_usage_num.begin(), context_free_discount_net_usage_num.begin()+n ); - std::sort( context_free_discount_net_usage_den.begin(), context_free_discount_net_usage_den.begin()+n ); - - std::sort( max_block_cpu_usage.begin(), max_block_cpu_usage.begin()+n ); - std::sort( target_block_cpu_usage_pct.begin(), target_block_cpu_usage_pct.begin()+n ); - std::sort( max_transaction_cpu_usage.begin(), max_transaction_cpu_usage.begin()+n ); - std::sort( base_per_transaction_cpu_usage.begin(), base_per_transaction_cpu_usage.begin()+n ); - std::sort( base_per_action_cpu_usage.begin(), base_per_action_cpu_usage.begin()+n ); - std::sort( base_setcode_cpu_usage.begin(), base_setcode_cpu_usage.begin()+n ); - std::sort( per_signature_cpu_usage.begin(), per_signature_cpu_usage.begin()+n ); - std::sort( context_free_discount_cpu_usage_num.begin(), context_free_discount_cpu_usage_num.begin()+n ); - std::sort( context_free_discount_cpu_usage_den.begin(), context_free_discount_cpu_usage_den.begin()+n ); - - std::sort( max_transaction_lifetime.begin(), max_transaction_lifetime.begin()+n ); - std::sort( deferred_trx_expiration_window.begin(), deferred_trx_expiration_window.begin()+n ); - std::sort( max_transaction_delay.begin(), max_transaction_delay.begin()+n ); - std::sort( max_inline_action_size.begin(), max_inline_action_size.begin()+n ); - std::sort( max_inline_action_depth.begin(), max_inline_action_depth.begin()+n ); - std::sort( max_authority_depth.begin(), max_authority_depth.begin()+n ); - std::sort( max_generated_transaction_count.begin(), max_generated_transaction_count.begin()+n ); - - std::sort( max_storage_size.begin(), max_storage_size.begin()+n ); - std::sort( storage_reserve_ratio.begin(), storage_reserve_ratio.begin()+n ); - std::sort( percent_of_max_inflation_rate.begin(), percent_of_max_inflation_rate.begin()+n ); - } // should use producer_schedule_type from libraries/chain/include/eosio/chain/producer_schedule.hpp bytes packed_schedule = pack(schedule); set_active_producers( packed_schedule.data(), packed_schedule.size() ); - size_t median = n/2; + // size_t median = n/2; global_state_singleton gs( _self, _self ); auto parameters = gs.exists() ? gs.get() : get_default_parameters(); + /* parameters.max_block_net_usage = max_block_net_usage[median]; parameters.target_block_net_usage_pct = target_block_net_usage_pct[median]; parameters.max_transaction_net_usage = max_transaction_net_usage[median]; @@ -346,6 +319,7 @@ namespace eosiosystem { parameters.max_storage_size = max_storage_size[median]; parameters.storage_reserve_ratio = storage_reserve_ratio[median]; parameters.percent_of_max_inflation_rate = percent_of_max_inflation_rate[median]; + */ // not voted on parameters.first_block_time_in_cycle = cycle_time; diff --git a/contracts/eosio.system/voting.hpp b/contracts/eosio.system/voting.hpp index ed521d8352a4b199025721ad5832e1839804f953..acd7fc183b11d6d978d5e039dbca26edd0a12609 100644 --- a/contracts/eosio.system/voting.hpp +++ b/contracts/eosio.system/voting.hpp @@ -45,7 +45,7 @@ namespace eosiosystem { struct producer_info { account_name owner; uint128_t total_votes = 0; - eosio_parameters prefs; + // eosio_parameters prefs; eosio::bytes packed_key; /// a packed public key object system_token_type per_block_payments; time last_rewards_claim = 0; @@ -56,7 +56,7 @@ namespace eosiosystem { uint128_t by_votes()const { return total_votes; } bool active() const { return packed_key.size() == sizeof(public_key); } - EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(prefs)(packed_key) + EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(packed_key) (per_block_payments)(last_rewards_claim) (time_became_active)(last_produced_block_time) ) }; @@ -86,60 +86,6 @@ namespace eosiosystem { typedef eosio::multi_index< N(voters), voter_info> voters_table; - ACTION( SystemAccount, regproducer ) { - account_name producer; - bytes producer_key; - eosio_parameters prefs; - - EOSLIB_SERIALIZE( regproducer, (producer)(producer_key)(prefs) ) - }; - - /** - * This method will create a producer_config and producer_info object for 'producer' - * - * @pre producer is not already registered - * @pre producer to register is an account - * @pre authority of producer to register - * - */ - static void on( const regproducer& reg ) { - require_auth( reg.producer ); - - producers_table producers_tbl( SystemAccount, SystemAccount ); - auto prod = producers_tbl.find( reg.producer ); - - if ( prod != producers_tbl.end() ) { - producers_tbl.modify( prod, reg.producer, [&]( producer_info& info ){ - info.prefs = reg.prefs; - info.packed_key = reg.producer_key; - }); - } else { - producers_tbl.emplace( reg.producer, [&]( producer_info& info ){ - info.owner = reg.producer; - info.total_votes = 0; - info.prefs = reg.prefs; - info.packed_key = reg.producer_key; - }); - } - } - - ACTION( SystemAccount, unregprod ) { - account_name producer; - - EOSLIB_SERIALIZE( unregprod, (producer) ) - }; - - static void on( const unregprod& unreg ) { - require_auth( unreg.producer ); - - producers_table producers_tbl( SystemAccount, SystemAccount ); - auto prod = producers_tbl.find( unreg.producer ); - eosio_assert( prod != producers_tbl.end(), "producer not found" ); - - producers_tbl.modify( prod, 0, [&]( producer_info& info ){ - info.packed_key.clear(); - }); - } static void increase_voting_power( account_name acnt, system_token_type amount ) { voters_table voters_tbl( SystemAccount, SystemAccount ); diff --git a/contracts/eosiolib/fixed_key.hpp b/contracts/eosiolib/fixed_key.hpp index 99fc64cf40b7b429adcc2bbdaf6ae2e6c41b21ec..a011f2f743fb2273d1dc97afa402d67515986006 100644 --- a/contracts/eosiolib/fixed_key.hpp +++ b/contracts/eosiolib/fixed_key.hpp @@ -203,7 +203,7 @@ namespace eosio { * @return if c1 > c2, return true, otherwise false */ template - bool operator>(const fixed_key &c1, const fixed_key &c2) { + bool operator>(const fixed_key& c1, const fixed_key& c2) { return c1._data > c2._data; } diff --git a/contracts/eosiolib/public_key.hpp b/contracts/eosiolib/public_key.hpp index b7781a98943c0bd7b0ccd980f34466d2c632aeca..414d535bedd750b2b9aba83b8e449e60819b01f1 100644 --- a/contracts/eosiolib/public_key.hpp +++ b/contracts/eosiolib/public_key.hpp @@ -7,6 +7,12 @@ namespace eosio { unsigned_int type; std::array data; + friend bool operator == ( const public_key& a, const public_key& b ) { + return std::tie(a.type,a.data) == std::tie(b.type,b.data); + } + friend bool operator != ( const public_key& a, const public_key& b ) { + return std::tie(a.type,a.data) != std::tie(b.type,b.data); + } EOSLIB_SERIALIZE( public_key, (type)(data) ) }; } diff --git a/libraries/chain/abi_serializer.cpp b/libraries/chain/abi_serializer.cpp index 0a8704985a1903de68cfe73b82cb251479692238..1597ba3a43feeadba2e45e6d0bdcc88a27892b0d 100644 --- a/libraries/chain/abi_serializer.cpp +++ b/libraries/chain/abi_serializer.cpp @@ -317,7 +317,6 @@ namespace eosio { namespace chain { uint32_t i = 0; if (va.size() > 0) { for( const auto& field : st.fields ) { - idump((field.type)(va[i])(i)); if( va.size() > i ) variant_to_binary(field.type, va[i], ds); else diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index af23a7947517cb40b34a429c33767032238d7825..7f131426cbea78a6542794d95a54220509231e42 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -1029,11 +1029,14 @@ bool controller::push_next_unapplied_transaction( fc::time_point deadline ) { } transaction_trace_ptr controller::sync_push( const transaction_metadata_ptr& trx, time_point deadline ) { - FC_ASSERT( deadline != fc::time_point() ); - transaction_trace_ptr trace; - trx->on_result = [&]( const transaction_trace_ptr& t ){ trace = t; }; - my->push_transaction( trx, deadline ); - return trace; + auto start = fc::time_point::now(); + try { + FC_ASSERT( deadline != fc::time_point() ); + transaction_trace_ptr trace; + trx->on_result = [&]( const transaction_trace_ptr& t ){ trace = t; }; + my->push_transaction( trx, deadline ); + return trace; + } FC_CAPTURE_AND_RETHROW( (fc::time_point::now()-start)(deadline) ) } bool controller::push_next_scheduled_transaction( fc::time_point deadline ) { diff --git a/libraries/chain/eosio_contract.cpp b/libraries/chain/eosio_contract.cpp index 6ac5da294064c52daf40c17277770864ed793a20..eebb41947cf560ad7d30907250017243913929d1 100644 --- a/libraries/chain/eosio_contract.cpp +++ b/libraries/chain/eosio_contract.cpp @@ -130,6 +130,7 @@ void apply_eosio_setcode(apply_context& context) { int64_t old_size = (int64_t)account.code.size() * config::setcode_ram_bytes_multiplier; int64_t new_size = code_size * config::setcode_ram_bytes_multiplier; + context.checktime( act.code.size() * 20 ); FC_ASSERT( account.code_version != code_id, "contract is already running this version of code" ); // wlog( "set code: ${size}", ("size",act.code.size())); @@ -174,6 +175,8 @@ void apply_eosio_setabi(apply_context& context) { int64_t old_size = (int64_t)account.abi.size(); int64_t new_size = (int64_t)fc::raw::pack_size(act.abi); + context.checktime( new_size * 2 ); + db.modify( account, [&]( auto& a ) { a.set_abi( act.abi ); }); @@ -187,7 +190,6 @@ void apply_eosio_setabi(apply_context& context) { } void apply_eosio_updateauth(apply_context& context) { -// context.require_write_lock( config::eosio_auth_scope ); auto update = context.act.data_as(); context.require_authorization(update.account); // only here to mark the single authority on this action as used @@ -217,6 +219,9 @@ void apply_eosio_updateauth(apply_context& context) { validate_authority_precondition(context, update.auth); + + context.checktime( 5000 ); + auto permission = authorization.find_permission({update.account, update.permission}); // If a parent_id of 0 is going to be used to indicate the absence of a parent, then we need to make sure that the chain @@ -291,6 +296,8 @@ void apply_eosio_deleteauth(apply_context& context) { -(int64_t)(config::billable_size_v + permission.auth.get_billable_size()) ); db.remove(permission); + + context.checktime( 3000 ); } void apply_eosio_linkauth(apply_context& context) { @@ -338,6 +345,8 @@ void apply_eosio_linkauth(apply_context& context) { (int64_t)(config::billable_size_v) ); } + + context.checktime( 3000 ); } FC_CAPTURE_AND_RETHROW((requirement)) } @@ -359,6 +368,7 @@ void apply_eosio_unlinkauth(apply_context& context) { ); db.remove(*link); + context.checktime( 3000 ); } void apply_eosio_onerror(apply_context& context) { @@ -483,6 +493,8 @@ void apply_eosio_postrecovery(apply_context& context) { } context.console_append_formatted("Recovery Started for account ${account} : ${memo}\n", mutable_variant_object()("account", account)("memo", recover_act.memo)); + + context.checktime( 3000 ); } static void remove_pending_recovery(apply_context& context, const account_name& account) { @@ -514,6 +526,8 @@ void apply_eosio_passrecovery(apply_context& context) { remove_pending_recovery(context, account); context.console_append_formatted("Account ${account} successfully recovered!\n", mutable_variant_object()("account", account)); + + context.checktime( 3000 ); } void apply_eosio_vetorecovery(apply_context& context) { @@ -530,6 +544,8 @@ void apply_eosio_vetorecovery(apply_context& context) { remove_pending_recovery(context, account); context.console_append_formatted("Recovery for account ${account} vetoed!\n", mutable_variant_object()("account", account)); + + context.checktime( 3000 ); } void apply_eosio_canceldelay(apply_context& context) { @@ -552,6 +568,7 @@ void apply_eosio_canceldelay(apply_context& context) { found = true; break; } + context.checktime( 20 ); } if( found ) break; } @@ -559,6 +576,8 @@ void apply_eosio_canceldelay(apply_context& context) { FC_ASSERT (found, "canceling_auth in canceldelay action was not found as authorization in the original delayed transaction"); context.cancel_deferred_transaction(transaction_id_to_sender_id(trx_id), account_name()); + + context.checktime( 1000 ); } } } // namespace eosio::chain diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index 581c304532143b729887e631ecc61471f5965754..2ddb0c98bd68a49ebbb4ac3b7fc2f439e0140170 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -390,7 +390,6 @@ namespace impl { template static void extract( const variant& v, packed_transaction& ptrx, Resolver resolver ) { const variant_object& vo = v.get_object(); - wdump((vo)); EOS_ASSERT(vo.contains("signatures"), packed_transaction_type_exception, "Missing signatures"); EOS_ASSERT(vo.contains("compression"), packed_transaction_type_exception, "Missing compression"); from_variant(vo["signatures"], ptrx.signatures); diff --git a/libraries/chain/include/eosio/chain/account_object.hpp b/libraries/chain/include/eosio/chain/account_object.hpp index 6fa8e0e594e52c2b2b1887644cee5892826b2a96..135de713675b61a25902f4f0ec29f69cd1093597 100644 --- a/libraries/chain/include/eosio/chain/account_object.hpp +++ b/libraries/chain/include/eosio/chain/account_object.hpp @@ -21,7 +21,7 @@ namespace eosio { namespace chain { uint8_t vm_version = 0; bool privileged = false; - time_point_sec last_code_update; + time_point last_code_update; digest_type code_version; block_timestamp_type creation_date; diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index dd939a1b92e88864e4a48740d0a46b947e02b9ff..f82dd45b7b422215acc11e0562675c7f5218cc4b 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -81,7 +81,7 @@ namespace eosio { namespace chain { bool push_next_unapplied_transaction( fc::time_point deadline = fc::time_point::maximum() ); - transaction_trace_ptr sync_push( const transaction_metadata_ptr& trx, fc::time_point deadline = fc::time_point::now() + fc::milliseconds(25) ); + transaction_trace_ptr sync_push( const transaction_metadata_ptr& trx, fc::time_point deadline = fc::time_point::now() + fc::milliseconds(30) ); /** * Attempt to execute a specific transaction in our deferred trx database diff --git a/libraries/chain/resource_limits.cpp b/libraries/chain/resource_limits.cpp index cc65d6eeedbec9b5f92f13d2e28f18ca1dd1a564..a44d409ec26ff97756d537219abfb49e1c8f2f56 100644 --- a/libraries/chain/resource_limits.cpp +++ b/libraries/chain/resource_limits.cpp @@ -296,9 +296,12 @@ int64_t resource_limits_manager::get_account_cpu_limit( const account_name& name return -1; } + auto total_cpu_weight = state.total_cpu_weight; + if( total_cpu_weight == 0 ) total_cpu_weight = 1; + uint128_t consumed_ex = (uint128_t)usage.cpu_usage.consumed * (uint128_t)config::rate_limiting_precision; uint128_t virtual_capacity_ex = (uint128_t)state.virtual_cpu_limit * (uint128_t)config::rate_limiting_precision; - uint128_t usable_capacity_ex = (uint128_t)(virtual_capacity_ex * limits.cpu_weight) / (uint128_t)state.total_cpu_weight; + uint128_t usable_capacity_ex = (uint128_t)(virtual_capacity_ex * limits.cpu_weight) / (uint128_t)total_cpu_weight; if (usable_capacity_ex < consumed_ex) { return 0; @@ -317,7 +320,11 @@ int64_t resource_limits_manager::get_account_net_limit( const account_name& name uint128_t consumed_ex = (uint128_t)usage.net_usage.consumed * (uint128_t)config::rate_limiting_precision; uint128_t virtual_capacity_ex = (uint128_t)state.virtual_net_limit * (uint128_t)config::rate_limiting_precision; - uint128_t usable_capacity_ex = (uint128_t)(virtual_capacity_ex * limits.net_weight) / (uint128_t)state.total_net_weight; + + auto total_net_weight = state.total_net_weight; + if( total_net_weight == 0 ) total_net_weight = 1; + + uint128_t usable_capacity_ex = (uint128_t)(virtual_capacity_ex * limits.net_weight) / (uint128_t)total_net_weight; if (usable_capacity_ex < consumed_ex) { return 0; diff --git a/libraries/chain/transaction_context.cpp b/libraries/chain/transaction_context.cpp index 1a9f7804598b3b18570445c3ffa5cb36d212163b..2c3ff7bf54502c8369e8a74673ad6ba01312f20a 100644 --- a/libraries/chain/transaction_context.cpp +++ b/libraries/chain/transaction_context.cpp @@ -180,6 +180,7 @@ namespace eosio { namespace chain { void transaction_context::check_time()const { if( BOOST_UNLIKELY(fc::time_point::now() > deadline) ) { + wlog( "deadline passed" ); throw checktime_exceeded(); } } diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 70ddf334bec75cec7cfee05661607cfa7c905458..8450644eacb6c8235e67ee5c70969f345d48d70b 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -246,6 +246,7 @@ namespace chain_apis { const string read_only::KEYi64 = "i64"; read_only::get_info_results read_only::get_info(const read_only::get_info_params&) const { + const auto& rm = db.get_resource_limits_manager(); return { eosio::utilities::common::itoh(static_cast(app().version())), db.head_block_num(), @@ -254,6 +255,10 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params db.head_block_id(), db.head_block_time(), db.head_block_producer(), + rm.get_virtual_block_cpu_limit(), + rm.get_virtual_block_net_limit(), + rm.get_block_cpu_limit(), + rm.get_block_net_limit() //std::bitset<64>(db.get_dynamic_global_properties().recent_slots_filled).to_string(), //__builtin_popcountll(db.get_dynamic_global_properties().recent_slots_filled) / 64.0 }; @@ -446,6 +451,13 @@ read_only::get_account_results read_only::get_account( const get_account_params& const auto& d = db.db(); const auto& rm = db.get_resource_limits_manager(); rm.get_account_limits( result.account_name, result.ram_quota, result.net_weight, result.cpu_weight ); + + const auto& a = db.get_account(result.account_name); + + result.privileged = a.privileged; + result.last_code_update = a.last_code_update; + result.created = a.creation_date; + result.net_limit = rm.get_account_net_limit( result.account_name ); result.cpu_limit = rm.get_account_cpu_limit( result.account_name ); result.ram_usage = rm.get_account_ram_usage( result.account_name ); diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index 89069970499b66ad043b878a5a805218ea7bd75c..416ad10a817f9daf0cd20a8b7af9290be74c46ee 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -65,6 +65,12 @@ public: chain::block_id_type head_block_id; fc::time_point_sec head_block_time; account_name head_block_producer; + + uint64_t virtual_block_cpu_limit = 0; + uint64_t virtual_block_net_limit = 0; + + uint64_t block_cpu_limit = 0; + uint64_t block_net_limit = 0; //string recent_slots; //double participation_rate = 0; }; @@ -77,6 +83,10 @@ public: struct get_account_results { name account_name; + bool privileged = false; + fc::time_point last_code_update; + fc::time_point created; + int64_t ram_quota = 0; int64_t net_weight = 0; int64_t cpu_weight = 0; @@ -357,7 +367,7 @@ private: FC_REFLECT( eosio::chain_apis::permission, (perm_name)(parent)(required_auth) ) FC_REFLECT(eosio::chain_apis::empty, ) FC_REFLECT(eosio::chain_apis::read_only::get_info_results, - (server_version)(head_block_num)(last_irreversible_block_num)(last_irreversible_block_id)(head_block_id)(head_block_time)(head_block_producer) ) + (server_version)(head_block_num)(last_irreversible_block_num)(last_irreversible_block_id)(head_block_id)(head_block_time)(head_block_producer)(virtual_block_cpu_limit)(virtual_block_net_limit)(block_cpu_limit)(block_net_limit) ) FC_REFLECT(eosio::chain_apis::read_only::get_block_params, (block_num_or_id)) FC_REFLECT( eosio::chain_apis::read_write::push_transaction_results, (transaction_id)(processed) ) @@ -369,7 +379,7 @@ FC_REFLECT( eosio::chain_apis::read_only::get_currency_balance_params, (code)(ac FC_REFLECT( eosio::chain_apis::read_only::get_currency_stats_params, (code)(symbol)); FC_REFLECT( eosio::chain_apis::read_only::get_currency_stats_result, (supply)(max_supply)(issuer)); -FC_REFLECT( eosio::chain_apis::read_only::get_account_results, (account_name)(ram_quota)(net_weight)(cpu_weight)(net_limit)(cpu_limit)(ram_usage)(permissions) ) +FC_REFLECT( eosio::chain_apis::read_only::get_account_results, (account_name)(privileged)(last_code_update)(created)(ram_quota)(net_weight)(cpu_weight)(net_limit)(cpu_limit)(ram_usage)(permissions) ) FC_REFLECT( eosio::chain_apis::read_only::get_code_results, (account_name)(code_hash)(wast)(abi) ) FC_REFLECT( eosio::chain_apis::read_only::get_account_params, (account_name) ) FC_REFLECT( eosio::chain_apis::read_only::get_code_params, (account_name) ) diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index fe2446f1d4013821d3707ac583b28cc5d29d87ce..4a211d60ca718bd6cf2541056418e1c032896520 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -342,13 +342,17 @@ void print_result( const fc::variant& result ) { try { if( soft_except ) { edump((soft_except->to_detail_string())); } + auto hard_except = processed["hard_except"].as>(); + if( hard_except ) { + edump((hard_except->to_detail_string())); + } } else { const auto& actions = processed["action_traces"].get_array(); for( const auto& a : actions ) { print_action_tree( a ); } + wlog( "\rwarning: transaction executed locally, but may not be confirmed by the network yet" ); } - wlog( "\rwarning: transaction executed locally, but may not be confirmed by the network yet" ); } FC_CAPTURE_AND_RETHROW( (result) ) } using std::cout; @@ -399,9 +403,8 @@ chain::action create_action(const vector& authorization, const fc::variant regproducer_variant(const account_name& producer, public_key_type key, - uint64_t max_storage_size, - uint32_t percent_of_max_inflation_rate, - uint32_t storage_reserve_ratio) { + string url) { + /* fc::variant_object params = fc::mutable_variant_object() ("max_block_net_usage", config::default_max_block_net_usage) ("target_block_net_usage_pct", config::default_target_block_net_usage_pct) @@ -428,11 +431,12 @@ fc::variant regproducer_variant(const account_name& producer, ("max_storage_size", max_storage_size) ("percent_of_max_inflation_rate", percent_of_max_inflation_rate) ("storage_reserve_ratio", storage_reserve_ratio); + */ return fc::mutable_variant_object() ("producer", producer) - ("producer_key", fc::raw::pack(key)) - ("prefs", params); + ("producer_key", key) + ("url", url); } chain::action create_transfer(const string& contract, const name& sender, const name& recipient, asset amount, const string& memo ) { @@ -621,17 +625,13 @@ CLI::callback_t old_host_port = [](CLI::results_t) { struct register_producer_subcommand { string producer_str; string producer_key_str; - uint64_t max_storage_size = 10 * 1024 * 1024; - uint32_t percent_of_max_inflation_rate = 0; - uint32_t storage_reserve_ratio = 1000; + string url; register_producer_subcommand(CLI::App* actionRoot) { auto register_producer = actionRoot->add_subcommand("regproducer", localized("Register a new producer")); register_producer->add_option("account", producer_str, localized("The account to register as a producer"))->required(); register_producer->add_option("producer_key", producer_key_str, localized("The producer's public key"))->required(); - register_producer->add_option("max_storage_size", max_storage_size, localized("The max storage size"), true); - register_producer->add_option("percent_of_max_inflation_rate", percent_of_max_inflation_rate, localized("Percent of max inflation rate"), true); - register_producer->add_option("storage_reserve_ratio", storage_reserve_ratio, localized("Storage Reserve Ratio"), true); + register_producer->add_option("url", url, localized("url where info about producer can be found"), true); add_standard_transaction_options(register_producer); @@ -641,7 +641,7 @@ struct register_producer_subcommand { producer_key = public_key_type(producer_key_str); } EOS_RETHROW_EXCEPTIONS(public_key_type_exception, "Invalid producer public key: ${public_key}", ("public_key", producer_key_str)) - auto regprod_var = regproducer_variant(producer_str, producer_key, max_storage_size, percent_of_max_inflation_rate, storage_reserve_ratio); + auto regprod_var = regproducer_variant(producer_str, producer_key, url ); send_actions({create_action({permission_level{producer_str,config::active_name}}, config::system_account_name, N(regproducer), regprod_var)}); }); } @@ -686,19 +686,22 @@ struct vote_producer_proxy_subcommand { struct vote_producers_subcommand { string voter_str; - std::vector producers; + vector producer_names; vote_producers_subcommand(CLI::App* actionRoot) { auto vote_producers = actionRoot->add_subcommand("prods", localized("Vote for one or more producers")); vote_producers->add_option("voter", voter_str, localized("The voting account"))->required(); - vote_producers->add_option("producers", producers, localized("The account(s) to vote for. All options from this position and following will be treated as the producer list."))->required(); + vote_producers->add_option("producers", producer_names, localized("The account(s) to vote for. All options from this position and following will be treated as the producer list."))->required(); add_standard_transaction_options(vote_producers); vote_producers->set_callback([this] { + + std::sort( producer_names.begin(), producer_names.end() ); + fc::variant act_payload = fc::mutable_variant_object() ("voter", voter_str) ("proxy", "") - ("producers", producers); + ("producers", producer_names); send_actions({create_action({permission_level{voter_str,config::active_name}}, config::system_account_name, N(voteproducer), act_payload)}); }); } @@ -727,6 +730,7 @@ struct delegate_bandwidth_subcommand { ("stake_net_quantity", stake_net_amount + " EOS") ("stake_cpu_quantity", stake_cpu_amount + " EOS") ("stake_storage_quantity", stake_storage_amount + " EOS"); + wdump((act_payload)); send_actions({create_action({permission_level{from_str,config::active_name}}, config::system_account_name, N(delegatebw), act_payload)}); }); }