mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
fix: in case of all known, update header_head and sync_head (#1619)
* fix: in case of all known for Headers received, update sync_head to the last header * refactor: push this logic down into pipe
This commit is contained in:
parent
6ad54b9840
commit
d8ca684260
2 changed files with 19 additions and 7 deletions
|
@ -205,6 +205,24 @@ pub fn sync_block_headers(
|
|||
ctx: &mut BlockContext,
|
||||
batch: &mut store::Batch,
|
||||
) -> Result<(), Error> {
|
||||
let bhs_last = headers.last().unwrap().clone();
|
||||
let last_h = bhs_last.hash();
|
||||
if let Ok(_) = batch.get_block_header(&last_h) {
|
||||
info!(
|
||||
LOGGER,
|
||||
"All known, ignoring. Update sync_head to {} at {}", last_h, bhs_last.height,
|
||||
);
|
||||
|
||||
let res = update_sync_head(&bhs_last, batch);
|
||||
if let &Err(ref e) = &res {
|
||||
error!(
|
||||
LOGGER,
|
||||
"Block header {} update_sync_head fail: {:?}", last_h, e
|
||||
);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(header) = headers.first() {
|
||||
debug!(
|
||||
LOGGER,
|
||||
|
@ -664,6 +682,7 @@ fn update_sync_head(bh: &BlockHeader, batch: &mut store::Batch) -> Result<(), Er
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Update the header head so we can keep syncing from where we left off.
|
||||
fn update_header_head(
|
||||
bh: &BlockHeader,
|
||||
ctx: &mut BlockContext,
|
||||
|
|
|
@ -263,13 +263,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
|||
return false;
|
||||
}
|
||||
|
||||
// headers will just set us backward if even the last is unknown
|
||||
let last_h = bhs.last().unwrap().hash();
|
||||
if let Ok(_) = w(&self.chain).get_block_header(&last_h) {
|
||||
info!(LOGGER, "All known, ignoring");
|
||||
return true;
|
||||
}
|
||||
|
||||
// try to add headers to our header chain
|
||||
let res = w(&self.chain).sync_block_headers(&bhs, self.chain_opts());
|
||||
if let &Err(ref e) = &res {
|
||||
|
|
Loading…
Reference in a new issue