From 095e76075dcb517d737fb451f90803fc2a465eeb Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 15 May 2018 15:39:08 -0400 Subject: [PATCH] Implement regproducer::location to Fix #3090 --- contracts/eosio.system/eosio.system.abi | 1 + contracts/eosio.system/eosio.system.hpp | 2 +- contracts/eosio.system/voting.cpp | 14 ++++++++------ programs/cleos/main.cpp | 10 +++++++--- unittests/bootseq_tests.cpp | 1 + unittests/eosio.system_tests.cpp | 10 ++++++++++ 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/contracts/eosio.system/eosio.system.abi b/contracts/eosio.system/eosio.system.abi index d844c689f..bc57f417a 100644 --- a/contracts/eosio.system/eosio.system.abi +++ b/contracts/eosio.system/eosio.system.abi @@ -152,6 +152,7 @@ {"name":"producer", "type":"account_name"}, {"name":"producer_key", "type":"public_key"}, {"name":"url", "type":"string"} + {"name":"location", "type":"uint16"} ] },{ "name": "unregprod", diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index 41a10d792..d622c9b79 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -181,7 +181,7 @@ namespace eosiosystem { // functions defined in voting.cpp - void regproducer( const account_name producer, const public_key& producer_key, const std::string& url ); + void regproducer( const account_name producer, const public_key& producer_key, const std::string& url, uint16_t location ); void unregprod( const account_name producer ); diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index 99f43ecb3..274a8fc10 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -34,7 +34,7 @@ namespace eosiosystem { * @pre authority of producer to register * */ - void system_contract::regproducer( const account_name producer, const eosio::public_key& producer_key, const std::string& url ) { //, const eosio_parameters& prefs ) { + void system_contract::regproducer( const account_name producer, const eosio::public_key& producer_key, const std::string& url, uint16_t location ) { eosio_assert( url.size() < 512, "url too long" ); //eosio::print("produce_key: ", producer_key.size(), ", sizeof(public_key): ", sizeof(public_key), "\n"); require_auth( producer ); @@ -45,15 +45,17 @@ namespace eosiosystem { if( producer_key != prod->producer_key ) { _producers.modify( prod, producer, [&]( producer_info& info ){ info.producer_key = producer_key; - info.url = url; + info.url = url; + info.location = location; }); } } else { _producers.emplace( producer, [&]( producer_info& info ){ - info.owner = producer; - info.total_votes = 0; - info.producer_key = producer_key; - info.url = url; + info.owner = producer; + info.total_votes = 0; + info.producer_key = producer_key; + info.url = url; + info.location = location; }); } } diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index edfc7451d..5405f71a6 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -450,7 +450,7 @@ chain::action create_delegate(const name& from, const name& receiver, const asse fc::variant regproducer_variant(const account_name& producer, public_key_type key, - string url) { + string url, uint16_t location = 0) { /* fc::variant_object params = fc::mutable_variant_object() ("max_block_net_usage", config::default_max_block_net_usage) @@ -485,7 +485,9 @@ fc::variant regproducer_variant(const account_name& producer, return fc::mutable_variant_object() ("producer", producer) ("producer_key", key) - ("url", url); + ("url", url) + ("location", 0) + ; } chain::action create_transfer(const string& contract, const name& sender, const name& recipient, asset amount, const string& memo ) { @@ -783,12 +785,14 @@ struct register_producer_subcommand { string producer_str; string producer_key_str; string url; + uint16_t loc = 0; register_producer_subcommand(CLI::App* actionRoot) { auto register_producer = actionRoot->add_subcommand("regproducer", localized("Register a new producer")); register_producer->add_option("account", producer_str, localized("The account to register as a producer"))->required(); register_producer->add_option("producer_key", producer_key_str, localized("The producer's public key"))->required(); register_producer->add_option("url", url, localized("url where info about producer can be found"), true); + register_producer->add_option("location", loc, localized("relative location for purpose of nearest neighbor scheduling"), 0); add_standard_transaction_options(register_producer); @@ -798,7 +802,7 @@ struct register_producer_subcommand { producer_key = public_key_type(producer_key_str); } EOS_RETHROW_EXCEPTIONS(public_key_type_exception, "Invalid producer public key: ${public_key}", ("public_key", producer_key_str)) - auto regprod_var = regproducer_variant(producer_str, producer_key, url ); + auto regprod_var = regproducer_variant(producer_str, producer_key, url, loc ); send_actions({create_action({permission_level{producer_str,config::active_name}}, config::system_account_name, N(regproducer), regprod_var)}); }); } diff --git a/unittests/bootseq_tests.cpp b/unittests/bootseq_tests.cpp index 8b0349bc2..e47caf59f 100644 --- a/unittests/bootseq_tests.cpp +++ b/unittests/bootseq_tests.cpp @@ -278,6 +278,7 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) { ("producer", name(pro)) ("producer_key", get_public_key( pro, "active" ) ) ("url", "" ) + ("location", 0 ) ); } produce_blocks(10); diff --git a/unittests/eosio.system_tests.cpp b/unittests/eosio.system_tests.cpp index aa8077929..119b770f6 100644 --- a/unittests/eosio.system_tests.cpp +++ b/unittests/eosio.system_tests.cpp @@ -301,6 +301,7 @@ public: ("producer", acnt ) ("producer_key", get_public_key( acnt, "active" ) ) ("url", "" ) + ("location", 0 ) ); BOOST_REQUIRE_EQUAL( success(), r); return r; @@ -876,6 +877,7 @@ BOOST_FIXTURE_TEST_CASE( producer_register_unregister, eosio_system_tester ) try ("producer", "alice1111111") ("producer_key", key ) ("url", "http://block.one") + ("location", "0") ) ); @@ -923,6 +925,7 @@ BOOST_FIXTURE_TEST_CASE( vote_for_producer, eosio_system_tester, * boost::unit_t ("producer", "alice1111111") ("producer_key", get_public_key( N(alice1111111), "active") ) ("url", "http://block.one") + ("location", 0 ) ) ); auto prod = get_producer_info( "alice1111111" ); @@ -1028,6 +1031,7 @@ BOOST_FIXTURE_TEST_CASE( unregistered_producer_voting, eosio_system_tester, * bo ("producer", "alice1111111") ("producer_key", get_public_key( N(alice1111111), "active") ) ("url", "") + ("location", 0) ) ); //and then unregisters @@ -1080,6 +1084,7 @@ BOOST_FIXTURE_TEST_CASE( vote_same_producer_30_times, eosio_system_tester ) try ("producer", "alice1111111") ("producer_key", get_public_key(N(alice1111111), "active") ) ("url", "") + ("location", 0) ) ); @@ -1106,6 +1111,7 @@ BOOST_FIXTURE_TEST_CASE( producer_keep_votes, eosio_system_tester, * boost::unit ("producer", "alice1111111") ("producer_key", get_public_key( N(alice1111111), "active") ) ("url", "") + ("location", 0) ) ); @@ -1144,6 +1150,7 @@ BOOST_FIXTURE_TEST_CASE( producer_keep_votes, eosio_system_tester, * boost::unit ("producer", "alice1111111") ("producer_key", get_public_key( N(alice1111111), "active") ) ("url", "") + ("location", 0) ) ); prod = get_producer_info( "alice1111111" ); @@ -1156,6 +1163,7 @@ BOOST_FIXTURE_TEST_CASE( producer_keep_votes, eosio_system_tester, * boost::unit ("producer", "alice1111111") ("producer_key", get_public_key( N(alice1111111), "active") ) ("url","") + ("location", 0) ) ); prod = get_producer_info( "alice1111111" ); @@ -1175,6 +1183,7 @@ BOOST_FIXTURE_TEST_CASE( vote_for_two_producers, eosio_system_tester, * boost::u ("producer", "alice1111111") ("producer_key", get_public_key( N(alice1111111), "active") ) ("url","") + ("location", 0) ) ); //bob111111111 becomes a producer @@ -1184,6 +1193,7 @@ BOOST_FIXTURE_TEST_CASE( vote_for_two_producers, eosio_system_tester, * boost::u ("producer", "bob111111111") ("producer_key", get_public_key( N(alice1111111), "active") ) ("url","") + ("location", 0) ) ); -- GitLab