Skip to content

Commit f8cb708

Browse files
authored
ValidatorNode::download_certificates returns ConfirmedBlockCertificates (#2973)
1 parent 3d05b4d commit f8cb708

File tree

8 files changed

+31
-21
lines changed

8 files changed

+31
-21
lines changed

linera-core/src/client/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,13 +1311,11 @@ where
13111311

13121312
// Check the signatures and keep only the ones that are valid.
13131313
let mut certificates = Vec::new();
1314-
for certificate in remote_certificates {
1315-
let sender_chain_id = certificate.inner().chain_id();
1316-
let height = certificate.inner().height();
1317-
let epoch = certificate.inner().epoch();
1318-
let confirmed_block_certificate = certificate
1319-
.try_into()
1320-
.map_err(|_| NodeError::UnexpectedCertificateValue)?;
1314+
for confirmed_block_certificate in remote_certificates {
1315+
let block = &confirmed_block_certificate.inner().executed_block().block;
1316+
let sender_chain_id = block.chain_id;
1317+
let height = block.height;
1318+
let epoch = block.epoch;
13211319
match self.check_certificate(max_epoch, &committees, &confirmed_block_certificate)? {
13221320
CheckCertificateResult::FutureEpoch => {
13231321
warn!(

linera-core/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub trait ValidatorNode {
100100
async fn download_certificates(
101101
&self,
102102
hashes: Vec<CryptoHash>,
103-
) -> Result<Vec<Certificate>, NodeError>;
103+
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError>;
104104

105105
/// Returns the hash of the `Certificate` that last used a blob.
106106
async fn blob_last_used_by(&self, blob_id: BlobId) -> Result<CryptoHash, NodeError>;

linera-core/src/remote_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<N: ValidatorNode> RemoteNode<N> {
284284
pub async fn download_certificates(
285285
&self,
286286
hashes: Vec<CryptoHash>,
287-
) -> Result<Vec<Certificate>, NodeError> {
287+
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
288288
if hashes.is_empty() {
289289
return Ok(Vec::new());
290290
}

linera-core/src/unit_tests/test_utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use linera_base::{
2121
};
2222
use linera_chain::{
2323
data_types::BlockProposal,
24-
types::{Certificate, ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
24+
types::{ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
2525
};
2626
use linera_execution::{
2727
committee::{Committee, ValidatorName},
@@ -176,12 +176,11 @@ where
176176
async fn download_certificates(
177177
&self,
178178
hashes: Vec<CryptoHash>,
179-
) -> Result<Vec<Certificate>, NodeError> {
179+
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
180180
self.spawn_and_receive(move |validator, sender| {
181181
validator.do_download_certificates(hashes, sender)
182182
})
183183
.await
184-
.map(|certs| certs.into_iter().map(Certificate::from).collect())
185184
}
186185

187186
async fn blob_last_used_by(&self, blob_id: BlobId) -> Result<CryptoHash, NodeError> {

linera-rpc/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl ValidatorNode for Client {
164164
async fn download_certificates(
165165
&self,
166166
hashes: Vec<CryptoHash>,
167-
) -> Result<Vec<Certificate>, NodeError> {
167+
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
168168
Ok(match self {
169169
Client::Grpc(grpc_client) => grpc_client.download_certificates(hashes).await?,
170170

linera-rpc/src/grpc/client.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,21 @@ impl ValidatorNode for GrpcClient {
339339
async fn download_certificates(
340340
&self,
341341
hashes: Vec<CryptoHash>,
342-
) -> Result<Vec<Certificate>, NodeError> {
342+
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
343343
let mut missing_hashes = hashes;
344344
let mut certs_collected = Vec::with_capacity(missing_hashes.len());
345345
loop {
346346
// Macro doesn't compile if we pass `missing_hashes.clone()` directly to `client_delegate!`.
347347
let missing = missing_hashes.clone();
348-
let mut received: Vec<Certificate> =
349-
client_delegate!(self, download_certificates, missing)?.try_into()?;
348+
let mut received: Vec<ConfirmedBlockCertificate> = Vec::<Certificate>::try_from(
349+
client_delegate!(self, download_certificates, missing)?,
350+
)?
351+
.into_iter()
352+
.map(|cert| {
353+
ConfirmedBlockCertificate::try_from(cert)
354+
.map_err(|_| NodeError::UnexpectedCertificateValue)
355+
})
356+
.collect::<Result<_, _>>()?;
350357

351358
// In the case of the server not returning any certificates, we break the loop.
352359
if received.is_empty() {

linera-rpc/src/simple/client.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,15 @@ impl ValidatorNode for SimpleClient {
158158
async fn download_certificates(
159159
&self,
160160
hashes: Vec<CryptoHash>,
161-
) -> Result<Vec<Certificate>, NodeError> {
162-
self.query(RpcMessage::DownloadCertificates(Box::new(hashes)))
163-
.await
161+
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
162+
self.query::<Vec<Certificate>>(RpcMessage::DownloadCertificates(Box::new(hashes)))
163+
.await?
164+
.into_iter()
165+
.map(|cert| {
166+
cert.try_into()
167+
.map_err(|_| NodeError::UnexpectedCertificateValue)
168+
})
169+
.collect()
164170
}
165171

166172
async fn blob_last_used_by(&self, blob_id: BlobId) -> Result<CryptoHash, NodeError> {

linera-service/src/schema_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use linera_base::{
99
};
1010
use linera_chain::{
1111
data_types::BlockProposal,
12-
types::{Certificate, ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
12+
types::{ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
1313
};
1414
use linera_client::{
1515
chain_listener::{ChainListenerConfig, ClientContext},
@@ -93,7 +93,7 @@ impl ValidatorNode for DummyValidatorNode {
9393
async fn download_certificates(
9494
&self,
9595
_: Vec<CryptoHash>,
96-
) -> Result<Vec<Certificate>, NodeError> {
96+
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
9797
Err(NodeError::UnexpectedMessage)
9898
}
9999

0 commit comments

Comments
 (0)