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:
Antioch Peverell 2018-04-18 01:41:51 +01:00 committed by GitHub
parent bd64c6099f
commit 2503811e89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View file

@ -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,

View file

@ -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()?;

View file

@ -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>;