From 6144a9b97b842a5b25333965b46194d0dfd7eb8f Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 22 May 2018 16:52:54 -0400 Subject: [PATCH] Segregate EOSIO.SYSTEM funds #3291 - all ram trading fees sent from user to eosio.ramfee (also implement 1% fee Fix #3182) - all tokens received for ram sent to eosio.ram - all proceeds from selling ram sent from eosio.ram - all staked tokens sent to eosio.stake - all unstaked tokens sent from eosio.stake - fix build dependency issue with ram_tests --- contracts/eosio.system/delegate_bandwidth.cpp | 27 ++++++++++++++----- externals/binaryen | 2 +- libraries/appbase | 2 +- unittests/CMakeLists.txt | 2 +- unittests/bootseq_tests.cpp | 2 +- unittests/eosio_system_tester.hpp | 2 +- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/contracts/eosio.system/delegate_bandwidth.cpp b/contracts/eosio.system/delegate_bandwidth.cpp index 181f3ca3b..c6600dce4 100644 --- a/contracts/eosio.system/delegate_bandwidth.cpp +++ b/contracts/eosio.system/delegate_bandwidth.cpp @@ -107,24 +107,32 @@ namespace eosiosystem { require_auth( payer ); eosio_assert( quant.amount > 0, "must purchase a positive amount" ); + auto fee = quant; + fee.amount /= 200; /// .5% fee + auto quant_after_fee = quant; + quant_after_fee.amount -= fee.amount; + if( payer != N(eosio) ) { INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)}, - { payer, N(eosio), quant, std::string("buy ram") } ); + { payer, N(eosio.ram), quant_after_fee, std::string("buy ram") } ); } + if( fee.amount > 0 ) { + INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)}, + { payer, N(eosio.ramfee), fee, std::string("ram fee") } ); + } int64_t bytes_out; auto itr = _rammarket.find(S(4,RAMCORE)); _rammarket.modify( itr, 0, [&]( auto& es ) { - bytes_out = es.convert( quant, S(0,RAM) ).amount; + bytes_out = es.convert( quant_after_fee, S(0,RAM) ).amount; }); - eosio_assert( bytes_out > 0, "must reserve a positive amount" ); _gstate.total_ram_bytes_reserved += uint64_t(bytes_out); - _gstate.total_ram_stake += quant.amount; + _gstate.total_ram_stake += quant_after_fee.amount; user_resources_table userres( _self, receiver ); auto res_itr = userres.find( receiver ); @@ -176,7 +184,12 @@ namespace eosiosystem { if( N(eosio) != account ) { INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)}, - { N(eosio), account, asset(tokens_out), std::string("sell ram") } ); + { N(eosio.ram), account, asset(tokens_out), std::string("sell ram") } ); + auto fee = tokens_out.amount / 200; + if( fee > 0 ) { + INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)}, + { account, N(eosio.ramfee), asset(fee), std::string("sell ram fee") } ); + } } } @@ -317,7 +330,7 @@ namespace eosiosystem { auto transfer_amount = net_balance + cpu_balance; if ( asset(0) < transfer_amount ) { INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {from,N(active)}, - { source_stake_from, N(eosio), asset(transfer_amount), std::string("stake bandwidth") } ); + { source_stake_from, N(eosio.stake), asset(transfer_amount), std::string("stake bandwidth") } ); } } @@ -380,7 +393,7 @@ namespace eosiosystem { // consecutive missed blocks. INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)}, - { N(eosio), req->owner, req->net_amount + req->cpu_amount, std::string("unstake") } ); + { N(eosio.stake), req->owner, req->net_amount + req->cpu_amount, std::string("unstake") } ); refunds_tbl.erase( req ); } diff --git a/externals/binaryen b/externals/binaryen index b4b5dc9de..579f3a099 160000 --- a/externals/binaryen +++ b/externals/binaryen @@ -1 +1 @@ -Subproject commit b4b5dc9dee60489c4206af99227524b13f2eb3aa +Subproject commit 579f3a099c286a45f58ea1ffc7bf671c415be0a6 diff --git a/libraries/appbase b/libraries/appbase index 70e23f7eb..50dc015b2 160000 --- a/libraries/appbase +++ b/libraries/appbase @@ -1 +1 @@ -Subproject commit 70e23f7ebbdccb64f9ac11ade9fa41ba78b31b5e +Subproject commit 50dc015b2f0e25c0cd01cf520245da23c0ed446b diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index f82f48562..7eccb70e2 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -27,7 +27,7 @@ target_link_libraries( unit_test eosio_chain chainbase eosio_testing eos_utiliti target_include_directories( unit_test PUBLIC ${CMAKE_BINARY_DIR}/contracts ${CMAKE_CURRENT_BINARY_DIR}/tests/contracts ) target_include_directories( unit_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/wasm_tests ) target_include_directories( unit_test PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include ) -add_dependencies(unit_test asserter test_api test_api_mem test_api_db test_api_multi_index exchange eosio.token proxy identity identity_test stltest infinite eosio.system eosio.token eosio.bios test.inline multi_index_test noop dice eosio.msig payloadless tic_tac_toe) +add_dependencies(unit_test asserter test_api test_api_mem test_api_db test_ram_limit test_api_multi_index exchange eosio.token proxy identity identity_test stltest infinite eosio.system eosio.token eosio.bios test.inline multi_index_test noop dice eosio.msig payloadless tic_tac_toe) #Manually run unit_test for all supported runtimes #To run unit_test with all log from blockchain displayed, put --verbose after --, i.e. unit_test -- --verbose diff --git a/unittests/bootseq_tests.cpp b/unittests/bootseq_tests.cpp index 786c64146..b2b9ea6c4 100644 --- a/unittests/bootseq_tests.cpp +++ b/unittests/bootseq_tests.cpp @@ -182,7 +182,7 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) { try { // Create eosio.msig and eosio.token - create_accounts({N(eosio.msig), N(eosio.token)}); + create_accounts({N(eosio.msig), N(eosio.token), N(eosio.ram), N(eosio.ramfee), N(eosio.stake) }); // Set code for the following accounts: // - eosio (code: eosio.bios) (already set by tester constructor) diff --git a/unittests/eosio_system_tester.hpp b/unittests/eosio_system_tester.hpp index 673af4a6f..e17548042 100644 --- a/unittests/eosio_system_tester.hpp +++ b/unittests/eosio_system_tester.hpp @@ -46,7 +46,7 @@ public: produce_blocks( 2 ); - create_accounts( { N(eosio.token) } ); + create_accounts({N(eosio.msig), N(eosio.token), N(eosio.ram), N(eosio.ramfee), N(eosio.stake) }); produce_blocks( 100 ); -- GitLab