提交 ce1c8799 编写于 作者: A arhag

Merge branch 'slim' of https://github.com/eosio/eos into slim

......@@ -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
......
......@@ -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",
......
......@@ -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
......
......@@ -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<eosio::producer_schedule> 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<account_name>& 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
......
......@@ -7,6 +7,8 @@
#include <eosiolib/action.hpp>
#include <eosiolib/public_key.hpp>
#include <eosiolib/types.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/privileged.h>
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,
......
......@@ -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<public_key>( packed_producer_key );
if ( prod != producers_tbl.end() ) {
producers_tbl.modify( prod, producer, [&]( producer_info& info ){
info.prefs = prefs;
info.packed_key = eosio::pack<public_key>( 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<public_key>( 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<N(prototalvote)>();
/*
std::array<uint64_t, 21> max_block_net_usage;
std::array<uint32_t, 21> target_block_net_usage_pct;
std::array<uint32_t, 21> base_per_transaction_net_usage;
......@@ -233,6 +232,7 @@ namespace eosiosystem {
std::array<uint32_t, 21> max_storage_size;
std::array<uint32_t, 21> percent_of_max_inflation_rate;
std::array<uint32_t, 21> 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<public_key>( 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;
......
......@@ -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 );
......
......@@ -203,7 +203,7 @@ namespace eosio {
* @return if c1 > c2, return true, otherwise false
*/
template<size_t Size>
bool operator>(const fixed_key<Size> &c1, const fixed_key<Size> &c2) {
bool operator>(const fixed_key<Size>& c1, const fixed_key<Size>& c2) {
return c1._data > c2._data;
}
......
......@@ -7,6 +7,12 @@ namespace eosio {
unsigned_int type;
std::array<char,33> 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) )
};
}
......@@ -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
......
......@@ -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 ) {
......
......@@ -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<updateauth>();
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_object> + 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<permission_link_object>)
);
}
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
......@@ -390,7 +390,6 @@ namespace impl {
template<typename Resolver>
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);
......
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
......@@ -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();
}
}
......
......@@ -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<uint32_t>(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 );
......
......@@ -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) )
......
......@@ -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<optional<fc::exception>>();
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<permission_level>& 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<std::string> producers;
vector<eosio::name> 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)});
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册