Skip to content

Commit 93b0f13

Browse files
deuszxafck
andauthored
Fix sender block sync. (linera-io#4722)
## Motivation Backport of linera-io#4721 ## Proposal Synchronize sender blocks, including its sender dependencies (i.e. past blocks in which sender chain had sent a message to our). ## Test Plan CI ## Release Plan - These changes should be released in a new SDK, ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist) Co-authored-by: Andreas Fackler <[email protected]>
1 parent 9997d9b commit 93b0f13

File tree

1 file changed

+28
-40
lines changed

1 file changed

+28
-40
lines changed

linera-core/src/client/mod.rs

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,12 +1501,10 @@ pub enum ChainClientError {
15011501
#[error("Epoch is already revoked")]
15021502
EpochAlreadyRevoked,
15031503

1504-
#[error(
1505-
"Failed to download missing sender blocks from chain {chain_id} at heights {heights:?}"
1506-
)]
1507-
CannotDownloadMissingSenderBlocks {
1504+
#[error("Failed to download missing sender blocks from chain {chain_id} at height {height}")]
1505+
CannotDownloadMissingSenderBlock {
15081506
chain_id: ChainId,
1509-
heights: Vec<BlockHeight>,
1507+
height: BlockHeight,
15101508
},
15111509
}
15121510

@@ -2225,58 +2223,48 @@ impl<Env: Environment> ChainClient<Env> {
22252223

22262224
let (_, committee) = self.admin_committee().await?;
22272225
let nodes = self.client.make_nodes(&committee)?;
2228-
let (max_epoch, committees) = self.client.admin_committees().await?;
22292226

22302227
// Download certificates for each sender chain at the specific heights.
2231-
let certificates = stream::iter(missing_blocks.into_iter())
2228+
stream::iter(missing_blocks.into_iter())
22322229
.map(|(sender_chain_id, heights)| {
2230+
let height = heights.into_iter().max();
22332231
let nodes = nodes.clone();
2232+
let this = self.clone();
22342233
async move {
2234+
let Some(height) = height else {
2235+
return Ok(());
2236+
};
22352237
// Try to download from any node.
22362238
for node in &nodes {
2237-
if let Ok(certs) = node
2238-
.download_certificates_by_heights(sender_chain_id, heights.clone())
2239+
if let Err(err) = this
2240+
.download_sender_block_with_sending_ancestors(
2241+
sender_chain_id,
2242+
height,
2243+
node,
2244+
)
22392245
.await
22402246
{
2241-
return Ok::<Vec<_>, ChainClientError>(certs);
2247+
tracing::debug!(
2248+
%height,
2249+
%sender_chain_id,
2250+
%err,
2251+
validator = %node.public_key,
2252+
"Failed to fetch sender block",
2253+
);
2254+
} else {
2255+
return Ok::<_, ChainClientError>(());
22422256
}
22432257
}
22442258
// If all nodes fail, return an error.
2245-
Err(ChainClientError::CannotDownloadMissingSenderBlocks {
2259+
Err(ChainClientError::CannotDownloadMissingSenderBlock {
22462260
chain_id: sender_chain_id,
2247-
heights,
2261+
height,
22482262
})
22492263
}
22502264
})
22512265
.buffer_unordered(self.options.max_joined_tasks)
22522266
.try_collect::<Vec<_>>()
22532267
.await?;
2254-
2255-
// Process and validate the downloaded certificates.
2256-
let mut valid_certificates = Vec::new();
2257-
for certificate in certificates.into_iter().flatten() {
2258-
match Client::<Env>::check_certificate(max_epoch, &committees, &certificate)? {
2259-
CheckCertificateResult::FutureEpoch | CheckCertificateResult::OldEpoch => {
2260-
// Skip certificates from unrecognized epochs.
2261-
continue;
2262-
}
2263-
CheckCertificateResult::New => {
2264-
valid_certificates.push(certificate);
2265-
}
2266-
}
2267-
}
2268-
2269-
// Receive and process the certificates.
2270-
for certificate in valid_certificates {
2271-
self.client
2272-
.receive_sender_certificate(
2273-
certificate,
2274-
ReceiveCertificateMode::AlreadyChecked,
2275-
Some(nodes.clone()),
2276-
)
2277-
.await?;
2278-
}
2279-
22802268
Ok(())
22812269
}
22822270

@@ -2314,9 +2302,9 @@ impl<Env: Environment> ChainClient<Env> {
23142302
.download_certificates_by_heights(sender_chain_id, vec![current_height])
23152303
.await?;
23162304
let Some(certificate) = downloaded.into_iter().next() else {
2317-
return Err(ChainClientError::CannotDownloadMissingSenderBlocks {
2305+
return Err(ChainClientError::CannotDownloadMissingSenderBlock {
23182306
chain_id: sender_chain_id,
2319-
heights: vec![current_height],
2307+
height: current_height,
23202308
});
23212309
};
23222310

0 commit comments

Comments
 (0)