mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-08 04:11:08 +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()
|
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.
|
/// Tip (head) of the block chain.
|
||||||
pub fn head(&self) -> Result<Tip, Error> {
|
pub fn head(&self) -> Result<Tip, Error> {
|
||||||
self.store
|
self.store
|
||||||
|
@ -1159,14 +1151,6 @@ impl Chain {
|
||||||
.block_exists(&h)
|
.block_exists(&h)
|
||||||
.map_err(|e| ErrorKind::StoreErr(e, "chain block exists".to_owned()).into())
|
.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(
|
fn setup_head(
|
||||||
|
@ -1296,7 +1280,8 @@ fn setup_head(
|
||||||
head.last_block_h,
|
head.last_block_h,
|
||||||
head.height,
|
head.height,
|
||||||
);
|
);
|
||||||
batch.reset_head()?;
|
batch.reset_header_head()?;
|
||||||
|
batch.reset_sync_head()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.commit()?;
|
batch.commit()?;
|
||||||
|
|
|
@ -175,16 +175,16 @@ impl<'a> Batch<'a> {
|
||||||
self.db.put_ser(&vec![SYNC_HEAD_PREFIX], t)
|
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> {
|
pub fn reset_sync_head(&self) -> Result<(), Error> {
|
||||||
let head = self.header_head()?;
|
let head = self.header_head()?;
|
||||||
self.save_sync_head(&head)
|
self.save_sync_head(&head)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset both header_head and sync_head to the current head of the body chain
|
/// Reset header_head to the current head of the body chain.
|
||||||
pub fn reset_head(&self) -> Result<(), Error> {
|
pub fn reset_header_head(&self) -> Result<(), Error> {
|
||||||
let tip = self.head()?;
|
let tip = self.head()?;
|
||||||
self.save_header_head(&tip)?;
|
self.save_header_head(&tip)
|
||||||
self.save_sync_head(&tip)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get block
|
/// get block
|
||||||
|
|
|
@ -215,11 +215,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
||||||
if let &Err(ref e) = &res {
|
if let &Err(ref e) = &res {
|
||||||
debug!("Block header {} refused by chain: {:?}", bhash, e.kind());
|
debug!("Block header {} refused by chain: {:?}", bhash, e.kind());
|
||||||
if e.is_bad_data() {
|
if e.is_bad_data() {
|
||||||
debug!(
|
|
||||||
"header_received: {} is a bad header, resetting header head",
|
|
||||||
bhash
|
|
||||||
);
|
|
||||||
let _ = self.chain().reset_head();
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// we got an error when trying to process the block header
|
// we got an error when trying to process the block header
|
||||||
|
@ -444,13 +439,7 @@ impl NetToChainAdapter {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(ref e) if e.is_bad_data() => {
|
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);
|
self.validate_chain(bhash);
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -486,9 +475,9 @@ impl NetToChainAdapter {
|
||||||
// We are out of consensus at this point and want to track the problem
|
// We are out of consensus at this point and want to track the problem
|
||||||
// down as soon as possible.
|
// down as soon as possible.
|
||||||
// Skip this if we are currently syncing (too slow).
|
// 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.sync_state.is_syncing()
|
||||||
&& self.config.chain_validation_mode == ChainValidationMode::EveryBlock
|
|
||||||
{
|
{
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,6 @@ impl HeaderSync {
|
||||||
header_head.height,
|
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.
|
// Rebuild the sync MMR to match our updated sync_head.
|
||||||
self.chain.rebuild_sync_mmr(&header_head).unwrap();
|
self.chain.rebuild_sync_mmr(&header_head).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -198,8 +198,6 @@ impl SyncRunner {
|
||||||
ch.height,
|
ch.height,
|
||||||
ch.last_block_h
|
ch.last_block_h
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = self.chain.reset_head();
|
|
||||||
is_syncing = false;
|
is_syncing = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue