mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
parent
d8ca684260
commit
4d2cbe6596
3 changed files with 9 additions and 17 deletions
|
@ -975,10 +975,10 @@ impl Chain {
|
||||||
.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 header_head
|
/// Reset sync_head to the provided head.
|
||||||
pub fn init_sync_head(&self, header_head: &Tip) -> Result<(), Error> {
|
pub fn reset_sync_head(&self, head: &Tip) -> Result<(), Error> {
|
||||||
let batch = self.store.batch()?;
|
let batch = self.store.batch()?;
|
||||||
batch.init_sync_head(header_head)?;
|
batch.save_sync_head(head)?;
|
||||||
batch.commit()?;
|
batch.commit()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1074,14 +1074,13 @@ fn setup_head(
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
head = tip;
|
|
||||||
info!(LOGGER, "chain: init: saved genesis: {:?}", genesis.hash());
|
info!(LOGGER, "chain: init: saved genesis: {:?}", genesis.hash());
|
||||||
}
|
}
|
||||||
Err(e) => return Err(ErrorKind::StoreErr(e, "chain init load head".to_owned()))?,
|
Err(e) => return Err(ErrorKind::StoreErr(e, "chain init load head".to_owned()))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize header_head and sync_head as necessary for chain init.
|
// Initialize header_head and sync_head as necessary for chain init.
|
||||||
batch.init_sync_head(&head)?;
|
batch.reset_head()?;
|
||||||
batch.commit()?;
|
batch.commit()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -206,21 +206,14 @@ impl<'a> Batch<'a> {
|
||||||
self.db.put_ser(&vec![SYNC_HEAD_PREFIX], t)
|
self.db.put_ser(&vec![SYNC_HEAD_PREFIX], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_sync_head(&self, t: &Tip) -> Result<(), Error> {
|
pub fn reset_sync_head(&self) -> Result<(), Error> {
|
||||||
let header_tip = match self.store.get_header_head() {
|
let head = self.get_header_head()?;
|
||||||
Ok(hh) => hh,
|
self.save_sync_head(&head)
|
||||||
Err(store::Error::NotFoundErr(_)) => {
|
|
||||||
self.save_header_head(t)?;
|
|
||||||
t.clone()
|
|
||||||
}
|
|
||||||
Err(e) => return Err(e),
|
|
||||||
};
|
|
||||||
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
|
||||||
pub fn reset_head(&self) -> Result<(), Error> {
|
pub fn reset_head(&self) -> Result<(), Error> {
|
||||||
let tip = self.store.head()?;
|
let tip = self.head()?;
|
||||||
self.save_header_head(&tip)?;
|
self.save_header_head(&tip)?;
|
||||||
self.save_sync_head(&tip)
|
self.save_sync_head(&tip)
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ fn do_header_sync(
|
||||||
header_head.hash(),
|
header_head.hash(),
|
||||||
header_head.height,
|
header_head.height,
|
||||||
);
|
);
|
||||||
chain.init_sync_head(&header_head).unwrap();
|
chain.reset_sync_head(&header_head).unwrap();
|
||||||
history_locators.clear();
|
history_locators.clear();
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue