From bc6342ea6531fec2d9d43020f8474b69d690bcb5 Mon Sep 17 00:00:00 2001 From: Antioch Peverell <30642645+antiochp@users.noreply.github.com> Date: Fri, 6 Apr 2018 18:14:50 +0100 Subject: [PATCH] Fix issue where we have no metadata for a block (#938) when restarting node before initial sync completed --- chain/src/chain.rs | 16 +++++++++++----- grin/src/server.rs | 3 ++- p2p/src/protocol.rs | 8 ++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 8ea011ac..34fe38f8 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -160,15 +160,20 @@ impl Chain { // check if we have a head in store, otherwise the genesis block is it let head = store.head(); + let txhashset_md = match head { Ok(h) => { // Add the height to the metadata for the use of the rewind log, as this isn't // stored - let mut ts = store.get_block_pmmr_file_metadata(&h.last_block_h)?; - ts.output_file_md.block_height = h.height; - ts.rproof_file_md.block_height = h.height; - ts.kernel_file_md.block_height = h.height; - Some(ts) + if let Ok(mut ts) = store.get_block_pmmr_file_metadata(&h.last_block_h) { + ts.output_file_md.block_height = h.height; + ts.rproof_file_md.block_height = h.height; + ts.kernel_file_md.block_height = h.height; + Some(ts) + } else { + debug!(LOGGER, "metadata not found for {} @ {}", h.height, h.hash()); + None + } } Err(NotFoundErr) => None, Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())), @@ -178,6 +183,7 @@ impl Chain { txhashset::TxHashSet::open(db_root.clone(), store.clone(), txhashset_md)?; let head = store.head(); + let head = match head { Ok(h) => h, Err(NotFoundErr) => { diff --git a/grin/src/server.rs b/grin/src/server.rs index 26aec924..1872c28c 100644 --- a/grin/src/server.rs +++ b/grin/src/server.rs @@ -116,7 +116,8 @@ impl Server { global::ChainTypes::AutomatedTesting => genesis::genesis_dev(), _ => pow::mine_genesis_block(config.mining_config.clone())?, }; - info!(LOGGER, "Starting server, genesis block: {}", genesis.hash(),); + + info!(LOGGER, "Starting server, genesis block: {}", genesis.hash()); let shared_chain = Arc::new(chain::Chain::init( config.db_root.clone(), diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index 4273371f..21a603c7 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -248,6 +248,14 @@ impl MessageHandler for Protocol { tmp_zip, self.addr, ); + + debug!( + LOGGER, + "handle_payload: txhashset archive for {} at {}, DONE", + sm_arch.hash, + sm_arch.height + ); + Ok(None) }