diff --git a/libraries/chain/block_database.cpp b/libraries/chain/block_database.cpp index 6d962c4a..c0005971 100644 --- a/libraries/chain/block_database.cpp +++ b/libraries/chain/block_database.cpp @@ -120,7 +120,7 @@ bool block_database::contains( const block_id_type& id )const _block_num_to_pos.seekg( index_pos ); _block_num_to_pos.read( (char*)&e, sizeof(e) ); - return e.block_id == id; + return e.block_id == id && e.block_size > 0; } block_id_type block_database::fetch_block_id( uint32_t block_num )const diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index 1db6b568..4a5cf899 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -114,11 +114,41 @@ void database::close(uint32_t blocks_to_rewind) _pending_block_session.reset(); for(uint32_t i = 0; i < blocks_to_rewind && head_block_num() > 0; ++i) + { + block_id_type popped_block_id = head_block_id(); pop_block(); + _fork_db.remove(popped_block_id); + try + { + _block_id_to_block.remove(popped_block_id); + } + catch (const fc::key_not_found_exception&) + { + } + } // pop all of the blocks that we can given our undo history, this should // throw when there is no more undo history to pop - try { while( true ) { elog("pop"); pop_block(); } } catch (...){} + try + { + while( true ) + { + 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 (...) + { + } object_database::flush(); object_database::close(); diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 55005b86..124e0e13 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2375,16 +2375,28 @@ namespace graphene { namespace net { namespace detail { ("is_first", is_first_item_for_other_peer)("size", item_hashes_received.size())); if (!is_first_item_for_other_peer) { + bool first = true; while (!item_hashes_received.empty() && _delegate->has_item(item_id(blockchain_item_ids_inventory_message_received.item_type, item_hashes_received.front()))) { assert(item_hashes_received.front() != item_hash_t()); originating_peer->last_block_delegate_has_seen = item_hashes_received.front(); - ++originating_peer->last_block_number_delegate_has_seen; + if (first) + { + // we don't yet know the block number of the first block they sent, so look it up + originating_peer->last_block_number_delegate_has_seen = _delegate->get_block_number(item_hashes_received.front()); + first = false; + } + else + ++originating_peer->last_block_number_delegate_has_seen; // subsequent blocks will follow in immediate sequence originating_peer->last_block_time_delegate_has_seen = _delegate->get_block_time(item_hashes_received.front()); - dlog("popping item because delegate has already seen it. peer's last block the delegate has seen is now ${block_id} (${block_num})", - ("block_id", originating_peer->last_block_delegate_has_seen )("block_num", originating_peer->last_block_number_delegate_has_seen)); + dlog("popping item because delegate has already seen it. peer ${peer}'s last block the delegate has seen is now ${block_id} (actual block #${actual_block_num}, tracked block #${tracked_block_num})", + ("peer", originating_peer->get_remote_endpoint()) + ("block_id", originating_peer->last_block_delegate_has_seen) + ("actual_block_num", _delegate->get_block_number(item_hashes_received.front())) + ("tracked_block_num", originating_peer->last_block_number_delegate_has_seen)); + assert(originating_peer->last_block_number_delegate_has_seen == _delegate->get_block_number(originating_peer->last_block_delegate_has_seen)); item_hashes_received.pop_front(); } dlog("after removing all items we have already seen, item_hashes_received.size() = ${size}", ("size", item_hashes_received.size())); diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index ef3e4118..f7205b73 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -43,8 +43,11 @@ #include #include #include -#ifndef WIN32 -#include + +#ifdef WIN32 +# include +#else +# include #endif using namespace graphene::app; @@ -255,11 +258,9 @@ int main( int argc, char** argv ) else { fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler"); -#ifdef __unix__ fc::set_signal_handler([&exit_promise](int signal) { exit_promise->set_value(signal); }, SIGINT); -#endif ilog( "Entering Daemon Mode, ^C to exit" ); exit_promise->wait(); diff --git a/programs/delayed_node/main.cpp b/programs/delayed_node/main.cpp index 97a8b4ed..62509b01 100644 --- a/programs/delayed_node/main.cpp +++ b/programs/delayed_node/main.cpp @@ -40,8 +40,10 @@ #include #include -#ifndef WIN32 -#include +#ifdef WIN32 +# include +#else +# include #endif using namespace graphene; @@ -159,11 +161,9 @@ int main(int argc, char** argv) { node.startup_plugins(); fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler"); -#if defined __APPLE__ || defined __unix__ fc::set_signal_handler([&exit_promise](int signal) { exit_promise->set_value(signal); }, SIGINT); -#endif ilog("Started delayed node on a chain with ${h} blocks.", ("h", node.chain_database()->head_block_num())); ilog("Chain ID is ${id}", ("id", node.chain_database()->get_chain_id()) ); diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index d3dc7455..74126d39 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -40,8 +40,10 @@ #include #include -#ifndef WIN32 -#include +#ifdef WIN32 +# include +#else +# include #endif using namespace graphene; @@ -156,11 +158,9 @@ int main(int argc, char** argv) { node.startup_plugins(); fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler"); -#if defined __APPLE__ || defined __unix__ fc::set_signal_handler([&exit_promise](int signal) { exit_promise->set_value(signal); }, SIGINT); -#endif ilog("Started witness node on a chain with ${h} blocks.", ("h", node.chain_database()->head_block_num())); ilog("Chain ID is ${id}", ("id", node.chain_database()->get_chain_id()) );