When rolling back on save, remove the rolled back blocks from our
databases so when we restart and begin syncing, we re-download and
push those rolled back blocks (fixes bug introduced in
a5071f2568).
Fix logging of incorrect block numbers in p2p log.
This commit is contained in:
parent
3cf1eb5d5c
commit
a943de8b76
6 changed files with 60 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -43,8 +43,11 @@
|
|||
#include <fc/log/file_appender.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/log/logger_config.hpp>
|
||||
#ifndef WIN32
|
||||
#include <csignal>
|
||||
|
||||
#ifdef WIN32
|
||||
# include <signal.h>
|
||||
#else
|
||||
# include <csignal>
|
||||
#endif
|
||||
|
||||
using namespace graphene::app;
|
||||
|
|
@ -255,11 +258,9 @@ int main( int argc, char** argv )
|
|||
else
|
||||
{
|
||||
fc::promise<int>::ptr exit_promise = new fc::promise<int>("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();
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <csignal>
|
||||
#ifdef WIN32
|
||||
# include <signal.h>
|
||||
#else
|
||||
# include <csignal>
|
||||
#endif
|
||||
|
||||
using namespace graphene;
|
||||
|
|
@ -159,11 +161,9 @@ int main(int argc, char** argv) {
|
|||
node.startup_plugins();
|
||||
|
||||
fc::promise<int>::ptr exit_promise = new fc::promise<int>("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()) );
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <csignal>
|
||||
#ifdef WIN32
|
||||
# include <signal.h>
|
||||
#else
|
||||
# include <csignal>
|
||||
#endif
|
||||
|
||||
using namespace graphene;
|
||||
|
|
@ -156,11 +158,9 @@ int main(int argc, char** argv) {
|
|||
node.startup_plugins();
|
||||
|
||||
fc::promise<int>::ptr exit_promise = new fc::promise<int>("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()) );
|
||||
|
|
|
|||
Loading…
Reference in a new issue