Skip to content

Commit

Permalink
ValidatorNode::download_certificates returns ConfirmedBlockCertificat…
Browse files Browse the repository at this point in the history
  • Loading branch information
deuszx authored Nov 27, 2024
1 parent 3d05b4d commit f8cb708
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
12 changes: 5 additions & 7 deletions linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,13 +1311,11 @@ where

// Check the signatures and keep only the ones that are valid.
let mut certificates = Vec::new();
for certificate in remote_certificates {
let sender_chain_id = certificate.inner().chain_id();
let height = certificate.inner().height();
let epoch = certificate.inner().epoch();
let confirmed_block_certificate = certificate
.try_into()
.map_err(|_| NodeError::UnexpectedCertificateValue)?;
for confirmed_block_certificate in remote_certificates {
let block = &confirmed_block_certificate.inner().executed_block().block;
let sender_chain_id = block.chain_id;
let height = block.height;
let epoch = block.epoch;
match self.check_certificate(max_epoch, &committees, &confirmed_block_certificate)? {
CheckCertificateResult::FutureEpoch => {
warn!(
Expand Down
2 changes: 1 addition & 1 deletion linera-core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub trait ValidatorNode {
async fn download_certificates(
&self,
hashes: Vec<CryptoHash>,
) -> Result<Vec<Certificate>, NodeError>;
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError>;

/// Returns the hash of the `Certificate` that last used a blob.
async fn blob_last_used_by(&self, blob_id: BlobId) -> Result<CryptoHash, NodeError>;
Expand Down
2 changes: 1 addition & 1 deletion linera-core/src/remote_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl<N: ValidatorNode> RemoteNode<N> {
pub async fn download_certificates(
&self,
hashes: Vec<CryptoHash>,
) -> Result<Vec<Certificate>, NodeError> {
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
if hashes.is_empty() {
return Ok(Vec::new());
}
Expand Down
5 changes: 2 additions & 3 deletions linera-core/src/unit_tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use linera_base::{
};
use linera_chain::{
data_types::BlockProposal,
types::{Certificate, ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
types::{ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
};
use linera_execution::{
committee::{Committee, ValidatorName},
Expand Down Expand Up @@ -176,12 +176,11 @@ where
async fn download_certificates(
&self,
hashes: Vec<CryptoHash>,
) -> Result<Vec<Certificate>, NodeError> {
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
self.spawn_and_receive(move |validator, sender| {
validator.do_download_certificates(hashes, sender)
})
.await
.map(|certs| certs.into_iter().map(Certificate::from).collect())
}

async fn blob_last_used_by(&self, blob_id: BlobId) -> Result<CryptoHash, NodeError> {
Expand Down
2 changes: 1 addition & 1 deletion linera-rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl ValidatorNode for Client {
async fn download_certificates(
&self,
hashes: Vec<CryptoHash>,
) -> Result<Vec<Certificate>, NodeError> {
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
Ok(match self {
Client::Grpc(grpc_client) => grpc_client.download_certificates(hashes).await?,

Expand Down
13 changes: 10 additions & 3 deletions linera-rpc/src/grpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,21 @@ impl ValidatorNode for GrpcClient {
async fn download_certificates(
&self,
hashes: Vec<CryptoHash>,
) -> Result<Vec<Certificate>, NodeError> {
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
let mut missing_hashes = hashes;
let mut certs_collected = Vec::with_capacity(missing_hashes.len());
loop {
// Macro doesn't compile if we pass `missing_hashes.clone()` directly to `client_delegate!`.
let missing = missing_hashes.clone();
let mut received: Vec<Certificate> =
client_delegate!(self, download_certificates, missing)?.try_into()?;
let mut received: Vec<ConfirmedBlockCertificate> = Vec::<Certificate>::try_from(
client_delegate!(self, download_certificates, missing)?,
)?
.into_iter()
.map(|cert| {
ConfirmedBlockCertificate::try_from(cert)
.map_err(|_| NodeError::UnexpectedCertificateValue)
})
.collect::<Result<_, _>>()?;

// In the case of the server not returning any certificates, we break the loop.
if received.is_empty() {
Expand Down
12 changes: 9 additions & 3 deletions linera-rpc/src/simple/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,15 @@ impl ValidatorNode for SimpleClient {
async fn download_certificates(
&self,
hashes: Vec<CryptoHash>,
) -> Result<Vec<Certificate>, NodeError> {
self.query(RpcMessage::DownloadCertificates(Box::new(hashes)))
.await
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
self.query::<Vec<Certificate>>(RpcMessage::DownloadCertificates(Box::new(hashes)))
.await?
.into_iter()
.map(|cert| {
cert.try_into()
.map_err(|_| NodeError::UnexpectedCertificateValue)
})
.collect()
}

async fn blob_last_used_by(&self, blob_id: BlobId) -> Result<CryptoHash, NodeError> {
Expand Down
4 changes: 2 additions & 2 deletions linera-service/src/schema_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use linera_base::{
};
use linera_chain::{
data_types::BlockProposal,
types::{Certificate, ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
types::{ConfirmedBlockCertificate, GenericCertificate, LiteCertificate},
};
use linera_client::{
chain_listener::{ChainListenerConfig, ClientContext},
Expand Down Expand Up @@ -93,7 +93,7 @@ impl ValidatorNode for DummyValidatorNode {
async fn download_certificates(
&self,
_: Vec<CryptoHash>,
) -> Result<Vec<Certificate>, NodeError> {
) -> Result<Vec<ConfirmedBlockCertificate>, NodeError> {
Err(NodeError::UnexpectedMessage)
}

Expand Down

0 comments on commit f8cb708

Please sign in to comment.