From 06f499d9cda8d769c940f9b24e5e06256aedc76d Mon Sep 17 00:00:00 2001 From: Bart Wyatt Date: Thu, 29 Mar 2018 14:25:10 -0400 Subject: [PATCH] - change name and type of commitment to network size of a transaction to match the rest of the system and imply its multiplier. Additionally changed to a VLQ encoded unsigned int. - change name and type of commitment to the cpu usage for the context_free portion of a transaction to match the rest of the system and imply its multiplier. Additionally changed to a VLQ encoded unsigned int. - exposed VLQ encoded unsigned int and ZigZag encoded signed integer types to the ABI built-ins as "varuint32" and "varint32" respectively - Fixed the unit tests that broke as a result of the above --- contracts/eosiolib/transaction.hpp | 6 ++-- libraries/chain/contracts/abi_serializer.cpp | 2 ++ .../chain/contracts/chain_initializer.cpp | 4 +-- .../chain/include/eosio/chain/transaction.hpp | 12 +++---- libraries/chain/test/transaction_test.cpp | 4 +-- tests/api_tests/api_tests.cpp | 4 +-- tests/tests/abi_tests.cpp | 32 +++++++++---------- 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/contracts/eosiolib/transaction.hpp b/contracts/eosiolib/transaction.hpp index 436648335..abeb86498 100644 --- a/contracts/eosiolib/transaction.hpp +++ b/contracts/eosiolib/transaction.hpp @@ -37,13 +37,13 @@ namespace eosio { region_id region; uint16_t ref_block_num; uint32_t ref_block_prefix; - uint16_t packed_bandwidth_words = 0; /// number of 8 byte words this transaction can compress into - uint16_t context_free_cpu_bandwidth = 0; /// number of CPU usage units to bill transaction for + unsigned_int net_usage_words = 0UL; /// number of 8 byte words this transaction can serialize into after compressions + unsigned_int context_free_kilo_cpu_usage = 0UL; /// number of CPU usage units to bill transaction for vector context_free_actions; vector actions; - EOSLIB_SERIALIZE( transaction, (expiration)(region)(ref_block_num)(ref_block_prefix)(packed_bandwidth_words)(context_free_cpu_bandwidth)(context_free_actions)(actions) ) + EOSLIB_SERIALIZE( transaction, (expiration)(region)(ref_block_num)(ref_block_prefix)(net_usage_words)(context_free_kilo_cpu_usage)(context_free_actions)(actions) ) }; class deferred_transaction : public transaction { diff --git a/libraries/chain/contracts/abi_serializer.cpp b/libraries/chain/contracts/abi_serializer.cpp index 162ab1048..fe7cf8d0b 100644 --- a/libraries/chain/contracts/abi_serializer.cpp +++ b/libraries/chain/contracts/abi_serializer.cpp @@ -77,10 +77,12 @@ namespace eosio { namespace chain { namespace contracts { built_in_types.emplace("uint64", pack_unpack()); built_in_types.emplace("uint128", pack_unpack()); built_in_types.emplace("uint256", pack_unpack()); + built_in_types.emplace("varuint32", pack_unpack()); built_in_types.emplace("int8", pack_unpack()); built_in_types.emplace("int16", pack_unpack()); built_in_types.emplace("int32", pack_unpack()); built_in_types.emplace("int64", pack_unpack()); + built_in_types.emplace("varint32", pack_unpack()); built_in_types.emplace("float64", pack_unpack()); built_in_types.emplace("name", pack_unpack()); built_in_types.emplace("account_name", pack_unpack()); diff --git a/libraries/chain/contracts/chain_initializer.cpp b/libraries/chain/contracts/chain_initializer.cpp index f14b2bd04..46747ede2 100644 --- a/libraries/chain/contracts/chain_initializer.cpp +++ b/libraries/chain/contracts/chain_initializer.cpp @@ -221,8 +221,8 @@ abi_def chain_initializer::eos_contract_abi(const abi_def& eosio_system_abi) {"region", "uint16"}, {"ref_block_num", "uint16"}, {"ref_block_prefix", "uint16"}, - {"packed_bandwidth_words", "uint16"}, - {"context_free_cpu_bandwidth", "uint16"} + {"net_usage_words", "varuint32"}, + {"context_free_kilo_cpu_usage", "varuint32"} } }); diff --git a/libraries/chain/include/eosio/chain/transaction.hpp b/libraries/chain/include/eosio/chain/transaction.hpp index 89efa7974..5bd14d702 100644 --- a/libraries/chain/include/eosio/chain/transaction.hpp +++ b/libraries/chain/include/eosio/chain/transaction.hpp @@ -112,11 +112,11 @@ namespace eosio { namespace chain { */ struct transaction_header { time_point_sec expiration; ///< the time at which a transaction expires - uint16_t region = 0; ///< the computational memory region this transaction applies to. - uint16_t ref_block_num = 0; ///< specifies a block num in the last 2^16 blocks. - uint32_t ref_block_prefix = 0; ///< specifies the lower 32 bits of the blockid at get_ref_blocknum - uint16_t packed_bandwidth_words = 0; /// number of 8 byte words this transaction can compress into - uint16_t context_free_cpu_bandwidth = 0; /// number of CPU usage units to bill transaction for + uint16_t region = 0U; ///< the computational memory region this transaction applies to. + 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 net_usage_words = 0UL; /// number of 8 byte words this transaction serialize too taking any compression into account + fc::unsigned_int context_free_kilo_cpu_usage = 0UL; /// number of kilo CPU usage units to bill transaction for to process context free actions /** * @return the absolute block number given the relative ref_block_num @@ -269,7 +269,7 @@ namespace eosio { namespace chain { FC_REFLECT( eosio::chain::permission_level, (actor)(permission) ) FC_REFLECT( eosio::chain::action, (account)(name)(authorization)(data) ) -FC_REFLECT( eosio::chain::transaction_header, (expiration)(region)(ref_block_num)(ref_block_prefix)(packed_bandwidth_words)(context_free_cpu_bandwidth) ) +FC_REFLECT( eosio::chain::transaction_header, (expiration)(region)(ref_block_num)(ref_block_prefix)(net_usage_words)(context_free_kilo_cpu_usage) ) FC_REFLECT_DERIVED( eosio::chain::transaction, (eosio::chain::transaction_header), (context_free_actions)(actions) ) 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/test/transaction_test.cpp b/libraries/chain/test/transaction_test.cpp index d7329fc18..37307adca 100644 --- a/libraries/chain/test/transaction_test.cpp +++ b/libraries/chain/test/transaction_test.cpp @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_SUITE(transaction_test) { try { - std::string expected = "78da63606060d8bf7ff5eab2198ace0c20c03861f9320ec9091b4f31a8954a826846906888e7442f10bde2ad9191a04051625e4a7eae424a6249a242466a512a00bf3414bb"; + std::string expected = "78da63606060d8bf7ff5eab2198ace4026e384e5cb3824276c3cc5a0562a09a21981820c219e13bd40f48ab74646820245897929f9b90a298925890a19a945a900b6a614bb"; transaction trx; trx.region = 0xBFBFU; @@ -84,7 +84,7 @@ BOOST_AUTO_TEST_SUITE(transaction_test) expected.actions.emplace_back(vector{{N(decomp), config::active_name}}, test_action {"random data here"}); - char compressed_tx_raw[] = "78da63606060d8bf7ff5eab2198ace0c20c03861f9320ec9091b4f31a8954a826846906888e7442f10bde2ad9191a04051625e4a7eae424a6249a242466a512a00bf3414bb"; + char compressed_tx_raw[] = "78da63606060d8bf7ff5eab2198ace4026e384e5cb3824276c3cc5a0562a09a21981820c219e13bd40f48ab74646820245897929f9b90a298925890a19a945a900b6a614bb"; packed_transaction t; t.data.resize((sizeof(compressed_tx_raw) - 1) / 2); diff --git a/tests/api_tests/api_tests.cpp b/tests/api_tests/api_tests.cpp index 8fd05b157..d07c66f87 100644 --- a/tests/api_tests/api_tests.cpp +++ b/tests/api_tests/api_tests.cpp @@ -605,13 +605,13 @@ BOOST_FIXTURE_TEST_CASE(transaction_tests, tester) { try { control->push_deferred_transactions( true ); // test test_transaction_size - CALL_TEST_FUNCTION(*this, "test_transaction", "test_transaction_size", fc::raw::pack(56) ); + CALL_TEST_FUNCTION(*this, "test_transaction", "test_transaction_size", fc::raw::pack(54) ); control->push_deferred_transactions( true ); // test test_read_transaction // this is a bit rough, but I couldn't figure out a better way to compare the hashes auto tx_trace = CALL_TEST_FUNCTION( *this, "test_transaction", "test_read_transaction", {} ); - string sha_expect = "bdeb5b58dda272e4b23ee7d2a5f0ff034820c156364893b758892e06fa39e7fe"; + string sha_expect = "96f7634b737511212dedb9c3eb42672882b066c7af3601a4b50beda56deb977e"; BOOST_CHECK_EQUAL(tx_trace.action_traces.front().console == sha_expect, true); // test test_tapos_block_num CALL_TEST_FUNCTION(*this, "test_transaction", "test_tapos_block_num", fc::raw::pack(control->head_block_num()) ); diff --git a/tests/tests/abi_tests.cpp b/tests/tests/abi_tests.cpp index 438011b50..c98aef5c9 100644 --- a/tests/tests/abi_tests.cpp +++ b/tests/tests/abi_tests.cpp @@ -1701,8 +1701,8 @@ BOOST_AUTO_TEST_CASE(general) "region": "1", "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"}], - "packed_bandwidth_words":15, - "context_free_cpu_bandwidth":43 + "net_usage_words":15, + "context_free_kilo_cpu_usage":43 }, "transaction_arr": [{ "ref_block_num":"1", @@ -1711,8 +1711,8 @@ BOOST_AUTO_TEST_CASE(general) "region": "1", "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"}], - "packed_bandwidth_words":15, - "context_free_cpu_bandwidth":43 + "net_usage_words":15, + "context_free_kilo_cpu_usage":43 },{ "ref_block_num":"2", "ref_block_prefix":"3", @@ -1720,8 +1720,8 @@ BOOST_AUTO_TEST_CASE(general) "region": "1", "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":""}], - "packed_bandwidth_words":21, - "context_free_cpu_bandwidth":87 + "net_usage_words":21, + "context_free_kilo_cpu_usage":87 }], "strx": { "ref_block_num":"1", @@ -1732,8 +1732,8 @@ BOOST_AUTO_TEST_CASE(general) "context_free_data" : ["abcdef","0123456789","ABCDEF0123456789abcdef"], "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"}], - "packed_bandwidth_words":15, - "context_free_cpu_bandwidth":43 + "net_usage_words":15, + "context_free_kilo_cpu_usage":43 }, "strx_arr": [{ "ref_block_num":"1", @@ -1744,8 +1744,8 @@ BOOST_AUTO_TEST_CASE(general) "context_free_data" : ["abcdef","0123456789","ABCDEF0123456789abcdef"], "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"}], - "packed_bandwidth_words":15, - "context_free_cpu_bandwidth":43 + "net_usage_words":15, + "context_free_kilo_cpu_usage":43 },{ "ref_block_num":"2", "ref_block_prefix":"3", @@ -1755,8 +1755,8 @@ BOOST_AUTO_TEST_CASE(general) "context_free_data" : ["abcdef","0123456789","ABCDEF0123456789abcdef"], "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":""}], - "packed_bandwidth_words":15, - "context_free_cpu_bandwidth":43 + "net_usage_words":15, + "context_free_kilo_cpu_usage":43 }], "keyweight": {"key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight":"100"}, "keyweight_arr": [{"key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight":"100"},{"key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV", "weight":"200"}], @@ -2609,8 +2609,8 @@ BOOST_AUTO_TEST_CASE(packed_transaction) txn.actions.emplace_back( vector{{N(testapi4), config::active_name}}, action2{ 61, 23, (uint8_t)2}); - txn.packed_bandwidth_words = 15; - txn.context_free_cpu_bandwidth = 43; + txn.net_usage_words = 15; + txn.context_free_kilo_cpu_usage = 43; // pack the transaction to verify that the var unpacking logic is correct auto packed_txn = chain::packed_transaction(txn); @@ -2690,8 +2690,8 @@ BOOST_AUTO_TEST_CASE(packed_transaction) BOOST_REQUIRE_EQUAL(txn.actions.size(), txn2.actions.size()); for (unsigned int i = 0; i < txn.actions.size(); ++i) verify_action_equal(txn.actions[i], txn2.actions[i]); - BOOST_REQUIRE_EQUAL(txn.packed_bandwidth_words, txn2.packed_bandwidth_words); - BOOST_REQUIRE_EQUAL(txn.context_free_cpu_bandwidth, txn2.context_free_cpu_bandwidth); + BOOST_REQUIRE_EQUAL(txn.net_usage_words.value, txn2.net_usage_words.value); + BOOST_REQUIRE_EQUAL(txn.context_free_kilo_cpu_usage.value, txn2.context_free_kilo_cpu_usage.value); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE(abi_type_repeat) -- GitLab