diff --git a/contracts/eosio.msig/eosio.msig.abi b/contracts/eosio.msig/eosio.msig.abi index 0c690f88670b24031379145e98ff39fcba0f6a0a..7a500522b9b1c2ec93aa8f346bcecdda6a6e198c 100644 --- a/contracts/eosio.msig/eosio.msig.abi +++ b/contracts/eosio.msig/eosio.msig.abi @@ -31,7 +31,7 @@ {"name": "ref_block_num", "type": "uint16"}, {"name": "ref_block_prefix", "type": "uint32"}, {"name": "max_net_usage_words", "type": "varuint32"}, - {"name": "max_kcpu_usage", "type": "varuint32"}, + {"name": "max_cpu_usage_ms", "type": "uint8"}, {"name": "delay_sec", "type": "varuint32"} ] },{ diff --git a/contracts/eosiolib/transaction.hpp b/contracts/eosiolib/transaction.hpp index 731c897094287268ae31e24f8df889eaebddb3a9..e80aca4d82a211ddc45a780544b7402fe7ce92bb 100644 --- a/contracts/eosiolib/transaction.hpp +++ b/contracts/eosiolib/transaction.hpp @@ -32,10 +32,10 @@ namespace eosio { uint16_t ref_block_num; uint32_t ref_block_prefix; unsigned_int net_usage_words = 0UL; /// number of 8 byte words this transaction can serialize into after compressions - unsigned_int kcpu_usage = 0UL; /// number of CPU usage units to bill transaction for + uint8_t max_cpu_usage_ms = 0UL; /// number of CPU usage units to bill transaction for unsigned_int delay_sec = 0UL; /// number of CPU usage units to bill transaction for - EOSLIB_SERIALIZE( transaction_header, (expiration)(ref_block_num)(ref_block_prefix)(net_usage_words)(kcpu_usage)(delay_sec) ) + EOSLIB_SERIALIZE( transaction_header, (expiration)(ref_block_num)(ref_block_prefix)(net_usage_words)(max_cpu_usage_ms)(delay_sec) ) }; class transaction : public transaction_header { diff --git a/libraries/chain/apply_context.cpp b/libraries/chain/apply_context.cpp index 4f845b272a11035522e10c0bc076a42954af8f98..49a7249aac61d657c745d96b1ab716714ccb455f 100644 --- a/libraries/chain/apply_context.cpp +++ b/libraries/chain/apply_context.cpp @@ -477,7 +477,6 @@ void apply_context::db_update_i64( int iterator, account_name payer, const char* } db.modify( obj, [&]( auto& o ) { - o.value.resize( 0 ); o.value.resize( buffer_size ); memcpy( o.value.data(), buffer, buffer_size ); o.payer = payer; diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index 5be85682a5a70536162415567687b27cfb934b86..c85fe4502a0eb591b8bfe0a5b18ae0d4564899ae 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -3,34 +3,6 @@ namespace eosio { namespace chain { -#if 0 - /** - * Perform context free validation of transaction state - */ - void validate_transaction( const transaction& trx ) { - EOS_ASSERT( !trx.actions.empty(), tx_no_action, "transaction must have at least one action" ); - - // Check for at least one authorization in the context-aware actions - bool has_auth = false; - for( const auto& act : trx.actions ) { - has_auth |= !act.authorization.empty(); - if( has_auth ) break; - } - EOS_ASSERT( has_auth, tx_no_auths, "transaction must have at least one authorization" ); - - // Check that there are no authorizations in any of the context-free actions - for (const auto &act : trx.context_free_actions) { - EOS_ASSERT( act.authorization.empty(), cfa_irrelevant_auth, - "context-free actions cannot require authorization" ); - } - - EOS_ASSERT( trx.max_kcpu_usage.value < UINT32_MAX / 1024UL, transaction_exception, "declared max_kcpu_usage overflows when expanded to max cpu usage" ); - EOS_ASSERT( trx.max_net_usage_words.value < UINT32_MAX / 8UL, transaction_exception, "declared max_net_usage_words overflows when expanded to max net usage" ); - } /// validate_transaction - -#endif - - block_state::block_state( const block_header_state& prev, block_timestamp_type when ) :block_header_state( prev.generate_next( when ) ), block( std::make_shared() ) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index fc7ab5db7414b3132d00e1cd8a760e24e3793a79..32ed292d368be3f10ba9874db076673b7dabf647 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -612,7 +612,6 @@ struct controller_impl { : transaction_receipt::delayed; trace->receipt = push_receipt(trx->packed_trx, s, trace->cpu_usage, trace->net_usage); pending->_pending_block_state->trxs.emplace_back(trx); - unapplied_transactions.erase( trx->signed_id ); } else { transaction_receipt_header r; r.status = transaction_receipt::executed; @@ -629,6 +628,10 @@ struct controller_impl { trx_context.squash(); restore.cancel(); + + if (!implicit) { + unapplied_transactions.erase( trx->signed_id ); + } return trace; } catch (const fc::exception& e) { trace->except = e; @@ -1282,7 +1285,9 @@ vector controller::get_scheduled_transactions() const { const auto& idx = db().get_index(); vector result; - result.reserve(idx.size()); + + static const size_t max_reserve = 64; + result.reserve(std::min(idx.size(), max_reserve)); auto itr = idx.begin(); while( itr != idx.end() && itr->delay_until <= pending_block_time() ) { diff --git a/libraries/chain/eosio_contract_abi.cpp b/libraries/chain/eosio_contract_abi.cpp index 185f1a6a02e2163ea7cd9ed083498b8d41cbd329..185395dd17eabda5bc7ecb47e3f87b399911a643 100644 --- a/libraries/chain/eosio_contract_abi.cpp +++ b/libraries/chain/eosio_contract_abi.cpp @@ -178,7 +178,7 @@ abi_def eosio_contract_abi(const abi_def& eosio_system_abi) {"ref_block_num", "uint16"}, {"ref_block_prefix", "uint32"}, {"max_net_usage_words", "varuint32"}, - {"max_kcpu_usage", "varuint32"}, + {"max_cpu_usage_ms", "uint8"}, {"delay_sec", "varuint32"} } }); diff --git a/libraries/chain/include/eosio/chain/transaction.hpp b/libraries/chain/include/eosio/chain/transaction.hpp index 7e9989f7b224429ec5fd293e3dafb3b30eab0b17..77e4575fb9d86e3454eecbc46fc9ac55a8c3e6d2 100644 --- a/libraries/chain/include/eosio/chain/transaction.hpp +++ b/libraries/chain/include/eosio/chain/transaction.hpp @@ -32,7 +32,7 @@ namespace eosio { namespace chain { uint16_t ref_block_num = 0U; ///< specifies a block num in the last 2^16 blocks. uint32_t ref_block_prefix = 0UL; ///< specifies the lower 32 bits of the blockid at get_ref_blocknum fc::unsigned_int max_net_usage_words = 0UL; /// upper limit on total network bandwidth (in 8 byte words) billed for this transaction - fc::unsigned_int max_kcpu_usage = 0UL; /// upper limit on the total number of kilo CPU usage units billed for this transaction + uint8_t max_cpu_usage_ms = 0UL; /// upper limit on the total number of kilo CPU usage units billed for this transaction fc::unsigned_int delay_sec = 0UL; /// number of seconds to delay this transaction for during which it may be canceled. /** @@ -187,7 +187,7 @@ namespace eosio { namespace chain { } } /// namespace eosio::chain FC_REFLECT( eosio::chain::transaction_header, (expiration)(ref_block_num)(ref_block_prefix) - (max_net_usage_words)(max_kcpu_usage)(delay_sec) ) + (max_net_usage_words)(max_cpu_usage_ms)(delay_sec) ) FC_REFLECT_DERIVED( eosio::chain::transaction, (eosio::chain::transaction_header), (context_free_actions)(actions)(transaction_extensions) ) FC_REFLECT_DERIVED( eosio::chain::signed_transaction, (eosio::chain::transaction), (signatures)(context_free_data) ) FC_REFLECT_ENUM( eosio::chain::packed_transaction::compression_type, (none)(zlib)) diff --git a/libraries/chain/transaction.cpp b/libraries/chain/transaction.cpp index 7165b6c039544a5ec0ca0dc21282bab59a4e459e..18dfcf1b1ca43704ae4e7b04f893dcc6522cc886 100644 --- a/libraries/chain/transaction.cpp +++ b/libraries/chain/transaction.cpp @@ -58,8 +58,6 @@ bool transaction_header::verify_reference_block( const block_id_type& reference_ } void transaction_header::validate()const { - EOS_ASSERT( max_kcpu_usage.value < UINT32_MAX / 1024UL, transaction_exception, - "declared max_kcpu_usage overflows when expanded to max cpu usage" ); EOS_ASSERT( max_net_usage_words.value < UINT32_MAX / 8UL, transaction_exception, "declared max_net_usage_words overflows when expanded to max net usage" ); } diff --git a/libraries/chain/transaction_context.cpp b/libraries/chain/transaction_context.cpp index a21e9da1aa91cc3b02c3166d6b9abc8aed9d0599..35b4fcda20118504a51423a746d1710ca2c8ea54 100644 --- a/libraries/chain/transaction_context.cpp +++ b/libraries/chain/transaction_context.cpp @@ -50,7 +50,8 @@ namespace eosio { namespace chain { uint64_t trx_specified_net_usage_limit = static_cast(trx.max_net_usage_words.value)*8; if( trx_specified_net_usage_limit > 0 ) max_net = std::min( max_net, trx_specified_net_usage_limit ); - uint64_t trx_specified_cpu_usage_limit = static_cast(trx.max_kcpu_usage.value)*1024; + + uint64_t trx_specified_cpu_usage_limit = 1000 * uint64_t( trx.max_cpu_usage_ms ); if( trx_specified_cpu_usage_limit > 0 ) max_cpu = std::min( max_cpu, trx_specified_cpu_usage_limit ); diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index 30de1eee7fefc3d73d6e511a9195d77a5f8a3a14..6952b81136c4d4c1c2af091ec5e2a16614219ffb 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -189,7 +189,7 @@ namespace eosio { namespace testing { trx.set_reference_block( control->head_block_id() ); trx.max_net_usage_words = 0; // No limit - trx.max_kcpu_usage = 0; // No limit + trx.max_cpu_usage_ms = 0; // No limit trx.delay_sec = delay_sec; } diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index f0cd9276f2b22a3fa6dbcc23f955bc80979cfe39..86371fdb1cd8b2b39a0b3cbe6ce356d2465875dd 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -157,7 +157,7 @@ bool tx_dont_broadcast = false; bool tx_skip_sign = false; bool tx_print_json = false; -uint32_t tx_max_cpu_usage = 0; +uint8_t tx_max_cpu_usage = 0; uint32_t tx_max_net_usage = 0; vector tx_permission; @@ -185,7 +185,7 @@ void add_standard_transaction_options(CLI::App* cmd, string default_permission = msg += " (defaults to '" + default_permission + "')"; cmd->add_option("-p,--permission", tx_permission, localized(msg.c_str())); - cmd->add_option("--max-cpu-usage", tx_max_cpu_usage, localized("set an upper limit on the cpu usage budget, in instructions-retired, for the execution of the transaction (defaults to 0 which means no limit)")); + cmd->add_option("--max-cpu-usage-ms", tx_max_cpu_usage, localized("set an upper limit on the milliseconds of cpu usage budget, for the execution of the transaction (defaults to 0 which means no limit)")); cmd->add_option("--max-net-usage", tx_max_net_usage, localized("set an upper limit on the net usage budget, in bytes, for the transaction (defaults to 0 which means no limit)")); } @@ -273,7 +273,7 @@ fc::variant push_transaction( signed_transaction& trx, int32_t extra_kcpu = 1000 auto required_keys = determine_required_keys(trx); size_t num_keys = required_keys.is_array() ? required_keys.get_array().size() : 1; - trx.max_kcpu_usage = (tx_max_cpu_usage + 1023)/1024; + trx.max_cpu_usage_ms = tx_max_net_usage; trx.max_net_usage_words = (tx_max_net_usage + 7)/8; if (!tx_skip_sign) { @@ -1983,7 +1983,7 @@ int main( int argc, char** argv ) { trx.ref_block_num = 0; trx.ref_block_prefix = 0; trx.max_net_usage_words = 0; - trx.max_kcpu_usage = 0; + trx.max_cpu_usage_ms = 0; trx.delay_sec = 0; trx.actions = { chain::action(trxperm, name(proposed_contract), name(proposed_action), proposed_trx_serialized) }; diff --git a/scripts/eosio_build_amazon.sh b/scripts/eosio_build_amazon.sh index d5051ace0276c4d79eae872861efc57ce1d8b613..733c292b44162e6599bd0e5efb7298a20c0f9fb3 100644 --- a/scripts/eosio_build_amazon.sh +++ b/scripts/eosio_build_amazon.sh @@ -1,6 +1,6 @@ OS_VER=$( cat /etc/os-release | grep VERSION_ID | cut -d'=' -f2 | sed 's/[^0-9\.]//gI' | cut -d'.' -f1 ) - MEM_MEG=$( free -m | grep Mem | tr -s ' ' | cut -d\ -f2 ) + MEM_MEG=$( free -m | sed -n 2p | tr -s ' ' | cut -d\ -f2 ) CPU_SPEED=$( lscpu | grep "MHz" | tr -s ' ' | cut -d\ -f3 | cut -d'.' -f1 ) CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 ) MEM_GIG=$(( (($MEM_MEG / 1000) / 2) )) diff --git a/scripts/eosio_build_centos.sh b/scripts/eosio_build_centos.sh index 6973ae4ed2de516220436f64fbb88f186af0f428..376529741adea41a669e8b24c942e071de364d98 100644 --- a/scripts/eosio_build_centos.sh +++ b/scripts/eosio_build_centos.sh @@ -1,7 +1,7 @@ OS_VER=$( cat /etc/os-release | grep VERSION_ID | cut -d'=' -f2 | sed 's/[^0-9\.]//gI' \ | cut -d'.' -f1 ) - MEM_MEG=$( free -m | grep Mem | tr -s ' ' | cut -d\ -f2 ) + MEM_MEG=$( free -m | sed -n 2p | tr -s ' ' | cut -d\ -f2 ) CPU_SPEED=$( lscpu | grep "MHz" | tr -s ' ' | cut -d\ -f3 | cut -d'.' -f1 ) CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 ) MEM_GIG=$(( (($MEM_MEG / 1000) / 2) )) diff --git a/scripts/eosio_build_fedora.sh b/scripts/eosio_build_fedora.sh index 64475416656188102e6bdb82d707b11f1a782971..90ed6e6451c7bc2568819575145e6f222884fe4a 100644 --- a/scripts/eosio_build_fedora.sh +++ b/scripts/eosio_build_fedora.sh @@ -1,6 +1,6 @@ OS_VER=$( cat /etc/os-release | grep VERSION_ID | cut -d'=' -f2 | sed 's/[^0-9\.]//gI' ) - MEM_MEG=$( free -m | grep Mem | tr -s ' ' | cut -d\ -f2 ) + MEM_MEG=$( free -m | sed -n 2p | tr -s ' ' | cut -d\ -f2 ) CPU_SPEED=$( lscpu | grep "MHz" | tr -s ' ' | cut -d\ -f3 | cut -d'.' -f1 ) CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 ) MEM_GIG=$(( (($MEM_MEG / 1000) / 2) )) diff --git a/scripts/eosio_build_ubuntu.sh b/scripts/eosio_build_ubuntu.sh index d6b7f315e8bb5819cac1b9a9648843decdb042b4..ef50b3581fba5ceafde0b686fa70ed610e5f27fa 100644 --- a/scripts/eosio_build_ubuntu.sh +++ b/scripts/eosio_build_ubuntu.sh @@ -2,7 +2,7 @@ OS_MAJ=`echo "${OS_VER}" | cut -d'.' -f1` OS_MIN=`echo "${OS_VER}" | cut -d'.' -f2` - MEM_MEG=$( free -m | grep Mem | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 ) + MEM_MEG=$( free -m | sed -n 2p | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 ) CPU_SPEED=$( lscpu | grep -m1 "MHz" | tr -s ' ' | cut -d\ -f3 || cut -d' ' -f3 | cut -d'.' -f1 ) CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 ) diff --git a/tests/testUtils.py b/tests/testUtils.py index c978ccb28fef7ee1910d196278fc0cfae2d2a42f..ffc4c79b966fc0d3cdc641cef76199f2628c5648 100755 --- a/tests/testUtils.py +++ b/tests/testUtils.py @@ -1251,7 +1251,7 @@ class Cluster(object): if self.staging: cmdArr.append("--nogen") - nodeosArgs="--max-pending-transaction-time 5000" + nodeosArgs="--max-transaction-time 5000" if not self.walletd: nodeosArgs += " --plugin eosio::wallet_api_plugin" if self.enableMongo: diff --git a/unittests/abi_tests.cpp b/unittests/abi_tests.cpp index 4e2b4a58d19b43738c07ef6c5805df250f479fc3..07080919a4650fd6cbc38942ca50e00f1a8970f1 100644 --- a/unittests/abi_tests.cpp +++ b/unittests/abi_tests.cpp @@ -1807,7 +1807,7 @@ BOOST_AUTO_TEST_CASE(general) "context_free_actions":[{"account":"contextfree1", "name":"cfactionname1", "authorization":[{"actor":"cfacc1","permission":"cfpermname1"}], "data":"778899"}], "actions":[{"account":"accountname1", "name":"actionname1", "authorization":[{"actor":"acc1","permission":"permname1"}], "data":"445566"}], "max_net_usage_words":15, - "max_kcpu_usage":43, + "max_cpu_usage_ms":43, "delay_sec":0 }, "transaction_arr": [{ @@ -1817,7 +1817,7 @@ BOOST_AUTO_TEST_CASE(general) "context_free_actions":[{"account":"contextfree1", "name":"cfactionname1", "authorization":[{"actor":"cfacc1","permission":"cfpermname1"}], "data":"778899"}], "actions":[{"account":"acc1", "name":"actionname1", "authorization":[{"actor":"acc1","permission":"permname1"}], "data":"445566"}], "max_net_usage_words":15, - "max_kcpu_usage":43, + "max_cpu_usage_ms":43, "delay_sec":0 },{ "ref_block_num":"2", @@ -1826,7 +1826,7 @@ BOOST_AUTO_TEST_CASE(general) "context_free_actions":[{"account":"contextfree1", "name":"cfactionname1", "authorization":[{"actor":"cfacc1","permission":"cfpermname1"}], "data":"778899"}], "actions":[{"account":"acc2", "name":"actionname2", "authorization":[{"actor":"acc2","permission":"permname2"}], "data":""}], "max_net_usage_words":21, - "max_kcpu_usage":87, + "max_cpu_usage_ms":87, "delay_sec":0 }], "strx": { @@ -1839,7 +1839,7 @@ BOOST_AUTO_TEST_CASE(general) "context_free_actions":[{"account":"contextfree1", "name":"cfactionname1", "authorization":[{"actor":"cfacc1","permission":"cfpermname1"}], "data":"778899"}], "actions":[{"account":"accountname1", "name":"actionname1", "authorization":[{"actor":"acc1","permission":"permname1"}], "data":"445566"}], "max_net_usage_words":15, - "max_kcpu_usage":43, + "max_cpu_usage_ms":43, "delay_sec":0 }, "strx_arr": [{ @@ -1852,7 +1852,7 @@ BOOST_AUTO_TEST_CASE(general) "context_free_actions":[{"account":"contextfree1", "name":"cfactionname1", "authorization":[{"actor":"cfacc1","permission":"cfpermname1"}], "data":"778899"}], "actions":[{"account":"acc1", "name":"actionname1", "authorization":[{"actor":"acc1","permission":"permname1"}], "data":"445566"}], "max_net_usage_words":15, - "max_kcpu_usage":43, + "max_cpu_usage_ms":43, "delay_sec":0 },{ "ref_block_num":"2", @@ -1864,7 +1864,7 @@ BOOST_AUTO_TEST_CASE(general) "context_free_actions":[{"account":"contextfree2", "name":"cfactionname2", "authorization":[{"actor":"cfacc2","permission":"cfpermname2"}], "data":"667788"}], "actions":[{"account":"acc2", "name":"actionname2", "authorization":[{"actor":"acc2","permission":"permname2"}], "data":""}], "max_net_usage_words":15, - "max_kcpu_usage":43, + "max_cpu_usage_ms":43, "delay_sec":0 }], "keyweight": {"key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight":"100"}, @@ -2549,7 +2549,7 @@ BOOST_AUTO_TEST_CASE(packed_transaction) vector{{N(testapi4), config::active_name}}, action2{ 61, 23, (uint8_t)2}); txn.max_net_usage_words = 15; - txn.max_kcpu_usage = 43; + txn.max_cpu_usage_ms = 43; // pack the transaction to verify that the var unpacking logic is correct auto packed_txn = chain::packed_transaction(txn); @@ -2630,7 +2630,7 @@ BOOST_AUTO_TEST_CASE(packed_transaction) for (unsigned int i = 0; i < txn.actions.size(); ++i) verify_action_equal(txn.actions[i], txn2.actions[i]); BOOST_REQUIRE_EQUAL(txn.max_net_usage_words.value, txn2.max_net_usage_words.value); - BOOST_REQUIRE_EQUAL(txn.max_kcpu_usage.value, txn2.max_kcpu_usage.value); + BOOST_REQUIRE_EQUAL(txn.max_cpu_usage_ms, txn2.max_cpu_usage_ms); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE(abi_type_repeat) diff --git a/unittests/multisig_tests.cpp b/unittests/multisig_tests.cpp index c1b996169f9eacb2c59d13322c3189c5197d85bb..f25d48eb799e831c89ae5017ba929c89212180bf 100644 --- a/unittests/multisig_tests.cpp +++ b/unittests/multisig_tests.cpp @@ -84,7 +84,7 @@ transaction eosio_msig_tester::reqauth( account_name from, const vector