mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
init_head and not reset_head on startup (#971)
so we do not reset the sync_head if we restart during a sync
This commit is contained in:
parent
bd64c6099f
commit
2503811e89
3 changed files with 14 additions and 3 deletions
|
@ -216,9 +216,8 @@ impl Chain {
|
||||||
Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())),
|
Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset sync_head and header_head to head of current chain.
|
// Initialize header_head and sync_head as necessary for chain init.
|
||||||
// Make sure sync_head is available for later use when needed.
|
store.init_head()?;
|
||||||
store.reset_head()?;
|
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
|
|
@ -88,6 +88,15 @@ impl ChainStore for ChainKVStore {
|
||||||
self.db.put_ser(&vec![SYNC_HEAD_PREFIX], t)
|
self.db.put_ser(&vec![SYNC_HEAD_PREFIX], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init_head(&self) -> Result<(), Error> {
|
||||||
|
if self.get_header_head().is_err() {
|
||||||
|
let tip = self.head()?;
|
||||||
|
self.save_header_head(&tip)?;
|
||||||
|
}
|
||||||
|
let header_tip = self.get_header_head()?;
|
||||||
|
self.save_sync_head(&header_tip)
|
||||||
|
}
|
||||||
|
|
||||||
// Reset both header_head and sync_head to the current head of the body chain
|
// Reset both header_head and sync_head to the current head of the body chain
|
||||||
fn reset_head(&self) -> Result<(), Error> {
|
fn reset_head(&self) -> Result<(), Error> {
|
||||||
let tip = self.head()?;
|
let tip = self.head()?;
|
||||||
|
|
|
@ -288,6 +288,9 @@ pub trait ChainStore: Send + Sync {
|
||||||
/// Save the provided tip as the current head of the sync header chain
|
/// Save the provided tip as the current head of the sync header chain
|
||||||
fn save_sync_head(&self, t: &Tip) -> Result<(), store::Error>;
|
fn save_sync_head(&self, t: &Tip) -> Result<(), store::Error>;
|
||||||
|
|
||||||
|
/// Initialize header_head if necessary and set sync_head to header_head.
|
||||||
|
fn init_head(&self) -> Result<(), store::Error>;
|
||||||
|
|
||||||
/// Reset header_head and sync_head to head of current body chain
|
/// Reset header_head and sync_head to head of current body chain
|
||||||
fn reset_head(&self) -> Result<(), store::Error>;
|
fn reset_head(&self) -> Result<(), store::Error>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue