mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Fix fast sync mode failure when 'sync_state' was switched to 'HeaderSync' (#1286)
This commit is contained in:
parent
f5b03a6d5a
commit
3b6b85ec57
2 changed files with 46 additions and 15 deletions
|
@ -229,24 +229,45 @@ impl MessageHandler for Protocol {
|
|||
let sm_arch: TxHashSetArchive = msg.body()?;
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive for {} at {}",
|
||||
"handle_payload: txhashset archive for {} at {}. size={}",
|
||||
sm_arch.hash,
|
||||
sm_arch.height,
|
||||
sm_arch.bytes,
|
||||
);
|
||||
if !self.adapter.txhashset_receive_ready() {
|
||||
error!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive received but SyncStatus not on TxHashsetDownload",
|
||||
);
|
||||
return Err(Error::BadMessage);
|
||||
}
|
||||
|
||||
let mut tmp = env::temp_dir();
|
||||
tmp.push("txhashset.zip");
|
||||
{
|
||||
let mut tmp_zip = File::create(tmp.clone())?;
|
||||
let mut save_txhashset_to_file = |file| -> Result<(), Error> {
|
||||
let mut tmp_zip = File::create(file)?;
|
||||
msg.copy_attachment(sm_arch.bytes as usize, &mut tmp_zip)?;
|
||||
tmp_zip.sync_all()?;
|
||||
Ok(())
|
||||
};
|
||||
|
||||
if let Err(e) = save_txhashset_to_file(tmp.clone()){
|
||||
error!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive save to file fail. err={:?}",
|
||||
e
|
||||
);
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
trace!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive save to file {:?} success",
|
||||
tmp,
|
||||
);
|
||||
|
||||
let tmp_zip = File::open(tmp)?;
|
||||
self.adapter.txhashset_write(
|
||||
let res = self.adapter.txhashset_write(
|
||||
sm_arch.hash,
|
||||
tmp_zip,
|
||||
self.addr,
|
||||
|
@ -254,9 +275,10 @@ impl MessageHandler for Protocol {
|
|||
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive for {} at {}, DONE",
|
||||
"handle_payload: txhashset archive for {} at {}, DONE. Data Ok: {}",
|
||||
sm_arch.hash,
|
||||
sm_arch.height
|
||||
sm_arch.height,
|
||||
res
|
||||
);
|
||||
|
||||
Ok(None)
|
||||
|
|
|
@ -119,8 +119,14 @@ pub fn run_sync(
|
|||
|
||||
// run the header sync every 10s
|
||||
if si.header_sync_due(&header_head) {
|
||||
header_sync(peers.clone(), chain.clone());
|
||||
sync_state.update(SyncStatus::HeaderSync{current_height: header_head.height, highest_height: si.highest_height});
|
||||
let status = sync_state.status();
|
||||
match status{
|
||||
SyncStatus::TxHashsetDownload => (),
|
||||
_ => {
|
||||
header_sync(peers.clone(), chain.clone());
|
||||
sync_state.update(SyncStatus::HeaderSync{current_height: header_head.height, highest_height: si.highest_height});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if fast_sync_enabled {
|
||||
|
@ -252,12 +258,6 @@ fn fast_sync(peers: Arc<Peers>, chain: Arc<chain::Chain>, header_head: &chain::T
|
|||
|
||||
if let Some(peer) = peers.most_work_peer() {
|
||||
if let Ok(p) = peer.try_read() {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"Header head before txhashset request: {} / {}",
|
||||
header_head.height,
|
||||
header_head.last_block_h
|
||||
);
|
||||
|
||||
// ask for txhashset at 90% of horizon, this still leaves time for download
|
||||
// and validation to happen and stay within horizon
|
||||
|
@ -265,7 +265,16 @@ fn fast_sync(peers: Arc<Peers>, chain: Arc<chain::Chain>, header_head: &chain::T
|
|||
for _ in 0..(horizon - horizon / 10) {
|
||||
txhashset_head = chain.get_block_header(&txhashset_head.previous).unwrap();
|
||||
}
|
||||
p.send_txhashset_request(txhashset_head.height, txhashset_head.hash())
|
||||
let bhash = txhashset_head.hash();
|
||||
debug!(
|
||||
LOGGER,
|
||||
"fast_sync: before txhashset request, header head: {} / {}, txhashset_head: {} / {}",
|
||||
header_head.height,
|
||||
header_head.last_block_h,
|
||||
txhashset_head.height,
|
||||
bhash
|
||||
);
|
||||
p.send_txhashset_request(txhashset_head.height, bhash)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue