Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make full node process warp sync if it was enabled #1379

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions full-node/src/consensus_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,15 @@ impl SyncBackground {
all::BlockAnnounceOutcome::InvalidHeader(_) => unreachable!(),
}
}
WakeUpReason::NetworkEvent(network_service::Event::GrandpaNeighborPacket {
chain_id,
peer_id,
finalized_block_height,
}) if chain_id == self.network_chain_id => {
let source_id = *self.peers_source_id_map.get(&peer_id).unwrap();
self.sync
.update_source_finality_state(source_id, finalized_block_height);
}
WakeUpReason::NetworkEvent(_) => {
// Different chain index.
}
Expand Down Expand Up @@ -1602,10 +1611,55 @@ impl SyncBackground {
self.sync = idle;
(self, false)
}
all::ProcessOne::VerifyWarpSyncFragment(_)
| all::ProcessOne::WarpSyncBuildRuntime(_)
| all::ProcessOne::WarpSyncBuildChainInformation(_)
| all::ProcessOne::WarpSyncFinished { .. } => unreachable!(),
all::ProcessOne::VerifyWarpSyncFragment(verify) => {
let (new_sync, outcome) = verify.perform(rand::random());
self.sync = new_sync;
match outcome {
Ok((fragment_hash, fragment_height)) => {
self.log_callback.log(
LogLevel::Debug,
format!(
"justification-verification-success; fragment_hash={}, fragment_height={fragment_height}",
hex::encode(&fragment_hash)
),
);
}
Err(err) => {
self.log_callback.log(
LogLevel::Warn,
format!("failed-justification-verification; error={err}"),
);
}
}
(self, true)
}
all::ProcessOne::WarpSyncBuildRuntime(build_runtime) => {
let (new_sync, outcome) =
build_runtime.build(all::ExecHint::CompileAheadOfTime, true);
self.sync = new_sync;
if let Err(err) = outcome {
self.log_callback.log(
LogLevel::Warn,
format!("failed-warp-sync-runtime-compilation; error={err}"),
);
}
(self, true)
}
all::ProcessOne::WarpSyncBuildChainInformation(build_chain_information) => {
let (new_sync, outcome) = build_chain_information.build();
self.sync = new_sync;
if let Err(err) = outcome {
self.log_callback.log(
LogLevel::Warn,
format!("failed-warp-sync-chain-information-build; error={err}"),
);
}
(self, true)
}
all::ProcessOne::WarpSyncFinished { sync, .. } => {
self.sync = sync;
(self, true)
}
all::ProcessOne::VerifyBlock(verify) => {
let when_verification_started = Instant::now();
let mut database_accesses_duration = Duration::new(0, 0);
Expand Down
13 changes: 12 additions & 1 deletion full-node/src/network_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ pub enum Event {
scale_encoded_header: Vec<u8>,
is_best: bool,
},
GrandpaNeighborPacket {
chain_id: ChainId,
peer_id: PeerId,
finalized_block_height: u64,
},
}

pub struct NetworkService {
Expand Down Expand Up @@ -1581,7 +1586,13 @@ async fn background_task(mut inner: Inner) {
state.set_id,
state.commit_finalized_height,
));
// TODO: report to the sync state machine

debug_assert!(inner.event_pending_send.is_none());
inner.event_pending_send = Some(Event::GrandpaNeighborPacket {
chain_id,
peer_id,
finalized_block_height: state.commit_finalized_height,
});
}
WakeUpReason::NetworkEvent(service::Event::GrandpaCommitMessage {
chain_id,
Expand Down