From 0e43c707394b971b9f2697649252c8e66141a69d Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Thu, 6 Apr 2017 11:48:12 -0500 Subject: [PATCH] Resolve #3: No maintenance Everything related to the maintenance interval is now gone, including (and especially, really) the skipped blocks during the maintenance period. --- libraries/chain/database.cpp | 1 - libraries/chain/db_block.cpp | 9 -- libraries/chain/db_maint.cpp | 88 ------------------- libraries/chain/db_management.cpp | 33 +------ libraries/chain/db_producer_schedule.cpp | 9 -- libraries/chain/db_update.cpp | 12 --- libraries/chain/get_config.cpp | 2 - libraries/chain/include/eos/chain/config.hpp | 2 - .../chain/include/eos/chain/database.hpp | 21 +---- .../eos/chain/global_property_object.hpp | 18 +--- .../eos/chain/protocol/chain_parameters.hpp | 4 - tests/tests/block_tests.cpp | 8 +- 12 files changed, 8 insertions(+), 199 deletions(-) delete mode 100644 libraries/chain/db_maint.cpp diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index acf4dad982e..9cf61689ff2 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -26,7 +26,6 @@ #include "db_debug.cpp" #include "db_getter.cpp" #include "db_init.cpp" -#include "db_maint.cpp" #include "db_management.cpp" #include "db_update.cpp" #include "db_producer_schedule.cpp" diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 70c70adf0c7..759c25e66b5 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -430,8 +430,6 @@ void database::_apply_block( const signed_block& next_block ) const producer_object& signing_producer = validate_block_header(skip, next_block); const auto& global_props = get_global_properties(); - const auto& dynamic_global_props = get(); - bool maint_needed = (dynamic_global_props.next_maintenance_time <= next_block.timestamp); _current_block_num = next_block_num; _current_trx_in_block = 0; @@ -452,19 +450,12 @@ void database::_apply_block( const signed_block& next_block ) update_signing_producer(signing_producer, next_block); update_last_irreversible_block(); - // Are we at the maintenance interval? - if( maint_needed ) - perform_chain_maintenance(next_block, global_props); - create_block_summary(next_block); clear_expired_transactions(); - // n.b., update_maintenance_flag() happens this late - // because get_slot_time() / get_slot_at_time() is needed above // TODO: figure out if we could collapse this function into // update_global_dynamic_data() as perhaps these methods only need // to be called for header validation? - update_maintenance_flag( maint_needed ); update_producer_schedule(); if( !_node_property_object.debug_updates.empty() ) apply_debug_updates(); diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp deleted file mode 100644 index 9cc730661da..00000000000 --- a/libraries/chain/db_maint.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include -#include - -#include - -#include -#include -#include - -namespace eos { namespace chain { - -void database::perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props) -{ - const auto& gpo = get_global_properties(); - - modify(gpo, [this](global_property_object& p) { - if( p.pending_parameters ) - { - p.parameters = std::move(*p.pending_parameters); - p.pending_parameters.reset(); - } - }); - - auto next_maintenance_time = get().next_maintenance_time; - auto maintenance_interval = gpo.parameters.maintenance_interval; - - if( next_maintenance_time <= next_block.timestamp ) - { - if( next_block.block_num() == 1 ) - next_maintenance_time = time_point_sec() + - (((next_block.timestamp.sec_since_epoch() / maintenance_interval) + 1) * maintenance_interval); - else - { - // We want to find the smallest k such that next_maintenance_time + k * maintenance_interval > head_block_time() - // This implies k > ( head_block_time() - next_maintenance_time ) / maintenance_interval - // - // Let y be the right-hand side of this inequality, i.e. - // y = ( head_block_time() - next_maintenance_time ) / maintenance_interval - // - // and let the fractional part f be y-floor(y). Clearly 0 <= f < 1. - // We can rewrite f = y-floor(y) as floor(y) = y-f. - // - // Clearly k = floor(y)+1 has k > y as desired. Now we must - // show that this is the least such k, i.e. k-1 <= y. - // - // But k-1 = floor(y)+1-1 = floor(y) = y-f <= y. - // So this k suffices. - // - auto y = (head_block_time() - next_maintenance_time).to_seconds() / maintenance_interval; - next_maintenance_time += (y+1) * maintenance_interval; - } - } - - const dynamic_global_property_object& dgpo = get_dynamic_global_properties(); - - modify(dgpo, [next_maintenance_time](dynamic_global_property_object& d) { - d.next_maintenance_time = next_maintenance_time; - d.accounts_registered_this_interval = 0; - }); -} - -} } diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index 83a1de8c1cc..bc7f047e9a5 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -98,7 +98,7 @@ void database::reindex(fc::path data_dir, uint64_t shared_file_size, const genes void database::wipe(const fc::path& data_dir, bool include_blocks) { ilog("Wiping database", ("include_blocks", include_blocks)); - close(false); + close(); chainbase::database::wipe(data_dir); if( include_blocks ) fc::remove_all( data_dir / "database" ); @@ -135,40 +135,11 @@ void database::open(const fc::path& data_dir, uint64_t shared_file_size, FC_CAPTURE_LOG_AND_RETHROW( (data_dir) ) } -void database::close(bool rewind) +void database::close() { // TODO: Save pending tx's on close() clear_pending(); - // pop all of the blocks that we can given our undo history, this should - // throw when there is no more undo history to pop - if(rewind && is_open()) - { - try - { - uint32_t cutoff = get_dynamic_global_properties().last_irreversible_block_num; - - while( head_block_num() > cutoff ) - { - // elog("pop"); - block_id_type popped_block_id = head_block_id(); - pop_block(); - _fork_db.remove(popped_block_id); // doesn't throw on missing - try - { - _block_id_to_block.remove(popped_block_id); - } - catch (const fc::key_not_found_exception&) - { - } - } - } - catch ( const fc::exception& e ) - { - wlog( "Database close unexpected exception: ${e}", ("e", e) ); - } - } - // Since pop_block() will move tx's in the popped blocks into pending, // we have to clear_pending() after we're done popping to get a clean // DB state (issue #336). diff --git a/libraries/chain/db_producer_schedule.cpp b/libraries/chain/db_producer_schedule.cpp index 5bcb8353412..292c69b5b50 100644 --- a/libraries/chain/db_producer_schedule.cpp +++ b/libraries/chain/db_producer_schedule.cpp @@ -56,15 +56,6 @@ fc::time_point_sec database::get_slot_time(uint32_t slot_num)const int64_t head_block_abs_slot = head_block_time().sec_since_epoch() / interval; fc::time_point_sec head_slot_time(head_block_abs_slot * interval); - const global_property_object& gpo = get_global_properties(); - - if( dpo.dynamic_flags & dynamic_global_property_object::maintenance_flag ) - slot_num += gpo.parameters.maintenance_skip_slots; - - // "slot 0" is head_slot_time - // "slot 1" is head_slot_time, - // plus maint interval if head block is a maint block - // plus block interval if head block is not a maint block return head_slot_time + (slot_num * interval); } diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 06312b3b6f8..93748eaaff6 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -148,16 +148,4 @@ void database::clear_expired_transactions() transaction_idx.remove(*dedupe_index.rbegin()); } FC_CAPTURE_AND_RETHROW() } -void database::update_maintenance_flag( bool new_maintenance_flag ) -{ - modify( get_dynamic_global_properties(), [&]( dynamic_global_property_object& dpo ) - { - auto maintenance_flag = dynamic_global_property_object::maintenance_flag; - dpo.dynamic_flags = - (dpo.dynamic_flags & ~maintenance_flag) - | (new_maintenance_flag ? maintenance_flag : 0); - } ); - return; -} - } } diff --git a/libraries/chain/get_config.cpp b/libraries/chain/get_config.cpp index 18d5f391324..09b91ef4b4b 100644 --- a/libraries/chain/get_config.cpp +++ b/libraries/chain/get_config.cpp @@ -40,8 +40,6 @@ fc::variant_object get_config() result[ "EOS_DEFAULT_MAX_TRANSACTION_SIZE" ] = EOS_DEFAULT_MAX_TRANSACTION_SIZE; result[ "EOS_DEFAULT_MAX_BLOCK_SIZE" ] = EOS_DEFAULT_MAX_BLOCK_SIZE; result[ "EOS_DEFAULT_MAX_TIME_UNTIL_EXPIRATION" ] = EOS_DEFAULT_MAX_TIME_UNTIL_EXPIRATION; - result[ "EOS_DEFAULT_MAINTENANCE_INTERVAL" ] = EOS_DEFAULT_MAINTENANCE_INTERVAL; - result[ "EOS_DEFAULT_MAINTENANCE_SKIP_SLOTS" ] = EOS_DEFAULT_MAINTENANCE_SKIP_SLOTS; result[ "EOS_MIN_UNDO_HISTORY" ] = EOS_MIN_UNDO_HISTORY; result[ "EOS_MAX_UNDO_HISTORY" ] = EOS_MAX_UNDO_HISTORY; result[ "EOS_MIN_BLOCK_SIZE_LIMIT" ] = EOS_MIN_BLOCK_SIZE_LIMIT; diff --git a/libraries/chain/include/eos/chain/config.hpp b/libraries/chain/include/eos/chain/config.hpp index 6f9728248e7..4be15050db8 100644 --- a/libraries/chain/include/eos/chain/config.hpp +++ b/libraries/chain/include/eos/chain/config.hpp @@ -37,8 +37,6 @@ #define EOS_DEFAULT_MAX_TRANSACTION_SIZE 2048 #define EOS_DEFAULT_MAX_BLOCK_SIZE (EOS_DEFAULT_MAX_TRANSACTION_SIZE*EOS_DEFAULT_BLOCK_INTERVAL*200000) #define EOS_DEFAULT_MAX_TIME_UNTIL_EXPIRATION (60*60*24) // seconds, aka: 1 day -#define EOS_DEFAULT_MAINTENANCE_INTERVAL (60*60*24) // seconds, aka: 1 day -#define EOS_DEFAULT_MAINTENANCE_SKIP_SLOTS 3 // number of slots to skip for maintenance interval #define EOS_MIN_UNDO_HISTORY 10 #define EOS_MAX_UNDO_HISTORY 10000 diff --git a/libraries/chain/include/eos/chain/database.hpp b/libraries/chain/include/eos/chain/database.hpp index 9f7875f4f83..b11ef471389 100644 --- a/libraries/chain/include/eos/chain/database.hpp +++ b/libraries/chain/include/eos/chain/database.hpp @@ -104,7 +104,7 @@ namespace eos { namespace chain { * Will close the database before wiping. Database will be closed when this function returns. */ void wipe(const fc::path& data_dir, bool include_blocks); - void close(bool rewind = true); + void close(); //////////////////// db_block.cpp //////////////////// @@ -286,25 +286,6 @@ namespace eos { namespace chain { void update_signing_producer(const producer_object& signing_producer, const signed_block& new_block); void update_last_irreversible_block(); void clear_expired_transactions(); - void update_maintenance_flag( bool new_maintenance_flag ); - - ///Steps performed only at maintenance intervals - ///@{ - - //////////////////// db_maint.cpp //////////////////// - - void initialize_budget_record( fc::time_point_sec now, budget_record& rec )const; - void process_budget(); - void pay_workers( share_type& budget ); - void perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props); - void update_active_produceres(); - void update_active_committee_members(); - void update_worker_votes(); - - template - void perform_account_maintenance(std::tuple helpers); - ///@} - ///@} vector< signed_transaction > _pending_tx; fork_database _fork_db; diff --git a/libraries/chain/include/eos/chain/global_property_object.hpp b/libraries/chain/include/eos/chain/global_property_object.hpp index 117e5738f9e..5d53d0f8f9e 100644 --- a/libraries/chain/include/eos/chain/global_property_object.hpp +++ b/libraries/chain/include/eos/chain/global_property_object.hpp @@ -51,7 +51,7 @@ namespace eos { namespace chain { chain_parameters parameters; optional pending_parameters; - vector active_producers; // updated once per maintenance interval + vector active_producers; }; /** @@ -72,7 +72,6 @@ namespace eos { namespace chain { block_id_type head_block_id; time_point_sec time; producer_id_type current_producer; - time_point_sec next_maintenance_time; uint32_t accounts_registered_this_interval = 0; /** * Every time a block is missed this increases by @@ -104,20 +103,6 @@ namespace eos { namespace chain { uint32_t dynamic_flags = 0; uint32_t last_irreversible_block_num = 0; - - enum dynamic_flag_bits - { - /** - * If maintenance_flag is set, then the head block is a - * maintenance block. This means - * get_time_slot(1) - head_block_time() will have a gap - * due to maintenance duration. - * - * This flag answers the question, "Was maintenance - * performed in the last call to apply_block()?" - */ - maintenance_flag = 0x01 - }; }; using global_property_multi_index = chainbase::shared_multi_index_container< @@ -148,7 +133,6 @@ FC_REFLECT(eos::chain::dynamic_global_property_object, (head_block_id) (time) (current_producer) - (next_maintenance_time) (accounts_registered_this_interval) (recently_missed_count) (current_aslot) diff --git a/libraries/chain/include/eos/chain/protocol/chain_parameters.hpp b/libraries/chain/include/eos/chain/protocol/chain_parameters.hpp index 6dd9602ec76..b7a49527057 100644 --- a/libraries/chain/include/eos/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/eos/chain/protocol/chain_parameters.hpp @@ -32,8 +32,6 @@ namespace eos { namespace chain { struct chain_parameters { uint8_t block_interval = EOS_DEFAULT_BLOCK_INTERVAL; ///< interval in seconds between blocks - uint32_t maintenance_interval = EOS_DEFAULT_MAINTENANCE_INTERVAL; ///< interval in sections between blockchain maintenance events - uint8_t maintenance_skip_slots = EOS_DEFAULT_MAINTENANCE_SKIP_SLOTS; ///< number of block_intervals to skip at maintenance time uint32_t maximum_transaction_size = EOS_DEFAULT_MAX_TRANSACTION_SIZE; ///< maximum allowable size in bytes for a transaction uint32_t maximum_block_size = EOS_DEFAULT_MAX_BLOCK_SIZE; ///< maximum allowable size in bytes for a block uint32_t maximum_time_until_expiration = EOS_DEFAULT_MAX_TIME_UNTIL_EXPIRATION; ///< maximum lifetime in seconds for transactions to be valid, before expiring @@ -47,8 +45,6 @@ namespace eos { namespace chain { FC_REFLECT( eos::chain::chain_parameters, (block_interval) - (maintenance_interval) - (maintenance_skip_slots) (maximum_transaction_size) (maximum_block_size) (maximum_time_until_expiration) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 8a2339dffb8..0f58993caf9 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -271,7 +271,7 @@ BOOST_FIXTURE_TEST_CASE(restart_db, testing_fixture) BOOST_CHECK_EQUAL(db.head_block_num(), 10); - db.close(false); + db.close(); db.open(); BOOST_CHECK_EQUAL(db.head_block_num(), 10); @@ -292,7 +292,7 @@ BOOST_FIXTURE_TEST_CASE(sleepy_db, testing_fixture) BOOST_CHECK_EQUAL(sleepy.head_block_num(), 10); net.disconnect_database(sleepy); - sleepy.close(false); + sleepy.close(); } producer.produce_blocks(5); @@ -310,7 +310,7 @@ BOOST_FIXTURE_TEST_CASE(reindex, testing_fixture) { try { MKDB(db) db.produce_blocks(100); - db.close(false); + db.close(); db.reindex(); db.produce_blocks(20); BOOST_CHECK_EQUAL(db.head_block_num(), 120); @@ -330,7 +330,7 @@ BOOST_FIXTURE_TEST_CASE(wipe, testing_fixture) BOOST_CHECK_EQUAL(db1.head_block_id().str(), db3.head_block_id().str()); net.disconnect_database(db3); - db3.close(false); + db3.close(); db3.wipe(); db3.open(); BOOST_CHECK_EQUAL(db3.head_block_num(), 0);