未验证 提交 1e40cc33 编写于 作者: A arhag 提交者: GitHub

Merge pull request #3623 from EOSIO/3621-fix-setparams

Fix setparams actions in eosio.system contract
......@@ -242,16 +242,11 @@
{"name":"max_authority_depth", "type":"uint16"}
]
},{
"name": "eosio_parameters",
"base": "blockchain_parameters",
"fields": [
{"name":"max_ram_size", "type":"uint64"}
]
},{
"name": "eosio_global_state",
"base": "eosio_parameters",
"base": "blockchain_parameters",
"fields": [
{"name":"max_ram_size", "type":"uint64"},
{"name":"total_ram_bytes_reserved", "type":"uint64"},
{"name":"total_ram_stake", "type":"int64"},
{"name":"last_producer_schedule_update", "type":"time_point_sec"},
......@@ -384,7 +379,7 @@
"name": "setparams",
"base": "",
"fields": [
{"name":"params", "type":"eosio_parameters"}
{"name":"params", "type":"blockchain_parameters"}
]
}
],
......@@ -525,12 +520,6 @@
"index_type": "i64",
"key_names" : ["owner"],
"key_types" : ["uint64"]
},{
"name": "totalband",
"type": "total_resources",
"index_type": "i64",
"key_names" : ["owner"],
"key_types" : ["uint64"]
},{
"name": "delband",
"type": "delegated_bandwidth",
......
......@@ -73,6 +73,13 @@ namespace eosiosystem {
_global.set( _gstate, _self );
}
void system_contract::setparams( const eosio::blockchain_parameters& params ) {
require_auth( N(eosio) );
(eosio::blockchain_parameters&)(_gstate) = params;
eosio_assert( 3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3" );
set_blockchain_parameters( params );
}
void system_contract::setpriv( account_name account, uint8_t ispriv ) {
require_auth( _self );
set_privileged( account, ispriv );
......@@ -165,30 +172,18 @@ namespace eosiosystem {
set_resource_limits( newact, 0, 0, 0 );
}
void system_contract::setparams( const eosio_parameters& params ) {
require_auth( N(eosio) );
(eosiosystem::eosio_parameters&)(_gstate) = params;
eosio_assert( 3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3" );
set_blockchain_parameters( params );
}
} /// eosio.system
EOSIO_ABI( eosiosystem::system_contract,
(setram)
// delegate_bandwith.cpp
(delegatebw)(undelegatebw)(refund)
(buyram)(buyrambytes)(sellram)
// native.hpp (newaccount definition is actually in eosio.system.cpp)
(newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(canceldelay)(onerror)
// eosio.system.cpp
(setram)(setparams)(setpriv)(bidname)
// delegate_bandwidth.cpp
(buyrambytes)(buyram)(sellram)(delegatebw)(undelegatebw)(refund)
// voting.cpp
(regproducer)(unregprod)(voteproducer)(regproxy)
// producer_pay.cpp
(regproxy)(regproducer)(unregprod)(voteproducer)
(claimrewards)
// native.hpp
(onblock)
(newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(postrecovery)(passrecovery)(vetorecovery)(onerror)(canceldelay)
//this file
(bidname)
(setpriv)
(setparams)
(onblock)(claimrewards)
)
......@@ -20,13 +20,6 @@ namespace eosiosystem {
using eosio::const_mem_fun;
using eosio::block_timestamp;
struct eosio_parameters : eosio::blockchain_parameters {
uint64_t max_ram_size = 64ll*1024 * 1024 * 1024;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE_DERIVED( eosio_parameters, eosio::blockchain_parameters, (max_ram_size) )
};
struct name_bid {
account_name newname;
account_name high_bidder;
......@@ -42,11 +35,10 @@ namespace eosiosystem {
> name_bid_table;
struct eosio_global_state : eosio_parameters {
struct eosio_global_state : eosio::blockchain_parameters {
uint64_t free_ram()const { return max_ram_size - total_ram_bytes_reserved; }
uint64_t max_ram_size = 64ll*1024 * 1024 * 1024;
uint64_t total_ram_bytes_reserved = 0;
int64_t total_ram_stake = 0;
......@@ -64,7 +56,8 @@ namespace eosiosystem {
block_timestamp last_name_close;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE_DERIVED( eosio_global_state, eosio_parameters, (total_ram_bytes_reserved)(total_ram_stake)
EOSLIB_SERIALIZE_DERIVED( eosio_global_state, eosio::blockchain_parameters,
(max_ram_size)(total_ram_bytes_reserved)(total_ram_stake)
(last_producer_schedule_update)(last_pervote_bucket_fill)
(pervote_bucket)(perblock_bucket)(savings)(total_unpaid_blocks)(total_activated_stake)(thresh_activated_stake_time)
(last_producer_schedule_id)(last_producer_schedule_size)(total_producer_vote_weight)(last_name_close) )
......@@ -157,7 +150,7 @@ namespace eosiosystem {
// functions defined in delegate_bandwidth.cpp
/**
* Stakes SYS from the balance of 'from' for the benfit of 'receiver'.
* Stakes SYS from the balance of 'from' for the benfit of 'receiver'.
* If transfer == true, then 'receiver' can unstake to their account
* Else 'from' can unstake at any time.
*/
......@@ -171,7 +164,7 @@ namespace eosiosystem {
* left to delegate.
*
* This will cause an immediate reduction in net/cpu bandwidth of the
* receiver.
* receiver.
*
* A transaction is scheduled to send the tokens back to 'from' after
* the staking period has passed. If existing transaction is scheduled, it
......@@ -217,7 +210,7 @@ namespace eosiosystem {
void regproxy( const account_name proxy, bool isproxy );
void setparams( const eosio_parameters& params );
void setparams( const eosio::blockchain_parameters& params );
// functions defined in producer_pay.cpp
void claimrewards( const account_name& owner );
......
......@@ -79,7 +79,7 @@ namespace eosiosystem {
*
* 2. new accounts must stake a minimal number of tokens (as set in system parameters)
* therefore, this method will execute an inline buyram from receiver for newacnt in
* an amount equal to the current new account creation fee.
* an amount equal to the current new account creation fee.
*/
void newaccount( account_name creator,
account_name newact
......@@ -104,18 +104,9 @@ namespace eosiosystem {
account_name code,
action_name type*/ ) {}
void postrecovery( /*account_name account,
const authority& data,
const std::string& memo*/ ) {}
void passrecovery( /*account_name account*/ ) {}
void vetorecovery( /*account_name account*/ ) {}
void onerror( /*const bytes&*/ ) {}
void canceldelay( /*permission_level canceling_auth, transaction_id_type trx_id*/ ) {}
void onerror( /*const bytes&*/ ) {}
};
}
......@@ -10,12 +10,6 @@
using namespace eosio_system;
struct eosio_parameters : eosio::chain::chain_config {
uint64_t max_ram_size;
};
FC_REFLECT_DERIVED(eosio_parameters, (eosio::chain::chain_config), (max_ram_size));
BOOST_AUTO_TEST_SUITE(eosio_system_tests)
BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
......@@ -32,7 +26,7 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
const asset initial_ramfee_balance = get_balance(N(eosio.ramfee));
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_from_string("200.0000") ) );
BOOST_REQUIRE_EQUAL( core_from_string("800.0000"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( initial_ram_balance + core_from_string("199.0000"), get_balance(N(eosio.ram)) );
BOOST_REQUIRE_EQUAL( initial_ram_balance + core_from_string("199.0000"), get_balance(N(eosio.ram)) );
BOOST_REQUIRE_EQUAL( initial_ramfee_balance + core_from_string("1.0000"), get_balance(N(eosio.ramfee)) );
total = get_total_stake( "alice1111111" );
......@@ -1494,7 +1488,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
const int64_t from_pervote_bucket = int64_t( vote_shares[prod_index] * expected_pervote_bucket);
BOOST_REQUIRE( 1 >= abs(int32_t(initial_tot_unpaid_blocks - tot_unpaid_blocks) - int32_t(initial_unpaid_blocks - unpaid_blocks)) );
if (from_pervote_bucket >= 100 * 10000) {
BOOST_REQUIRE( within_one( from_perblock_bucket + from_pervote_bucket, balance.get_amount() - initial_balance.get_amount() ) );
BOOST_REQUIRE( within_one( expected_pervote_bucket - from_pervote_bucket, pervote_bucket ) );
......@@ -1504,7 +1498,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
BOOST_REQUIRE( within_one( expected_pervote_bucket, vpay_balance.get_amount() ) );
BOOST_REQUIRE( within_one( perblock_bucket, bpay_balance.get_amount() ) );
}
produce_blocks(5);
BOOST_REQUIRE_EQUAL(wasm_assert_msg("already claimed rewards within past day"),
......@@ -2560,9 +2554,8 @@ BOOST_FIXTURE_TEST_CASE( setparams, eosio_system_tester ) try {
prod_perms.push_back( { name(x), config::active_name } );
}
eosio_parameters params;
(eosio::chain::chain_config&)params = control->get_global_properties().configuration;
params.max_ram_size = 65ll*1024 * 1024 * 1024;
eosio::chain::chain_config params;
params = control->get_global_properties().configuration;
//change some values
params.max_block_net_usage += 10;
params.max_transaction_lifetime += 1;
......@@ -2646,7 +2639,7 @@ BOOST_FIXTURE_TEST_CASE( setram_effect, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( success(), buyram( name_a, name_a, core_from_string("300.0000") ) );
BOOST_REQUIRE_EQUAL( core_from_string("700.0000"), get_balance(name_a) );
const uint64_t bought_bytes_a = get_total_stake(name_a)["ram_bytes"].as_uint64() - init_bytes_a;
// after buying and selling balance should be 700 + 300 * 0.995 * 0.995 = 997.0075
BOOST_REQUIRE_EQUAL( success(), sellram(name_a, bought_bytes_a ) );
BOOST_REQUIRE_EQUAL( core_from_string("997.0075"), get_balance(name_a) );
......@@ -2661,13 +2654,13 @@ BOOST_FIXTURE_TEST_CASE( setram_effect, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( success(), buyram( name_b, name_b, core_from_string("300.0000") ) );
BOOST_REQUIRE_EQUAL( core_from_string("700.0000"), get_balance(name_b) );
const uint64_t bought_bytes_b = get_total_stake(name_b)["ram_bytes"].as_uint64() - init_bytes_b;
// increase max_ram_size, ram bought by name_b loses part of its value
// increase max_ram_size, ram bought by name_b loses part of its value
BOOST_REQUIRE_EQUAL( wasm_assert_msg("ram may only be increased"),
push_action(config::system_account_name, N(setram), mvo()("max_ram_size", 64ll*1024 * 1024 * 1024)) );
BOOST_REQUIRE_EQUAL( success(),
BOOST_REQUIRE_EQUAL( success(),
push_action(config::system_account_name, N(setram), mvo()("max_ram_size", 80ll*1024 * 1024 * 1024)) );
BOOST_REQUIRE_EQUAL( success(), sellram(name_b, bought_bytes_b ) );
BOOST_REQUIRE( core_from_string("900.0000") < get_balance(name_b) );
BOOST_REQUIRE( core_from_string("950.0000") > get_balance(name_b) );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册