Skip to content

Commit 239cd5d

Browse files
authored
Use the latest committee instead of the "local" one. (#3735)
## Motivation When downloading blobs or certificates from validators, it is better to contact the latest validators. The "local" ones may already be offline, or the client may fail to even obtain them, if the to-be-synchronized chain does not exist in the database yet. ## Proposal Use the latest committee, so synchronizing works even if the chain does not exist in storage yet. ## Test Plan #3732 works for me now. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - Fixes #3733. - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 210aede commit 239cd5d

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

linera-core/src/client/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,15 @@ where
940940
.ok_or(LocalNodeError::InactiveChain(self.chain_id))
941941
}
942942

943+
/// Obtains the committee for the latest epoch.
944+
#[instrument(level = "trace")]
945+
pub async fn latest_committee(&self) -> Result<Committee, LocalNodeError> {
946+
let (mut committees, epoch) = self.known_committees().await?;
947+
committees
948+
.remove(&epoch)
949+
.ok_or(LocalNodeError::InactiveChain(self.chain_id))
950+
}
951+
943952
/// Obtains all the committees trusted by either the local chain or its admin chain. Also
944953
/// return the latest trusted epoch.
945954
#[instrument(level = "trace")]
@@ -963,19 +972,11 @@ where
963972
.collect())
964973
}
965974

966-
/// Obtains the validators trusted by the local chain.
975+
/// Obtains the validators for the latest epoch.
967976
#[instrument(level = "trace")]
968977
async fn validator_nodes(&self) -> Result<Vec<RemoteNode<P::Node>>, ChainClientError> {
969-
match self.local_committee().await {
970-
Ok(committee) => Ok(self.make_nodes(&committee)?),
971-
Err(LocalNodeError::InactiveChain(_)) => Ok(Vec::new()),
972-
Err(LocalNodeError::WorkerError(WorkerError::ChainError(error)))
973-
if matches!(*error, ChainError::InactiveChain(_)) =>
974-
{
975-
Ok(Vec::new())
976-
}
977-
Err(e) => Err(e.into()),
978-
}
978+
let committee = self.latest_committee().await?;
979+
Ok(self.make_nodes(&committee)?)
979980
}
980981

981982
/// Obtains the current epoch of the local chain.

linera-core/src/remote_node.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,24 @@ impl<N: ValidatorNode> RemoteNode<N> {
174174
limit: Some(limit),
175175
};
176176
let query = ChainInfoQuery::new(chain_id).with_sent_certificate_hashes_in_range(range);
177-
if let Ok(info) = self.handle_chain_info_query(query).await {
178-
let certificates = self
179-
.node
180-
.download_certificates(info.requested_sent_certificate_hashes)
181-
.await?
182-
.into_iter()
183-
.map(|c| {
184-
ConfirmedBlockCertificate::try_from(c)
185-
.map_err(|_| NodeError::InvalidChainInfoResponse)
186-
})
187-
.collect::<Result<_, _>>()?;
188-
Ok(Some(certificates))
189-
} else {
190-
Ok(None)
177+
match self.handle_chain_info_query(query).await {
178+
Ok(info) => {
179+
let certificates = self
180+
.node
181+
.download_certificates(info.requested_sent_certificate_hashes)
182+
.await?
183+
.into_iter()
184+
.map(|c| {
185+
ConfirmedBlockCertificate::try_from(c)
186+
.map_err(|_| NodeError::InvalidChainInfoResponse)
187+
})
188+
.collect::<Result<_, _>>()?;
189+
Ok(Some(certificates))
190+
}
191+
Err(error) => {
192+
tracing::warn!("Failed to query certificates: {error}");
193+
Ok(None)
194+
}
191195
}
192196
}
193197

0 commit comments

Comments
 (0)