Skip to content

Commit 9c0c4dd

Browse files
authored
Speed up find_received_certificates. (linera-io#1384)
Look them up locally first before trying to download certificates.
1 parent 6d21bfb commit 9c0c4dd

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

linera-core/src/client.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,13 @@ where
517517
{
518518
debug!("Accepting redundant notification for new message");
519519
}
520-
if let Err(e) =
521-
Self::find_received_certificates_from_validator(this.clone(), name, node).await
520+
if let Err(e) = Self::find_received_certificates_from_validator(
521+
this.clone(),
522+
name,
523+
node,
524+
local_node.clone(),
525+
)
526+
.await
522527
{
523528
error!("Fail to process notification: {e}");
524529
}
@@ -852,6 +857,7 @@ where
852857
committees: BTreeMap<Epoch, Committee>,
853858
max_epoch: Epoch,
854859
mut node: A,
860+
mut node_client: LocalNodeClient<S>,
855861
) -> Result<(ValidatorName, u64, Vec<Certificate>), NodeError>
856862
where
857863
A: ValidatorNode + Send + Sync + 'static + Clone,
@@ -866,6 +872,16 @@ where
866872
for entry in response.info.requested_received_log {
867873
let query = ChainInfoQuery::new(entry.chain_id)
868874
.with_sent_certificates_in_range(BlockHeightRange::single(entry.height));
875+
let local_response = node_client
876+
.handle_chain_info_query(query.clone())
877+
.await
878+
.map_err(|error| NodeError::LocalNodeQuery {
879+
error: error.to_string(),
880+
})?;
881+
if !local_response.info.requested_sent_certificates.is_empty() {
882+
new_tracker += 1;
883+
continue;
884+
}
869885

870886
let mut response = node.handle_chain_info_query(query).await?;
871887
let Some(certificate) = response.info.requested_sent_certificates.pop() else {
@@ -961,6 +977,7 @@ where
961977
self.node_client
962978
.synchronize_chain_state(nodes.clone(), self.admin_id)
963979
.await?;
980+
let node_client = self.node_client.clone();
964981
// Now we should have a complete view of all committees in the system.
965982
let (committees, max_epoch) = self.known_committees().await?;
966983
// Proceed to downloading received certificates.
@@ -972,8 +989,15 @@ where
972989
|name, node| {
973990
let tracker = *trackers.get(&name).unwrap_or(&0);
974991
let committees = committees.clone();
992+
let node_client = node_client.clone();
975993
Box::pin(Self::synchronize_received_certificates_from_validator(
976-
chain_id, name, tracker, committees, max_epoch, node,
994+
chain_id,
995+
name,
996+
tracker,
997+
committees,
998+
max_epoch,
999+
node,
1000+
node_client,
9771001
))
9781002
},
9791003
)
@@ -1005,6 +1029,7 @@ where
10051029
this: Arc<Mutex<Self>>,
10061030
name: ValidatorName,
10071031
node: A,
1032+
node_client: LocalNodeClient<S>,
10081033
) -> Result<(), ChainClientError>
10091034
where
10101035
A: ValidatorNode + Send + Sync + 'static + Clone,
@@ -1025,6 +1050,7 @@ where
10251050
committees,
10261051
max_epoch,
10271052
node,
1053+
node_client,
10281054
)
10291055
.await?;
10301056
// Process received certificates. If the client state has changed during the

linera-core/src/node.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ pub enum NodeError {
171171
SubscriptionError { transport: String },
172172
#[error("Failed to subscribe; tonic status: {status}")]
173173
SubscriptionFailed { status: String },
174+
175+
#[error("Failed to make a chain info query on the local node: {error}")]
176+
LocalNodeQuery { error: String },
174177
}
175178

176179
impl CrossChainMessageDelivery {

linera-rpc/tests/staged/formats.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,10 @@ NodeError:
508508
SubscriptionFailed:
509509
STRUCT:
510510
- status: STR
511+
19:
512+
LocalNodeQuery:
513+
STRUCT:
514+
- error: STR
511515
Operation:
512516
ENUM:
513517
0:

0 commit comments

Comments
 (0)