From 08e60fbeee71b8db063e51aaf2d87507521e00b6 Mon Sep 17 00:00:00 2001 From: Khaled Al-Hassanieh Date: Thu, 24 May 2018 15:07:40 -0400 Subject: [PATCH 01/38] Fixed rest of ram_tests --- unittests/eosio.system_tests.cpp | 6 +++--- unittests/ram_tests.cpp | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index b3a9de1a240..0613ba6ea3a 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -40,8 +40,8 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try { transfer( "eosio", "alice1111111", core_from_string("100000000.0000"), "eosio" ); BOOST_REQUIRE_EQUAL( core_from_string("100000998.0050"), get_balance( "alice1111111" ) ); - // alice buys ram for 10000000.0000, 0.5% = 50000.0000 got to ramfee - // after fee 9950000.0000 got to bought bytes + // alice buys ram for 10000000.0000, 0.5% = 50000.0000 go to ramfee + // after fee 9950000.0000 go to bought bytes // when selling back bought bytes, pay 0.5% fee and get back 99.5% of 9950000.0000 = 9900250.0000 // expected account after that is 90000998.0050 + 9900250.0000 = 99901248.0050 with a difference // of order 0.0001 due to rounding errors @@ -2351,7 +2351,7 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try { produce_block( fc::days(14) ); produce_block(); - // highest bid is from david for prefd but not bids can be closed yet + // highest bid is from david for prefd but no bids can be closed yet BOOST_REQUIRE_EXCEPTION( create_account_with_resources( N(prefd), N(david) ), fc::exception, fc_assert_exception_message_is( not_closed_message ) ); diff --git a/unittests/ram_tests.cpp b/unittests/ram_tests.cpp index 90a9460c62d..ee08d76eb42 100644 --- a/unittests/ram_tests.cpp +++ b/unittests/ram_tests.cpp @@ -40,7 +40,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, eosio_system::eosio_system_tester) { try { buyrambytes(N(eosio), N(eosio), 70000); produce_blocks(10); create_account_with_resources(N(testram11111),N(eosio), init_request_bytes); - create_account_with_resources(N(testram22222),N(eosio), init_request_bytes); + create_account_with_resources(N(testram22222),N(eosio), init_request_bytes + 1150); produce_blocks(10); BOOST_REQUIRE_EQUAL( success(), stake( "eosio.stake", "testram11111", core_from_string("10.0000"), core_from_string("5.0000") ) ); produce_blocks(10); @@ -189,7 +189,6 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, eosio_system::eosio_system_tester) { try { fc_exception_message_starts_with("account testram11111 has insufficient ram")); produce_blocks(1); -#if 0 // verify that the new entry is under the allocation bytes limit tester->push_action( N(testram11111), N(setentry), {N(testram11111),N(testram22222)}, mvo() ("payer", "testram22222") @@ -260,7 +259,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, eosio_system::eosio_system_tester) { try { ("to", 22) ("size", 1910)); produce_blocks(1); -#endif + } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END() From 3ed6e906e72b27e130d82cd3d9cb5c286dbfe4fb Mon Sep 17 00:00:00 2001 From: Khaled Al-Hassanieh Date: Thu, 24 May 2018 18:55:13 -0400 Subject: [PATCH 02/38] Changes to producer deactivation - incomplete --- contracts/eosio.system/voting.cpp | 17 ++++- unittests/eosio.system_tests.cpp | 112 ++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 5 deletions(-) diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index 0c4d5616b67..acd6028d0ee 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -79,7 +79,7 @@ namespace eosiosystem { for ( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 21 && 0 < it->total_votes; ++it ) { if( !it->active() ) continue; - +#if 0 if ( it->time_became_active.slot == 0 ) { _producers.modify( *it, 0, [&](auto& p) { p.time_became_active = block_time; @@ -93,7 +93,22 @@ namespace eosiosystem { continue; } +#else + if ( it->time_became_active.slot > 0 && + block_time.slot > (2 * 21 * 12 * 100) + it->time_became_active.slot && + block_time.slot > it->last_produced_block_time.slot + blocks_per_day ) { + _producers.modify( *it, 0, [&](auto& p) { + p.producer_key = public_key(); + p.time_became_active.slot = 0; + }); + continue; + } else { + _producers.modify( *it, 0, [&](auto& p) { + p.time_became_active = block_time; + }); + } +#endif top_producers.emplace_back( std::pair({{it->owner, it->producer_key}, it->location})); } diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index 0613ba6ea3a..696aaf4e227 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -1292,7 +1292,6 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni const double usecs_per_year = secs_per_year * 1000000; const double cont_rate = 4.879/100.; - const asset net = core_from_string("80.0000"); const asset cpu = core_from_string("80.0000"); create_account_with_resources( N(producvotera), config::system_account_name, core_from_string("1.0000"), false, net, cpu ); @@ -1543,7 +1542,7 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni // wait two more hours, now most producers haven't produced in a day and will // be deactivated - produce_block(fc::seconds(2 * 3600)); + produce_block(fc::seconds(9 * 3600)); produce_blocks(8 * 21 * 12); { @@ -1772,8 +1771,6 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try { create_account_with_resources( N(producvoterb), config::system_account_name, core_from_string("1.0000"), false, large_asset, large_asset ); create_account_with_resources( N(producvoterc), config::system_account_name, core_from_string("1.0000"), false, large_asset, large_asset ); - - // create accounts {defproducera, defproducerb, ..., defproducerz} and register as producers std::vector producer_names; producer_names.reserve('z' - 'a' + 1); @@ -2427,4 +2424,111 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try { } FC_LOG_AND_RETHROW() +BOOST_FIXTURE_TEST_CASE( vote_producers_in_and_out, eosio_system_tester ) try { + + const asset net = core_from_string("80.0000"); + const asset cpu = core_from_string("80.0000"); + std::vector voters = { N(producvotera), N(producvoterb), N(producvoterc), N(producvoterd) }; + for (const auto& v: voters) { + create_account_with_resources(v, config::system_account_name, core_from_string("1.0000"), false, net, cpu); + } + + // create accounts {defproducera, defproducerb, ..., defproducerz} and register as producers + std::vector producer_names; + { + producer_names.reserve('z' - 'a' + 1); + const std::string root("defproducer"); + for ( char c = 'a'; c <= 'z'; ++c ) { + producer_names.emplace_back(root + std::string(1, c)); + } + setup_producer_accounts(producer_names); + for (const auto& p: producer_names) { + BOOST_REQUIRE_EQUAL( success(), regproducer(p) ); + produce_blocks(1); + ilog( "------ get pro----------" ); + wdump((p)); + BOOST_TEST(0 == get_producer_info(p)["total_votes"].as()); + } + } + + for (const auto& v: voters) { + transfer( config::system_account_name, v, core_from_string("200000000.0000"), config::system_account_name ); + BOOST_REQUIRE_EQUAL(success(), stake(v, core_from_string("30000000.0000"), core_from_string("30000000.0000")) ); + } + + { + BOOST_REQUIRE_EQUAL(success(), push_action(N(producvotera), N(voteproducer), mvo() + ("voter", "producvotera") + ("proxy", name(0).to_string()) + ("producers", vector(producer_names.begin(), producer_names.begin()+20)) + ) + ); + + BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterb), N(voteproducer), mvo() + ("voter", "producvoterb") + ("proxy", name(0).to_string()) + ("producers", vector(producer_names.begin(), producer_names.begin()+21)) + ) + ); + + BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterc), N(voteproducer), mvo() + ("voter", "producvoterc") + ("proxy", name(0).to_string()) + ("producers", vector(producer_names.begin(), producer_names.end())) + ) + ); + } + + // give a chance for everyone to produce blocks + { + produce_blocks(23 * 12 + 20); + bool all_21_produced = true; + for (uint32_t i = 0; i < 21; ++i) { + if (0 == get_producer_info(producer_names[i])["unpaid_blocks"].as()) { + all_21_produced = false; + } + } + bool rest_didnt_produce = true; + for (uint32_t i = 21; i < producer_names.size(); ++i) { + if (0 < get_producer_info(producer_names[i])["unpaid_blocks"].as()) { + rest_didnt_produce = false; + } + } + BOOST_REQUIRE(all_21_produced && rest_didnt_produce); + } + + produce_block(fc::hours(7)); + + { + const uint32_t voted_out_index = 20; + const uint32_t new_prod_index = 23; + BOOST_REQUIRE_EQUAL(success(), stake("producvoterd", core_from_string("40000000.0000"), core_from_string("40000000.0000"))); + BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterd), N(voteproducer), mvo() + ("voter", "producvoterd") + ("proxy", name(0).to_string()) + ("producers", vector{ producer_names[new_prod_index] }) + ) + ); + BOOST_REQUIRE_EQUAL(0, get_producer_info(producer_names[new_prod_index])["unpaid_blocks"].as()); + produce_blocks(4 * 12 * 21); + BOOST_REQUIRE(0 < get_producer_info(producer_names[new_prod_index])["unpaid_blocks"]); + const uint32_t initial_unpaid_blocks = get_producer_info(producer_names[voted_out_index])["unpaid_blocks"].as(); + produce_blocks(2 * 12 * 21); + BOOST_REQUIRE_EQUAL(initial_unpaid_blocks, get_producer_info(producer_names[voted_out_index])["unpaid_blocks"].as()); + produce_blocks(2 * 12 * 21); + produce_block(fc::hours(12)); + produce_blocks(2 * 12 * 21); + produce_block(fc::hours(12)); + BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterd), N(voteproducer), mvo() + ("voter", "producvoterd") + ("proxy", name(0).to_string()) + ("producers", vector{ producer_names[voted_out_index] }) + ) + ); + produce_blocks(2 * 12 * 21); + BOOST_REQUIRE_EQUAL(fc::crypto::public_key(), fc::crypto::public_key(get_producer_info(producer_names[voted_out_index])["producer_key"].as_string())); + } + +} FC_LOG_AND_RETHROW() + BOOST_AUTO_TEST_SUITE_END() From 1fbc65b89f9a5c9fcebd5394750a2c2a7227ea3b Mon Sep 17 00:00:00 2001 From: arhag Date: Thu, 24 May 2018 22:39:41 -0400 Subject: [PATCH 03/38] add version and genesis configuration to beginning of blocks.log --- libraries/chain/block_log.cpp | 98 ++++++++++++++++++- libraries/chain/controller.cpp | 2 +- .../chain/include/eosio/chain/block_log.hpp | 7 ++ 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index cc09a85f76b..d30373e0c38 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -11,6 +11,8 @@ namespace eosio { namespace chain { + const uint32_t block_log::supported_version = 1; + namespace detail { class block_log_impl { public: @@ -22,6 +24,7 @@ namespace eosio { namespace chain { fc::path index_file; bool block_write; bool index_write; + bool genesis_written_to_block_log = false; inline void check_block_read() { if (block_write) { @@ -118,6 +121,16 @@ namespace eosio { namespace chain { if (log_size) { ilog("Log is nonempty"); + my->check_block_read(); + my->block_stream.seekg( 0 ); + uint32_t version = 0; + my->block_stream.read( (char*)&version, sizeof(version) ); + FC_ASSERT( version > 0, "Block log was not setup properly with genesis information." ); + FC_ASSERT( version == block_log::supported_version, + "Unsupported version of block log. Block log version is ${version} while code supports version ${supported}", + ("version", version)("supported", block_log::supported_version) ); + + my->genesis_written_to_block_log = true; // Assume it was constructed properly. my->head = read_head(); my->head_id = my->head->id(); edump((my->head->block_num())); @@ -157,6 +170,8 @@ namespace eosio { namespace chain { uint64_t block_log::append(const signed_block_ptr& b) { try { + FC_ASSERT( my->genesis_written_to_block_log, "Cannot append to block log until the genesis is first written" ); + my->check_block_write(); my->check_index_write(); @@ -184,6 +199,46 @@ namespace eosio { namespace chain { my->index_stream.flush(); } + uint64_t block_log::reset_to_genesis( const genesis_state& gs, const signed_block_ptr& genesis_block ) { + if( my->block_stream.is_open() ) + my->block_stream.close(); + if( my->index_stream.is_open() ) + my->index_stream.close(); + + fc::remove_all( my->block_file ); + fc::remove_all( my->index_file ); + + my->block_stream.open(my->block_file.generic_string().c_str(), LOG_WRITE); + my->index_stream.open(my->index_file.generic_string().c_str(), LOG_WRITE); + my->block_write = true; + my->index_write = true; + + auto data = fc::raw::pack( gs ); + uint32_t version = 0; // version of 0 is invalid; it indicates that the genesis was not properly written to the block log + my->block_stream.write( (char*)&version, sizeof(version) ); + my->block_stream.write( data.data(), data.size() ); + my->genesis_written_to_block_log = true; + + auto ret = append( genesis_block ); + + auto pos = my->block_stream.tellp(); + + my->block_stream.close(); + my->block_stream.open(my->block_file.generic_string().c_str(), std::ios::in | std::ios::out | std::ios::binary ); // Bypass append-only writing just once + + static_assert( block_log::supported_version > 0, "a version number of zero is not supported" ); + version = block_log::supported_version; + my->block_stream.seekp( 0 ); + my->block_stream.write( (char*)&version, sizeof(version) ); // Finally write actual version to disk. + my->block_stream.seekp( pos ); + flush(); + + my->block_write = false; + my->check_block_write(); // Reset to append-only writing. + + return ret; + } + std::pair block_log::read_block(uint64_t pos)const { my->check_block_read(); @@ -245,7 +300,6 @@ namespace eosio { namespace chain { my->index_stream.open(my->index_file.generic_string().c_str(), LOG_WRITE); my->index_write = true; - uint64_t pos = 0; uint64_t end_pos; my->check_block_read(); @@ -253,8 +307,12 @@ namespace eosio { namespace chain { my->block_stream.read((char*)&end_pos, sizeof(end_pos)); signed_block tmp; + uint64_t pos = 4; // Skip version which should have already been checked. my->block_stream.seekg(pos); + genesis_state gs; + fc::raw::unpack(my->block_stream, gs); + while( pos < end_pos ) { fc::raw::unpack(my->block_stream, tmp); my->block_stream.read((char*)&pos, sizeof(pos)); @@ -296,12 +354,24 @@ namespace eosio { namespace chain { old_block_stream.open( (backup_dir / "blocks.log").generic_string().c_str(), LOG_READ ); new_block_stream.open( block_log_path.generic_string().c_str(), LOG_WRITE ); - uint64_t pos = 0; - uint64_t end_pos = old_block_stream.tellg(); old_block_stream.seekg( 0, std::ios::end ); - end_pos = static_cast(old_block_stream.tellg()) - end_pos; + uint64_t end_pos = old_block_stream.tellg(); old_block_stream.seekg( 0 ); + uint32_t version = 0; + old_block_stream.read( (char*)&version, sizeof(version) ); + FC_ASSERT( version > 0, "Block log was not setup properly with genesis information." ); + FC_ASSERT( version == block_log::supported_version, + "Unsupported version of block log. Block log version is ${version} while code supports version ${supported}", + ("version", version)("supported", block_log::supported_version) ); + + genesis_state gs; + fc::raw::unpack(old_block_stream, gs); + + auto data = fc::raw::pack( gs ); + new_block_stream.write( (char*)&version, sizeof(version) ); + new_block_stream.write( data.data(), data.size() ); + std::exception_ptr except_ptr; vector incomplete_block_data; optional bad_block; @@ -309,6 +379,7 @@ namespace eosio { namespace chain { block_id_type previous; + uint64_t pos = old_block_stream.tellg(); while( pos < end_pos ) { signed_block tmp; @@ -387,4 +458,23 @@ namespace eosio { namespace chain { return backup_dir; } + genesis_state block_log::extract_genesis_state( const fc::path& data_dir ) { + FC_ASSERT( fc::is_directory(data_dir) && fc::is_regular_file(data_dir / "blocks.log"), + "Block log not found in '${blocks_dir}'", ("blocks_dir", data_dir) ); + + std::fstream block_stream; + block_stream.open( (data_dir / "blocks.log").generic_string().c_str(), LOG_READ ); + + uint32_t version = 0; + block_stream.read( (char*)&version, sizeof(version) ); + FC_ASSERT( version > 0, "Block log was not setup properly with genesis information." ); + FC_ASSERT( version == block_log::supported_version, + "Unsupported version of block log. Block log version is ${version} while code supports version ${supported}", + ("version", version)("supported", block_log::supported_version) ); + + genesis_state gs; + fc::raw::unpack(block_stream, gs); + return gs; + } + } } /// eosio::chain diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 77fea81f93b..8017b6d350c 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -224,7 +224,7 @@ struct controller_impl { replaying = false; } else if( !end ) { - blog.append( head->block ); + blog.reset_to_genesis( conf.genesis, head->block ); } } diff --git a/libraries/chain/include/eosio/chain/block_log.hpp b/libraries/chain/include/eosio/chain/block_log.hpp index 59db7ef7b79..98a02a2fb14 100644 --- a/libraries/chain/include/eosio/chain/block_log.hpp +++ b/libraries/chain/include/eosio/chain/block_log.hpp @@ -5,6 +5,7 @@ #pragma once #include #include +#include namespace eosio { namespace chain { @@ -43,6 +44,8 @@ namespace eosio { namespace chain { uint64_t append(const signed_block_ptr& b); void flush(); + uint64_t reset_to_genesis( const genesis_state& gs, const signed_block_ptr& genesis_block ); + std::pair read_block(uint64_t file_pos)const; signed_block_ptr read_block_by_num(uint32_t block_num)const; signed_block_ptr read_block_by_id(const block_id_type& id)const { @@ -58,8 +61,12 @@ namespace eosio { namespace chain { static const uint64_t npos = std::numeric_limits::max(); + static const uint32_t supported_version; + static fc::path repair_log( const fc::path& data_dir ); + static genesis_state extract_genesis_state( const fc::path& data_dir ); + private: void open(const fc::path& data_dir); void construct_index(); From 4012876d926293d04c39e0158a5a6254a9c3bfcb Mon Sep 17 00:00:00 2001 From: arhag Date: Thu, 24 May 2018 23:17:18 -0400 Subject: [PATCH 04/38] nodeos can now extract the genesis state from blocks.log Also return correct error code when database is dirty. --- .../chain/include/eosio/chain/exceptions.hpp | 2 ++ plugins/chain_plugin/chain_plugin.cpp | 33 ++++++++++++++++--- programs/nodeos/main.cpp | 17 +++++++--- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/libraries/chain/include/eosio/chain/exceptions.hpp b/libraries/chain/include/eosio/chain/exceptions.hpp index a871750fbc9..578decc9e7c 100644 --- a/libraries/chain/include/eosio/chain/exceptions.hpp +++ b/libraries/chain/include/eosio/chain/exceptions.hpp @@ -246,6 +246,8 @@ namespace eosio { namespace chain { 3100003, "unknown transaction" ) FC_DECLARE_DERIVED_EXCEPTION( fixed_reversible_db_exception, misc_exception, 3100004, "corrupted reversible block database was fixed" ) + FC_DECLARE_DERIVED_EXCEPTION( extract_genesis_state_exception, misc_exception, + 3100005, "extracted genesis state from blocks.log" ) FC_DECLARE_DERIVED_EXCEPTION( missing_plugin_exception, chain_exception, 3110000, "missing plugin exception" ) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 0c2113d30cb..25690cb5a30 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -117,7 +117,9 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip ("wasm-runtime", bpo::value()->value_name("wavm/binaryen"), "Override default WASM runtime") ("chain-state-db-size-mb", bpo::value()->default_value(config::default_state_size / (1024 * 1024)), "Maximum size (in MB) of the chain state database") ("reversible-blocks-db-size-mb", bpo::value()->default_value(config::default_reversible_cache_size / (1024 * 1024)), "Maximum size (in MB) of the reversible blocks database") - + ("contracts-console", bpo::bool_switch()->default_value(false), + "print contract's output to console") + ; #warning TODO: rate limiting /*("per-authorized-account-transaction-msg-rate-limit-time-frame-sec", bpo::value()->default_value(default_per_auth_account_time_frame_seconds), @@ -128,8 +130,12 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip "The time frame, in seconds, that the per-code-account-transaction-msg-rate-limit is imposed over.") ("per-code-account-transaction-msg-rate-limit", bpo::value()->default_value(default_per_code_account), "Limits the maximum rate of transaction messages that an account's code is allowed each per-code-account-transaction-msg-rate-limit-time-frame-sec.")*/ - ; + cli.add_options() + ("print-genesis-json", bpo::bool_switch()->default_value(false), + "extract genesis_state from blocks.log as JSON, print to console, and exit") + ("extract-genesis-json", bpo::value(), + "extract genesis_state from blocks.log as JSON, write into specified file, and exit") ("fix-reversible-blocks", bpo::bool_switch()->default_value(false), "recovers reversible block database if that database is in a bad state") ("force-all-checks", bpo::bool_switch()->default_value(false), @@ -140,8 +146,6 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip "clear chain state database, recover as many blocks as possible from the block log, and then replay those blocks") ("delete-all-blocks", bpo::bool_switch()->default_value(false), "clear chain state database and block log") - ("contracts-console", bpo::bool_switch()->default_value(false), - "print contract's output to console") ; } @@ -209,6 +213,27 @@ void chain_plugin::plugin_initialize(const variables_map& options) { my->chain_config->force_all_checks = options.at("force-all-checks").as(); my->chain_config->contracts_console = options.at("contracts-console").as(); + if( options.count("extract-genesis-json") || options.at("print-genesis-json").as() ) { + auto gs = block_log::extract_genesis_state( my->blocks_dir ); + + if( options.at("print-genesis-json").as() ) { + ilog( "Genesis JSON:\n${genesis}", ("genesis", json::to_pretty_string(gs)) ); + } + + if( options.count("extract-genesis-json") ) { + auto p = options.at("extract-genesis-json").as(); + + if( p.is_relative() ) { + p = bfs::current_path() / p; + } + + fc::json::save_to_file( gs, p, true ); + ilog( "Saved genesis JSON to '${path}'", ("path", p.generic_string()) ); + } + + EOS_THROW( extract_genesis_state_exception, "extracted genesis state from blocks.log" ); + } + if( options.at("delete-all-blocks").as() ) { ilog("Deleting state database and blocks"); fc::remove_all( my->chain_config->state_dir ); diff --git a/programs/nodeos/main.cpp b/programs/nodeos/main.cpp index 910c6f10443..6e16ad9c008 100644 --- a/programs/nodeos/main.cpp +++ b/programs/nodeos/main.cpp @@ -80,11 +80,13 @@ void initialize_logging() } enum return_codes { - OTHER_FAIL = -2, - INITIALIZE_FAIL = -1, - SUCCESS = 0, - BAD_ALLOC = 1, - FIXED_REVERSIBLE = 2 + OTHER_FAIL = -2, + INITIALIZE_FAIL = -1, + SUCCESS = 0, + BAD_ALLOC = 1, + DATABASE_DIRTY = 2, + FIXED_REVERSIBLE = 3, + EXTRACTED_GENESIS = 4 }; int main(int argc, char** argv) @@ -103,6 +105,8 @@ int main(int argc, char** argv) ilog("eosio root is ${root}", ("root", root.string())); app().startup(); app().exec(); + } catch( const extract_genesis_state_exception& e ) { + return EXTRACTED_GENESIS; } catch( const fixed_reversible_db_exception& e ) { return FIXED_REVERSIBLE; } catch( const fc::exception& e ) { @@ -117,11 +121,14 @@ int main(int argc, char** argv) } catch( const std::runtime_error& e ) { if( std::string(e.what()) == "database dirty flag set" ) { elog( "database dirty flag set (likely due to unclean shutdown): replay required" ); + return DATABASE_DIRTY; } else if( std::string(e.what()) == "database metadata dirty flag set" ) { elog( "database metadata dirty flag set (likely due to unclean shutdown): replay required" ); + return DATABASE_DIRTY; } else { elog( "${e}", ("e",e.what())); } + return OTHER_FAIL; } catch( const std::exception& e ) { elog("${e}", ("e",e.what())); return OTHER_FAIL; From 5146bbbc9873d1a01a7453710b9605ab321368e0 Mon Sep 17 00:00:00 2001 From: arhag Date: Thu, 24 May 2018 23:51:46 -0400 Subject: [PATCH 05/38] genesis_state should only be provided to nodeos on a fresh blockchain Also fixed --genesis-timestamp bug. --- plugins/chain_plugin/chain_plugin.cpp | 70 +++++++++++++-------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 25690cb5a30..13a84ae35fe 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -57,8 +57,6 @@ class chain_plugin_impl { {} bfs::path blocks_dir; - bfs::path genesis_file; - time_point genesis_timestamp; bool readonly = false; flat_map loaded_checkpoints; @@ -109,8 +107,6 @@ chain_plugin::~chain_plugin(){} void chain_plugin::set_program_options(options_description& cli, options_description& cfg) { cfg.add_options() - ("genesis-json", bpo::value()->default_value("genesis.json"), "File to read Genesis State from") - ("genesis-timestamp", bpo::value(), "override the initial timestamp in the Genesis State file") ("blocks-dir", bpo::value()->default_value("blocks"), "the location of the blocks directory (absolute path or relative to application data dir)") ("checkpoint", bpo::value>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.") @@ -132,6 +128,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip "Limits the maximum rate of transaction messages that an account's code is allowed each per-code-account-transaction-msg-rate-limit-time-frame-sec.")*/ cli.add_options() + ("genesis-json", bpo::value(), "File to read Genesis State from") + ("genesis-timestamp", bpo::value(), "override the initial timestamp in the Genesis State file") ("print-genesis-json", bpo::bool_switch()->default_value(false), "extract genesis_state from blocks.log as JSON, print to console, and exit") ("extract-genesis-json", bpo::value(), @@ -152,29 +150,6 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip void chain_plugin::plugin_initialize(const variables_map& options) { ilog("initializing chain plugin"); - if(options.count("genesis-json")) { - auto genesis = options.at("genesis-json").as(); - if(genesis.is_relative()) - my->genesis_file = app().config_dir() / genesis; - else - my->genesis_file = genesis; - } - if(options.count("genesis-timestamp")) { - string tstr = options.at("genesis-timestamp").as(); - if (strcasecmp (tstr.c_str(), "now") == 0) { - my->genesis_timestamp = fc::time_point::now(); - auto epoch_ms = my->genesis_timestamp.time_since_epoch().count() / 1000; - auto diff_ms = epoch_ms % block_interval_ms; - if (diff_ms > 0) { - auto delay_ms = (block_interval_ms - diff_ms); - my->genesis_timestamp += fc::microseconds(delay_ms * 10000); - dlog ("pausing ${ms} milliseconds to the next interval",("ms",delay_ms)); - } - } - else { - my->genesis_timestamp = time_point::from_iso_string (tstr); - } - } if (options.count("blocks-dir")) { auto bld = options.at("blocks-dir").as(); if(bld.is_relative()) @@ -272,15 +247,38 @@ void chain_plugin::plugin_initialize(const variables_map& options) { EOS_THROW( fixed_reversible_db_exception, "fixed corrupted reversible blocks database" ); } - if( !fc::exists( my->genesis_file ) ) { - wlog( "\n generating default genesis file ${f}", ("f", my->genesis_file.generic_string() ) ); - genesis_state default_genesis; - fc::json::save_to_file( default_genesis, my->genesis_file, true ); - } + if( options.count("genesis-json") ) { + FC_ASSERT( !fc::exists( my->blocks_dir / "blocks.log" ), "Genesis State can only be specified on a fresh blockchain." ); - my->chain_config->genesis = fc::json::from_file(my->genesis_file).as(); - if( my->genesis_timestamp.sec_since_epoch() > 0 ) { - my->chain_config->genesis.initial_timestamp = my->genesis_timestamp; + auto genesis_file = options.at("genesis-json").as(); + if( genesis_file.is_relative() ) { + genesis_file = bfs::current_path() / genesis_file; + } + + FC_ASSERT( fc::is_regular_file( genesis_file ), + "Specified genesis file '${genesis}' does not exist.", + ("genesis", genesis_file.generic_string()) ); + + my->chain_config->genesis = fc::json::from_file(genesis_file).as(); + + ilog( "Using genesis state provided in '${genesis}'", ("genesis", genesis_file.generic_string()) ); + + if( options.count("genesis-timestamp") ) { + string tstr = options.at("genesis-timestamp").as(); + if( strcasecmp (tstr.c_str(), "now") == 0 ) { + my->chain_config->genesis.initial_timestamp = fc::time_point::now(); + auto epoch_us = my->chain_config->genesis.initial_timestamp.time_since_epoch().count(); + auto diff_us = epoch_us % config::block_interval_us; + if (diff_us > 0) { + auto delay_us = (config::block_interval_us - diff_us); + my->chain_config->genesis.initial_timestamp += fc::microseconds(delay_us); + dlog("pausing ${us} microseconds to the next interval",("us",delay_us)); + } + } else { + my->chain_config->genesis.initial_timestamp = time_point::from_iso_string( tstr ); + } + ilog( "Adjusting genesis timestamp to ${timestamp}", ("timestamp", my->chain_config->genesis.initial_timestamp) ); + } } my->chain.emplace(*my->chain_config); @@ -342,7 +340,7 @@ void chain_plugin::plugin_startup() ("num", my->chain->head_block_num())("ts", (std::string)my->chain_config->genesis.initial_timestamp)); my->chain_config.reset(); -} FC_CAPTURE_LOG_AND_RETHROW( (my->genesis_file.generic_string()) ) } +} FC_CAPTURE_AND_RETHROW() } void chain_plugin::plugin_shutdown() { my->accepted_block_header_connection.reset(); From 7d7ca90418bf0db546de77a2d865b6c1b5f1b2d5 Mon Sep 17 00:00:00 2001 From: Khaled Al-Hassanieh Date: Fri, 25 May 2018 10:56:33 -0400 Subject: [PATCH 06/38] Change producer deactivation logic, fix unit tests --- contracts/eosio.system/voting.cpp | 23 +++++++++-------------- unittests/eosio.system_tests.cpp | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index acd6028d0ee..cfa602c33b0 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -79,8 +79,14 @@ namespace eosiosystem { for ( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 21 && 0 < it->total_votes; ++it ) { if( !it->active() ) continue; -#if 0 - if ( it->time_became_active.slot == 0 ) { + + /** + If it's the first time or it's been over a day since a producer was last voted in, + update his info. Otherwise, a producer gets a grace period of 7 hours after which + he gets deactivated if he hasn't produced in 24 hours. + */ + if ( it->time_became_active.slot == 0 || + block_time.slot > it->time_became_active.slot + blocks_per_day ) { _producers.modify( *it, 0, [&](auto& p) { p.time_became_active = block_time; }); @@ -91,24 +97,13 @@ namespace eosiosystem { p.time_became_active.slot = 0; }); - continue; - } -#else - if ( it->time_became_active.slot > 0 && - block_time.slot > (2 * 21 * 12 * 100) + it->time_became_active.slot && - block_time.slot > it->last_produced_block_time.slot + blocks_per_day ) { - _producers.modify( *it, 0, [&](auto& p) { - p.producer_key = public_key(); - p.time_became_active.slot = 0; - }); - continue; } else { _producers.modify( *it, 0, [&](auto& p) { p.time_became_active = block_time; }); } -#endif + top_producers.emplace_back( std::pair({{it->owner, it->producer_key}, it->location})); } diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index 696aaf4e227..adf42845cc7 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -1542,7 +1542,14 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni // wait two more hours, now most producers haven't produced in a day and will // be deactivated - produce_block(fc::seconds(9 * 3600)); + BOOST_REQUIRE_EQUAL(success(), push_action(N(producvotera), N(voteproducer), mvo() + ("voter", "producvotera") + ("proxy", name(0).to_string()) + ("producers", vector(producer_names.begin(), producer_names.begin()+21)) + ) + ); + + produce_block(fc::hours(9)); produce_blocks(8 * 21 * 12); { @@ -2497,9 +2504,8 @@ BOOST_FIXTURE_TEST_CASE( vote_producers_in_and_out, eosio_system_tester ) try { BOOST_REQUIRE(all_21_produced && rest_didnt_produce); } - produce_block(fc::hours(7)); - { + produce_block(fc::hours(7)); const uint32_t voted_out_index = 20; const uint32_t new_prod_index = 23; BOOST_REQUIRE_EQUAL(success(), stake("producvoterd", core_from_string("40000000.0000"), core_from_string("40000000.0000"))); @@ -2515,10 +2521,7 @@ BOOST_FIXTURE_TEST_CASE( vote_producers_in_and_out, eosio_system_tester ) try { const uint32_t initial_unpaid_blocks = get_producer_info(producer_names[voted_out_index])["unpaid_blocks"].as(); produce_blocks(2 * 12 * 21); BOOST_REQUIRE_EQUAL(initial_unpaid_blocks, get_producer_info(producer_names[voted_out_index])["unpaid_blocks"].as()); - produce_blocks(2 * 12 * 21); - produce_block(fc::hours(12)); - produce_blocks(2 * 12 * 21); - produce_block(fc::hours(12)); + produce_block(fc::hours(24)); BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterd), N(voteproducer), mvo() ("voter", "producvoterd") ("proxy", name(0).to_string()) @@ -2526,7 +2529,8 @@ BOOST_FIXTURE_TEST_CASE( vote_producers_in_and_out, eosio_system_tester ) try { ) ); produce_blocks(2 * 12 * 21); - BOOST_REQUIRE_EQUAL(fc::crypto::public_key(), fc::crypto::public_key(get_producer_info(producer_names[voted_out_index])["producer_key"].as_string())); + BOOST_REQUIRE(fc::crypto::public_key() != fc::crypto::public_key(get_producer_info(producer_names[voted_out_index])["producer_key"].as_string())); + BOOST_REQUIRE_EQUAL(success(), push_action(producer_names[voted_out_index], N(claimrewards), mvo()("owner", producer_names[voted_out_index]))); } } FC_LOG_AND_RETHROW() From 6b6e694afc21867fe604aa7b94155dd075a376e3 Mon Sep 17 00:00:00 2001 From: Anton Perkov Date: Fri, 25 May 2018 10:59:48 -0400 Subject: [PATCH 07/38] buyram: don't charge fee to eosio account #3414 --- contracts/eosio.system/delegate_bandwidth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/eosio.system/delegate_bandwidth.cpp b/contracts/eosio.system/delegate_bandwidth.cpp index e945b592484..681f533a1cd 100644 --- a/contracts/eosio.system/delegate_bandwidth.cpp +++ b/contracts/eosio.system/delegate_bandwidth.cpp @@ -117,7 +117,7 @@ namespace eosiosystem { { payer, N(eosio.ram), quant_after_fee, std::string("buy ram") } ); } - if( fee.amount > 0 ) { + if( payer != N(eosio) && fee.amount > 0 ) { INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)}, { payer, N(eosio.ramfee), fee, std::string("ram fee") } ); } From a815dcaaddc31750886fd327e1911e337dd7eb18 Mon Sep 17 00:00:00 2001 From: Khaled Al-Hassanieh Date: Fri, 25 May 2018 11:10:24 -0400 Subject: [PATCH 08/38] Fixed merge issue --- unittests/eosio.system_tests.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index 5915c2e9415..bb41e3eda40 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -2466,6 +2466,8 @@ BOOST_FIXTURE_TEST_CASE( vote_producers_in_and_out, eosio_system_tester ) try { BOOST_REQUIRE_EQUAL(success(), push_action(producer_names[voted_out_index], N(claimrewards), mvo()("owner", producer_names[voted_out_index]))); } +} FC_LOG_AND_RETHROW() + BOOST_FIXTURE_TEST_CASE( setparams, eosio_system_tester ) try { //install multisig contract abi_serializer msig_abi_ser = initialize_multisig(); From 3baa61d81108342111026775c5000428d938a831 Mon Sep 17 00:00:00 2001 From: Eric Iles Date: Fri, 25 May 2018 11:42:16 -0400 Subject: [PATCH 09/38] Update boost to 1.67.0 in builder --- Docker/builder/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Docker/builder/Dockerfile b/Docker/builder/Dockerfile index c0bfec7aeae..a01cce4942f 100644 --- a/Docker/builder/Dockerfile +++ b/Docker/builder/Dockerfile @@ -26,13 +26,13 @@ RUN wget --no-check-certificate https://cmake.org/files/v3.9/cmake-3.9.6-Linux-x ENV CC clang ENV CXX clang++ -RUN wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2 -O - | tar -xj \ - && cd boost_1_66_0 \ +RUN wget https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2 -O - | tar -xj \ + && cd boost_1_67_0 \ && ./bootstrap.sh --prefix=/usr/local \ && echo 'using clang : 4.0 : clang++-4.0 ;' >> project-config.jam \ && ./b2 -d0 -j$(nproc) --with-thread --with-date_time --with-system --with-filesystem --with-program_options \ --with-signals --with-serialization --with-chrono --with-test --with-context --with-locale --with-coroutine --with-iostreams toolset=clang link=static install \ - && cd .. && rm -rf boost_1_66_0 + && cd .. && rm -rf boost_1_67_0 RUN wget https://github.com/mongodb/mongo-c-driver/releases/download/1.9.3/mongo-c-driver-1.9.3.tar.gz -O - | tar -xz \ && cd mongo-c-driver-1.9.3 \ From 6d36665c897ade71294682a604963cde7aaffd4a Mon Sep 17 00:00:00 2001 From: Todd Fleming Date: Fri, 25 May 2018 11:54:48 -0400 Subject: [PATCH 10/38] bios-boot-tutorial: command line, increase producer stake --- .../bios-boot-tutorial/bios-boot-tutorial.py | 168 ++++++++++++------ 1 file changed, 114 insertions(+), 54 deletions(-) diff --git a/tutorials/bios-boot-tutorial/bios-boot-tutorial.py b/tutorials/bios-boot-tutorial/bios-boot-tutorial.py index a8fb0e58476..0f85d2e7cad 100755 --- a/tutorials/bios-boot-tutorial/bios-boot-tutorial.py +++ b/tutorials/bios-boot-tutorial/bios-boot-tutorial.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import argparse import json import numpy import os @@ -14,14 +15,14 @@ unlockTimeout = 99999999999 nodesDir = './nodes/' contractsDir = '../../build/contracts/' -cleos = 'cleos --wallet-url http://localhost:6666 --url http://localhost:8000 ' +cleos = 'cleos --wallet-url http://localhost:6666 ' nodeos = 'nodeos' fastUnstakeSystem = './fast.refund/eosio.system/eosio.system.wasm' logFile = open('test.log', 'a') symbol = 'SYS' maxUserKeys = 10 # Maximum user keys to import into wallet -minProducerStake = 20.0000 # Minimum producer CPU and BW stake +minProducerStake = 200.0000 # Minimum producer CPU and BW stake extraIssue = 10.0000 # Extra amount to issue to cover buying ram limitUsers = 0 # Limit number of users if >0 limitProducers = 0 # Limit number of producers if >0 @@ -60,15 +61,15 @@ def jsonArg(a): return " '" + json.dumps(a) + "' " def run(args): - print('test.py:', args) + print('bios-boot-tutorial.py:', args) logFile.write(args + '\n') if subprocess.call(args, shell=True): - print('test.py: exiting because of error') + print('bios-boot-tutorial.py: exiting because of error') sys.exit(1) def retry(args): while True: - print('test.py:', args) + print('bios-boot-tutorial.py:', args) logFile.write(args + '\n') if subprocess.call(args, shell=True): print('*** Retry') @@ -76,18 +77,18 @@ def retry(args): break def background(args): - print('test.py:', args) + print('bios-boot-tutorial.py:', args) logFile.write(args + '\n') return subprocess.Popen(args, shell=True) def getOutput(args): - print('test.py:', args) + print('bios-boot-tutorial.py:', args) logFile.write(args + '\n') proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE) return proc.communicate()[0].decode('utf-8') def getJsonOutput(args): - print('test.py:', args) + print('bios-boot-tutorial.py:', args) logFile.write(args + '\n') proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE) return json.loads(proc.communicate()[0]) @@ -201,9 +202,11 @@ def vote(b, e): def claimRewards(): table = getJsonOutput(cleos + 'get table eosio eosio producers -l 100') + times = [] for row in table['rows']: if row['unpaid_blocks'] and not row['last_claim_time']: - run(cleos + 'system claimrewards ' + row['owner']) + times.append(getJsonOutput(cleos + 'system claimrewards -j ' + row['owner'])['processed']['elapsed']) + print('Elapsed time for claimrewards:', times) def vote(b, e): for i in range(b, e): @@ -246,15 +249,13 @@ def sendUnstakedFunds(b, e): a = accounts[i] run(cleos + 'transfer eosio ' + a['name'] + ' "10.0000 ' + symbol + '"') -def randomTransfer(b, e, n): - for i in range(n): - for j in range(20): - src = accounts[random.randint(b, e - 1)]['name'] - dest = src - while dest == src: - dest = accounts[random.randint(b, e - 1)]['name'] - run(cleos + 'transfer -f ' + src + ' ' + dest + ' "0.0001 ' + symbol + '"' + ' || true') - sleep(.25) +def randomTransfer(b, e): + for j in range(20): + src = accounts[random.randint(b, e - 1)]['name'] + dest = src + while dest == src: + dest = accounts[random.randint(b, e - 1)]['name'] + run(cleos + 'transfer -f ' + src + ' ' + dest + ' "0.0001 ' + symbol + '"' + ' || true') def msigProposeReplaceSystem(proposer, proposalName): requestedPermissions = [] @@ -295,39 +296,98 @@ def produceNewAccounts(): f.write(' {"name":"%s", "pvt":"%s", "pub":"%s"},\n' % (name, r[1], r[2])) logFile.write('\n\n' + '*' * 80 + '\n\n\n') -run('killall keosd nodeos || true') -sleep(1.5) -startWallet() -importKeys() -startNode(0, {'name': 'eosio', 'pvt': eosioPvt, 'pub': eosioPub}) -sleep(1.5) -createSystemAccounts() -run(cleos + 'set contract eosio.token ' + contractsDir + 'eosio.token/') -run(cleos + 'set contract eosio.msig ' + contractsDir + 'eosio.msig/') -run(cleos + 'push action eosio.token create \'["eosio", "10000000000.0000 %s"]\' -p eosio.token' % (symbol)) -totalAllocation = fillStake(0, len(accounts)) -run(cleos + 'push action eosio.token issue \'["eosio", "%s", "memo"]\' -p eosio' % intToCurrency(totalAllocation)) -sleep(1) -retry(cleos + 'set contract eosio ' + contractsDir + 'eosio.system/') -sleep(1) -run(cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active') -createStakedAccounts(0, len(accounts)) -regProducers(firstProducer, firstProducer + numProducers) -sleep(1) -listProducers() -startProducers(firstProducer, firstProducer + numProducers) -sleep(producerSyncDelay) -vote(0, 0 + numVoters) -sleep(1) -listProducers() -sleep(5) -claimRewards() -proxyVotes(0, 0 + numVoters) -resign('eosio', 'eosio.prods') -for a in systemAccounts: - resign(a, 'eosio') -# msigReplaceSystem() -run(cleos + 'push action eosio.token issue \'["eosio", "%d.0000 %s", "memo"]\' -p eosio' % ((len(accounts)) * 10, symbol)) -sendUnstakedFunds(0, numSenders) -randomTransfer(0, numSenders, 8) -run('tail -n 60 ' + nodesDir + '00-eosio/stderr') + +def stepKillAll(): + run('killall keosd nodeos || true') + sleep(1.5) +def stepStartWallet(): + startWallet() + importKeys() +def stepStartBoot(): + startNode(0, {'name': 'eosio', 'pvt': eosioPvt, 'pub': eosioPub}) + sleep(1.5) +def stepInstallSystemContracts(): + run(cleos + 'set contract eosio.token ' + contractsDir + 'eosio.token/') + run(cleos + 'set contract eosio.msig ' + contractsDir + 'eosio.msig/') +def stepCreateTokens(): + run(cleos + 'push action eosio.token create \'["eosio", "10000000000.0000 %s"]\' -p eosio.token' % (symbol)) + totalAllocation = fillStake(0, len(accounts)) + run(cleos + 'push action eosio.token issue \'["eosio", "%s", "memo"]\' -p eosio' % intToCurrency(totalAllocation)) + sleep(1) +def stepSetSystemContract(): + retry(cleos + 'set contract eosio ' + contractsDir + 'eosio.system/') + sleep(1) + run(cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active') +def stepCreateStakedAccounts(): + createStakedAccounts(0, len(accounts)) +def stepRegProducers(): + regProducers(firstProducer, firstProducer + numProducers) + sleep(1) + listProducers() +def stepStartProducers(): + startProducers(firstProducer, firstProducer + numProducers) + sleep(producerSyncDelay) +def stepVote(): + vote(0, 0 + numVoters) + sleep(1) + listProducers() + sleep(5) +def stepProxyVotes(): + proxyVotes(0, 0 + numVoters) +def stepResign(): + resign('eosio', 'eosio.prods') + for a in systemAccounts: + resign(a, 'eosio') +def stepIssueUnstaked(): + run(cleos + 'push action eosio.token issue \'["eosio", "%d.0000 %s", "memo"]\' -p eosio' % ((len(accounts)) * 10, symbol)) + sendUnstakedFunds(0, numSenders) +def stepTransfer(): + while True: + randomTransfer(0, numSenders) +def stepLog(): + run('tail -n 60 ' + nodesDir + '00-eosio/stderr') + +commands = [ + ('k', 'kill', stepKillAll, True, "Kill all nodeos and keosd processes"), + ('w', 'wallet', stepStartWallet, True, "Start keosd, create wallet, fill with keys"), + ('b', 'boot', stepStartBoot, True, "Start boot node"), + ('s', 'sys', createSystemAccounts, True, "Create system accounts (eosio.*)"), + ('c', 'contracts', stepInstallSystemContracts, True, "Install system contracts (token, msig)"), + ('t', 'tokens', stepCreateTokens, True, "Create tokens"), + ('S', 'sys-contract', stepSetSystemContract, True, "Set system contract"), + ('T', 'stake', stepCreateStakedAccounts, True, "Create staked accounts"), + ('p', 'reg-prod', stepRegProducers, True, "Register producers"), + ('P', 'start-prod', stepStartProducers, True, "Start producers"), + ('v', 'vote', stepVote, True, "Vote for producers"), + ('R', 'claim', claimRewards, True, "Claim rewards"), + ('x', 'proxy', stepProxyVotes, True, "Proxy votes"), + ('q', 'resign', stepResign, True, "Resign eosio"), + ('m', 'msg-replace', msigReplaceSystem, False, "Replace system contract using msig"), + ('u', 'issue', stepIssueUnstaked, True, "Issue unstaked tokens"), + ('X', 'xfer', stepTransfer, False, "Random transfer tokens (infinite loop)"), + ('l', 'log', stepLog, True, "Show tail of node's log"), +] + +parser = argparse.ArgumentParser() +parser.add_argument('-a', '--all', action='store_true', help="Do everything marked with (*)") +parser.add_argument('-H', '--http-port', type=int, default=8000, help='Http port for cleos') +for (flag, command, function, inAll, help) in commands: + prefix = '' + if inAll: prefix += '*' + if prefix: help = '(' + prefix + ') ' + help + if flag: + parser.add_argument('-' + flag, '--' + command, action='store_true', help=help, dest=command) + else: + parser.add_argument('--' + command, action='store_true', help=help, dest=command) +args = parser.parse_args() + +cleos += '--url http://localhost:%d ' % args.http_port + +haveCommand = False +for (flag, command, function, inAll, help) in commands: + if getattr(args, command) or inAll and args.all: + if function: + haveCommand = True + function() +if not haveCommand: + print('bios-boot-tutorial.py: Tell me what to do. -a does almost everything. -h shows options.') From 6d865d9c3c8f6a9239e06a1c0b53cd450de32784 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Fri, 25 May 2018 13:37:33 -0400 Subject: [PATCH 11/38] Don't use eosio.token for txn_test_gen_plugin; make separate account Don't use the eosio.token account for txn_test_gen_plugin usage; this frequently clashes will a real network. Create another account where we upload eosio.token for txn_test_gen_plugin usage --- .../txn_test_gen_plugin.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp index ac16f67da0b..20212a2b7e4 100644 --- a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp +++ b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp @@ -73,7 +73,7 @@ struct txn_test_gen_plugin_impl { void create_test_accounts(const std::string& init_name, const std::string& init_priv_key) { name newaccountA("txn.test.a"); name newaccountB("txn.test.b"); - name newaccountC("eosio.token"); + name newaccountC("txn.test.t"); name creator(init_name); abi_def currency_abi_def = fc::json::from_string(eosio_token_abi).as(); @@ -109,7 +109,7 @@ struct txn_test_gen_plugin_impl { trx.actions.emplace_back(vector{{creator,"active"}}, newaccount{creator, newaccountB, owner_auth, active_auth}); } - //create "eosio.token" account + //create "txn.test.t" account { auto owner_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}}; auto active_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}}; @@ -123,7 +123,7 @@ struct txn_test_gen_plugin_impl { push_transaction(trx); } - //set eosio.token contract & initialize it + //set txn.test.t contract to eosio.token & initialize it { signed_transaction trx; @@ -144,34 +144,34 @@ struct txn_test_gen_plugin_impl { { action act; - act.account = N(eosio.token); + act.account = N(txn.test.t); act.name = N(create); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"eosio.token\",\"maximum_supply\":\"1000000000.0000 CUR\"}}")); + act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"txn.test.t\",\"maximum_supply\":\"1000000000.0000 CUR\"}}")); trx.actions.push_back(act); } { action act; - act.account = N(eosio.token); + act.account = N(txn.test.t); act.name = N(issue); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = eosio_token_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"eosio.token\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}")); + act.data = eosio_token_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"txn.test.t\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}")); trx.actions.push_back(act); } { action act; - act.account = N(eosio.token); + act.account = N(txn.test.t); act.name = N(transfer); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"eosio.token\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); + act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); trx.actions.push_back(act); } { action act; - act.account = N(eosio.token); + act.account = N(txn.test.t); act.name = N(transfer); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"eosio.token\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); + act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); trx.actions.push_back(act); } @@ -196,12 +196,12 @@ struct txn_test_gen_plugin_impl { running = true; //create the actions here - act_a_to_b.account = N(eosio.token); + act_a_to_b.account = N(txn.test.t); act_a_to_b.name = N(transfer); act_a_to_b.authorization = vector{{name("txn.test.a"),config::active_name}}; act_a_to_b.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.a\",\"to\":\"txn.test.b\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt)))); - act_b_to_a.account = N(eosio.token); + act_b_to_a.account = N(txn.test.t); act_b_to_a.name = N(transfer); act_b_to_a.authorization = vector{{name("txn.test.b"),config::active_name}}; act_b_to_a.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.b\",\"to\":\"txn.test.a\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt)))); From 7ae937eca545a4baed847c1740a70f70e668ae95 Mon Sep 17 00:00:00 2001 From: arhag Date: Fri, 25 May 2018 14:09:11 -0400 Subject: [PATCH 12/38] chain ID is now hash of genesis state #3415 Also the initial public key of the 'eosio' account can now be specified in CMake rather than specifying the chain ID. --- CMakeLists.txt | 8 +- libraries/chain/CMakeLists.txt | 21 ++---- libraries/chain/chain_id.cpp.in | 6 -- libraries/chain/controller.cpp | 10 ++- libraries/chain/genesis_state.cpp | 8 +- libraries/chain/genesis_state_root_key.cpp.in | 12 +++ .../chain/include/eosio/chain/controller.hpp | 2 + .../chain/include/eosio/chain/core_symbol.hpp | 8 -- .../include/eosio/chain/genesis_state.hpp | 8 +- .../eosio/chain/transaction_metadata.hpp | 21 +++--- libraries/chain/include/eosio/chain/types.hpp | 8 +- libraries/testing/tester.cpp | 30 ++++---- plugins/chain_plugin/chain_plugin.cpp | 25 ++++++- .../eosio/chain_plugin/chain_plugin.hpp | 5 +- plugins/net_plugin/net_plugin.cpp | 20 ++--- .../txn_test_gen_plugin.cpp | 6 +- programs/cleos/main.cpp | 20 +++-- tests/chain_tests/block_tests.cpp | 36 ++++----- unittests/api_tests.cpp | 50 ++++++------- unittests/auth_tests.cpp | 8 +- unittests/currency_tests.cpp | 8 +- unittests/delay_tests.cpp | 26 +++---- unittests/dice_tests.cpp | 62 ++++++++-------- unittests/eosio_system_tester.hpp | 6 +- unittests/exchange_tests.cpp | 4 +- unittests/misc_tests.cpp | 4 +- unittests/multi_index_tests.cpp | 4 +- unittests/multisig_tests.cpp | 2 +- unittests/wasm_tests.cpp | 74 +++++++++---------- 29 files changed, 274 insertions(+), 228 deletions(-) delete mode 100644 libraries/chain/chain_id.cpp.in create mode 100644 libraries/chain/genesis_state_root_key.cpp.in delete mode 100644 libraries/chain/include/eosio/chain/core_symbol.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 092eac8cd54..aa6a78fb0a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,7 +190,13 @@ if (CORE_SYMBOL_NAME_LENGTH GREATER 7) message(FATAL_ERROR "CORE_SYMBOL_NAME lenght must be a between 1 and 7 characters") endif() -message( STATUS "Using ${CORE_SYMBOL_NAME} as CORE symbol name") +message( STATUS "Using '${CORE_SYMBOL_NAME}' as CORE symbol name" ) + +if ("${EOSIO_ROOT_KEY}" STREQUAL "") + set(EOSIO_ROOT_KEY "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV") +endif() + +message( STATUS "Using '${EOSIO_ROOT_KEY}' as public key for eosio account" ) include(wasm) diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 20b12847cb1..03f620c24f6 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -1,16 +1,9 @@ -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/chain/core_symbol.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/chain/core_symbol.hpp) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/eosio/chain/core_symbol.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/eosio/chain/core_symbol.hpp) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/genesis_state_root_key.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/genesis_state_root_key.cpp) -# set the chain id -if (NOT "${CHAIN_ID}" STREQUAL "") - set(eosio_CHAIN_ID "${CHAIN_ID}") -else() - ## sha256("eosio::chain version 1.0") - set(eosio_CHAIN_ID "144B6AB7924EA47BAE7A5846B4494A35563AE816E2ED5AFFA7A9C990C2B3CFB3") -endif() - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/chain_id.cpp.in ${CMAKE_CURRENT_SOURCE_DIR}/chain_id.cpp) - -file(GLOB HEADERS "include/eosio/chain/*.hpp" "include/eosio/chain/contracts/*.hpp") +file(GLOB HEADERS "include/eosio/chain/*.hpp" + "include/eosio/chain/contracts/*.hpp" + "${CMAKE_CURRENT_BINARY_DIR}/include/eosio/chain/core_symbol.hpp" ) ## SORT .cpp by most likely to change / break compile add_library( eosio_chain @@ -25,12 +18,12 @@ add_library( eosio_chain authorization_manager.cpp resource_limits.cpp block_log.cpp - genesis_state.cpp transaction_context.cpp eosio_contract.cpp eosio_contract_abi.cpp chain_config.cpp - chain_id.cpp + genesis_state.cpp + ${CMAKE_CURRENT_BINARY_DIR}/genesis_state_root_key.cpp # chain_config.cpp # block_trace.cpp diff --git a/libraries/chain/chain_id.cpp.in b/libraries/chain/chain_id.cpp.in deleted file mode 100644 index 204f0eca894..00000000000 --- a/libraries/chain/chain_id.cpp.in +++ /dev/null @@ -1,6 +0,0 @@ -#include - -namespace eosio { namespace chain { - chain_id_type::chain_id_type( const fc::string& s ) { id = fc::sha256(s); } - chain_id_type::chain_id_type() { id = fc::sha256("${eosio_CHAIN_ID}"); } -}} // namespace eosio::chain diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 8017b6d350c..7e632988b14 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -56,6 +56,7 @@ struct controller_impl { resource_limits_manager resource_limits; authorization_manager authorization; controller::config conf; + chain_id_type chain_id; bool replaying = false; bool replaying_irreversible = false; @@ -103,7 +104,8 @@ struct controller_impl { wasmif( cfg.wasm_runtime ), resource_limits( db ), authorization( s, db ), - conf( cfg ) + conf( cfg ), + chain_id( cfg.genesis.compute_chain_id() ) { #define SET_APP_HANDLER( receiver, contract, action) \ @@ -645,7 +647,7 @@ struct controller_impl { if( !self.skip_auth_check() && !implicit ) { authorization.check_authorization( trx->trx.actions, - trx->recover_keys(), + trx->recover_keys( chain_id ), {}, trx_context.delay, [](){} @@ -1290,6 +1292,10 @@ bool controller::contracts_console()const { return my->conf.contracts_console; } +chain_id_type controller::get_chain_id()const { + return my->chain_id; +} + const apply_handler* controller::find_apply_handler( account_name receiver, account_name scope, action_name act ) const { auto native_handler_scope = my->apply_handlers.find( receiver ); diff --git a/libraries/chain/genesis_state.cpp b/libraries/chain/genesis_state.cpp index d0e42fcd519..1835378ba58 100644 --- a/libraries/chain/genesis_state.cpp +++ b/libraries/chain/genesis_state.cpp @@ -10,9 +10,15 @@ namespace eosio { namespace chain { +genesis_state::genesis_state() { + initial_timestamp = fc::time_point::from_iso_string( "2018-03-02T12:00:00" ); + initial_key = fc::variant(eosio_root_key).as(); +} chain::chain_id_type genesis_state::compute_chain_id() const { - return config::chain_id; + digest_type::encoder enc; + fc::raw::pack( enc, *this ); + return enc.result(); } } } // namespace eosio::chain diff --git a/libraries/chain/genesis_state_root_key.cpp.in b/libraries/chain/genesis_state_root_key.cpp.in new file mode 100644 index 00000000000..6530698e33a --- /dev/null +++ b/libraries/chain/genesis_state_root_key.cpp.in @@ -0,0 +1,12 @@ +/** + * @file + * @copyright defined in eos/LICENSE.txt + */ + +#include + +namespace eosio { namespace chain { + +const string genesis_state::eosio_root_key = "${EOSIO_ROOT_KEY}"; + +} } // namespace eosio::chain diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 689753efd75..d2cb25aa6d2 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -154,6 +154,8 @@ namespace eosio { namespace chain { bool contracts_console()const; + chain_id_type get_chain_id()const; + signal accepted_block_header; signal accepted_block; signal irreversible_block; diff --git a/libraries/chain/include/eosio/chain/core_symbol.hpp b/libraries/chain/include/eosio/chain/core_symbol.hpp deleted file mode 100644 index 119ed916f93..00000000000 --- a/libraries/chain/include/eosio/chain/core_symbol.hpp +++ /dev/null @@ -1,8 +0,0 @@ -/** @file - * @copyright defined in eos/LICENSE.txt - * - * \warning This file is machine generated. DO NOT EDIT. See core_symbol.hpp.in for changes. - */ - -#define CORE_SYMBOL SY(4,SYS) -#define CORE_SYMBOL_NAME "SYS" diff --git a/libraries/chain/include/eosio/chain/genesis_state.hpp b/libraries/chain/include/eosio/chain/genesis_state.hpp index e570d9614fe..9fd05a82dc6 100644 --- a/libraries/chain/include/eosio/chain/genesis_state.hpp +++ b/libraries/chain/include/eosio/chain/genesis_state.hpp @@ -16,6 +16,10 @@ namespace eosio { namespace chain { struct genesis_state { + genesis_state(); + + static const string eosio_root_key; + chain_config initial_configuration = { .max_block_net_usage = config::default_max_block_net_usage, .target_block_net_usage_pct = config::default_target_block_net_usage_pct, @@ -38,8 +42,8 @@ struct genesis_state { .max_authority_depth = config::default_max_auth_depth, }; - time_point initial_timestamp = fc::time_point::from_iso_string( "2018-03-02T12:00:00" ); - public_key_type initial_key = fc::variant("EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV").as(); + time_point initial_timestamp; + public_key_type initial_key; /** * Get the chain_id corresponding to this genesis state. diff --git a/libraries/chain/include/eosio/chain/transaction_metadata.hpp b/libraries/chain/include/eosio/chain/transaction_metadata.hpp index a7a04407269..d89d09a6288 100644 --- a/libraries/chain/include/eosio/chain/transaction_metadata.hpp +++ b/libraries/chain/include/eosio/chain/transaction_metadata.hpp @@ -15,12 +15,12 @@ namespace eosio { namespace chain { */ class transaction_metadata { public: - transaction_id_type id; - transaction_id_type signed_id; - signed_transaction trx; - packed_transaction packed_trx; - optional> signing_keys; - bool accepted = false; + transaction_id_type id; + transaction_id_type signed_id; + signed_transaction trx; + packed_transaction packed_trx; + optional>> signing_keys; + bool accepted = false; transaction_metadata( const signed_transaction& t, packed_transaction::compression_type c = packed_transaction::none ) :trx(t),packed_trx(t, c) { @@ -36,11 +36,10 @@ class transaction_metadata { signed_id = digest_type::hash(packed_trx); } - const flat_set& recover_keys() { - // TODO: Update caching logic below when we use a proper chain id setup for the particular blockchain rather than just chain_id_type() - if( !signing_keys ) - signing_keys = trx.get_signature_keys( chain_id_type() ); - return *signing_keys; + const flat_set& recover_keys( const chain_id_type& chain_id ) { + if( !signing_keys || signing_keys->first != chain_id ) // Unlikely for more than one chain_id to be used in one nodeos instance + signing_keys = std::make_pair( chain_id, trx.get_signature_keys( chain_id ) ); + return signing_keys->second; } uint32_t total_actions()const { return trx.context_free_actions.size() + trx.actions.size(); } diff --git a/libraries/chain/include/eosio/chain/types.hpp b/libraries/chain/include/eosio/chain/types.hpp index 98f05b33770..1d5cdfe827a 100644 --- a/libraries/chain/include/eosio/chain/types.hpp +++ b/libraries/chain/include/eosio/chain/types.hpp @@ -88,12 +88,19 @@ namespace eosio { namespace chain { struct void_t{}; + using chain_id_type = fc::sha256; + /* + struct genesis_state; + struct chain_id_type { chain_id_type(const fc::string& s); + //chain_id_type( const genesis_state& gs ); chain_id_type(); operator fc::sha256() { return id; } fc::sha256 id; }; + */ + using chainbase::allocator; using shared_string = boost::interprocess::basic_string, allocator>; @@ -228,4 +235,3 @@ FC_REFLECT_ENUM(eosio::chain::object_type, (OBJECT_TYPE_COUNT) ) FC_REFLECT( eosio::chain::void_t, ) -FC_REFLECT(eosio::chain::chain_id_type, (id) ) diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index 69d1862f87a..863b5d381ca 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -268,7 +268,7 @@ namespace eosio { namespace testing { }); set_transaction_headers(trx); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); return push_transaction( trx ); } @@ -312,7 +312,7 @@ namespace eosio { namespace testing { trx.actions.emplace_back(std::move(act)); set_transaction_headers(trx); if (authorizer) { - trx.sign(get_private_key(authorizer, "active"), chain_id_type()); + trx.sign(get_private_key(authorizer, "active"), control->get_chain_id()); } try { push_transaction(trx); @@ -369,7 +369,7 @@ namespace eosio { namespace testing { trx.actions.emplace_back( get_action( code, acttype, auths, data ) ); set_transaction_headers( trx, expiration, delay_sec ); for (const auto& auth : auths) { - trx.sign( get_private_key( auth.actor, auth.permission.to_string() ), chain_id_type() ); + trx.sign( get_private_key( auth.actor, auth.permission.to_string() ), control->get_chain_id() ); } return push_transaction( trx ); @@ -411,7 +411,7 @@ namespace eosio { namespace testing { abi_serializer::from_variant(pretty_trx, trx, get_resolver()); set_transaction_headers(trx); for(auto iter = keys.begin(); iter != keys.end(); iter++) - trx.sign( *iter, chain_id_type() ); + trx.sign( *iter, control->get_chain_id() ); return push_transaction( trx ); } @@ -457,7 +457,7 @@ namespace eosio { namespace testing { abi_serializer::from_variant(pretty_trx, trx, get_resolver()); set_transaction_headers(trx); - trx.sign( get_private_key( from, "active" ), chain_id_type() ); + trx.sign( get_private_key( from, "active" ), control->get_chain_id() ); return push_transaction( trx, fc::time_point::maximum(), billed_cpu_time_us ); } @@ -491,7 +491,7 @@ namespace eosio { namespace testing { abi_serializer::from_variant(pretty_trx, trx, get_resolver()); set_transaction_headers(trx); - trx.sign( get_private_key( from, name(config::active_name).to_string() ), chain_id_type() ); + trx.sign( get_private_key( from, name(config::active_name).to_string() ), control->get_chain_id() ); return push_transaction( trx ); } @@ -518,7 +518,7 @@ namespace eosio { namespace testing { abi_serializer::from_variant(pretty_trx, trx, get_resolver()); set_transaction_headers(trx); - trx.sign( get_private_key( currency, name(config::active_name).to_string() ), chain_id_type() ); + trx.sign( get_private_key( currency, name(config::active_name).to_string() ), control->get_chain_id() ); return push_transaction( trx ); } @@ -529,7 +529,7 @@ namespace eosio { namespace testing { trx.actions.emplace_back( vector{{account, config::active_name}}, linkauth(account, code, type, req)); set_transaction_headers(trx); - trx.sign( get_private_key( account, "active" ), chain_id_type() ); + trx.sign( get_private_key( account, "active" ), control->get_chain_id() ); push_transaction( trx ); } @@ -541,7 +541,7 @@ namespace eosio { namespace testing { trx.actions.emplace_back( vector{{account, config::active_name}}, unlinkauth(account, code, type )); set_transaction_headers(trx); - trx.sign( get_private_key( account, "active" ), chain_id_type() ); + trx.sign( get_private_key( account, "active" ), control->get_chain_id() ); push_transaction( trx ); } @@ -565,7 +565,7 @@ namespace eosio { namespace testing { set_transaction_headers(trx); for (const auto& key: keys) { - trx.sign( key, chain_id_type() ); + trx.sign( key, control->get_chain_id() ); } push_transaction( trx ); @@ -591,7 +591,7 @@ namespace eosio { namespace testing { set_transaction_headers(trx); for (const auto& key: keys) { - trx.sign( key, chain_id_type() ); + trx.sign( key, control->get_chain_id() ); } push_transaction( trx ); @@ -621,9 +621,9 @@ namespace eosio { namespace testing { set_transaction_headers(trx); if( signer ) { - trx.sign( *signer, chain_id_type() ); + trx.sign( *signer, control->get_chain_id() ); } else { - trx.sign( get_private_key( account, "active" ), chain_id_type() ); + trx.sign( get_private_key( account, "active" ), control->get_chain_id() ); } push_transaction( trx ); } FC_CAPTURE_AND_RETHROW( (account) ) @@ -640,9 +640,9 @@ namespace eosio { namespace testing { set_transaction_headers(trx); if( signer ) { - trx.sign( *signer, chain_id_type() ); + trx.sign( *signer, control->get_chain_id() ); } else { - trx.sign( get_private_key( account, "active" ), chain_id_type() ); + trx.sign( get_private_key( account, "active" ), control->get_chain_id() ); } push_transaction( trx ); } diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index dd88e890dd7..a4b515df8c7 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -62,7 +62,7 @@ class chain_plugin_impl { fc::optional fork_db; fc::optional block_logger; - fc::optional chain_config = controller::config(); + fc::optional chain_config; fc::optional chain; chain_id_type chain_id; //txn_msg_rate_limits rate_limits; @@ -150,6 +150,16 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip void chain_plugin::plugin_initialize(const variables_map& options) { ilog("initializing chain plugin"); + try { + genesis_state gs; // Check if EOSIO_ROOT_KEY is bad + } catch( const fc::exception& ) { + elog( "EOSIO_ROOT_KEY ('${root_key}') is invalid. Recompile with a valid public key.", + ("root_key", genesis_state::eosio_root_key) ); + throw; + } + + my->chain_config = controller::config(); + if (options.count("blocks-dir")) { auto bld = options.at("blocks-dir").as(); if(bld.is_relative()) @@ -189,7 +199,13 @@ void chain_plugin::plugin_initialize(const variables_map& options) { my->chain_config->contracts_console = options.at("contracts-console").as(); if( options.count("extract-genesis-json") || options.at("print-genesis-json").as() ) { - auto gs = block_log::extract_genesis_state( my->blocks_dir ); + genesis_state gs; + + if( fc::exists( my->blocks_dir / "blocks.log" ) ) { + gs = block_log::extract_genesis_state( my->blocks_dir ); + } else { + wlog( "No blocks.log found at '${p}'. Using default genesis state.", ("p", (my->blocks_dir / "blocks.log").generic_string()) ); + } if( options.at("print-genesis-json").as() ) { ilog( "Genesis JSON:\n${genesis}", ("genesis", json::to_pretty_string(gs)) ); @@ -452,8 +468,8 @@ controller::config& chain_plugin::chain_config() { controller& chain_plugin::chain() { return *my->chain; } const controller& chain_plugin::chain() const { return *my->chain; } -void chain_plugin::get_chain_id(chain_id_type &cid)const { - memcpy(cid.id.data(), my->chain_id.id.data(), cid.id.data_size()); +chain::chain_id_type chain_plugin::get_chain_id()const { + return my->chain_id; } namespace chain_apis { @@ -464,6 +480,7 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params const auto& rm = db.get_resource_limits_manager(); return { eosio::utilities::common::itoh(static_cast(app().version())), + db.get_chain_id(), db.head_block_num(), db.last_irreversible_block_num(), db.last_irreversible_block_id(), diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index fe138e7fd31..f58b4958eba 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -60,6 +60,7 @@ class read_only { struct get_info_results { string server_version; + chain::chain_id_type chain_id; uint32_t head_block_num = 0; uint32_t last_irreversible_block_num = 0; chain::block_id_type last_irreversible_block_id; @@ -378,7 +379,7 @@ class chain_plugin : public plugin { // Only call this after plugin_startup()! const controller& chain() const; - void get_chain_id(chain::chain_id_type& cid) const; + chain::chain_id_type get_chain_id() const; private: unique_ptr my; @@ -389,7 +390,7 @@ class chain_plugin : public plugin { FC_REFLECT( eosio::chain_apis::permission, (perm_name)(parent)(required_auth) ) FC_REFLECT(eosio::chain_apis::empty, ) FC_REFLECT(eosio::chain_apis::read_only::get_info_results, -(server_version)(head_block_num)(last_irreversible_block_num)(last_irreversible_block_id)(head_block_id)(head_block_time)(head_block_producer)(virtual_block_cpu_limit)(virtual_block_net_limit)(block_cpu_limit)(block_net_limit) ) +(server_version)(chain_id)(head_block_num)(last_irreversible_block_num)(last_irreversible_block_id)(head_block_id)(head_block_time)(head_block_producer)(virtual_block_cpu_limit)(virtual_block_net_limit)(block_cpu_limit)(block_net_limit) ) FC_REFLECT(eosio::chain_apis::read_only::get_block_params, (block_num_or_id)) FC_REFLECT( eosio::chain_apis::read_write::push_transaction_results, (transaction_id)(processed) ) diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 20fe52f0ac9..232376c58fd 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -52,7 +52,7 @@ namespace eosio { namespace bip = boost::interprocess; class connection; - + class sync_manager; class dispatch_manager; @@ -409,7 +409,7 @@ namespace eosio { } } set_is_known; - + struct update_block_num { uint32_t new_bnum; update_block_num(uint32_t bnum) : new_bnum(bnum) {} @@ -579,7 +579,7 @@ namespace eosio { * encountered unpacking or processing the message. */ bool process_next_message(net_plugin_impl& impl, uint32_t message_length); - + bool add_peer_block(const peer_block_state &pbs); }; @@ -1607,7 +1607,7 @@ namespace eosio { pending_notify.known_blocks.mode = normal; pending_notify.known_blocks.ids.push_back( bid ); pending_notify.known_trx.mode = none; - + peer_block_state pbstate = {bid, bnum, false,true,time_point()}; // skip will be empty if our producer emitted this block so just send it if (( large_msg_notify && msgsiz > just_send_it_max) && skip) { @@ -1644,11 +1644,11 @@ namespace eosio { c->last_req.reset(); } c->add_peer_block({id, bnum, false,true,time_point()}); - + fc_dlog(logger, "canceling wait on ${p}", ("p",c->peer_name())); c->cancel_wait(); } - + void dispatch_manager::rejected_block (const block_id_type& id) { fc_dlog(logger,"not sending rejected transaction ${tid}",("tid",id)); for (auto org = received_blocks.begin(); org != received_blocks.end(); org++) { @@ -1743,7 +1743,7 @@ namespace eosio { } } - + void dispatch_manager::recv_transaction (connection_ptr c, const transaction_id_type& id) { received_transactions.emplace_back((transaction_origin){id, c}); if (c && @@ -1766,7 +1766,7 @@ namespace eosio { } } } - + void dispatch_manager::recv_notice (connection_ptr c, const notice_message& msg, bool generated) { request_message req; req.req_trx.mode = none; @@ -2180,7 +2180,7 @@ namespace eosio { fc_dlog(logger, "skipping duplicate check, addr == ${pa}, id = ${ni}",("pa",c->peer_addr)("ni",c->last_handshake_recv.node_id)); } - if( msg.chain_id.id != chain_id.id) { + if( msg.chain_id != chain_id) { elog( "Peer on a different chain. Closing connection"); c->enqueue( go_away_message(go_away_reason::wrong_chain) ); return; @@ -2886,7 +2886,7 @@ namespace eosio { } my->chain_plug = app().find_plugin(); - my->chain_plug->get_chain_id(my->chain_id); + my->chain_id = app().get_plugin().get_chain_id(); fc::rand_pseudo_bytes(my->node_id.data(), my->node_id.data_size()); ilog("my node_id is ${id}",("id",my->node_id)); diff --git a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp index ac16f67da0b..af2210e54b7 100644 --- a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp +++ b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp @@ -79,8 +79,7 @@ struct txn_test_gen_plugin_impl { abi_def currency_abi_def = fc::json::from_string(eosio_token_abi).as(); controller& cc = app().get_plugin().chain(); - chain::chain_id_type chainid; - app().get_plugin().get_chain_id(chainid); + auto chainid = app().get_plugin().get_chain_id(); fc::crypto::private_key txn_test_receiver_A_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'a'))); fc::crypto::private_key txn_test_receiver_B_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'b'))); @@ -233,8 +232,7 @@ struct txn_test_gen_plugin_impl { void send_transaction() { controller& cc = app().get_plugin().chain(); - chain::chain_id_type chainid; - app().get_plugin().get_chain_id(chainid); + auto chainid = app().get_plugin().get_chain_id(); name sender("txn.test.a"); name recipient("txn.test.b"); diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 795379173f6..9bd2bdc3b3e 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -256,9 +256,8 @@ fc::variant determine_required_keys(const signed_transaction& trx) { return required_keys["required_keys"]; } -void sign_transaction(signed_transaction& trx, fc::variant& required_keys) { - // TODO determine chain id - fc::variants sign_args = {fc::variant(trx), required_keys, fc::variant(chain_id_type{})}; +void sign_transaction(signed_transaction& trx, fc::variant& required_keys, const chain_id_type& chain_id) { + fc::variants sign_args = {fc::variant(trx), required_keys, fc::variant(chain_id)}; const auto& signed_trx = call(wallet_url, wallet_sign_trx, sign_args); trx = signed_trx.as(); } @@ -289,7 +288,7 @@ fc::variant push_transaction( signed_transaction& trx, int32_t extra_kcpu = 1000 trx.max_net_usage_words = (tx_max_net_usage + 7)/8; if (!tx_skip_sign) { - sign_transaction(trx, required_keys); + sign_transaction(trx, required_keys, info.chain_id); } if (!tx_dont_broadcast) { @@ -2138,16 +2137,27 @@ int main( int argc, char** argv ) { // sign subcommand string trx_json_to_sign; string str_private_key; + string str_chain_id; bool push_trx = false; auto sign = app.add_subcommand("sign", localized("Sign a transaction"), false); sign->add_option("transaction", trx_json_to_sign, localized("The JSON string or filename defining the transaction to sign"), true)->required(); sign->add_option("-k,--private-key", str_private_key, localized("The private key that will be used to sign the transaction")); + sign->add_option("-c,--chain-id", str_chain_id, localized("The chain id that will be used to sign the transaction")); sign->add_flag( "-p,--push-transaction", push_trx, localized("Push transaction after signing")); sign->set_callback([&] { signed_transaction trx = json_from_file_or_string(trx_json_to_sign).as(); + chain_id_type chain_id; + + if( str_chain_id.size() == 0 ) { + ilog( "grabbing chain_id from nodeos" ); + auto info = get_info(); + chain_id = info.chain_id; + } else { + chain_id = chain_id_type(str_chain_id); + } if( str_private_key.size() == 0 ) { std::cerr << localized("private key: "); @@ -2157,7 +2167,7 @@ int main( int argc, char** argv ) { } auto priv_key = fc::crypto::private_key::regenerate(*utilities::wif_to_key(str_private_key)); - trx.sign(priv_key, chain_id_type{}); + trx.sign(priv_key, chain_id); if(push_trx) { auto trx_result = call(push_txn_func, packed_transaction(trx, packed_transaction::none)); diff --git a/tests/chain_tests/block_tests.cpp b/tests/chain_tests/block_tests.cpp index 1fe730f9fa9..33119ed9110 100644 --- a/tests/chain_tests/block_tests.cpp +++ b/tests/chain_tests/block_tests.cpp @@ -324,7 +324,7 @@ BOOST_AUTO_TEST_CASE(trx_uniqueness) { .active = authority(chain.get_public_key(new_account_name, "active")) }); chain.set_transaction_headers(trx, 90); - trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type()); + trx.sign(chain.get_private_key(config::system_account_name, "active"), chain.control->get_chain_id()); chain.push_transaction(trx); BOOST_CHECK_THROW(chain.push_transaction(trx), tx_duplicate); @@ -346,12 +346,12 @@ BOOST_AUTO_TEST_CASE(invalid_expiration) { }); trx.ref_block_num = static_cast(chain.control->head_block_num()); trx.ref_block_prefix = static_cast(chain.control->head_block_id()._hash[1]); - trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type()); + trx.sign(chain.get_private_key(config::system_account_name, "active"), chain.control->get_chain_id()); // Unset expiration should throw BOOST_CHECK_THROW(chain.push_transaction(trx), transaction_exception); memset(&trx.expiration, 0, sizeof(trx.expiration)); // currently redundant, as default is all zeros, but may not always be. - trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type()); + trx.sign(chain.get_private_key(config::system_account_name, "active"), chain.control->get_chain_id()); // Expired transaction (January 1970) should throw BOOST_CHECK_THROW(chain.push_transaction(trx), transaction_exception); BOOST_REQUIRE_EQUAL( chain.validate(), true ); @@ -374,7 +374,7 @@ BOOST_AUTO_TEST_CASE(transaction_expiration) { trx.ref_block_num = static_cast(chain.control->head_block_num()); trx.ref_block_prefix = static_cast(chain.control->head_block_id()._hash[1]); trx.expiration = chain.control->head_block_time() + fc::microseconds(i * 1000000); - trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type()); + trx.sign(chain.get_private_key(config::system_account_name, "active"), chain.control->get_chain_id()); // expire in 1st time, pass in 2nd time if (i == 0) @@ -401,7 +401,7 @@ BOOST_AUTO_TEST_CASE(invalid_tapos) { trx.ref_block_num = static_cast(chain.control->head_block_num() + 1); trx.ref_block_prefix = static_cast(chain.control->head_block_id()._hash[1]); trx.expiration = chain.control->head_block_time() + fc::microseconds(1000000); - trx.sign(chain.get_private_key(config::system_account_name, "active"), chain_id_type()); + trx.sign(chain.get_private_key(config::system_account_name, "active"), chain.control->get_chain_id()); BOOST_CHECK_THROW(chain.push_transaction(trx), invalid_ref_block_exception); @@ -427,13 +427,13 @@ BOOST_AUTO_TEST_CASE(irrelevant_auth) { .active = authority( chain.get_public_key( new_account_name, "active" ) ) }); chain.set_transaction_headers(trx); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); chain.push_transaction(trx, skip_transaction_signatures); chain.control->clear_pending(); // Add unneeded signature - trx.sign( chain.get_private_key( name("random"), "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( name("random"), "active" ), chain.control->get_chain_id() ); // Check that it throws for irrelevant signatures BOOST_CHECK_THROW(chain.push_transaction( trx ), tx_irrelevant_sig); @@ -460,7 +460,7 @@ BOOST_AUTO_TEST_CASE(no_auth) { .active = authority() }); chain.set_transaction_headers(trx); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); // Check that it throws for no auth BOOST_CHECK_THROW(chain.push_transaction( trx ), action_validate_exception); @@ -954,21 +954,21 @@ BOOST_AUTO_TEST_CASE(irrelevant_sig_soft_check) { .active = authority( chain.get_public_key( new_account_name, "active" ) ) }); chain.set_transaction_headers(trx); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); - trx.sign( chain.get_private_key( name("random"), "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); + trx.sign( chain.get_private_key( name("random"), "active" ), chain.control->get_chain_id() ); // Check that it throws for irrelevant signatures BOOST_REQUIRE_THROW(chain.push_transaction( trx ), tx_irrelevant_sig); // Check that it throws for multiple signatures by the same key trx.signatures.clear(); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); BOOST_REQUIRE_THROW(chain.push_transaction( trx ), tx_duplicate_sig); // Sign the transaction properly and push to the block trx.signatures.clear(); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); chain.push_transaction( trx ); // Produce block so the transaction gets included in the block @@ -1003,8 +1003,8 @@ BOOST_AUTO_TEST_CASE(irrelevant_sig_hard_check) { .active = authority( chain.get_public_key( new_account_name, "active" ) ) }); chain.set_transaction_headers(trx); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); - trx.sign( chain.get_private_key( name("random"), "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); + trx.sign( chain.get_private_key( name("random"), "active" ), chain.control->get_chain_id() ); // Force push transaction with irrelevant signatures using a skip flag chain.push_transaction( trx, skip_transaction_signatures ); @@ -1035,8 +1035,8 @@ BOOST_AUTO_TEST_CASE(irrelevant_sig_hard_check) { .active = authority( chain.get_public_key( new_account_name, "active" ) ) }); chain.set_transaction_headers(trx); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); - trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); + trx.sign( chain.get_private_key( config::system_account_name, "active" ), chain.control->get_chain_id() ); // Force push transaction with multiple signatures by the same key using a skip flag chain.push_transaction( trx, skip_transaction_signatures ); @@ -1129,7 +1129,7 @@ BOOST_AUTO_TEST_CASE(get_required_keys) auto required_keys = chain.validating_node->get_required_keys(trx, available_keys); BOOST_TEST( required_keys.size() == 1 ); BOOST_TEST( *required_keys.begin() == priv_key_needed.get_public_key() ); - trx.sign( priv_key_needed, chain_id_type() ); + trx.sign( priv_key_needed, chain.control->get_chain_id() ); chain.push_transaction(trx); chain.produce_blocks(); diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index fff62942e98..ec2bc55872e 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -148,8 +148,8 @@ transaction_trace_ptr CallAction(TESTER& test, T ac, const vector& trx.actions.push_back(act); test.set_transaction_headers(trx); - auto sigs = trx.sign(test.get_private_key(scope[0], "active"), chain_id_type()); - trx.get_signature_keys(chain_id_type()); + auto sigs = trx.sign(test.get_private_key(scope[0], "active"), test.control->get_chain_id()); + trx.get_signature_keys(test.control->get_chain_id()); auto res = test.push_transaction(trx); BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); test.produce_block(); @@ -172,8 +172,8 @@ transaction_trace_ptr CallFunction(TESTER& test, T ac, const vector& data, trx.actions.push_back(act); test.set_transaction_headers(trx, test.DEFAULT_EXPIRATION_DELTA); - auto sigs = trx.sign(test.get_private_key(scope[0], "active"), chain_id_type()); - trx.get_signature_keys(chain_id_type() ); + auto sigs = trx.sign(test.get_private_key(scope[0], "active"), test.control->get_chain_id()); + trx.get_signature_keys(test.control->get_chain_id() ); auto res = test.push_transaction(trx); BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); test.produce_block(); @@ -265,8 +265,8 @@ BOOST_FIXTURE_TEST_CASE(action_receipt_tests, TESTER) { try { act.authorization = {{config::system_account_name, config::active_name}}; trx.actions.push_back(act); this->set_transaction_headers(trx, this->DEFAULT_EXPIRATION_DELTA); - trx.sign(this->get_private_key(config::system_account_name, "active"), chain_id_type()); - trx.get_signature_keys(chain_id_type() ); + trx.sign(this->get_private_key(config::system_account_name, "active"), control->get_chain_id()); + trx.get_signature_keys(control->get_chain_id() ); auto res = this->push_transaction(trx); BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); this->produce_block(); @@ -335,7 +335,7 @@ BOOST_FIXTURE_TEST_CASE(action_tests, TESTER) { try { // test require_notice auto scope = std::vector{N(testapi)}; - auto test_require_notice = [](auto& test, std::vector& data, std::vector& scope){ + auto test_require_notice = [this](auto& test, std::vector& data, std::vector& scope){ signed_transaction trx; auto tm = test_api_action{}; @@ -345,7 +345,7 @@ BOOST_FIXTURE_TEST_CASE(action_tests, TESTER) { try { trx.actions.push_back(act); test.set_transaction_headers(trx); - trx.sign(test.get_private_key(N(inita), "active"), chain_id_type()); + trx.sign(test.get_private_key(N(inita), "active"), control->get_chain_id()); auto res = test.push_transaction(trx); BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); }; @@ -397,9 +397,9 @@ BOOST_FIXTURE_TEST_CASE(action_tests, TESTER) { try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key(N(testapi), "active"), chain_id_type()); - trx.sign(get_private_key(N(acc3), "active"), chain_id_type()); - trx.sign(get_private_key(N(acc4), "active"), chain_id_type()); + trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id()); + trx.sign(get_private_key(N(acc3), "active"), control->get_chain_id()); + trx.sign(get_private_key(N(acc4), "active"), control->get_chain_id()); auto res = push_transaction(trx); BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); } @@ -464,7 +464,7 @@ BOOST_FIXTURE_TEST_CASE(cf_action_tests, TESTER) { try { set_transaction_headers(trx); // signing a transaction with only context_free_actions should not be allowed - // auto sigs = trx.sign(get_private_key(N(testapi), "active"), chain_id_type()); + // auto sigs = trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id()); BOOST_CHECK_EXCEPTION(push_transaction(trx), tx_no_auths, [](const fc::exception& e) { @@ -481,7 +481,7 @@ BOOST_FIXTURE_TEST_CASE(cf_action_tests, TESTER) { try { trx.actions.push_back(act1); set_transaction_headers(trx); // run normal passing case - auto sigs = trx.sign(get_private_key(N(testapi), "active"), chain_id_type()); + auto sigs = trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id()); auto res = push_transaction(trx); BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); @@ -495,7 +495,7 @@ BOOST_FIXTURE_TEST_CASE(cf_action_tests, TESTER) { try { trx.actions.push_back(act2); set_transaction_headers(trx); // run (dummy_action.b = 200) case looking for invalid use of context_free api - sigs = trx.sign(get_private_key(N(testapi), "active"), chain_id_type()); + sigs = trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id()); BOOST_CHECK_EXCEPTION(push_transaction(trx), assert_exception, [](const fc::exception& e) { return expect_assert_message(e, "this API may only be called from context_free apply"); @@ -520,7 +520,7 @@ BOOST_FIXTURE_TEST_CASE(cf_action_tests, TESTER) { try { trx.context_free_actions.emplace_back(cfa_act); trx.signatures.clear(); set_transaction_headers(trx); - sigs = trx.sign(get_private_key(N(testapi), "active"), chain_id_type()); + sigs = trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id()); BOOST_CHECK_EXCEPTION(push_transaction(trx), assert_exception, [](const fc::exception& e) { return expect_assert_message(e, "only context free api's can be used in this context" ); @@ -564,7 +564,7 @@ BOOST_FIXTURE_TEST_CASE(cfa_tx_signature, TESTER) try { set_transaction_headers(tx2); const private_key_type& priv_key = get_private_key("dummy", "active"); - BOOST_TEST((std::string)tx1.sign(priv_key, chain_id_type()) != (std::string)tx2.sign(priv_key, chain_id_type())); + BOOST_TEST((std::string)tx1.sign(priv_key, control->get_chain_id()) != (std::string)tx2.sign(priv_key, control->get_chain_id())); BOOST_REQUIRE_EQUAL( validate(), true ); } FC_LOG_AND_RETHROW() @@ -590,7 +590,7 @@ BOOST_FIXTURE_TEST_CASE(cfa_stateful_api, TESTER) try { action act({}, test_api_action{}); trx.context_free_actions.push_back(act); set_transaction_headers(trx); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); BOOST_CHECK_EXCEPTION(push_transaction( trx ), fc::exception, [&](const fc::exception &e) { return expect_assert_message(e, "only context free api's can be used in this context"); @@ -620,7 +620,7 @@ BOOST_FIXTURE_TEST_CASE(deferred_cfa_failed, TESTER) try { action act({}, test_api_action{}); trx.context_free_actions.push_back(act); set_transaction_headers(trx, 10, 2); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); BOOST_CHECK_EXCEPTION(push_transaction( trx ), fc::exception, [&](const fc::exception &e) { @@ -656,7 +656,7 @@ BOOST_FIXTURE_TEST_CASE(deferred_cfa_success, TESTER) try { action act({}, test_api_action{}); trx.context_free_actions.push_back(act); set_transaction_headers(trx, 10, 2); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); auto trace = push_transaction( trx ); BOOST_REQUIRE(trace != nullptr); if (trace) { @@ -699,8 +699,8 @@ void call_test(TESTER& test, T ac, uint32_t billed_cpu_time_us , uint32_t max_cp trx.actions.push_back(act); test.set_transaction_headers(trx); //trx.max_cpu_usage_ms = max_cpu_usage_ms; - auto sigs = trx.sign(test.get_private_key(N(testapi), "active"), chain_id_type()); - trx.get_signature_keys(chain_id_type() ); + auto sigs = trx.sign(test.get_private_key(N(testapi), "active"), test.control->get_chain_id()); + trx.get_signature_keys(test.control->get_chain_id() ); auto res = test.push_transaction( trx, fc::time_point::now() + fc::milliseconds(max_cpu_usage_ms), billed_cpu_time_us ); BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed); test.produce_block(); @@ -1329,11 +1329,11 @@ BOOST_FIXTURE_TEST_CASE(crypto_tests, TESTER) { try { auto pl = vector{{N(testapi), config::active_name}}; action act(pl, test_api_action{}); - auto signatures = trx.sign(get_private_key(N(testapi), "active"), chain_id_type()); + auto signatures = trx.sign(get_private_key(N(testapi), "active"), control->get_chain_id()); produce_block(); - auto payload = fc::raw::pack( trx.sig_digest( chain_id_type() ) ); + auto payload = fc::raw::pack( trx.sig_digest( control->get_chain_id() ) ); auto pk = fc::raw::pack( get_public_key( N(testapi), "active" ) ); auto sigs = fc::raw::pack( signatures ); payload.insert( payload.end(), pk.begin(), pk.end() ); @@ -1769,8 +1769,8 @@ BOOST_FIXTURE_TEST_CASE(privileged_tests, tester) { try { set_tapos(trx); - auto sigs = trx.sign(get_private_key(config::system_account_name, "active"), chain_id_type()); - trx.get_signature_keys(chain_id_type() ); + auto sigs = trx.sign(get_private_key(config::system_account_name, "active"), control->get_chain_id()); + trx.get_signature_keys(control->get_chain_id() ); auto res = push_transaction(trx); BOOST_CHECK_EQUAL(res.status, transaction_receipt::executed); } diff --git a/unittests/auth_tests.cpp b/unittests/auth_tests.cpp index 17106603ecf..3c28e2d3d1f 100644 --- a/unittests/auth_tests.cpp +++ b/unittests/auth_tests.cpp @@ -407,9 +407,9 @@ try { }); chain.set_transaction_headers(trx); - trx.sign( chain.get_private_key( acc1, "active" ), chain_id_type() ); - trx.sign( chain.get_private_key( acc1, "owner" ), chain_id_type() ); - trx.sign( chain.get_private_key( acc1a, "owner" ), chain_id_type() ); + trx.sign( chain.get_private_key( acc1, "active" ), chain.control->get_chain_id() ); + trx.sign( chain.get_private_key( acc1, "owner" ), chain.control->get_chain_id() ); + trx.sign( chain.get_private_key( acc1a, "owner" ), chain.control->get_chain_id() ); return chain.push_transaction( trx ); }; @@ -459,7 +459,7 @@ try { }); chain.set_transaction_headers(trx); - trx.sign( chain.get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( chain.get_private_key( creator, "active" ), chain.control->get_chain_id() ); return chain.push_transaction( trx ); }; diff --git a/unittests/currency_tests.cpp b/unittests/currency_tests.cpp index eb5ba961376..761c3a1664e 100644 --- a/unittests/currency_tests.cpp +++ b/unittests/currency_tests.cpp @@ -45,7 +45,7 @@ class currency_tester : public TESTER { trx.actions.emplace_back(std::move(act)); set_transaction_headers(trx); - trx.sign(get_private_key(signer, "active"), chain_id_type()); + trx.sign(get_private_key(signer, "active"), control->get_chain_id()); return push_transaction(trx); } @@ -425,7 +425,7 @@ BOOST_FIXTURE_TEST_CASE( test_proxy, currency_tester ) try { trx.actions.emplace_back(std::move(setowner_act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(alice), "active"), chain_id_type()); + trx.sign(get_private_key(N(alice), "active"), control->get_chain_id()); push_transaction(trx); produce_block(); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -480,7 +480,7 @@ BOOST_FIXTURE_TEST_CASE( test_deferred_failure, currency_tester ) try { trx.actions.emplace_back(std::move(setowner_act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(bob), "active"), chain_id_type()); + trx.sign(get_private_key(N(bob), "active"), control->get_chain_id()); push_transaction(trx); produce_block(); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -531,7 +531,7 @@ BOOST_FIXTURE_TEST_CASE( test_deferred_failure, currency_tester ) try { trx.actions.emplace_back(std::move(setowner_act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(alice), "active"), chain_id_type()); + trx.sign(get_private_key(N(alice), "active"), control->get_chain_id()); push_transaction(trx); produce_block(); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); diff --git a/unittests/delay_tests.cpp b/unittests/delay_tests.cpp index b704cb40dee..444bcac8e47 100644 --- a/unittests/delay_tests.cpp +++ b/unittests/delay_tests.cpp @@ -39,7 +39,7 @@ BOOST_FIXTURE_TEST_CASE( delay_create_account, validating_tester) { try { }); set_transaction_headers(trx); trx.delay_sec = 3; - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); auto trace = push_transaction( trx ); @@ -66,7 +66,7 @@ BOOST_FIXTURE_TEST_CASE( delay_error_create_account, validating_tester) { try { }); set_transaction_headers(trx); trx.delay_sec = 3; - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); ilog( fc::json::to_pretty_string(trx) ); auto trace = push_transaction( trx ); @@ -1705,7 +1705,7 @@ BOOST_AUTO_TEST_CASE( mindelay_test ) { try { trx.actions.push_back(act); chain.set_transaction_headers(trx, 30, 10); - trx.sign(chain.get_private_key(N(tester), "active"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "active"), chain.control->get_chain_id()); trace = chain.push_transaction(trx); BOOST_REQUIRE_EQUAL(transaction_receipt::delayed, trace->receipt->status); gen_size = chain.control->db().get_index().size(); @@ -1905,7 +1905,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test ) { try { chain::canceldelay{{N(tester), config::active_name}, ids[0]}); chain.set_transaction_headers(trx); - trx.sign(chain.get_private_key(N(tester), "active"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "active"), chain.control->get_chain_id()); trace = chain.push_transaction(trx); //wdump((fc::json::to_pretty_string(trace))); BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); @@ -2082,7 +2082,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try { trx.actions.emplace_back(vector{{N(tester), config::active_name}}, chain::canceldelay{{N(tester), config::active_name}, trx_id}); chain.set_transaction_headers(trx); - trx.sign(chain.get_private_key(N(tester), "active"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "active"), chain.control->get_chain_id()); BOOST_REQUIRE_EXCEPTION( chain.push_transaction(trx), action_validate_exception, fc_exception_message_is("canceling_auth in canceldelay action was not found as authorization in the original delayed transaction") ); } @@ -2093,7 +2093,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try { trx.actions.emplace_back(vector{{N(tester), N(second)}}, chain::canceldelay{{N(tester), N(first)}, trx_id}); chain.set_transaction_headers(trx); - trx.sign(chain.get_private_key(N(tester), "second"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "second"), chain.control->get_chain_id()); BOOST_REQUIRE_THROW( chain.push_transaction(trx), irrelevant_auth_exception ); BOOST_REQUIRE_EXCEPTION( chain.push_transaction(trx), irrelevant_auth_exception, fc_exception_message_starts_with("canceldelay action declares irrelevant authority") ); @@ -2104,7 +2104,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try { trx.actions.emplace_back(vector{{N(tester), config::active_name}}, chain::canceldelay{{N(tester), N(first)}, trx_id}); chain.set_transaction_headers(trx); - trx.sign(chain.get_private_key(N(tester), "active"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "active"), chain.control->get_chain_id()); trace = chain.push_transaction(trx); BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); @@ -2168,7 +2168,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try { trx.actions.emplace_back(vector{{N(tester), N(first)}}, chain::canceldelay{{N(tester), N(second)}, trx_id}); chain.set_transaction_headers(trx); - trx.sign(chain.get_private_key(N(tester), "first"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "first"), chain.control->get_chain_id()); trace = chain.push_transaction(trx); BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); @@ -2221,7 +2221,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try { trx.actions.emplace_back(vector{{N(tester), N(active)}}, chain::canceldelay{{N(tester), config::owner_name}, trx_id}); chain.set_transaction_headers(trx); - trx.sign(chain.get_private_key(N(tester), "active"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "active"), chain.control->get_chain_id()); BOOST_REQUIRE_THROW( chain.push_transaction(trx), irrelevant_auth_exception ); } @@ -2230,7 +2230,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try { trx.actions.emplace_back(vector{{N(tester), config::owner_name}}, chain::canceldelay{{N(tester), config::owner_name}, trx_id}); chain.set_transaction_headers(trx); - trx.sign(chain.get_private_key(N(tester), "owner"), chain_id_type()); + trx.sign(chain.get_private_key(N(tester), "owner"), chain.control->get_chain_id()); trace = chain.push_transaction(trx); BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); @@ -2372,14 +2372,14 @@ BOOST_FIXTURE_TEST_CASE( delay_expired, validating_tester) { try { set_transaction_headers(trx); trx.delay_sec = 3; trx.expiration = control->head_block_time() + fc::microseconds(1000000); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); auto trace = push_transaction( trx ); BOOST_REQUIRE_EQUAL(transaction_receipt_header::delayed, trace->receipt->status); signed_block_ptr sb = produce_block(); - + sb = produce_block(); BOOST_REQUIRE_EQUAL(transaction_receipt_header::delayed, trace->receipt->status); @@ -2389,7 +2389,7 @@ BOOST_FIXTURE_TEST_CASE( delay_expired, validating_tester) { try { BOOST_REQUIRE_EQUAL(transaction_receipt_header::expired, sb->transactions[0].status); create_account(a); // account can still be created - + } FC_LOG_AND_RETHROW() } diff --git a/unittests/dice_tests.cpp b/unittests/dice_tests.cpp index 0d9ac54f18b..c1bc3075865 100644 --- a/unittests/dice_tests.cpp +++ b/unittests/dice_tests.cpp @@ -40,7 +40,7 @@ struct cancel_offer_t { checksum256_type commitment; static account_name get_account() { return N(dice); } - static action_name get_name() {return N(canceloffer); } + static action_name get_name() {return N(canceloffer); } }; FC_REFLECT(cancel_offer_t, (commitment)); @@ -49,7 +49,7 @@ struct reveal_t { checksum256_type source; static account_name get_account() { return N(dice); } - static action_name get_name() {return N(reveal); } + static action_name get_name() {return N(reveal); } }; FC_REFLECT(reveal_t, (commitment)(source)); @@ -58,7 +58,7 @@ struct deposit_t { asset amount; static account_name get_account() { return N(dice); } - static action_name get_name() {return N(deposit); } + static action_name get_name() {return N(deposit); } }; FC_REFLECT( deposit_t, (from)(amount) ); @@ -67,7 +67,7 @@ struct withdraw_t { asset amount; static account_name get_account() { return N(dice); } - static action_name get_name() {return N(withdraw); } + static action_name get_name() {return N(withdraw); } }; FC_REFLECT( withdraw_t, (to)(amount) ); @@ -107,7 +107,7 @@ struct dice_tester : TESTER { offer_bet_t{amount, account, commitment} ); trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( account, "active" ), chain_id_type()); + trx.sign(get_private_key( account, "active" ), control->get_chain_id()); auto ptrx = packed_transaction(trx,packed_transaction::none); push_transaction(ptrx); } @@ -118,7 +118,7 @@ struct dice_tester : TESTER { cancel_offer_t{commitment} ); trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( account, "active" ), chain_id_type()); + trx.sign(get_private_key( account, "active" ), control->get_chain_id()); auto ptrx = packed_transaction(trx,packed_transaction::none); push_transaction(ptrx); } @@ -129,7 +129,7 @@ struct dice_tester : TESTER { deposit_t{account, amount} ); trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( account, "active" ), chain_id_type()); + trx.sign(get_private_key( account, "active" ), control->get_chain_id()); auto ptrx = packed_transaction(trx,packed_transaction::none); push_transaction(ptrx); } @@ -140,7 +140,7 @@ struct dice_tester : TESTER { withdraw_t{account, amount} ); trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( account, "active" ), chain_id_type()); + trx.sign(get_private_key( account, "active" ), control->get_chain_id()); auto ptrx = packed_transaction(trx,packed_transaction::none); push_transaction(ptrx); } @@ -151,7 +151,7 @@ struct dice_tester : TESTER { reveal_t{commitment, source} ); trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( account, "active" ), chain_id_type()); + trx.sign(get_private_key( account, "active" ), control->get_chain_id()); auto ptrx = packed_transaction(trx,packed_transaction::none); push_transaction(ptrx); } @@ -225,12 +225,12 @@ BOOST_AUTO_TEST_SUITE(dice_tests) BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { create_accounts( {N(eosio.token), N(dice),N(alice),N(bob),N(carol),N(david)}, false); - + set_code(N(eosio.token), eosio_token_wast); set_abi(N(eosio.token), eosio_token_abi); produce_block(); - + add_dice_authority(N(alice)); add_dice_authority(N(bob)); add_dice_authority(N(carol)); @@ -258,7 +258,7 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { produce_block(); // Alice deposits 1000 - deposit( N(alice), core_from_string("1000.0000")); + deposit( N(alice), core_from_string("1000.0000")); produce_block(); BOOST_REQUIRE_EQUAL( balance_of(N(alice)), core_from_string("1000.0000")); @@ -266,13 +266,13 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { // Alice tries to bet 0 (fail) // secret : 9b886346e1351d4144d0b8392a975612eb0f8b6de7eae1cc9bcc55eb52be343c - BOOST_CHECK_THROW( offer_bet( N(alice), core_from_string("0.0000"), + BOOST_CHECK_THROW( offer_bet( N(alice), core_from_string("0.0000"), commitment_for("9b886346e1351d4144d0b8392a975612eb0f8b6de7eae1cc9bcc55eb52be343c") ), fc::exception); - + // Alice bets 10 (success) // secret : 0ba044d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46 - offer_bet( N(alice), core_from_string("10.0000"), + offer_bet( N(alice), core_from_string("10.0000"), commitment_for("0ba044d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46") ); produce_block(); @@ -286,14 +286,14 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { // Alice tries to bet 1000 (fail) // secret : a512f6b1b589a8906d574e9de74a529e504a5c53a760f0991a3e00256c027971 - BOOST_CHECK_THROW( offer_bet( N(alice), core_from_string("1000.0000"), + BOOST_CHECK_THROW( offer_bet( N(alice), core_from_string("1000.0000"), commitment_for("a512f6b1b589a8906d574e9de74a529e504a5c53a760f0991a3e00256c027971") ), fc::exception); produce_block(); // Bob tries to bet 90 without deposit // secret : 4facfc98932dde46fdc4403125a16337f6879a842a7ff8b0dc8e1ecddd59f3c8 - BOOST_CHECK_THROW( offer_bet( N(bob), core_from_string("90.0000"), + BOOST_CHECK_THROW( offer_bet( N(bob), core_from_string("90.0000"), commitment_for("4facfc98932dde46fdc4403125a16337f6879a842a7ff8b0dc8e1ecddd59f3c8") ), fc::exception); produce_block(); @@ -304,7 +304,7 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { // Bob bets 11 (success) // secret : eec3272712d974c474a3e7b4028b53081344a5f50008e9ccf918ba0725a8d784 - offer_bet( N(bob), core_from_string("11.0000"), + offer_bet( N(bob), core_from_string("11.0000"), commitment_for("eec3272712d974c474a3e7b4028b53081344a5f50008e9ccf918ba0725a8d784") ); produce_block(); @@ -319,14 +319,14 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { // Carol bets 10 (success) // secret : 3efb4bd5e19b780f4980c919330c0306f8157f93db1fc72c7cefec63e0e7f37a - offer_bet( N(carol), core_from_string("10.0000"), + offer_bet( N(carol), core_from_string("10.0000"), commitment_for("3efb4bd5e19b780f4980c919330c0306f8157f93db1fc72c7cefec63e0e7f37a") ); produce_block(); BOOST_REQUIRE_EQUAL( open_games(N(alice)), 1); BOOST_REQUIRE_EQUAL( open_offers(N(alice)), 0); - + BOOST_REQUIRE_EQUAL( open_games(N(carol)), 1); BOOST_REQUIRE_EQUAL( open_offers(N(carol)), 0); @@ -334,42 +334,42 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { // Alice tries to cancel a nonexistent bet (fail) - BOOST_CHECK_THROW( cancel_offer( N(alice), + BOOST_CHECK_THROW( cancel_offer( N(alice), commitment_for("00000000000000000000000000000000000000000000000000000000abb03c46") ), fc::exception); // Alice tries to cancel an in-game bet (fail) - BOOST_CHECK_THROW( cancel_offer( N(alice), + BOOST_CHECK_THROW( cancel_offer( N(alice), commitment_for("0ba044d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46") ), fc::exception); // Alice reveals secret (success) - reveal( N(alice), + reveal( N(alice), commitment_for("0ba044d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46"), checksum_type("0ba044d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46") ); produce_block(); // Alice tries to reveal again (fail) - BOOST_CHECK_THROW( reveal( N(alice), + BOOST_CHECK_THROW( reveal( N(alice), commitment_for("0ba044d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46"), checksum_type("0ba044d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46") ), fc::exception); // Bob tries to reveal an invalid (secret,commitment) pair (fail) - BOOST_CHECK_THROW( reveal( N(bob), + BOOST_CHECK_THROW( reveal( N(bob), commitment_for("121344d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46"), checksum_type("141544d2833758ee2c8f24d8a3f70c82c334abe6ce13219a4cf3b862abb03c46") ), fc::exception); // Bob tries to reveal a valid (secret,commitment) pair that has no offer/game (fail) - BOOST_CHECK_THROW( reveal( N(bob), + BOOST_CHECK_THROW( reveal( N(bob), commitment_for("e48c6884bb97ac5f5951df6012ce79f63bb8549ad0111315ad9ecbaf4c9b1eb8"), checksum_type("e48c6884bb97ac5f5951df6012ce79f63bb8549ad0111315ad9ecbaf4c9b1eb8") ), fc::exception); // Bob reveals Carol's secret (success) - reveal( N(bob), + reveal( N(bob), commitment_for("3efb4bd5e19b780f4980c919330c0306f8157f93db1fc72c7cefec63e0e7f37a"), checksum_type("3efb4bd5e19b780f4980c919330c0306f8157f93db1fc72c7cefec63e0e7f37a") ); @@ -377,7 +377,7 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { BOOST_REQUIRE_EQUAL( open_games(N(alice)), 0); BOOST_REQUIRE_EQUAL( open_offers(N(alice)), 0); BOOST_REQUIRE_EQUAL( balance_of(N(alice)), core_from_string("1010.0000")); - + BOOST_REQUIRE_EQUAL( open_games(N(carol)), 0); BOOST_REQUIRE_EQUAL( open_offers(N(carol)), 0); BOOST_REQUIRE_EQUAL( balance_of(N(carol)), core_from_string("290.0000")); @@ -386,19 +386,19 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try { withdraw( N(alice), core_from_string("1009.0000")); BOOST_REQUIRE_EQUAL( balance_of(N(alice)), core_from_string("1.0000")); - BOOST_REQUIRE_EQUAL( + BOOST_REQUIRE_EQUAL( get_currency_balance(N(eosio.token), symbol(CORE_SYMBOL), N(alice)), core_from_string("10009.0000") ); // Alice withdraw 2 (fail) - BOOST_CHECK_THROW( withdraw( N(alice), core_from_string("2.0000")), + BOOST_CHECK_THROW( withdraw( N(alice), core_from_string("2.0000")), fc::exception); // Alice withdraw 1 (success) withdraw( N(alice), core_from_string("1.0000")); - BOOST_REQUIRE_EQUAL( + BOOST_REQUIRE_EQUAL( get_currency_balance(N(eosio.token), symbol(CORE_SYMBOL), N(alice)), core_from_string("10010.0000") ); diff --git a/unittests/eosio_system_tester.hpp b/unittests/eosio_system_tester.hpp index ea676617d40..6b6c38976b1 100644 --- a/unittests/eosio_system_tester.hpp +++ b/unittests/eosio_system_tester.hpp @@ -125,7 +125,7 @@ class eosio_system_tester : public TESTER { ); set_transaction_headers(trx); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); return push_transaction( trx ); } @@ -168,7 +168,7 @@ class eosio_system_tester : public TESTER { ); set_transaction_headers(trx); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); return push_transaction( trx ); } @@ -209,7 +209,7 @@ class eosio_system_tester : public TESTER { } set_transaction_headers(trx); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); return push_transaction( trx ); } diff --git a/unittests/exchange_tests.cpp b/unittests/exchange_tests.cpp index 4178b39d7a9..2bc4d5a2b7f 100644 --- a/unittests/exchange_tests.cpp +++ b/unittests/exchange_tests.cpp @@ -70,7 +70,7 @@ class exchange_tester : public TESTER { signed_transaction trx; trx.actions.emplace_back(std::move(act)); set_transaction_headers(trx); - trx.sign(get_private_key(signer, "active"), chain_id_type()); + trx.sign(get_private_key(signer, "active"), control->get_chain_id()); return push_transaction(trx); } @@ -153,7 +153,7 @@ class exchange_tester : public TESTER { ("maximum_supply", maxsupply ) ("can_freeze", 0) ("can_recall", 0) - ("can_whitelist", 0) + ("can_whitelist", 0) ); } diff --git a/unittests/misc_tests.cpp b/unittests/misc_tests.cpp index 3c6a6a469d9..3f8fb23e10b 100644 --- a/unittests/misc_tests.cpp +++ b/unittests/misc_tests.cpp @@ -569,9 +569,9 @@ BOOST_AUTO_TEST_CASE(transaction_test) { try { trx.expiration = fc::time_point::now(); trx.validate(); BOOST_CHECK_EQUAL(0, trx.signatures.size()); - ((const signed_transaction &)trx).sign( test.get_private_key( N(eosio), "active" ), chain_id_type()); + ((const signed_transaction &)trx).sign( test.get_private_key( N(eosio), "active" ), test.control->get_chain_id()); BOOST_CHECK_EQUAL(0, trx.signatures.size()); - trx.sign( test.get_private_key( N(eosio), "active" ), chain_id_type() ); + trx.sign( test.get_private_key( N(eosio), "active" ), test.control->get_chain_id() ); BOOST_CHECK_EQUAL(1, trx.signatures.size()); trx.validate(); diff --git a/unittests/multi_index_tests.cpp b/unittests/multi_index_tests.cpp index 798754221dd..653f2e89dc3 100644 --- a/unittests/multi_index_tests.cpp +++ b/unittests/multi_index_tests.cpp @@ -44,7 +44,7 @@ BOOST_FIXTURE_TEST_CASE( multi_index_load, TESTER ) try { ); trx.actions.emplace_back(std::move(trigger_act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(multitest), "active"), chain_id_type()); + trx.sign(get_private_key(N(multitest), "active"), control->get_chain_id()); push_transaction(trx); } @@ -61,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE( multi_index_load, TESTER ) try { ); trx.actions.emplace_back(std::move(trigger_act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(multitest), "active"), chain_id_type()); + trx.sign(get_private_key(N(multitest), "active"), control->get_chain_id()); push_transaction(trx); } diff --git a/unittests/multisig_tests.cpp b/unittests/multisig_tests.cpp index d2044ef634c..f41fc6d88e9 100644 --- a/unittests/multisig_tests.cpp +++ b/unittests/multisig_tests.cpp @@ -91,7 +91,7 @@ class eosio_msig_tester : public tester { ); set_transaction_headers(trx); - trx.sign( get_private_key( creator, "active" ), chain_id_type() ); + trx.sign( get_private_key( creator, "active" ), control->get_chain_id() ); return push_transaction( trx ); } void create_currency( name contract, name manager, asset maxsupply ) { diff --git a/unittests/wasm_tests.cpp b/unittests/wasm_tests.cpp index c95390aa6c1..b5521a8ef5a 100644 --- a/unittests/wasm_tests.cpp +++ b/unittests/wasm_tests.cpp @@ -91,7 +91,7 @@ BOOST_FIXTURE_TEST_CASE( basic_test, TESTER ) try { trx.actions[0].authorization = {{N(asserter),config::active_name}}; set_transaction_headers(trx); - trx.sign( get_private_key( N(asserter), "active" ), chain_id_type() ); + trx.sign( get_private_key( N(asserter), "active" ), control->get_chain_id() ); auto result = push_transaction( trx ); BOOST_CHECK_EQUAL(result->receipt->status, transaction_receipt::executed); BOOST_CHECK_EQUAL(result->action_traces.size(), 1); @@ -117,7 +117,7 @@ BOOST_FIXTURE_TEST_CASE( basic_test, TESTER ) try { assertdef {0, "Should Assert!"} ); set_transaction_headers(trx); - trx.sign( get_private_key( N(asserter), "active" ), chain_id_type() ); + trx.sign( get_private_key( N(asserter), "active" ), control->get_chain_id() ); yes_assert_id = trx.id(); BOOST_CHECK_THROW(push_transaction( trx ), eosio_assert_message_exception); @@ -150,7 +150,7 @@ BOOST_FIXTURE_TEST_CASE( prove_mem_reset, TESTER ) try { provereset {} ); set_transaction_headers(trx); - trx.sign( get_private_key( N(asserter), "active" ), chain_id_type() ); + trx.sign( get_private_key( N(asserter), "active" ), control->get_chain_id() ); push_transaction( trx ); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -204,7 +204,7 @@ BOOST_FIXTURE_TEST_CASE( abi_from_variant, TESTER ) try { signed_transaction trx; abi_serializer::from_variant(pretty_trx, trx, resolver); set_transaction_headers(trx); - trx.sign( get_private_key( N(asserter), "active" ), chain_id_type() ); + trx.sign( get_private_key( N(asserter), "active" ), control->get_chain_id() ); push_transaction( trx ); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -230,7 +230,7 @@ BOOST_FIXTURE_TEST_CASE( f32_tests, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f32_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f32_tests), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -253,7 +253,7 @@ BOOST_FIXTURE_TEST_CASE( f32_test_bitwise, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f32_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f32_tests), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -276,7 +276,7 @@ BOOST_FIXTURE_TEST_CASE( f32_test_cmp, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f32_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f32_tests), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -301,7 +301,7 @@ BOOST_FIXTURE_TEST_CASE( f64_tests, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f_tests), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -324,7 +324,7 @@ BOOST_FIXTURE_TEST_CASE( f64_test_bitwise, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f_tests), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -347,7 +347,7 @@ BOOST_FIXTURE_TEST_CASE( f64_test_cmp, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f_tests), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -373,7 +373,7 @@ BOOST_FIXTURE_TEST_CASE( f32_f64_conversion_tests, tester ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f_tests), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -402,7 +402,7 @@ BOOST_FIXTURE_TEST_CASE( f32_f64_overflow_tests, tester ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(f_tests)+count, "active" ), chain_id_type()); + trx.sign(get_private_key( N(f_tests)+count, "active" ), control->get_chain_id()); try { push_transaction(trx); @@ -500,7 +500,7 @@ BOOST_FIXTURE_TEST_CASE(misaligned_tests, tester ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(aligncheck), "active" ), chain_id_type()); + trx.sign(get_private_key( N(aligncheck), "active" ), control->get_chain_id()); push_transaction(trx); produce_block(); @@ -565,7 +565,7 @@ BOOST_FIXTURE_TEST_CASE(cpu_usage_tests, tester ) try { set_transaction_headers(trx); trx.max_cpu_usage_ms = limit++; - trx.sign(get_private_key( N(f_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f_tests), "active" ), control->get_chain_id()); try { push_transaction(trx); @@ -625,7 +625,7 @@ BOOST_FIXTURE_TEST_CASE(weighted_cpu_limit_tests, tester ) try { } set_transaction_headers(trx); - trx.sign(get_private_key( N(f_tests), "active" ), chain_id_type()); + trx.sign(get_private_key( N(f_tests), "active" ), control->get_chain_id()); try { push_transaction(trx, fc::time_point::maximum(), 0); @@ -665,7 +665,7 @@ BOOST_FIXTURE_TEST_CASE( check_entry_behavior, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(entrycheck), "active" ), chain_id_type()); + trx.sign(get_private_key( N(entrycheck), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -689,7 +689,7 @@ BOOST_FIXTURE_TEST_CASE( check_entry_behavior_2, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(entrycheck), "active" ), chain_id_type()); + trx.sign(get_private_key( N(entrycheck), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -719,7 +719,7 @@ BOOST_FIXTURE_TEST_CASE( simple_no_memory_check, TESTER ) try { trx.actions.push_back(act); trx.expiration = control->head_block_time(); set_transaction_headers(trx); - trx.sign(get_private_key( N(nomem), "active" ), chain_id_type()); + trx.sign(get_private_key( N(nomem), "active" ), control->get_chain_id()); BOOST_CHECK_THROW(push_transaction( trx ), wasm_execution_error); } FC_LOG_AND_RETHROW() @@ -750,7 +750,7 @@ BOOST_FIXTURE_TEST_CASE( check_global_reset, TESTER ) try { } set_transaction_headers(trx); - trx.sign(get_private_key( N(globalreset), "active" ), chain_id_type()); + trx.sign(get_private_key( N(globalreset), "active" ), control->get_chain_id()); push_transaction(trx); produce_blocks(1); BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trx.id())); @@ -788,7 +788,7 @@ BOOST_FIXTURE_TEST_CASE( stl_test, TESTER ) try { trx.actions.push_back(std::move(msg_act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(stltest), "active"), chain_id_type()); + trx.sign(get_private_key(N(stltest), "active"), control->get_chain_id()); push_transaction(trx); produce_block(); @@ -818,7 +818,7 @@ BOOST_FIXTURE_TEST_CASE( big_memory, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(bigmem), "active" ), chain_id_type()); + trx.sign(get_private_key( N(bigmem), "active" ), control->get_chain_id()); //but should not be able to grow beyond largest page push_transaction(trx); @@ -998,7 +998,7 @@ BOOST_FIXTURE_TEST_CASE(noop, TESTER) try { trx.actions.emplace_back(std::move(act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(noop), "active"), chain_id_type()); + trx.sign(get_private_key(N(noop), "active"), control->get_chain_id()); push_transaction(trx); produce_block(); @@ -1022,7 +1022,7 @@ BOOST_FIXTURE_TEST_CASE(noop, TESTER) try { trx.actions.emplace_back(std::move(act)); set_transaction_headers(trx); - trx.sign(get_private_key(N(alice), "active"), chain_id_type()); + trx.sign(get_private_key(N(alice), "active"), control->get_chain_id()); push_transaction(trx); produce_block(); @@ -1054,7 +1054,7 @@ BOOST_FIXTURE_TEST_CASE(eosio_abi, TESTER) try { .active = authority( get_public_key( a, "active" ) ) }); set_transaction_headers(trx); - trx.sign( get_private_key( config::system_account_name, "active" ), chain_id_type() ); + trx.sign( get_private_key( config::system_account_name, "active" ), control->get_chain_id() ); auto result = push_transaction( trx ); fc::variant pretty_output; @@ -1085,7 +1085,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); push_transaction(trx); } @@ -1099,7 +1099,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); push_transaction(trx); } @@ -1113,7 +1113,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); push_transaction(trx); } @@ -1127,7 +1127,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); //should fail, a check to make sure assert() in wasm is being evaluated correctly BOOST_CHECK_THROW(push_transaction(trx), eosio_assert_message_exception); @@ -1143,7 +1143,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); //should fail, this element index (5) does not exist BOOST_CHECK_THROW(push_transaction(trx), eosio::chain::wasm_execution_error); @@ -1159,7 +1159,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); //should fail, this element index is out of range BOOST_CHECK_THROW(push_transaction(trx), eosio::chain::wasm_execution_error); @@ -1179,7 +1179,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); push_transaction(trx); } @@ -1192,7 +1192,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); push_transaction(trx); } set_code(N(tbl), table_checker_small_wast); @@ -1206,7 +1206,7 @@ BOOST_FIXTURE_TEST_CASE( check_table_maximum, TESTER ) try { act.authorization = vector{{N(tbl),config::active_name}}; trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(tbl), "active" ), chain_id_type()); + trx.sign(get_private_key( N(tbl), "active" ), control->get_chain_id()); //an element that is out of range and has no mmap access permission either (should be a trapped segv) BOOST_CHECK_EXCEPTION(push_transaction(trx), eosio::chain::wasm_execution_error, [](const eosio::chain::wasm_execution_error &e) {return true;}); @@ -1306,7 +1306,7 @@ BOOST_FIXTURE_TEST_CASE( lotso_stack_3, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(stackz), "active" ), chain_id_type()); + trx.sign(get_private_key( N(stackz), "active" ), control->get_chain_id()); push_transaction(trx); } } FC_LOG_AND_RETHROW() @@ -1368,7 +1368,7 @@ BOOST_FIXTURE_TEST_CASE( lotso_stack_6, TESTER ) try { trx.actions.push_back(act); set_transaction_headers(trx); - trx.sign(get_private_key( N(stackz), "active" ), chain_id_type()); + trx.sign(get_private_key( N(stackz), "active" ), control->get_chain_id()); push_transaction(trx); } } FC_LOG_AND_RETHROW() @@ -1517,7 +1517,7 @@ BOOST_FIXTURE_TEST_CASE(net_usage_tests, tester ) try { }); set_transaction_headers(trx); if (max_net_usage) trx.max_net_usage_words = max_net_usage; - trx.sign( get_private_key( account, "active" ), chain_id_type() ); + trx.sign( get_private_key( account, "active" ), control->get_chain_id() ); try { packed_transaction ptrx(trx); push_transaction(ptrx); @@ -1569,7 +1569,7 @@ BOOST_FIXTURE_TEST_CASE(weighted_net_usage_tests, tester ) try { .code = bytes(wasm.begin(), wasm.end()) }); set_transaction_headers(trx); - trx.sign( get_private_key( account, "active" ), chain_id_type() ); + trx.sign( get_private_key( account, "active" ), control->get_chain_id() ); try { packed_transaction ptrx(trx); push_transaction(ptrx ); From bd4d281837abeed482fa2e4868b07c184ecf7ae4 Mon Sep 17 00:00:00 2001 From: arhag Date: Fri, 25 May 2018 14:33:46 -0400 Subject: [PATCH 13/38] fix bug in chain_plugin with initializing chain_id --- plugins/chain_plugin/chain_plugin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index a4b515df8c7..521c2e508af 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -298,6 +298,7 @@ void chain_plugin::plugin_initialize(const variables_map& options) { } my->chain.emplace(*my->chain_config); + my->chain_id = my->chain->get_chain_id(); // set up method providers my->get_block_by_number_provider = app().get_method().register_provider([this](uint32_t block_num) -> signed_block_ptr { From 16b72a5cfb2b202c460f52b4fd0e430a3be10bfe Mon Sep 17 00:00:00 2001 From: arhag Date: Fri, 25 May 2018 14:54:55 -0400 Subject: [PATCH 14/38] forgot to normally use genesis_state extracted from blocks.log #3415 --- plugins/chain_plugin/chain_plugin.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 521c2e508af..1fa6063a8b6 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -295,6 +295,12 @@ void chain_plugin::plugin_initialize(const variables_map& options) { } ilog( "Adjusting genesis timestamp to ${timestamp}", ("timestamp", my->chain_config->genesis.initial_timestamp) ); } + + wlog( "Starting up fresh blockchain with provided genesis state." ); + } else if( fc::is_regular_file( my->blocks_dir / "blocks.log" ) ) { + my->chain_config->genesis = block_log::extract_genesis_state( my->blocks_dir ); + } else { + wlog( "Starting up fresh blockchain with default genesis state." ); } my->chain.emplace(*my->chain_config); From bd216257396c20db9fbc775ec2e038a296aa7bfb Mon Sep 17 00:00:00 2001 From: Anton Perkov Date: Fri, 25 May 2018 15:06:57 -0400 Subject: [PATCH 15/38] system contract undelegatebw bugfix: don't delete row if ram_bytes != 0, small change in resource_limits to make debuging less confusing #3366 --- contracts/eosio.system/delegate_bandwidth.cpp | 2 +- libraries/chain/resource_limits.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/contracts/eosio.system/delegate_bandwidth.cpp b/contracts/eosio.system/delegate_bandwidth.cpp index 681f533a1cd..a292f8552eb 100644 --- a/contracts/eosio.system/delegate_bandwidth.cpp +++ b/contracts/eosio.system/delegate_bandwidth.cpp @@ -259,7 +259,7 @@ namespace eosiosystem { set_resource_limits( receiver, tot_itr->ram_bytes, tot_itr->net_weight.amount, tot_itr->cpu_weight.amount ); - if ( tot_itr->net_weight == asset(0) && tot_itr->cpu_weight == asset(0) ) { + if ( tot_itr->net_weight == asset(0) && tot_itr->cpu_weight == asset(0) && tot_itr->ram_bytes == 0 ) { totals_tbl.erase( tot_itr ); } } // tot_itr can be invalid, should go out of scope diff --git a/libraries/chain/resource_limits.cpp b/libraries/chain/resource_limits.cpp index e09c0e4b73c..482d45119aa 100644 --- a/libraries/chain/resource_limits.cpp +++ b/libraries/chain/resource_limits.cpp @@ -396,9 +396,8 @@ account_resource_limit resource_limits_manager::get_account_cpu_limit_ex( const const auto& state = _db.get(); const auto& usage = _db.get(name); - int64_t x; - int64_t cpu_weight; - get_account_limits( name, x, x, cpu_weight ); + int64_t cpu_weight, x, y; + get_account_limits( name, x, y, cpu_weight ); if( cpu_weight < 0 || state.total_cpu_weight == 0 ) { return { -1, -1, -1 }; @@ -412,8 +411,6 @@ account_resource_limit resource_limits_manager::get_account_cpu_limit_ex( const uint128_t user_weight = cpu_weight; uint128_t all_user_weight = state.total_cpu_weight; - wdump((cpu_weight)); - auto max_user_use_in_window = (uint128_t(virtual_cpu_capacity_in_window) * user_weight) / all_user_weight; auto cpu_used_in_window = (usage.cpu_usage.value_ex * window_size) / config::rate_limiting_precision; @@ -460,9 +457,8 @@ account_resource_limit resource_limits_manager::get_account_net_limit_ex( const const auto& state = _db.get(); const auto& usage = _db.get(name); - int64_t x; - int64_t net_weight; - get_account_limits( name, x, net_weight, x ); + int64_t net_weight, x, y; + get_account_limits( name, x, net_weight, y ); if( net_weight < 0 || state.total_net_weight == 0) { return { -1, -1, -1 }; From e93d207f71d37774f603621555970e8f2bad2d30 Mon Sep 17 00:00:00 2001 From: Jonathan Giszczak Date: Fri, 25 May 2018 14:35:05 -0500 Subject: [PATCH 16/38] Remove snapshot submodule. Note that for existing checkouts, a copy remains in $GIT_DIR/modules so checkout of previous revisions does not require fetching from a remote repository. New checkouts will not have a copy unless an older revision is checked out, followed by git submodule update --init --recursive. --- .gitmodules | 3 --- programs/snapshot | 1 - 2 files changed, 4 deletions(-) delete mode 160000 programs/snapshot diff --git a/.gitmodules b/.gitmodules index e54d2b58108..a37b85cc328 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,9 +6,6 @@ path = libraries/appbase url = https://github.com/eosio/appbase ignore = dirty -[submodule "programs/snapshot"] - path = programs/snapshot - url = https://github.com/EOSIO/genesis.git [submodule "contracts/musl/upstream"] path = contracts/musl/upstream url = https://github.com/EOSIO/musl.git diff --git a/programs/snapshot b/programs/snapshot deleted file mode 160000 index e2a2e74e456..00000000000 --- a/programs/snapshot +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e2a2e74e456413f5d6e6439d4918d1b417ede1c3 From 6293147c6c2099e2841f254ecc232e75427add94 Mon Sep 17 00:00:00 2001 From: Bill Hamilton Date: Fri, 25 May 2018 19:49:27 +0000 Subject: [PATCH 17/38] Fedora: changed boost version from 1.66 to 1.67 --- eosio_build.sh | 2 +- scripts/eosio_build_darwin.sh | 2 +- scripts/eosio_build_fedora.sh | 32 ++++++++++++++++---------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/eosio_build.sh b/eosio_build.sh index a11ee2f3df1..204e85cce01 100755 --- a/eosio_build.sh +++ b/eosio_build.sh @@ -169,7 +169,7 @@ C_COMPILER=gcc MONGOD_CONF=/etc/mongod.conf export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm - export BOOST_ROOT="${HOME}/opt/boost_1_66_0" + export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "Linux Mint") FILE="${PWD}/scripts/eosio_build_ubuntu.sh" diff --git a/scripts/eosio_build_darwin.sh b/scripts/eosio_build_darwin.sh index c82d8cbb855..bee6307baec 100644 --- a/scripts/eosio_build_darwin.sh +++ b/scripts/eosio_build_darwin.sh @@ -202,7 +202,7 @@ printf "\\tExiting now.\\n\\n" exit 1; fi - if ! sudo rm -rf "/usr/local/lib/libboost*" + if ! sudo rm -rf /usr/local/lib/libboost* then printf "\\tUnable to remove boost libraries at this time. 2\\n" printf "\\tExiting now.\\n\\n" diff --git a/scripts/eosio_build_fedora.sh b/scripts/eosio_build_fedora.sh index c8cecb61c27..a34bb9ed9fa 100644 --- a/scripts/eosio_build_fedora.sh +++ b/scripts/eosio_build_fedora.sh @@ -59,7 +59,7 @@ DEP_ARRAY=( git gcc.x86_64 gcc-c++.x86_64 autoconf automake libtool make cmake.x86_64 \ bzip2-devel.x86_64 openssl-devel.x86_64 gmp-devel.x86_64 libstdc++-devel.x86_64 \ - python3-devel.x86_64 mongodb.x86_64 mongodb-server.x86_64 libedit.x86_64 \ + python2-devel.x86_64 python3-devel.x86_64 mongodb.x86_64 mongodb-server.x86_64 libedit.x86_64 \ graphviz.x86_64 doxygen.x86_64 ) COUNT=1 DISPLAY="" @@ -158,9 +158,9 @@ printf "\\n\\tChecking boost library installation.\\n" BVERSION=$( grep "BOOST_LIB_VERSION" "${BOOST_ROOT}/include/boost/version.hpp" 2>/dev/null \ | tail -1 | tr -s ' ' | cut -d\ -f3 | sed 's/[^0-9\._]//gI' ) - if [ "${BVERSION}" != "1_66" ]; then + if [ "${BVERSION}" != "1_67" ]; then printf "\\tRemoving existing boost libraries in %s/opt/boost* .\\n" "${HOME}" - if ! rm -rf "${HOME}/opt/boost*" + if ! rm -rf "${HOME}"/opt/boost* then printf "\\n\\tUnable to remove deprecated boost libraries at this time.\\n" printf "\\tExiting now.\\n\\n" @@ -173,51 +173,51 @@ printf "\\tExiting now.\\n\\n" exit 1; fi - STATUS=$( curl -LO -w '%{http_code}' --connect-timeout 30 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2 ) + STATUS=$( curl -LO -w '%{http_code}' --connect-timeout 30 https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2 ) if [ "${STATUS}" -ne 200 ]; then printf "\\tUnable to download Boost libraries at this time.\\n" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! tar xf "${TEMP_DIR}/boost_1_66_0.tar.bz2" + if ! tar xf "${TEMP_DIR}/boost_1_67_0.tar.bz2" then - printf "\\n\\tUnable to unarchive file %s/boost_1_66_0.tar.bz2.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to unarchive file %s/boost_1_67_0.tar.bz2.\\n" "${TEMP_DIR}" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! rm -f "${TEMP_DIR}/boost_1_66_0.tar.bz2" + if ! rm -f "${TEMP_DIR}/boost_1_67_0.tar.bz2" then - printf "\\n\\tUnable to remove file %s/boost_1_66_0.tar.bz2.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to remove file %s/boost_1_67_0.tar.bz2.\\n" "${TEMP_DIR}" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! cd "${TEMP_DIR}/boost_1_66_0/" + if ! cd "${TEMP_DIR}/boost_1_67_0/" then - printf "\\n\\tUnable to enter directory %s/boost_1_66_0.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to enter directory %s/boost_1_67_0.\\n" "${TEMP_DIR}" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! "${TEMP_DIR}/boost_1_66_0/bootstrap.sh" "--prefix=$BOOST_ROOT" + if ! "${TEMP_DIR}"/boost_1_67_0/bootstrap.sh "--prefix=${BOOST_ROOT}" then printf "\\n\\tInstallation of boost libraries failed. 0\\n" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! "${TEMP_DIR}/boost_1_66_0/b2" install + if ! "${TEMP_DIR}"/boost_1_67_0/b2 install then printf "\\n\\tInstallation of boost libraries failed. 1\\n" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! rm -rf "${TEMP_DIR}/boost_1_66_0" + if ! rm -rf "${TEMP_DIR}/boost_1_67_0" then - printf "\\n\\tUnable to remove directory %s/boost_1_66_0. 1\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to remove directory %s/boost_1_67_0. 1\\n" "${TEMP_DIR}" printf "\\tExiting now.\\n\\n" exit 1; fi - printf "\\n\\tBoost 1.66.0 successfully installed at %s/opt/boost_1_66_0.\\n\\n" "${HOME}" + printf "\\n\\tBoost 1.67.0 successfully installed at %s/opt/boost_1_67_0.\\n\\n" "${HOME}" else - printf "\\tBoost 1.66.0 found at %s/opt/boost_1_66_0.\\n" "${HOME}" + printf "\\tBoost 1.67.0 found at %s/opt/boost_1_67_0.\\n" "${HOME}" fi printf "\\n\\tChecking MongoDB C++ driver installation.\\n" From 91055a023e99c96ad366501555e0d2468801bc09 Mon Sep 17 00:00:00 2001 From: Eric Iles Date: Fri, 25 May 2018 16:09:16 -0400 Subject: [PATCH 18/38] Add configuration arguments --- .../bios-boot-tutorial/bios-boot-tutorial.py | 183 ++++++++++-------- 1 file changed, 98 insertions(+), 85 deletions(-) diff --git a/tutorials/bios-boot-tutorial/bios-boot-tutorial.py b/tutorials/bios-boot-tutorial/bios-boot-tutorial.py index 0f85d2e7cad..789ac295c5f 100755 --- a/tutorials/bios-boot-tutorial/bios-boot-tutorial.py +++ b/tutorials/bios-boot-tutorial/bios-boot-tutorial.py @@ -10,29 +10,12 @@ import sys import time -genesis = './genesis.json' -walletDir = os.path.abspath('./wallet/') +args = None +logFile = None + unlockTimeout = 99999999999 -nodesDir = './nodes/' -contractsDir = '../../build/contracts/' -cleos = 'cleos --wallet-url http://localhost:6666 ' -nodeos = 'nodeos' fastUnstakeSystem = './fast.refund/eosio.system/eosio.system.wasm' -logFile = open('test.log', 'a') - -symbol = 'SYS' -maxUserKeys = 10 # Maximum user keys to import into wallet -minProducerStake = 200.0000 # Minimum producer CPU and BW stake -extraIssue = 10.0000 # Extra amount to issue to cover buying ram -limitUsers = 0 # Limit number of users if >0 -limitProducers = 0 # Limit number of producers if >0 -numVoters = 10 # Number of users which cast votes -numProducersToVoteFor = 20 # Number of producers each user votes for -numSenders = 10 # Number of users to transfer funds randomly -producerSyncDelay = 80 # Time (s) to sleep to allow producers to sync - -eosioPub = 'EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr' -eosioPvt = '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p' + systemAccounts = [ 'eosio.bpay', 'eosio.msig', @@ -45,17 +28,6 @@ 'eosio.vpay', ] -with open('accounts.json') as f: - a = json.load(f) - if limitUsers: - del a['users'][limitUsers:] - if limitProducers: - del a['producers'][limitProducers:] - firstProducer = len(a['users']) - numProducers = len(a['producers']) - accounts = a['users'] + a['producers'] - -maxClients = numProducers + 10 def jsonArg(a): return " '" + json.dumps(a) + "' " @@ -99,31 +71,31 @@ def sleep(t): print('resume') def startWallet(): - run('rm -rf ' + walletDir) - run('mkdir -p ' + walletDir) - background('keosd --unlock-timeout %d --http-server-address 127.0.0.1:6666 --wallet-dir %s' % (unlockTimeout, walletDir)) + run('rm -rf ' + os.path.abspath(args.wallet_dir)) + run('mkdir -p ' + os.path.abspath(args.wallet_dir)) + background(args.keosd + ' --unlock-timeout %d --http-server-address 127.0.0.1:6666 --wallet-dir %s' % (unlockTimeout, os.path.abspath(args.wallet_dir))) sleep(.4) - run(cleos + 'wallet create') + run(args.cleos + 'wallet create') def importKeys(): - run(cleos + 'wallet import ' + eosioPvt) + run(args.cleos + 'wallet import ' + args.private_key) keys = {} for a in accounts: key = a['pvt'] if not key in keys: - if len(keys) >= maxUserKeys: + if len(keys) >= args.max_user_keys: break keys[key] = True - run(cleos + 'wallet import ' + key) + run(args.cleos + 'wallet import ' + key) for i in range(firstProducer, firstProducer + numProducers): a = accounts[i] key = a['pvt'] if not key in keys: keys[key] = True - run(cleos + 'wallet import ' + key) + run(args.cleos + 'wallet import ' + key) def startNode(nodeIndex, account): - dir = nodesDir + ('%02d-' % nodeIndex) + account['name'] + '/' + dir = args.nodes_dir + ('%02d-' % nodeIndex) + account['name'] + '/' run('rm -rf ' + dir) run('mkdir -p ' + dir) otherOpts = ''.join(list(map(lambda i: ' --p2p-peer-address localhost:' + str(9000 + i), range(nodeIndex)))) @@ -132,10 +104,10 @@ def startNode(nodeIndex, account): ' --plugin eosio::history_api_plugin' ) cmd = ( - nodeos + + args.nodeos + ' --max-transaction-time 200' ' --contracts-console' - ' --genesis-json ' + genesis + + ' --genesis-json ' + os.path.abspath(args.genesis) + ' --blocks-dir ' + os.path.abspath(dir) + '/blocks' ' --config-dir ' + os.path.abspath(dir) + ' --data-dir ' + os.path.abspath(dir) + @@ -160,10 +132,10 @@ def startProducers(b, e): def createSystemAccounts(): for a in systemAccounts: - run(cleos + 'create account eosio ' + a + ' ' + eosioPub) + run(args.cleos + 'create account eosio ' + a + ' ' + args.public_key) def intToCurrency(i): - return '%d.%04d %s' % (i // 10000, i % 10000, symbol) + return '%d.%04d %s' % (i // 10000, i % 10000, args.symbol) def fillStake(b, e): dist = numpy.random.pareto(1.161, e - b).tolist() # 1.161 = 80/20 rule @@ -174,58 +146,58 @@ def fillStake(b, e): for i in range(b, e): stake = round(factor * dist[i - b] * 10000 / 2) if i >= firstProducer and i < firstProducer + numProducers: - stake = max(stake, round(minProducerStake * 10000)) + stake = max(stake, round(args.min_producer_stake * 10000)) total += stake * 2 accounts[i]['stake'] = stake - return total + round(extraIssue * 10000) + return total + round(args.extra_issue * 10000) def createStakedAccounts(b, e): for i in range(b, e): a = accounts[i] stake = intToCurrency(a['stake']) - run(cleos + 'system newaccount eosio --transfer ' + a['name'] + ' ' + a['pub'] + ' --stake-net "' + stake + '" --stake-cpu "' + stake + '"') + run(args.cleos + 'system newaccount eosio --transfer ' + a['name'] + ' ' + a['pub'] + ' --stake-net "' + stake + '" --stake-cpu "' + stake + '"') def regProducers(b, e): for i in range(b, e): a = accounts[i] - retry(cleos + 'system regproducer ' + a['name'] + ' ' + a['pub'] + ' https://' + a['name'] + '.com' + '/' + a['pub']) + retry(args.cleos + 'system regproducer ' + a['name'] + ' ' + a['pub'] + ' https://' + a['name'] + '.com' + '/' + a['pub']) def listProducers(): - run(cleos + 'system listproducers') + run(args.cleos + 'system listproducers') def vote(b, e): for i in range(b, e): voter = accounts[i]['name'] - prods = random.sample(range(firstProducer, firstProducer + numProducers), numProducersToVoteFor) + prods = random.sample(range(firstProducer, firstProducer + numProducers), args.num_producers_vote) prods = ' '.join(map(lambda x: accounts[x]['name'], prods)) - retry(cleos + 'system voteproducer prods ' + voter + ' ' + prods) + retry(args.cleos + 'system voteproducer prods ' + voter + ' ' + prods) def claimRewards(): - table = getJsonOutput(cleos + 'get table eosio eosio producers -l 100') + table = getJsonOutput(args.cleos + 'get table eosio eosio producers -l 100') times = [] for row in table['rows']: if row['unpaid_blocks'] and not row['last_claim_time']: - times.append(getJsonOutput(cleos + 'system claimrewards -j ' + row['owner'])['processed']['elapsed']) + times.append(getJsonOutput(args.cleos + 'system claimrewards -j ' + row['owner'])['processed']['elapsed']) print('Elapsed time for claimrewards:', times) def vote(b, e): for i in range(b, e): voter = accounts[i]['name'] - prods = random.sample(range(firstProducer, firstProducer + numProducers), numProducersToVoteFor) + prods = random.sample(range(firstProducer, firstProducer + numProducers), args.num_producers_vote) prods = ' '.join(map(lambda x: accounts[x]['name'], prods)) - retry(cleos + 'system voteproducer prods ' + voter + ' ' + prods) + retry(args.cleos + 'system voteproducer prods ' + voter + ' ' + prods) def proxyVotes(b, e): vote(firstProducer, firstProducer + 1) proxy = accounts[firstProducer]['name'] - retry(cleos + 'system regproxy ' + proxy) + retry(args.cleos + 'system regproxy ' + proxy) sleep(1.0) for i in range(b, e): voter = accounts[i]['name'] - retry(cleos + 'system voteproducer proxy ' + voter + ' ' + proxy) + retry(args.cleos + 'system voteproducer proxy ' + voter + ' ' + proxy) def updateAuth(account, permission, parent, controller): - run(cleos + 'push action eosio updateauth' + jsonArg({ + run(args.cleos + 'push action eosio updateauth' + jsonArg({ 'account': account, 'permission': permission, 'parent': parent, @@ -242,12 +214,12 @@ def resign(account, controller): updateAuth(account, 'owner', '', controller) updateAuth(account, 'active', 'owner', controller) sleep(1) - run(cleos + 'get account ' + account) + run(args.cleos + 'get account ' + account) def sendUnstakedFunds(b, e): for i in range(b, e): a = accounts[i] - run(cleos + 'transfer eosio ' + a['name'] + ' "10.0000 ' + symbol + '"') + run(args.cleos + 'transfer eosio ' + a['name'] + ' "10.0000 ' + args.symbol + '"') def randomTransfer(b, e): for j in range(20): @@ -255,7 +227,7 @@ def randomTransfer(b, e): dest = src while dest == src: dest = accounts[random.randint(b, e - 1)]['name'] - run(cleos + 'transfer -f ' + src + ' ' + dest + ' "0.0001 ' + symbol + '"' + ' || true') + run(args.cleos + 'transfer -f ' + src + ' ' + dest + ' "0.0001 ' + args.symbol + '"' + ' || true') def msigProposeReplaceSystem(proposer, proposalName): requestedPermissions = [] @@ -264,20 +236,20 @@ def msigProposeReplaceSystem(proposer, proposalName): trxPermissions = [{'actor': 'eosio', 'permission': 'active'}] with open(fastUnstakeSystem, mode='rb') as f: setcode = {'account': 'eosio', 'vmtype': 0, 'vmversion': 0, 'code': f.read().hex()} - run(cleos + 'multisig propose ' + proposalName + jsonArg(requestedPermissions) + + run(args.cleos + 'multisig propose ' + proposalName + jsonArg(requestedPermissions) + jsonArg(trxPermissions) + 'eosio setcode' + jsonArg(setcode) + ' -p ' + proposer) def msigApproveReplaceSystem(proposer, proposalName): for i in range(firstProducer, firstProducer + numProducers): - run(cleos + 'multisig approve ' + proposer + ' ' + proposalName + + run(args.cleos + 'multisig approve ' + proposer + ' ' + proposalName + jsonArg({'actor': accounts[i]['name'], 'permission': 'active'}) + '-p ' + accounts[i]['name']) def msigExecReplaceSystem(proposer, proposalName): - retry(cleos + 'multisig exec ' + proposer + ' ' + proposalName + ' -p ' + proposer) + retry(args.cleos + 'multisig exec ' + proposer + ' ' + proposalName + ' -p ' + proposer) def msigReplaceSystem(): - run(cleos + 'push action eosio buyrambytes' + jsonArg(['eosio', accounts[0]['name'], 200000]) + '-p eosio') + run(args.cleos + 'push action eosio buyrambytes' + jsonArg(['eosio', accounts[0]['name'], 200000]) + '-p eosio') sleep(1) msigProposeReplaceSystem(accounts[0]['name'], 'fast.unstake') sleep(1) @@ -287,7 +259,7 @@ def msigReplaceSystem(): def produceNewAccounts(): with open('newusers', 'w') as f: for i in range(0, 3000): - x = getOutput(cleos + 'create key') + x = getOutput(args.cleos + 'create key') r = re.match('Private key: *([^ \n]*)\nPublic key: *([^ \n]*)', x, re.DOTALL | re.MULTILINE) name = 'user' for j in range(7, -1, -1): @@ -295,7 +267,6 @@ def produceNewAccounts(): print(i, name) f.write(' {"name":"%s", "pvt":"%s", "pub":"%s"},\n' % (name, r[1], r[2])) -logFile.write('\n\n' + '*' * 80 + '\n\n\n') def stepKillAll(): run('killall keosd nodeos || true') @@ -304,20 +275,20 @@ def stepStartWallet(): startWallet() importKeys() def stepStartBoot(): - startNode(0, {'name': 'eosio', 'pvt': eosioPvt, 'pub': eosioPub}) + startNode(0, {'name': 'eosio', 'pvt': args.private_key, 'pub': args.public_key}) sleep(1.5) def stepInstallSystemContracts(): - run(cleos + 'set contract eosio.token ' + contractsDir + 'eosio.token/') - run(cleos + 'set contract eosio.msig ' + contractsDir + 'eosio.msig/') + run(args.cleos + 'set contract eosio.token ' + args.contracts_dir + 'eosio.token/') + run(args.cleos + 'set contract eosio.msig ' + args.contracts_dir + 'eosio.msig/') def stepCreateTokens(): - run(cleos + 'push action eosio.token create \'["eosio", "10000000000.0000 %s"]\' -p eosio.token' % (symbol)) + run(args.cleos + 'push action eosio.token create \'["eosio", "10000000000.0000 %s"]\' -p eosio.token' % (args.symbol)) totalAllocation = fillStake(0, len(accounts)) - run(cleos + 'push action eosio.token issue \'["eosio", "%s", "memo"]\' -p eosio' % intToCurrency(totalAllocation)) + run(args.cleos + 'push action eosio.token issue \'["eosio", "%s", "memo"]\' -p eosio' % intToCurrency(totalAllocation)) sleep(1) def stepSetSystemContract(): - retry(cleos + 'set contract eosio ' + contractsDir + 'eosio.system/') + retry(args.cleos + 'set contract eosio ' + args.contracts_dir + 'eosio.system/') sleep(1) - run(cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active') + run(args.cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active') def stepCreateStakedAccounts(): createStakedAccounts(0, len(accounts)) def stepRegProducers(): @@ -326,26 +297,30 @@ def stepRegProducers(): listProducers() def stepStartProducers(): startProducers(firstProducer, firstProducer + numProducers) - sleep(producerSyncDelay) + sleep(args.producer_sync_delay) def stepVote(): - vote(0, 0 + numVoters) + vote(0, 0 + args.num_voters) sleep(1) listProducers() sleep(5) def stepProxyVotes(): - proxyVotes(0, 0 + numVoters) + proxyVotes(0, 0 + args.num_voters) def stepResign(): resign('eosio', 'eosio.prods') for a in systemAccounts: resign(a, 'eosio') def stepIssueUnstaked(): - run(cleos + 'push action eosio.token issue \'["eosio", "%d.0000 %s", "memo"]\' -p eosio' % ((len(accounts)) * 10, symbol)) - sendUnstakedFunds(0, numSenders) + run(args.cleos + 'push action eosio.token issue \'["eosio", "%d.0000 %s", "memo"]\' -p eosio' % ((len(accounts)) * 10, args.symbol)) + sendUnstakedFunds(0, args.num_senders) def stepTransfer(): while True: - randomTransfer(0, numSenders) + randomTransfer(0, args.num_senders) def stepLog(): - run('tail -n 60 ' + nodesDir + '00-eosio/stderr') + run('tail -n 60 ' + args.nodes_dir + '00-eosio/stderr') + +# Command Line Arguments + +parser = argparse.ArgumentParser() commands = [ ('k', 'kill', stepKillAll, True, "Kill all nodeos and keosd processes"), @@ -368,9 +343,30 @@ def stepLog(): ('l', 'log', stepLog, True, "Show tail of node's log"), ] -parser = argparse.ArgumentParser() + +parser.add_argument('--public-key', metavar='', help="EOSIO Public Key", default='EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr', dest="public_key") +parser.add_argument('--private-Key', metavar='', help="EOSIO Private Key", default='5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p', dest="private_key") +parser.add_argument('--cleos', metavar='', help="Cleos command", default='../../build/programs/cleos/cleos --wallet-url http://localhost:6666 ') +parser.add_argument('--nodeos', metavar='', help="Path to nodeos binary", default='../../build/programs/nodeos/nodeos') +parser.add_argument('--keosd', metavar='', help="Path to keosd binary", default='../../build/programs/keosd/keosd') +parser.add_argument('--contracts-dir', metavar='', help="Path to contracts directory", default='../../build/contracts/') +parser.add_argument('--nodes-dir', metavar='', help="Path to nodes directory", default='./nodes/') +parser.add_argument('--genesis', metavar='', help="Path to genesis.json", default="./genesis.json") +parser.add_argument('--wallet-dir', metavar='', help="Path to wallet directory", default='./wallet/') +parser.add_argument('--log-path', metavar='', help="Path to log file", default='./output.log') +parser.add_argument('--symbol', metavar='', help="The eosio.system symbol", default='SYS') +parser.add_argument('--user-limit', metavar='', help="Max number of users. (0 = no limit)", type=int, default=0) +parser.add_argument('--max-user-keys', metavar='', help="Maximum user keys to import into wallet", type=int, default=10) +parser.add_argument('--extra-issue', metavar='', help="Extra amount to issue to cover buying ram", type=float, default=10.0000) +parser.add_argument('--producer-limit', metavar='', help="Maximum number of producers. (0 = no limit)", type=int, default=0) +parser.add_argument('--min-producer-stake', metavar='', help="Minimum producer CPU and BW stake", type=float, default=200.0000) +parser.add_argument('--num-producers-vote', metavar='', help="Number of producers for which each user votes", type=int, default=20) +parser.add_argument('--num-voters', metavar='', help="Number of voters", type=int, default=10) +parser.add_argument('--num-senders', metavar='', help="Number of users to transfer funds randomly", type=int, default=10) +parser.add_argument('--producer-sync-delay', metavar='', help="Time (s) to sleep to allow producers to sync", type=int, default=80) parser.add_argument('-a', '--all', action='store_true', help="Do everything marked with (*)") -parser.add_argument('-H', '--http-port', type=int, default=8000, help='Http port for cleos') +parser.add_argument('-H', '--http-port', type=int, default=8000, metavar='', help='HTTP port for cleos') + for (flag, command, function, inAll, help) in commands: prefix = '' if inAll: prefix += '*' @@ -379,9 +375,26 @@ def stepLog(): parser.add_argument('-' + flag, '--' + command, action='store_true', help=help, dest=command) else: parser.add_argument('--' + command, action='store_true', help=help, dest=command) + args = parser.parse_args() -cleos += '--url http://localhost:%d ' % args.http_port +args.cleos += '--url http://localhost:%d ' % args.http_port + +logFile = open(args.log_path, 'a') + +logFile.write('\n\n' + '*' * 80 + '\n\n\n') + +with open('accounts.json') as f: + a = json.load(f) + if args.user_limit: + del a['users'][args.user_limit:] + if args.producer_limit: + del a['producers'][args.producer_limit:] + firstProducer = len(a['users']) + numProducers = len(a['producers']) + accounts = a['users'] + a['producers'] + +maxClients = numProducers + 10 haveCommand = False for (flag, command, function, inAll, help) in commands: From 0fd3259d4b02a722593890956b762d656a37712f Mon Sep 17 00:00:00 2001 From: Bill Hamilton Date: Fri, 25 May 2018 20:24:53 +0000 Subject: [PATCH 19/38] fedora: added bzip2 to dependency list for buildkite --- scripts/eosio_build_fedora.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/eosio_build_fedora.sh b/scripts/eosio_build_fedora.sh index a34bb9ed9fa..41ba1dc85a1 100644 --- a/scripts/eosio_build_fedora.sh +++ b/scripts/eosio_build_fedora.sh @@ -58,7 +58,7 @@ fi DEP_ARRAY=( git gcc.x86_64 gcc-c++.x86_64 autoconf automake libtool make cmake.x86_64 \ - bzip2-devel.x86_64 openssl-devel.x86_64 gmp-devel.x86_64 libstdc++-devel.x86_64 \ + bzip2.x86_64 bzip2-devel.x86_64 openssl-devel.x86_64 gmp-devel.x86_64 libstdc++-devel.x86_64 \ python2-devel.x86_64 python3-devel.x86_64 mongodb.x86_64 mongodb-server.x86_64 libedit.x86_64 \ graphviz.x86_64 doxygen.x86_64 ) COUNT=1 From 0eda814ce34a4df6b982223d54f565ad59774083 Mon Sep 17 00:00:00 2001 From: Eric Iles Date: Fri, 25 May 2018 16:46:26 -0400 Subject: [PATCH 20/38] Merge branch 'master' into bios-tuts-args [skip-ci] --- libraries/appbase | 2 +- libraries/chainbase | 2 +- programs/snapshot | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/appbase b/libraries/appbase index 50dc015b2f0..d8e24895d5d 160000 --- a/libraries/appbase +++ b/libraries/appbase @@ -1 +1 @@ -Subproject commit 50dc015b2f0e25c0cd01cf520245da23c0ed446b +Subproject commit d8e24895d5d3d019d5083ccafc9e290bdc96a32c diff --git a/libraries/chainbase b/libraries/chainbase index b40a1ec99ee..d48ebabf56b 160000 --- a/libraries/chainbase +++ b/libraries/chainbase @@ -1 +1 @@ -Subproject commit b40a1ec99ee0eb16e28ee1c1a9577f1af7d48b84 +Subproject commit d48ebabf56b4115753fcabb7648a0ffcf3b0f5e9 diff --git a/programs/snapshot b/programs/snapshot index e2a2e74e456..651f8491764 160000 --- a/programs/snapshot +++ b/programs/snapshot @@ -1 +1 @@ -Subproject commit e2a2e74e456413f5d6e6439d4918d1b417ede1c3 +Subproject commit 651f8491764b085de5c8c62cf4fb59d25704fede From c740baf05606a25b380de96141416085ced18900 Mon Sep 17 00:00:00 2001 From: arhag Date: Fri, 25 May 2018 16:50:13 -0400 Subject: [PATCH 21/38] chain_id_type should be its own type (without a public default constructor) rather than just a typedef of fc::sha256 #3415 Special exceptions had to be made to `fc::variant::as()const` and chain_plugin and net_plugin to access the private default constructor. This is an ugly hack but it works for now. Eventually I need to see if there is a better solution. --- libraries/chain/CMakeLists.txt | 1 + libraries/chain/chain_id_type.cpp | 27 +++++++++ libraries/chain/genesis_state.cpp | 2 +- .../include/eosio/chain/chain_id_type.hpp | 56 +++++++++++++++++++ .../chain/include/eosio/chain/config.hpp | 2 - libraries/chain/include/eosio/chain/types.hpp | 14 +---- plugins/chain_plugin/chain_plugin.cpp | 7 ++- programs/cleos/main.cpp | 5 +- tests/wallet_tests.cpp | 8 ++- 9 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 libraries/chain/chain_id_type.cpp create mode 100644 libraries/chain/include/eosio/chain/chain_id_type.hpp diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 03f620c24f6..08c7064515c 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -22,6 +22,7 @@ add_library( eosio_chain eosio_contract.cpp eosio_contract_abi.cpp chain_config.cpp + chain_id_type.cpp genesis_state.cpp ${CMAKE_CURRENT_BINARY_DIR}/genesis_state_root_key.cpp diff --git a/libraries/chain/chain_id_type.cpp b/libraries/chain/chain_id_type.cpp new file mode 100644 index 00000000000..85f41195b7f --- /dev/null +++ b/libraries/chain/chain_id_type.cpp @@ -0,0 +1,27 @@ +/** + * @file + * @copyright defined in eos/LICENSE.txt + */ + +#include +#include + +namespace eosio { namespace chain { + + void chain_id_type::reflector_verify()const { + FC_ASSERT( *reinterpret_cast(this) != fc::sha256(), "chain_id_type cannot be zero" ); + } + +} } // namespace eosio::chain + +namespace fc { + + void to_variant(const eosio::chain::chain_id_type& cid, fc::variant& v) { + to_variant( static_cast(cid), v); + } + + void from_variant(const fc::variant& v, eosio::chain::chain_id_type& cid) { + from_variant( v, static_cast(cid) ); + } + +} // fc diff --git a/libraries/chain/genesis_state.cpp b/libraries/chain/genesis_state.cpp index 1835378ba58..b69c6b6179e 100644 --- a/libraries/chain/genesis_state.cpp +++ b/libraries/chain/genesis_state.cpp @@ -18,7 +18,7 @@ genesis_state::genesis_state() { chain::chain_id_type genesis_state::compute_chain_id() const { digest_type::encoder enc; fc::raw::pack( enc, *this ); - return enc.result(); + return chain_id_type{enc.result()}; } } } // namespace eosio::chain diff --git a/libraries/chain/include/eosio/chain/chain_id_type.hpp b/libraries/chain/include/eosio/chain/chain_id_type.hpp new file mode 100644 index 00000000000..62e3b943f51 --- /dev/null +++ b/libraries/chain/include/eosio/chain/chain_id_type.hpp @@ -0,0 +1,56 @@ +/** + * @file + * @copyright defined in eos/LICENSE.txt + */ +#pragma once + +#include + +namespace eosio { + + class net_plugin_impl; + struct handshake_message; + + namespace chain_apis { + class read_only; + } + +namespace chain { + + struct chain_id_type : public fc::sha256 { + using fc::sha256::sha256; + + template + inline friend T& operator<<( T& ds, const chain_id_type& cid ) { + ds.write( cid.data(), cid.data_size() ); + return ds; + } + + template + inline friend T& operator>>( T& ds, chain_id_type& cid ) { + ds.read( cid.data(), cid.data_size() ); + return ds; + } + + void reflector_verify()const; + + private: + chain_id_type() = default; + + template + friend T fc::variant::as()const; + + friend class eosio::chain_apis::read_only; + + // Eventually net_plugin should be updated to not default construct chain_id. Then these two lines can be removed. + friend class eosio::net_plugin_impl; + friend struct eosio::handshake_message; + }; + +} } // namespace eosio::chain + +namespace fc { + class variant; + void to_variant(const eosio::chain::chain_id_type& cid, fc::variant& v); + void from_variant(const fc::variant& v, eosio::chain::chain_id_type& cid); +} // fc diff --git a/libraries/chain/include/eosio/chain/config.hpp b/libraries/chain/include/eosio/chain/config.hpp index b435a714dd8..d9c7fc31f33 100644 --- a/libraries/chain/include/eosio/chain/config.hpp +++ b/libraries/chain/include/eosio/chain/config.hpp @@ -115,8 +115,6 @@ const static int irreversible_threshold_percent= 70 * percent_1; const static uint64_t billable_alignment = 16; -const static chain_id_type chain_id = chain_id_type(); - template struct billable_size; diff --git a/libraries/chain/include/eosio/chain/types.hpp b/libraries/chain/include/eosio/chain/types.hpp index 1d5cdfe827a..de4a56bde87 100644 --- a/libraries/chain/include/eosio/chain/types.hpp +++ b/libraries/chain/include/eosio/chain/types.hpp @@ -4,6 +4,7 @@ */ #pragma once #include +#include #include @@ -88,19 +89,6 @@ namespace eosio { namespace chain { struct void_t{}; - using chain_id_type = fc::sha256; - /* - struct genesis_state; - - struct chain_id_type { - chain_id_type(const fc::string& s); - //chain_id_type( const genesis_state& gs ); - chain_id_type(); - operator fc::sha256() { return id; } - fc::sha256 id; - }; - */ - using chainbase::allocator; using shared_string = boost::interprocess::basic_string, allocator>; diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 1fa6063a8b6..1d91f2a859c 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -64,7 +64,7 @@ class chain_plugin_impl { fc::optional block_logger; fc::optional chain_config; fc::optional chain; - chain_id_type chain_id; + fc::optional chain_id; //txn_msg_rate_limits rate_limits; fc::optional wasm_runtime; @@ -304,7 +304,7 @@ void chain_plugin::plugin_initialize(const variables_map& options) { } my->chain.emplace(*my->chain_config); - my->chain_id = my->chain->get_chain_id(); + my->chain_id.emplace(my->chain->get_chain_id()); // set up method providers my->get_block_by_number_provider = app().get_method().register_provider([this](uint32_t block_num) -> signed_block_ptr { @@ -476,7 +476,8 @@ controller& chain_plugin::chain() { return *my->chain; } const controller& chain_plugin::chain() const { return *my->chain; } chain::chain_id_type chain_plugin::get_chain_id()const { - return my->chain_id; + FC_ASSERT( my->chain_id.valid(), "chain ID has not been initialized yet" ); + return *my->chain_id; } namespace chain_apis { diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 9bd2bdc3b3e..6a4f36ffbec 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -2149,7 +2149,8 @@ int main( int argc, char** argv ) { sign->set_callback([&] { signed_transaction trx = json_from_file_or_string(trx_json_to_sign).as(); - chain_id_type chain_id; + + fc::optional chain_id; if( str_chain_id.size() == 0 ) { ilog( "grabbing chain_id from nodeos" ); @@ -2167,7 +2168,7 @@ int main( int argc, char** argv ) { } auto priv_key = fc::crypto::private_key::regenerate(*utilities::wif_to_key(str_private_key)); - trx.sign(priv_key, chain_id); + trx.sign(priv_key, *chain_id); if(push_trx) { auto trx_result = call(push_txn_func, packed_transaction(trx, packed_transaction::none)); diff --git a/tests/wallet_tests.cpp b/tests/wallet_tests.cpp index dc854521dbd..51ca94818af 100644 --- a/tests/wallet_tests.cpp +++ b/tests/wallet_tests.cpp @@ -4,6 +4,7 @@ */ #include #include +#include #include #include @@ -103,7 +104,7 @@ BOOST_AUTO_TEST_CASE(wallet_manager_test) wm.import_key("test", key1); BOOST_CHECK_EQUAL(2, wm.list_keys().size()); auto keys = wm.list_keys(); - + auto pub_pri_pair = [](const char *key) -> auto { private_key_type prikey = private_key_type(std::string(key)); return std::pair(prikey.get_public_key(), prikey); @@ -145,12 +146,13 @@ BOOST_AUTO_TEST_CASE(wallet_manager_test) private_key_type pkey3{std::string(key3)}; chain::signed_transaction trx; + auto chain_id = genesis_state().compute_chain_id(); flat_set pubkeys; pubkeys.emplace(pkey1.get_public_key()); pubkeys.emplace(pkey2.get_public_key()); pubkeys.emplace(pkey3.get_public_key()); - trx = wm.sign_transaction(trx, pubkeys, chain_id_type{}); - const auto& pks = trx.get_signature_keys(chain_id_type{}); + trx = wm.sign_transaction(trx, pubkeys, chain_id ); + const auto& pks = trx.get_signature_keys(chain_id); BOOST_CHECK_EQUAL(3, pks.size()); BOOST_CHECK(find(pks.cbegin(), pks.cend(), pkey1.get_public_key()) != pks.cend()); BOOST_CHECK(find(pks.cbegin(), pks.cend(), pkey2.get_public_key()) != pks.cend()); From fe2296e8391818ecb7af98c283eea8a812928a30 Mon Sep 17 00:00:00 2001 From: Anton Perkov Date: Fri, 25 May 2018 16:53:47 -0400 Subject: [PATCH 22/38] system contract cleanup: remove special handling for eosio delegating/buying #3430 --- contracts/eosio.system/delegate_bandwidth.cpp | 20 ++++++++----------- unittests/eosio.system_tests.cpp | 2 -- unittests/eosio_system_tester.hpp | 3 --- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/contracts/eosio.system/delegate_bandwidth.cpp b/contracts/eosio.system/delegate_bandwidth.cpp index a292f8552eb..a66cc181103 100644 --- a/contracts/eosio.system/delegate_bandwidth.cpp +++ b/contracts/eosio.system/delegate_bandwidth.cpp @@ -112,12 +112,10 @@ namespace eosiosystem { 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.ram), quant_after_fee, std::string("buy ram") } ); - } + INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {payer,N(active)}, + { payer, N(eosio.ram), quant_after_fee, std::string("buy ram") } ); - if( payer != N(eosio) && fee.amount > 0 ) { + 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") } ); } @@ -182,14 +180,12 @@ namespace eosiosystem { }); set_resource_limits( res_itr->owner, res_itr->ram_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount ); - if( N(eosio) != account ) { - INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.ram),N(active)}, + INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio.ram),N(active)}, { 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), {account,N(active)}, - { account, N(eosio.ramfee), asset(fee), std::string("sell ram fee") } ); - } + auto fee = tokens_out.amount / 200; + if( fee > 0 ) { + INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {account,N(active)}, + { account, N(eosio.ramfee), asset(fee), std::string("sell ram fee") } ); } } diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index bb41e3eda40..5fdf47904f8 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -20,7 +20,6 @@ BOOST_AUTO_TEST_SUITE(eosio_system_tests) BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try { - BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) + get_balance( "eosio.ramfee" ) + get_balance( "eosio.stake" ) ); BOOST_REQUIRE_EQUAL( core_from_string("0.0000"), get_balance( "alice1111111" ) ); transfer( "eosio", "alice1111111", core_from_string("1000.0000"), "eosio" ); @@ -119,7 +118,6 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try { BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try { - BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance( "eosio" ) + get_balance( "eosio.ramfee" ) + get_balance( "eosio.stake" ) ); BOOST_REQUIRE_EQUAL( core_from_string("0.0000"), get_balance( "alice1111111" ) ); transfer( "eosio", "alice1111111", core_from_string("1000.0000"), "eosio" ); diff --git a/unittests/eosio_system_tester.hpp b/unittests/eosio_system_tester.hpp index ea676617d40..d6b24629dfa 100644 --- a/unittests/eosio_system_tester.hpp +++ b/unittests/eosio_system_tester.hpp @@ -81,9 +81,6 @@ class eosio_system_tester : public TESTER { create_account_with_resources( N(alice1111111), config::system_account_name, core_from_string("1.0000"), false ); create_account_with_resources( N(bob111111111), config::system_account_name, core_from_string("0.4500"), false ); create_account_with_resources( N(carol1111111), config::system_account_name, core_from_string("1.0000"), false ); - - - BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake")); } From 04aa1f884020a55661c646c531299901d5f0d802 Mon Sep 17 00:00:00 2001 From: arhag Date: Fri, 25 May 2018 16:54:57 -0400 Subject: [PATCH 23/38] clarify comment regarding access of chain_id_type() constructor --- libraries/chain/include/eosio/chain/chain_id_type.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/include/eosio/chain/chain_id_type.hpp b/libraries/chain/include/eosio/chain/chain_id_type.hpp index 62e3b943f51..597f9bfce12 100644 --- a/libraries/chain/include/eosio/chain/chain_id_type.hpp +++ b/libraries/chain/include/eosio/chain/chain_id_type.hpp @@ -37,12 +37,12 @@ namespace chain { private: chain_id_type() = default; + // Some exceptions are unfortunately necessary: template friend T fc::variant::as()const; friend class eosio::chain_apis::read_only; - // Eventually net_plugin should be updated to not default construct chain_id. Then these two lines can be removed. friend class eosio::net_plugin_impl; friend struct eosio::handshake_message; }; From 27c36c8274f3b4395e42bb507d6f742adea8f7d3 Mon Sep 17 00:00:00 2001 From: Eric Iles Date: Fri, 25 May 2018 16:55:03 -0400 Subject: [PATCH 24/38] Revert "Merge branch 'master' into bios-tuts-args [skip-ci]" This reverts commit 0eda814ce34a4df6b982223d54f565ad59774083. --- libraries/appbase | 2 +- libraries/chainbase | 2 +- programs/snapshot | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/appbase b/libraries/appbase index d8e24895d5d..50dc015b2f0 160000 --- a/libraries/appbase +++ b/libraries/appbase @@ -1 +1 @@ -Subproject commit d8e24895d5d3d019d5083ccafc9e290bdc96a32c +Subproject commit 50dc015b2f0e25c0cd01cf520245da23c0ed446b diff --git a/libraries/chainbase b/libraries/chainbase index d48ebabf56b..b40a1ec99ee 160000 --- a/libraries/chainbase +++ b/libraries/chainbase @@ -1 +1 @@ -Subproject commit d48ebabf56b4115753fcabb7648a0ffcf3b0f5e9 +Subproject commit b40a1ec99ee0eb16e28ee1c1a9577f1af7d48b84 diff --git a/programs/snapshot b/programs/snapshot index 651f8491764..e2a2e74e456 160000 --- a/programs/snapshot +++ b/programs/snapshot @@ -1 +1 @@ -Subproject commit 651f8491764b085de5c8c62cf4fb59d25704fede +Subproject commit e2a2e74e456413f5d6e6439d4918d1b417ede1c3 From ec7151cd300b86980e3d1d8bdb83904a2b59cc70 Mon Sep 17 00:00:00 2001 From: Anton Perkov Date: Fri, 25 May 2018 17:06:40 -0400 Subject: [PATCH 25/38] system contract cleanup: fixed and put back check for eosio balance #3430 --- unittests/eosio_system_tester.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittests/eosio_system_tester.hpp b/unittests/eosio_system_tester.hpp index d6b24629dfa..f1578526694 100644 --- a/unittests/eosio_system_tester.hpp +++ b/unittests/eosio_system_tester.hpp @@ -81,6 +81,8 @@ class eosio_system_tester : public TESTER { create_account_with_resources( N(alice1111111), config::system_account_name, core_from_string("1.0000"), false ); create_account_with_resources( N(bob111111111), config::system_account_name, core_from_string("0.4500"), false ); create_account_with_resources( N(carol1111111), config::system_account_name, core_from_string("1.0000"), false ); + + BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") ); } From 4d2a78e40a849e80faa2ca8dff950071deb60169 Mon Sep 17 00:00:00 2001 From: Bill Hamilton Date: Fri, 25 May 2018 21:44:41 +0000 Subject: [PATCH 26/38] Amazon: changed boost version from 1.66 to 1.67 --- eosio_build.sh | 4 ++-- scripts/eosio_build_amazon.sh | 29 +++++++++++++++-------------- scripts/eosio_build_darwin.sh | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/eosio_build.sh b/eosio_build.sh index a11ee2f3df1..1d3e5b58857 100755 --- a/eosio_build.sh +++ b/eosio_build.sh @@ -143,7 +143,7 @@ export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm export CMAKE=${HOME}/opt/cmake/bin/cmake export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_66_0" + export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "CentOS Linux") FILE="${PWD}/scripts/eosio_build_centos.sh" @@ -161,7 +161,7 @@ C_COMPILER=clang-4.0 MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_66_0" + export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "Fedora") FILE="${PWD}/scripts/eosio_build_fedora.sh" diff --git a/scripts/eosio_build_amazon.sh b/scripts/eosio_build_amazon.sh index 5eb077cd6d0..e1fcbbdacb1 100644 --- a/scripts/eosio_build_amazon.sh +++ b/scripts/eosio_build_amazon.sh @@ -214,9 +214,9 @@ printf "\\n\\tChecking boost library installation.\\n" BVERSION=$( grep "BOOST_LIB_VERSION" "${BOOST_ROOT}/include/boost/version.hpp" 2>/dev/null \ | tail -1 | tr -s ' ' | cut -d\ -f3 | sed 's/[^0-9\._]//gI' ) - if [ "${BVERSION}" != "1_66" ]; then + if [ "${BVERSION}" != "1_67" ]; then printf "\\tRemoving existing boost libraries in %s/opt/boost*.\\n" "${HOME}" - if ! rm -rf "${HOME}/opt/boost*" + if ! rm -rf "${HOME}"/opt/boost* then printf "\\n\\tUnable to remove deprecated boost libraries at this time.\\n" printf "\\n\\tExiting now.\\n" @@ -230,50 +230,51 @@ exit 1 fi STATUS=$(curl -LO -w '%{http_code}' --connect-timeout 30 \ - "https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2" ) + "https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2" ) if [ "${STATUS}" -ne 200 ]; then printf "\\tUnable to download Boost libraries at this time.\\n" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! tar xf "${TEMP_DIR}/boost_1_66_0.tar.bz2" + if ! tar xf "${TEMP_DIR}/boost_1_67_0.tar.bz2" then - printf "\\tUnable to decompress Boost libraries @ %s/boost_1_66_0.tar.bz2 at this time.\\n" "${TEMP_DIR}" + printf "\\tUnable to decompress Boost libraries @ %s/boost_1_67_0.tar.bz2 at this time.\\n" "${TEMP_DIR}" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! rm -f "${TEMP_DIR}/boost_1_66_0.tar.bz2" + if ! rm -f "${TEMP_DIR}/boost_1_67_0.tar.bz2" then - printf "\\tUnable to remove Boost libraries @ %s/boost_1_66_0.tar.bz2 at this time.\\n" "${TEMP_DIR}" + printf "\\tUnable to remove Boost libraries @ %s/boost_1_67_0.tar.bz2 at this time.\\n" "${TEMP_DIR}" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! cd "${TEMP_DIR}/boost_1_66_0/" + if ! cd "${TEMP_DIR}/boost_1_67_0/" then - printf "\\tUnable to change directory into %s/boost_1_66_0/ at this time.\\n" "${TEMP_DIR}" + printf "\\tUnable to change directory into %s/boost_1_67_0/ at this time.\\n" "${TEMP_DIR}" printf "\\tExiting now.\\n\\n" exit 1; fi - if ! ./bootstrap.sh "--prefix=$BOOST_ROOT" + if ! ./bootstrap.sh "--prefix=${BOOST_ROOT}" then printf "\\n\\tInstallation of boost libraries failed. 0\\n" printf "\\n\\tExiting now.\\n" exit 1 fi - if ! ./b2 install + if ! "${TEMP_DIR}"/boost_1_67_0/b2 install then printf "\\n\\tInstallation of boost libraries failed. 1\\n" printf "\\n\\tExiting now.\\n" exit 1 fi - if ! rm -rf "${TEMP_DIR}/boost_1_66_0/" + if ! rm -rf "${TEMP_DIR}/boost_1_67_0/" then - printf "\\n\\tUnable to remove boost libraries directory @ %s/boost_1_66_0/.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to remove boost libraries directory @ %s/boost_1_67_0/.\\n" "${TEMP_DIR}" printf "\\n\\tExiting now.\\n" exit 1 fi + printf "\\tBoost successfully installed @ %s/opt/boost_1_67_0.\\n" "${HOME}" else - printf "\\tBoost 1.66.0 found at %s/opt/boost_1_66_0.\\n" "${HOME}" + printf "\\tBoost 1.67.0 found at %s/opt/boost_1_67_0.\\n" "${HOME}" fi printf "\\n\\tChecking MongoDB installation.\\n" diff --git a/scripts/eosio_build_darwin.sh b/scripts/eosio_build_darwin.sh index c82d8cbb855..d2cb3ea71e4 100644 --- a/scripts/eosio_build_darwin.sh +++ b/scripts/eosio_build_darwin.sh @@ -180,7 +180,7 @@ if [ "${BVERSION}" != "106700" ]; then if [ ! -z "${BVERSION}" ]; then printf "\\tFound Boost Version %s.\\n" "${BVERSION}" - printf "\\tEOS.IO requires Boost version 1.66.\\n" + printf "\\tEOS.IO requires Boost version 1.67.\\n" printf "\\tWould you like to uninstall version %s and install Boost version 1.67.\\n" "${BVERSION}" select yn in "Yes" "No"; do case $yn in From ad64ec4b36b9facfad748f94e3f71db891dff824 Mon Sep 17 00:00:00 2001 From: Eric Iles Date: Fri, 25 May 2018 18:26:38 -0400 Subject: [PATCH 27/38] Update boost on coverage pipeline --- .buildkite/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/coverage.yml b/.buildkite/coverage.yml index 99c0e064c7a..8eda049bcbd 100644 --- a/.buildkite/coverage.yml +++ b/.buildkite/coverage.yml @@ -21,7 +21,7 @@ steps: mounts: - /etc/buildkite-agent/config:/config environment: - - BOOST_ROOT=/root/opt/boost_1_66_0 + - BOOST_ROOT=/root/opt/boost_1_67_0 - OPENSSL_ROOT_DIR=/usr/include/openssl - WASM_ROOT=/root/opt/wasm - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/opt/wasm/bin From 0770df787deedd57c7925c2e9d06eb821e8fcfbc Mon Sep 17 00:00:00 2001 From: arhag Date: Fri, 25 May 2018 18:29:18 -0400 Subject: [PATCH 28/38] fix eosio_msig_tests #3430 --- unittests/multisig_tests.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/unittests/multisig_tests.cpp b/unittests/multisig_tests.cpp index d2044ef634c..50da46df88d 100644 --- a/unittests/multisig_tests.cpp +++ b/unittests/multisig_tests.cpp @@ -420,7 +420,8 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_all_approve, eosio_msig_tester ) create_currency( N(eosio.token), config::system_account_name, core_from_string("10000000000.0000") ); issue(config::system_account_name, core_from_string("1000000000.0000")); - BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") ); + BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), + get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") ); set_code( config::system_account_name, eosio_system_wast ); set_abi( config::system_account_name, eosio_system_abi ); @@ -431,7 +432,8 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_all_approve, eosio_msig_tester ) create_account_with_resources( N(bob111111111), N(eosio), core_from_string("0.4500"), false ); create_account_with_resources( N(carol1111111), N(eosio), core_from_string("1.0000"), false ); - BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") ); + BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), + get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") ); vector perm = { { N(alice), config::active_name }, { N(bob), config::active_name }, {N(carol), config::active_name} }; @@ -541,7 +543,8 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_major_approve, eosio_msig_tester create_account_with_resources( N(bob111111111), N(eosio), core_from_string("0.4500"), false ); create_account_with_resources( N(carol1111111), N(eosio), core_from_string("1.0000"), false ); - BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") ); + BOOST_REQUIRE_EQUAL( core_from_string("1000000000.0000"), + get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") ); vector perm = { { N(alice), config::active_name }, { N(bob), config::active_name }, {N(carol), config::active_name}, {N(apple), config::active_name}}; From e918f01992b6368712c4f41a5df6ae8ab3e4817a Mon Sep 17 00:00:00 2001 From: Bill Hamilton Date: Fri, 25 May 2018 23:29:03 +0000 Subject: [PATCH 29/38] CentOS: changed boost version from 1.66 to 1.67 --- eosio_build.sh | 2 +- scripts/eosio_build_centos.sh | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/eosio_build.sh b/eosio_build.sh index a11ee2f3df1..81ed63c3b61 100755 --- a/eosio_build.sh +++ b/eosio_build.sh @@ -153,7 +153,7 @@ export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm export CMAKE=${HOME}/opt/cmake/bin/cmake export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_66_0" + export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "elementary OS") FILE="${PWD}/scripts/eosio_build_ubuntu.sh" diff --git a/scripts/eosio_build_centos.sh b/scripts/eosio_build_centos.sh index eeeafc22cad..cefc8127ccb 100644 --- a/scripts/eosio_build_centos.sh +++ b/scripts/eosio_build_centos.sh @@ -125,8 +125,9 @@ printf "\\n\\tYUM repository successfully updated.\\n\\n" - DEP_ARRAY=( git autoconf automake bzip2 libtool ocaml.x86_64 doxygen graphviz-devel.x86_64 libicu-devel.x86_64 \ - bzip2-devel.x86_64 openssl-devel.x86_64 gmp-devel.x86_64 python-devel.x86_64 gettext-devel.x86_64) + DEP_ARRAY=( git autoconf automake bzip2 libtool ocaml.x86_64 doxygen graphviz-devel.x86_64 \ + libicu-devel.x86_64 bzip2.x86_64 bzip2-devel.x86_64 openssl-devel.x86_64 gmp-devel.x86_64 \ + python-devel.x86_64 gettext-devel.x86_64) COUNT=1 DISPLAY="" DEP="" @@ -300,9 +301,9 @@ printf "\\n\\tChecking boost library installation.\\n" BVERSION=$( grep "#define BOOST_VERSION" "${BOOST_ROOT}/include/boost/version.hpp" 2>/dev/null \ | tail -1 | tr -s ' ' | cut -d\ -f3) - if [ "${BVERSION}" != "106600" ]; then + if [ "${BVERSION}" != "106700" ]; then printf "\\tRemoving existing boost libraries in %s/opt/boost* .\\n" "${HOME}" - if ! rm -rf "${HOME}/opt/boost*" + if ! rm -rf "${HOME}"/opt/boost* then printf "\\n\\tUnable to remove deprecated boost libraries at %s/opt/boost*.\\n" "${HOME}" printf "\\n\\tExiting now.\\n\\n" @@ -315,27 +316,27 @@ printf "\\n\\tExiting now.\\n\\n" exit 1; fi - STATUS=$(curl -LO -w '%{http_code}' --connect-timeout 30 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2) + STATUS=$(curl -LO -w '%{http_code}' --connect-timeout 30 https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2) if [ "${STATUS}" -ne 200 ]; then printf "\\tUnable to download Boost libraries at this time.\\n" printf "\\n\\tExiting now.\\n\\n" exit 1; fi - if ! tar xf "${TEMP_DIR}/boost_1_66_0.tar.bz2" + if ! tar xf "${TEMP_DIR}/boost_1_67_0.tar.bz2" then - printf "\\n\\tUnable to unarchive file %s/boost_1_66_0.tar.bz2.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to unarchive file %s/boost_1_67_0.tar.bz2.\\n" "${TEMP_DIR}" printf "\\n\\tExiting now.\\n\\n" exit 1; fi - if ! rm -f "${TEMP_DIR}/boost_1_66_0.tar.bz2" + if ! rm -f "${TEMP_DIR}/boost_1_67_0.tar.bz2" then - printf "\\n\\tUnable to remove file %s/boost_1_66_0.tar.bz2.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to remove file %s/boost_1_67_0.tar.bz2.\\n" "${TEMP_DIR}" printf "\\n\\tExiting now.\\n\\n" exit 1; fi - if ! cd "${TEMP_DIR}/boost_1_66_0/" + if ! cd "${TEMP_DIR}/boost_1_67_0/" then - printf "\\n\\tUnable to enter directory %s/boost_1_66_0.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to enter directory %s/boost_1_67_0.\\n" "${TEMP_DIR}" printf "\\n\\tExiting now.\\n\\n" exit 1; fi @@ -345,21 +346,21 @@ printf "\\n\\tExiting now.\\n\\n" exit 1; fi - if ! ./b2 install + if ! "${TEMP_DIR}"/boost_1_67_0/b2 -j2 install then printf "\\n\\tInstallation of boost libraries failed with the above error. 1\\n" printf "\\n\\tExiting now.\\n\\n" exit 1; fi - if ! rm -rf "${TEMP_DIR}/boost_1_66_0/" + if ! rm -rf "${TEMP_DIR}/boost_1_67_0/" then - printf "\\n\\tUnable to remove directory %s/boost_1_66_0.\\n" "${TEMP_DIR}" + printf "\\n\\tUnable to remove directory %s/boost_1_67_0.\\n" "${TEMP_DIR}" printf "\\n\\tExiting now.\\n\\n" exit 1; fi - printf "\\tBoost 1.66.0 successfully installed @ %s/opt/boost_1_66_0.\\n\\n" "${HOME}" + printf "\\tBoost 1.67.0 successfully installed @ %s/opt/boost_1_67_0.\\n\\n" "${HOME}" else - printf "\\tBoost 1.66.0 found at %s/opt/boost_1_66_0.\\n\\n" "${HOME}" + printf "\\tBoost 1.67.0 found at %s/opt/boost_1_67_0.\\n\\n" "${HOME}" fi printf "\\n\\tChecking MongoDB installation.\\n" From 26ff92535e92f268f78683ae361e5bb5580006c2 Mon Sep 17 00:00:00 2001 From: Bill Hamilton Date: Fri, 25 May 2018 23:31:24 +0000 Subject: [PATCH 30/38] changed to one line --- eosio_build.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/eosio_build.sh b/eosio_build.sh index 50ae5126f2e..82be9fa46c3 100755 --- a/eosio_build.sh +++ b/eosio_build.sh @@ -143,7 +143,6 @@ export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm export CMAKE=${HOME}/opt/cmake/bin/cmake export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "CentOS Linux") FILE="${PWD}/scripts/eosio_build_centos.sh" @@ -153,7 +152,6 @@ export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm export CMAKE=${HOME}/opt/cmake/bin/cmake export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "elementary OS") FILE="${PWD}/scripts/eosio_build_ubuntu.sh" @@ -161,7 +159,6 @@ C_COMPILER=clang-4.0 MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "Fedora") FILE="${PWD}/scripts/eosio_build_fedora.sh" @@ -169,7 +166,6 @@ C_COMPILER=gcc MONGOD_CONF=/etc/mongod.conf export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm - export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "Linux Mint") FILE="${PWD}/scripts/eosio_build_ubuntu.sh" @@ -177,7 +173,6 @@ C_COMPILER=clang-4.0 MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; "Ubuntu") FILE="${PWD}/scripts/eosio_build_ubuntu.sh" @@ -185,13 +180,13 @@ C_COMPILER=clang-4.0 MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf export PATH=${HOME}/opt/mongodb/bin:$PATH - export BOOST_ROOT="${HOME}/opt/boost_1_67_0" ;; *) printf "\\n\\tUnsupported Linux Distribution. Exiting now.\\n\\n" exit 1 esac + export BOOST_ROOT="${HOME}/opt/boost_1_67_0" OPENSSL_ROOT_DIR=/usr/include/openssl WASM_ROOT="${HOME}/opt/wasm" fi From 9583f90ba8d9e8c6db858b364331f0747cb97f3b Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 08:08:16 +0800 Subject: [PATCH 31/38] cleanup --- CMakeLists.txt | 6 +++--- libraries/chain/chain_id_type.cpp | 12 ++++++------ libraries/chain/genesis_state.cpp | 2 +- libraries/chain/genesis_state_root_key.cpp.in | 8 ++++---- .../chain/include/enumivo/chain/chain_id_type.hpp | 14 +++++++------- .../chain/include/enumivo/chain/genesis_state.hpp | 2 +- plugins/chain_plugin/chain_plugin.cpp | 8 ++++---- programs/enucli/main.cpp | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 715ee2a4f41..5a03aaed021 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,11 +192,11 @@ endif() message( STATUS "Using '${CORE_SYMBOL_NAME}' as CORE symbol name" ) -if ("${EOSIO_ROOT_KEY}" STREQUAL "") - set(EOSIO_ROOT_KEY "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV") +if ("${ENUMIVO_ROOT_KEY}" STREQUAL "") + set(ENUMIVO_ROOT_KEY "ENU6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV") endif() -message( STATUS "Using '${EOSIO_ROOT_KEY}' as public key for eosio account" ) +message( STATUS "Using '${ENUMIVO_ROOT_KEY}' as public key for enumivo account" ) include(wasm) diff --git a/libraries/chain/chain_id_type.cpp b/libraries/chain/chain_id_type.cpp index 85f41195b7f..caeecc7003b 100644 --- a/libraries/chain/chain_id_type.cpp +++ b/libraries/chain/chain_id_type.cpp @@ -3,24 +3,24 @@ * @copyright defined in eos/LICENSE.txt */ -#include -#include +#include +#include -namespace eosio { namespace chain { +namespace enumivo { namespace chain { void chain_id_type::reflector_verify()const { FC_ASSERT( *reinterpret_cast(this) != fc::sha256(), "chain_id_type cannot be zero" ); } -} } // namespace eosio::chain +} } // namespace enumivo::chain namespace fc { - void to_variant(const eosio::chain::chain_id_type& cid, fc::variant& v) { + void to_variant(const enumivo::chain::chain_id_type& cid, fc::variant& v) { to_variant( static_cast(cid), v); } - void from_variant(const fc::variant& v, eosio::chain::chain_id_type& cid) { + void from_variant(const fc::variant& v, enumivo::chain::chain_id_type& cid) { from_variant( v, static_cast(cid) ); } diff --git a/libraries/chain/genesis_state.cpp b/libraries/chain/genesis_state.cpp index 79f48e2822a..bf8dfb181d4 100644 --- a/libraries/chain/genesis_state.cpp +++ b/libraries/chain/genesis_state.cpp @@ -12,7 +12,7 @@ namespace enumivo { namespace chain { genesis_state::genesis_state() { initial_timestamp = fc::time_point::from_iso_string( "2018-03-02T12:00:00" ); - initial_key = fc::variant(eosio_root_key).as(); + initial_key = fc::variant(enumivo_root_key).as(); } chain::chain_id_type genesis_state::compute_chain_id() const { diff --git a/libraries/chain/genesis_state_root_key.cpp.in b/libraries/chain/genesis_state_root_key.cpp.in index 6530698e33a..368f8fcd65f 100644 --- a/libraries/chain/genesis_state_root_key.cpp.in +++ b/libraries/chain/genesis_state_root_key.cpp.in @@ -3,10 +3,10 @@ * @copyright defined in eos/LICENSE.txt */ -#include +#include -namespace eosio { namespace chain { +namespace enumivo { namespace chain { -const string genesis_state::eosio_root_key = "${EOSIO_ROOT_KEY}"; +const string genesis_state::enumivo_root_key = "${ENUMIVO_ROOT_KEY}"; -} } // namespace eosio::chain +} } // namespace enumivo::chain diff --git a/libraries/chain/include/enumivo/chain/chain_id_type.hpp b/libraries/chain/include/enumivo/chain/chain_id_type.hpp index 597f9bfce12..15885de57ad 100644 --- a/libraries/chain/include/enumivo/chain/chain_id_type.hpp +++ b/libraries/chain/include/enumivo/chain/chain_id_type.hpp @@ -6,7 +6,7 @@ #include -namespace eosio { +namespace enumivo { class net_plugin_impl; struct handshake_message; @@ -41,16 +41,16 @@ namespace chain { template friend T fc::variant::as()const; - friend class eosio::chain_apis::read_only; + friend class enumivo::chain_apis::read_only; - friend class eosio::net_plugin_impl; - friend struct eosio::handshake_message; + friend class enumivo::net_plugin_impl; + friend struct enumivo::handshake_message; }; -} } // namespace eosio::chain +} } // namespace enumivo::chain namespace fc { class variant; - void to_variant(const eosio::chain::chain_id_type& cid, fc::variant& v); - void from_variant(const fc::variant& v, eosio::chain::chain_id_type& cid); + void to_variant(const enumivo::chain::chain_id_type& cid, fc::variant& v); + void from_variant(const fc::variant& v, enumivo::chain::chain_id_type& cid); } // fc diff --git a/libraries/chain/include/enumivo/chain/genesis_state.hpp b/libraries/chain/include/enumivo/chain/genesis_state.hpp index c39d2bd65fd..70104d107c5 100644 --- a/libraries/chain/include/enumivo/chain/genesis_state.hpp +++ b/libraries/chain/include/enumivo/chain/genesis_state.hpp @@ -18,7 +18,7 @@ namespace enumivo { namespace chain { struct genesis_state { genesis_state(); - static const string eosio_root_key; + static const string enumivo_root_key; chain_config initial_configuration = { .max_block_net_usage = config::default_max_block_net_usage, diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 5b3571bff5f..1d3bcd25ac4 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -151,10 +151,10 @@ void chain_plugin::plugin_initialize(const variables_map& options) { ilog("initializing chain plugin"); try { - genesis_state gs; // Check if EOSIO_ROOT_KEY is bad + genesis_state gs; // Check if ENUMIVO_ROOT_KEY is bad } catch( const fc::exception& ) { - elog( "EOSIO_ROOT_KEY ('${root_key}') is invalid. Recompile with a valid public key.", - ("root_key", genesis_state::eosio_root_key) ); + elog( "ENUMIVO_ROOT_KEY ('${root_key}') is invalid. Recompile with a valid public key.", + ("root_key", genesis_state::enumivo_root_key) ); throw; } @@ -222,7 +222,7 @@ void chain_plugin::plugin_initialize(const variables_map& options) { ilog( "Saved genesis JSON to '${path}'", ("path", p.generic_string()) ); } - EOS_THROW( extract_genesis_state_exception, "extracted genesis state from blocks.log" ); + ENU_THROW( extract_genesis_state_exception, "extracted genesis state from blocks.log" ); } if( options.at("delete-all-blocks").as() ) { diff --git a/programs/enucli/main.cpp b/programs/enucli/main.cpp index 6d95babed08..cec80a4b871 100644 --- a/programs/enucli/main.cpp +++ b/programs/enucli/main.cpp @@ -2153,7 +2153,7 @@ int main( int argc, char** argv ) { fc::optional chain_id; if( str_chain_id.size() == 0 ) { - ilog( "grabbing chain_id from nodeos" ); + ilog( "grabbing chain_id from enunode" ); auto info = get_info(); chain_id = info.chain_id; } else { From 4cf9627dc08a7bdbd62a708597a2d8411ba6b367 Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 08:14:06 +0800 Subject: [PATCH 32/38] token to coin --- plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp index 62c813f46fb..c225f19b1c6 100644 --- a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp +++ b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp @@ -146,7 +146,7 @@ struct txn_test_gen_plugin_impl { act.account = N(txn.test.t); act.name = N(create); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = enumivo_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"txn.test.t\",\"maximum_supply\":\"1000000000.0000 CUR\"}}")); + act.data = enumivo_coin_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"txn.test.t\",\"maximum_supply\":\"1000000000.0000 CUR\"}}")); trx.actions.push_back(act); } { @@ -154,7 +154,7 @@ struct txn_test_gen_plugin_impl { act.account = N(txn.test.t); act.name = N(issue); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = enumivo_token_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"txn.test.t\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}")); + act.data = enumivo_coin_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"txn.test.t\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}")); trx.actions.push_back(act); } { @@ -162,7 +162,7 @@ struct txn_test_gen_plugin_impl { act.account = N(txn.test.t); act.name = N(transfer); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = enumivo_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); + act.data = enumivo_coin_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); trx.actions.push_back(act); } { @@ -170,7 +170,7 @@ struct txn_test_gen_plugin_impl { act.account = N(txn.test.t); act.name = N(transfer); act.authorization = vector{{newaccountC,config::active_name}}; - act.data = enumivo_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); + act.data = enumivo_coin_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}")); trx.actions.push_back(act); } From b36427cc50d64b106f7d88d76428820a2cee9197 Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 08:33:06 +0800 Subject: [PATCH 33/38] reduce ram --- unittests/ram_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/ram_tests.cpp b/unittests/ram_tests.cpp index b0c2fbd6795..bbf800aa2f1 100644 --- a/unittests/ram_tests.cpp +++ b/unittests/ram_tests.cpp @@ -214,7 +214,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, enumivo_system::enumivo_system_tester) { try ("payer", "testram11111") ("from", 13) ("to", 13) - ("size", 1720)); + ("size", 1719)); produce_blocks(1); // verify that new entries for testram22222 exceed the allocation bytes limit From e673f700431e2e7b43d5706bb82b096626f3e529 Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 08:50:45 +0800 Subject: [PATCH 34/38] reduce ram --- unittests/ram_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/ram_tests.cpp b/unittests/ram_tests.cpp index bbf800aa2f1..836cf834f7d 100644 --- a/unittests/ram_tests.cpp +++ b/unittests/ram_tests.cpp @@ -214,7 +214,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, enumivo_system::enumivo_system_tester) { try ("payer", "testram11111") ("from", 13) ("to", 13) - ("size", 1719)); + ("size", 1701)); produce_blocks(1); // verify that new entries for testram22222 exceed the allocation bytes limit From 2c923ca477a7ed296fa491bf4b31f87d981f6451 Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 08:54:46 +0800 Subject: [PATCH 35/38] reduce ram further --- unittests/ram_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/ram_tests.cpp b/unittests/ram_tests.cpp index 836cf834f7d..e2870055b26 100644 --- a/unittests/ram_tests.cpp +++ b/unittests/ram_tests.cpp @@ -214,7 +214,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, enumivo_system::enumivo_system_tester) { try ("payer", "testram11111") ("from", 13) ("to", 13) - ("size", 1701)); + ("size", 1675)); produce_blocks(1); // verify that new entries for testram22222 exceed the allocation bytes limit From 0943f3fb32865b0ef279615458b8832bdf18f67a Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 08:58:43 +0800 Subject: [PATCH 36/38] 1 short --- unittests/ram_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/ram_tests.cpp b/unittests/ram_tests.cpp index e2870055b26..3a2583f391e 100644 --- a/unittests/ram_tests.cpp +++ b/unittests/ram_tests.cpp @@ -214,7 +214,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, enumivo_system::enumivo_system_tester) { try ("payer", "testram11111") ("from", 13) ("to", 13) - ("size", 1675)); + ("size", 1674)); produce_blocks(1); // verify that new entries for testram22222 exceed the allocation bytes limit From a364677232f97346f10928ef3d28c821c56fd704 Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 09:03:07 +0800 Subject: [PATCH 37/38] lower still --- unittests/ram_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/ram_tests.cpp b/unittests/ram_tests.cpp index 3a2583f391e..75a4971aa2b 100644 --- a/unittests/ram_tests.cpp +++ b/unittests/ram_tests.cpp @@ -214,7 +214,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, enumivo_system::enumivo_system_tester) { try ("payer", "testram11111") ("from", 13) ("to", 13) - ("size", 1674)); + ("size", 1673)); produce_blocks(1); // verify that new entries for testram22222 exceed the allocation bytes limit From 0a0e1c2b6a37499e30e0f76daba69532f4f3dc8b Mon Sep 17 00:00:00 2001 From: enumivo Date: Sat, 26 May 2018 09:10:15 +0800 Subject: [PATCH 38/38] reduce ram --- unittests/ram_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/ram_tests.cpp b/unittests/ram_tests.cpp index 75a4971aa2b..9a9f02020a2 100644 --- a/unittests/ram_tests.cpp +++ b/unittests/ram_tests.cpp @@ -233,7 +233,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, enumivo_system::enumivo_system_tester) { try ("payer", "testram22222") ("from", 12) ("to", 21) - ("size", 1910)); + ("size", 1855)); produce_blocks(1); // verify that new entry for testram22222 exceed the allocation bytes limit