mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
cleanup unnecessary reset_head calls (#2072)
This commit is contained in:
parent
a24d613b05
commit
919fd84b78
5 changed files with 8 additions and 39 deletions
|
@ -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<Tip, Error> {
|
||||
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()?;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -198,8 +198,6 @@ impl SyncRunner {
|
|||
ch.height,
|
||||
ch.last_block_h
|
||||
);
|
||||
|
||||
let _ = self.chain.reset_head();
|
||||
is_syncing = false;
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue