Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Resolve #3: No maintenance
Browse files Browse the repository at this point in the history
Everything related to the maintenance interval is now gone, including
(and especially, really) the skipped blocks during the maintenance
period.
  • Loading branch information
nathanielhourt committed Apr 6, 2017
1 parent 712d0b9 commit 0e43c70
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 199 deletions.
1 change: 0 additions & 1 deletion libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 0 additions & 9 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic_global_property_object>();
bool maint_needed = (dynamic_global_props.next_maintenance_time <= next_block.timestamp);

_current_block_num = next_block_num;
_current_trx_in_block = 0;
Expand All @@ -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();
Expand Down
88 changes: 0 additions & 88 deletions libraries/chain/db_maint.cpp

This file was deleted.

33 changes: 2 additions & 31 deletions libraries/chain/db_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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).
Expand Down
9 changes: 0 additions & 9 deletions libraries/chain/db_producer_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 0 additions & 12 deletions libraries/chain/db_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

} }
2 changes: 0 additions & 2 deletions libraries/chain/get_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions libraries/chain/include/eos/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 1 addition & 20 deletions libraries/chain/include/eos/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ////////////////////

Expand Down Expand Up @@ -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<class... Types>
void perform_account_maintenance(std::tuple<Types...> helpers);
///@}
///@}

vector< signed_transaction > _pending_tx;
fork_database _fork_db;
Expand Down
18 changes: 1 addition & 17 deletions libraries/chain/include/eos/chain/global_property_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace eos { namespace chain {
chain_parameters parameters;
optional<chain_parameters> pending_parameters;

vector<producer_id_type> active_producers; // updated once per maintenance interval
vector<producer_id_type> active_producers;
};

/**
Expand All @@ -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
Expand Down Expand Up @@ -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<
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 0e43c70

Please sign in to comment.