From 919fd84b7824654ebfa6f77284d4ee68f53a271b Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Mon, 3 Dec 2018 22:27:03 +0000 Subject: [PATCH] cleanup unnecessary reset_head calls (#2072) --- chain/src/chain.rs | 19 ++----------------- chain/src/store.rs | 8 ++++---- servers/src/common/adapters.rs | 15 ++------------- servers/src/grin/sync/header_sync.rs | 3 --- servers/src/grin/sync/syncer.rs | 2 -- 5 files changed, 8 insertions(+), 39 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 878b670c0..ef7cb086e 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -1014,14 +1014,6 @@ impl Chain { self.orphans.len() } - /// Reset header_head and sync_head to head of current body chain - pub fn reset_head(&self) -> Result<(), Error> { - let batch = self.store.batch()?; - batch.reset_head()?; - batch.commit()?; - Ok(()) - } - /// Tip (head) of the block chain. pub fn head(&self) -> Result { self.store @@ -1159,14 +1151,6 @@ impl Chain { .block_exists(&h) .map_err(|e| ErrorKind::StoreErr(e, "chain block exists".to_owned()).into()) } - - /// Reset sync_head to the provided head. - pub fn reset_sync_head(&self, head: &Tip) -> Result<(), Error> { - let batch = self.store.batch()?; - batch.save_sync_head(head)?; - batch.commit()?; - Ok(()) - } } fn setup_head( @@ -1296,7 +1280,8 @@ fn setup_head( head.last_block_h, head.height, ); - batch.reset_head()?; + batch.reset_header_head()?; + batch.reset_sync_head()?; } batch.commit()?; diff --git a/chain/src/store.rs b/chain/src/store.rs index 060b94e26..4a0caa0ee 100644 --- a/chain/src/store.rs +++ b/chain/src/store.rs @@ -175,16 +175,16 @@ impl<'a> Batch<'a> { self.db.put_ser(&vec![SYNC_HEAD_PREFIX], t) } + /// Reset sync_head to the current head of the header chain. pub fn reset_sync_head(&self) -> Result<(), Error> { let head = self.header_head()?; self.save_sync_head(&head) } - // Reset both header_head and sync_head to the current head of the body chain - pub fn reset_head(&self) -> Result<(), Error> { + /// Reset header_head to the current head of the body chain. + pub fn reset_header_head(&self) -> Result<(), Error> { let tip = self.head()?; - self.save_header_head(&tip)?; - self.save_sync_head(&tip) + self.save_header_head(&tip) } /// get block diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index 0550500b3..b4f69a3cf 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -215,11 +215,6 @@ impl p2p::ChainAdapter for NetToChainAdapter { if let &Err(ref e) = &res { debug!("Block header {} refused by chain: {:?}", bhash, e.kind()); if e.is_bad_data() { - debug!( - "header_received: {} is a bad header, resetting header head", - bhash - ); - let _ = self.chain().reset_head(); return false; } else { // we got an error when trying to process the block header @@ -444,13 +439,7 @@ impl NetToChainAdapter { true } Err(ref e) if e.is_bad_data() => { - debug!("process_block: {} is a bad block, resetting head", bhash); - let _ = self.chain().reset_head(); - - // we potentially changed the state of the system here - // so check everything is still ok self.validate_chain(bhash); - false } Err(e) => { @@ -486,9 +475,9 @@ impl NetToChainAdapter { // We are out of consensus at this point and want to track the problem // down as soon as possible. // Skip this if we are currently syncing (too slow). - if self.chain().head().unwrap().height > 0 + if self.config.chain_validation_mode == ChainValidationMode::EveryBlock + && self.chain().head().unwrap().height > 0 && !self.sync_state.is_syncing() - && self.config.chain_validation_mode == ChainValidationMode::EveryBlock { let now = Instant::now(); diff --git a/servers/src/grin/sync/header_sync.rs b/servers/src/grin/sync/header_sync.rs index b5e239322..890314fd2 100644 --- a/servers/src/grin/sync/header_sync.rs +++ b/servers/src/grin/sync/header_sync.rs @@ -66,9 +66,6 @@ impl HeaderSync { header_head.height, ); - // Reset sync_head to the same as current header_head. - self.chain.reset_sync_head(&header_head).unwrap(); - // Rebuild the sync MMR to match our updated sync_head. self.chain.rebuild_sync_mmr(&header_head).unwrap(); diff --git a/servers/src/grin/sync/syncer.rs b/servers/src/grin/sync/syncer.rs index 3f6496c8f..5b09e556e 100644 --- a/servers/src/grin/sync/syncer.rs +++ b/servers/src/grin/sync/syncer.rs @@ -198,8 +198,6 @@ impl SyncRunner { ch.height, ch.last_block_h ); - - let _ = self.chain.reset_head(); is_syncing = false; } } else {