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

Do not perform client update if consensus state already exists #3555

Merged
merged 5 commits into from
Nov 9, 2023
Merged
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
21 changes: 20 additions & 1 deletion crates/relayer/src/foreign_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ define_error! {
height: Height,
}
|e| {
format_args!("client {} is already up-to-date with chain {}@{}",
format_args!("client {} is already up-to-date with chain {} at height {}",
e.client_id, e.chain_id, e.height)
},

Expand Down Expand Up @@ -1131,6 +1131,24 @@ impl<DstChain: ChainHandle, SrcChain: ChainHandle> ForeignClient<DstChain, SrcCh
}
);

let consensus_state = self.dst_chain().query_consensus_state(
QueryConsensusStateRequest {
client_id: self.id().clone(),
consensus_height: target_height,
query_height: QueryHeight::Latest,
},
IncludeProof::No,
);

if let Ok((consensus_state, _)) = consensus_state {
debug!("consensus state already exists at height {target_height}, skipping update");
trace!(?consensus_state, "consensus state");

// If the client already stores a consensus state for the target height,
// there is no need to update the client
return Ok(vec![]);
}

let src_application_latest_height = || {
self.src_chain().query_latest_height().map_err(|e| {
ForeignClientError::client_create(
Expand All @@ -1149,6 +1167,7 @@ impl<DstChain: ChainHandle, SrcChain: ChainHandle> ForeignClient<DstChain, SrcCh
"dst_chain": self.dst_chain().id(),
}
);

// Wait for the source network to produce block(s) & reach `target_height`.
while src_application_latest_height()? < target_height {
thread::sleep(Duration::from_millis(100));
Expand Down
Loading