Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 1404de9

Browse files
committed
Added API for setting resource limits from wasm
- added api to update producers from wasm - removed staked_balance objects and other deprecated code
1 parent 607267a commit 1404de9

14 files changed

+65
-343
lines changed

libraries/chain/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ add_library( eosio_chain
2222
chain_controller.cpp
2323

2424
contracts/eosio_contract.cpp
25-
contracts/producer_objects.cpp
26-
contracts/staked_balance_objects.cpp
2725
contracts/chain_initializer.cpp
2826
contracts/genesis_state.cpp
2927
contracts/abi_serializer.cpp

libraries/chain/chain_controller.cpp

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
#include <eosio/chain/chain_controller.hpp>
7-
#include <eosio/chain/contracts/staked_balance_objects.hpp>
87

98
#include <eosio/chain/block_summary_object.hpp>
109
#include <eosio/chain/global_property_object.hpp>
@@ -16,7 +15,6 @@
1615
#include <eosio/chain/permission_link_object.hpp>
1716
#include <eosio/chain/authority_checker.hpp>
1817
#include <eosio/chain/contracts/chain_initializer.hpp>
19-
#include <eosio/chain/contracts/producer_objects.hpp>
2018
#include <eosio/chain/scope_sequence_object.hpp>
2119
#include <eosio/chain/merkle.hpp>
2220

@@ -918,28 +916,8 @@ void chain_controller::create_block_summary(const signed_block& next_block) {
918916
* block_signing_key is null.
919917
*/
920918
producer_schedule_type chain_controller::_calculate_producer_schedule()const {
919+
producer_schedule_type schedule = get_global_properties().new_active_producers;
921920

922-
return get_global_properties().active_producers;
923-
924-
//const auto& producers_by_vote = _db.get_index<contracts::producer_votes_multi_index,contracts::by_votes>();
925-
//auto itr = producers_by_vote.begin();
926-
// FC_ASSERT( itr != producers_by_vote.end() );
927-
928-
producer_schedule_type schedule;
929-
uint32_t count = 0;
930-
wdump((schedule.producers));
931-
/*
932-
while( itr != producers_by_vote.end() && count < schedule.producers.size() ) {
933-
ilog( "." );
934-
schedule.producers[count].producer_name = itr->owner_name;
935-
schedule.producers[count].block_signing_key = get_producer(itr->owner_name).signing_key;
936-
++itr;
937-
if( schedule.producers[count].block_signing_key != public_key_type() ) {
938-
++count;
939-
}
940-
}
941-
*/
942-
ilog( "." );
943921
const auto& hps = _head_producer_schedule();
944922
schedule.version = hps.version;
945923
if( hps != schedule )
@@ -1087,6 +1065,7 @@ void chain_controller::_initialize_chain(contracts::chain_initializer& starter)
10871065
const auto& gp = _db.create<global_property_object>([&starter](global_property_object& p) {
10881066
p.configuration = starter.get_chain_start_configuration();
10891067
p.active_producers = starter.get_chain_start_producers();
1068+
p.new_active_producers = starter.get_chain_start_producers();
10901069
wdump((starter.get_chain_start_producers()));
10911070
});
10921071

@@ -1590,38 +1569,33 @@ void chain_controller::update_usage( transaction_metadata& meta, uint32_t act_us
15901569

15911570
auto head_time = head_block_time();
15921571
for( const auto& authaccnt : authorizing_accounts ) {
1572+
15931573
const auto& buo = _db.get<bandwidth_usage_object,by_owner>( authaccnt.first );
15941574
_db.modify( buo, [&]( auto& bu ){
15951575
bu.bytes.add_usage( trx_size, head_time );
15961576
bu.acts.add_usage( act_usage, head_time );
15971577
});
1598-
const auto& sbo = _db.get<contracts::staked_balance_object, contracts::by_owner_name>(authaccnt.first);
1599-
// TODO enable this after fixing divide by 0 with virtual_net_bandwidth and total_staked_tokens
1600-
/// note: buo.bytes.value is in ubytes and virtual_net_bandwidth is in bytes, so
1601-
// we convert to fixed int uin128_t with 60 bits of precision, divide by rate limiting precision
1602-
// then divide by virtual max_block_size which gives us % of virtual max block size in fixed width
16031578

16041579
uint128_t used_ubytes = buo.bytes.value;
16051580
uint128_t used_uacts = buo.acts.value;
16061581
uint128_t virtual_max_ubytes = dgpo.virtual_net_bandwidth * config::rate_limiting_precision;
16071582
uint128_t virtual_max_uacts = dgpo.virtual_act_bandwidth * config::rate_limiting_precision;
1608-
uint64_t user_stake = sbo.staked_balance;
16091583

16101584
if( !(_skip_flags & genesis_setup) ) {
1611-
FC_ASSERT( (used_ubytes * dgpo.total_staked_tokens) <= (user_stake * virtual_max_ubytes), "authorizing account '${n}' has insufficient net bandwidth for this transaction",
1585+
FC_ASSERT( (used_ubytes * dgpo.total_net_weight) <= (buo.net_weight * virtual_max_ubytes), "authorizing account '${n}' has insufficient net bandwidth for this transaction",
16121586
("n",name(authaccnt.first))
16131587
("used_bytes",double(used_ubytes)/1000000.)
1614-
("user_stake",user_stake)
1588+
("user_net_weight",buo.net_weight)
16151589
("virtual_max_bytes", double(virtual_max_ubytes)/1000000. )
1616-
("total_staked_tokens", dgpo.total_staked_tokens)
1590+
("total_net_weight", dgpo.total_net_weight)
16171591
);
1618-
FC_ASSERT( (used_uacts * dgpo.total_staked_tokens) <= (user_stake * virtual_max_uacts), "authorizing account '${n}' has insufficient compute bandwidth for this transaction",
1592+
FC_ASSERT( (used_uacts * dgpo.total_cpu_weight) <= (buo.cpu_weight* virtual_max_uacts), "authorizing account '${n}' has insufficient compute bandwidth for this transaction",
16191593
("n",name(authaccnt.first))
16201594
("used_acts",double(used_uacts)/1000000.)
1621-
("user_stake",user_stake)
1595+
("user_cpu_weight",buo.cpu_weight)
16221596
("virtual_max_uacts", double(virtual_max_uacts)/1000000. )
1623-
("total_staked_tokens", dgpo.total_staked_tokens)
1624-
);
1597+
("total_cpu_tokens", dgpo.total_cpu_weight)
1598+
);
16251599
}
16261600

16271601
// for any transaction not sent by code, update the affirmative last time a given permission was used

libraries/chain/contracts/chain_initializer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @copyright defined in eos/LICENSE.txt
44
*/
55
#include <eosio/chain/contracts/chain_initializer.hpp>
6-
#include <eosio/chain/contracts/objects.hpp>
76
#include <eosio/chain/contracts/eos_contract.hpp>
87
#include <eosio/chain/contracts/types.hpp>
98

@@ -31,9 +30,6 @@ producer_schedule_type chain_initializer::get_chain_start_producers() {
3130
}
3231

3332
void chain_initializer::register_types(chain_controller& chain, chainbase::database& db) {
34-
// Install the native contract's indexes; we can't do anything until our objects are recognized
35-
db.add_index<staked_balance_multi_index>();
36-
db.add_index<producer_votes_multi_index>();
3733

3834
#define SET_APP_HANDLER( contract, scope, action, nspace ) \
3935
chain._set_apply_handler( #contract, #scope, #action, &BOOST_PP_CAT(contracts::apply_, BOOST_PP_CAT(contract, BOOST_PP_CAT(_,action) ) ) )
@@ -223,7 +219,12 @@ std::vector<action> chain_initializer::prepare_database( chain_controller& chain
223219
p.auth.threshold = 1;
224220
p.auth.keys.push_back( key_weight{ .key = genesis.initial_key, .weight = 1 } );
225221
});
226-
db.create<bandwidth_usage_object>([&](auto& sb) { sb.owner = name; });
222+
db.create<bandwidth_usage_object>([&](auto& sb) {
223+
sb.owner = name;
224+
sb.net_weight = -1;
225+
sb.cpu_weight = -1;
226+
sb.db_reserved_capacity = -1;
227+
});
227228

228229
db.create<producer_object>( [&]( auto& pro ) {
229230
pro.owner = config::system_account_name;

libraries/chain/contracts/eosio_contract.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <eosio/chain/permission_object.hpp>
1616
#include <eosio/chain/permission_link_object.hpp>
1717
#include <eosio/chain/global_property_object.hpp>
18-
#include <eosio/chain/contracts/staked_balance_objects.hpp>
19-
#include <eosio/chain/contracts/producer_objects.hpp>
2018
#include <eosio/chain/contracts/types.hpp>
2119
#include <eosio/chain/producer_object.hpp>
2220

libraries/chain/contracts/producer_objects.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

libraries/chain/contracts/staked_balance_objects.cpp

Lines changed: 0 additions & 62 deletions
This file was deleted.

libraries/chain/include/eosio/chain/account_object.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace eosio { namespace chain {
1919
account_name name;
2020
uint8_t vm_type = 0;
2121
uint8_t vm_version = 0;
22+
bool privileged = false;
23+
bool frozen = false;
2224
digest_type code_version;
2325
block_timestamp_type creation_date;
2426

libraries/chain/include/eosio/chain/contracts/objects.hpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

libraries/chain/include/eosio/chain/contracts/producer_objects.hpp

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)