mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 05:47:58 +00:00
Warp sync part II (#9284)
* Gap sync * Gap epoch test * Simplified network requests * Update client/db/src/utils.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Fixed v1 migration and added some comments * Next epoch is always regular * Removed fork tree change * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Added a comment and converted assert to error Co-authored-by: cheme <emericchevalier.pro@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -47,8 +47,8 @@ pub struct StateSync<B: BlockT> {
|
||||
pub enum ImportResult<B: BlockT> {
|
||||
/// State is complete and ready for import.
|
||||
Import(B::Hash, B::Header, ImportedState<B>),
|
||||
/// Continue dowloading.
|
||||
Continue(StateRequest),
|
||||
/// Continue downloading.
|
||||
Continue,
|
||||
/// Bad state chunk.
|
||||
BadResponse,
|
||||
}
|
||||
@@ -134,7 +134,7 @@ impl<B: BlockT> StateSync<B> {
|
||||
ImportedState { block: self.target_block, state: std::mem::take(&mut self.state) },
|
||||
)
|
||||
} else {
|
||||
ImportResult::Continue(self.next_request())
|
||||
ImportResult::Continue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,9 @@ enum Phase<B: BlockT> {
|
||||
}
|
||||
|
||||
/// Import warp proof result.
|
||||
pub enum WarpProofImportResult<B: BlockT> {
|
||||
/// Start downloading state data.
|
||||
StateRequest(StateRequest),
|
||||
/// Continue dowloading warp sync proofs.
|
||||
WarpProofRequest(WarpProofRequest<B>),
|
||||
pub enum WarpProofImportResult {
|
||||
/// Import was successful.
|
||||
Success,
|
||||
/// Bad proof.
|
||||
BadResponse,
|
||||
}
|
||||
@@ -69,7 +67,7 @@ impl<B: BlockT> WarpSync<B> {
|
||||
Self { client, warp_sync_provider, phase, total_proof_bytes: 0 }
|
||||
}
|
||||
|
||||
/// Validate and import a state reponse.
|
||||
/// Validate and import a state response.
|
||||
pub fn import_state(&mut self, response: StateResponse) -> ImportResult<B> {
|
||||
match &mut self.phase {
|
||||
Phase::WarpProof { .. } => {
|
||||
@@ -80,19 +78,15 @@ impl<B: BlockT> WarpSync<B> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Validate and import a warp proof reponse.
|
||||
pub fn import_warp_proof(&mut self, response: EncodedProof) -> WarpProofImportResult<B> {
|
||||
/// Validate and import a warp proof response.
|
||||
pub fn import_warp_proof(&mut self, response: EncodedProof) -> WarpProofImportResult {
|
||||
match &mut self.phase {
|
||||
Phase::State(_) => {
|
||||
log::debug!(target: "sync", "Unexpected warp proof response");
|
||||
WarpProofImportResult::BadResponse
|
||||
},
|
||||
Phase::WarpProof { set_id, authorities, last_hash } => {
|
||||
match self.warp_sync_provider.verify(
|
||||
&response,
|
||||
*set_id,
|
||||
std::mem::take(authorities),
|
||||
) {
|
||||
match self.warp_sync_provider.verify(&response, *set_id, authorities.clone()) {
|
||||
Err(e) => {
|
||||
log::debug!(target: "sync", "Bad warp proof response: {:?}", e);
|
||||
return WarpProofImportResult::BadResponse
|
||||
@@ -103,17 +97,14 @@ impl<B: BlockT> WarpSync<B> {
|
||||
*authorities = new_authorities;
|
||||
*last_hash = new_last_hash.clone();
|
||||
self.total_proof_bytes += response.0.len() as u64;
|
||||
WarpProofImportResult::WarpProofRequest(WarpProofRequest {
|
||||
begin: new_last_hash,
|
||||
})
|
||||
WarpProofImportResult::Success
|
||||
},
|
||||
Ok(VerificationResult::Complete(new_set_id, _, header)) => {
|
||||
log::debug!(target: "sync", "Verified complete proof, set_id={:?}", new_set_id);
|
||||
self.total_proof_bytes += response.0.len() as u64;
|
||||
let state_sync = StateSync::new(self.client.clone(), header, false);
|
||||
let request = state_sync.next_request();
|
||||
self.phase = Phase::State(state_sync);
|
||||
WarpProofImportResult::StateRequest(request)
|
||||
WarpProofImportResult::Success
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -161,7 +152,7 @@ impl<B: BlockT> WarpSync<B> {
|
||||
}
|
||||
|
||||
/// Returns state sync estimated progress (percentage, bytes)
|
||||
pub fn progress(&self) -> WarpSyncProgress {
|
||||
pub fn progress(&self) -> WarpSyncProgress<B> {
|
||||
match &self.phase {
|
||||
Phase::WarpProof { .. } => WarpSyncProgress {
|
||||
phase: WarpSyncPhase::DownloadingWarpProofs,
|
||||
|
||||
Reference in New Issue
Block a user