Skip to content

Commit f39d804

Browse files
committed
[qs] send proof v2 support with flag
1 parent aa068dc commit f39d804

File tree

8 files changed

+80
-29
lines changed

8 files changed

+80
-29
lines changed

config/src/config/quorum_store_config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ pub struct QuorumStoreConfig {
9999
pub enable_opt_quorum_store: bool,
100100
pub opt_qs_minimum_batch_age_usecs: u64,
101101
pub enable_payload_v2: bool,
102+
/// Boolean flag that controls the usage of `BatchInfoExt::V1`
103+
pub enable_proof_v2: bool,
102104
}
103105

104106
impl Default for QuorumStoreConfig {
@@ -140,6 +142,7 @@ impl Default for QuorumStoreConfig {
140142
enable_opt_quorum_store: true,
141143
opt_qs_minimum_batch_age_usecs: Duration::from_millis(50).as_micros() as u64,
142144
enable_payload_v2: false,
145+
enable_proof_v2: false,
143146
}
144147
}
145148
}

consensus/src/network.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use aptos_consensus_types::{
2929
order_vote_msg::OrderVoteMsg,
3030
pipeline::{commit_decision::CommitDecision, commit_vote::CommitVote},
3131
proof_of_store::{
32-
BatchInfo, ProofOfStore, ProofOfStoreMsg, SignedBatchInfo, SignedBatchInfoMsg,
32+
BatchInfo, BatchInfoExt, ProofOfStore, ProofOfStoreMsg, SignedBatchInfo, SignedBatchInfoMsg,
3333
},
3434
proposal_msg::ProposalMsg,
3535
round_timeout::RoundTimeoutMsg,
@@ -212,9 +212,14 @@ pub trait QuorumStoreSender: Send + Clone {
212212

213213
async fn broadcast_proof_of_store_msg(&mut self, proof_of_stores: Vec<ProofOfStore<BatchInfo>>);
214214

215+
async fn broadcast_proof_of_store_msg_v2(
216+
&mut self,
217+
proof_of_stores: Vec<ProofOfStore<BatchInfoExt>>,
218+
);
219+
215220
async fn send_proof_of_store_msg_to_self(
216221
&mut self,
217-
proof_of_stores: Vec<ProofOfStore<BatchInfo>>,
222+
proof_of_stores: Vec<ProofOfStore<BatchInfoExt>>,
218223
);
219224
}
220225

@@ -582,9 +587,15 @@ impl QuorumStoreSender for NetworkSender {
582587
self.broadcast(msg).await
583588
}
584589

585-
async fn send_proof_of_store_msg_to_self(&mut self, proofs: Vec<ProofOfStore<BatchInfo>>) {
590+
async fn broadcast_proof_of_store_msg_v2(&mut self, proofs: Vec<ProofOfStore<BatchInfoExt>>) {
586591
fail_point!("consensus::send::proof_of_store", |_| ());
587-
let msg = ConsensusMsg::ProofOfStoreMsg(Box::new(ProofOfStoreMsg::new(proofs)));
592+
let msg = ConsensusMsg::ProofOfStoreMsgV2(Box::new(ProofOfStoreMsg::new(proofs)));
593+
self.broadcast(msg).await
594+
}
595+
596+
async fn send_proof_of_store_msg_to_self(&mut self, proofs: Vec<ProofOfStore<BatchInfoExt>>) {
597+
fail_point!("consensus::send::proof_of_store", |_| ());
598+
let msg = ConsensusMsg::ProofOfStoreMsgV2(Box::new(ProofOfStoreMsg::new(proofs)));
588599
self.send(msg, vec![self.author]).await
589600
}
590601
}

consensus/src/quorum_store/batch_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
},
1313
};
1414
use anyhow::bail;
15-
use aptos_consensus_types::proof_of_store::{BatchInfo, SignedBatchInfo};
15+
use aptos_consensus_types::proof_of_store::{BatchInfo, BatchInfoExt, SignedBatchInfo};
1616
use aptos_crypto::{CryptoMaterialError, HashValue};
1717
use aptos_executor_types::{ExecutorError, ExecutorResult};
1818
use aptos_infallible::Mutex;

consensus/src/quorum_store/proof_coordinator.rs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ pub(crate) struct ProofCoordinator {
171171
proof_cache: ProofCache,
172172
broadcast_proofs: bool,
173173
batch_expiry_gap_when_init_usecs: u64,
174+
enable_proof_v2_msg: bool,
174175
}
175176

176177
//PoQS builder object - gather signed digest to form PoQS
@@ -183,6 +184,7 @@ impl ProofCoordinator {
183184
proof_cache: ProofCache,
184185
broadcast_proofs: bool,
185186
batch_expiry_gap_when_init_usecs: u64,
187+
enable_proof_v2_msg: bool,
186188
) -> Self {
187189
Self {
188190
peer_id,
@@ -195,6 +197,7 @@ impl ProofCoordinator {
195197
proof_cache,
196198
broadcast_proofs,
197199
batch_expiry_gap_when_init_usecs,
200+
enable_proof_v2_msg,
198201
}
199202
}
200203

@@ -374,45 +377,56 @@ impl ProofCoordinator {
374377
let approx_created_ts_usecs = signed_batch_info
375378
.expiration()
376379
.saturating_sub(self.batch_expiry_gap_when_init_usecs);
380+
let self_peer_id = self.peer_id;
381+
let enable_broadcast_proofs = self.broadcast_proofs;
382+
let enable_proof_v2_msg = self.enable_proof_v2_msg;
377383

378-
let mut proofs = vec![];
379-
for signed_batch_info in signed_batch_infos.into_iter() {
384+
let mut proofs_iter = signed_batch_infos.into_iter().filter_map(|signed_batch_info| {
380385
let peer_id = signed_batch_info.signer();
381386
let digest = *signed_batch_info.digest();
382387
let batch_id = signed_batch_info.batch_id();
383388
match self.add_signature(signed_batch_info, &validator_verifier) {
384-
Ok(result) => {
385-
if let Some(proof) = result {
386-
debug!(
387-
LogSchema::new(LogEvent::ProofOfStoreReady),
388-
digest = digest,
389-
batch_id = batch_id.id,
390-
);
391-
let (info, sig) = proof.unpack();
392-
proofs.push(ProofOfStore::new(info.info().clone(), sig));
393-
}
389+
Ok(Some(proof)) => {
390+
debug!(
391+
LogSchema::new(LogEvent::ProofOfStoreReady),
392+
digest = digest,
393+
batch_id = batch_id.id,
394+
);
395+
Some(proof)
394396
},
397+
Ok(None) => None,
395398
Err(e) => {
396399
// Can happen if we already garbage collected, the commit notification is late, or the peer is misbehaving.
397400
if peer_id == self.peer_id {
398401
info!("QS: could not add signature from self, digest = {}, batch_id = {}, err = {:?}", digest, batch_id, e);
399402
} else {
400403
debug!("QS: could not add signature from peer {}, digest = {}, batch_id = {}, err = {:?}", peer_id, digest, batch_id, e);
401404
}
405+
None
402406
},
403407
}
404-
}
405-
if let Some(value) = self.batch_info_to_proof.get_mut(&info) {
406-
value.observe_voting_pct(approx_created_ts_usecs, &validator_verifier);
407-
}
408-
if !proofs.is_empty() {
409-
observe_batch(approx_created_ts_usecs, self.peer_id, BatchStage::POS_FORMED);
410-
if self.broadcast_proofs {
411-
network_sender.broadcast_proof_of_store_msg(proofs).await;
408+
}).peekable();
409+
if proofs_iter.peek().is_some() {
410+
observe_batch(approx_created_ts_usecs, self_peer_id, BatchStage::POS_FORMED);
411+
if enable_broadcast_proofs {
412+
if enable_proof_v2_msg {
413+
let proofs: Vec<_> = proofs_iter.collect();
414+
network_sender.broadcast_proof_of_store_msg_v2(proofs).await;
415+
} else {
416+
let proofs: Vec<_> = proofs_iter.map(|proof| {
417+
let (info, sig) = proof.unpack();
418+
ProofOfStore::new(info.info().clone(), sig)
419+
}).collect();
420+
network_sender.broadcast_proof_of_store_msg(proofs).await;
421+
}
412422
} else {
423+
let proofs: Vec<_> = proofs_iter.collect();
413424
network_sender.send_proof_of_store_msg_to_self(proofs).await;
414425
}
415426
}
427+
if let Some(value) = self.batch_info_to_proof.get_mut(&info) {
428+
value.observe_voting_pct(approx_created_ts_usecs, &validator_verifier);
429+
}
416430
},
417431
}
418432
}),

consensus/src/quorum_store/quorum_store_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ impl InnerBuilder {
351351
self.proof_cache,
352352
self.broadcast_proofs,
353353
self.config.batch_expiry_gap_when_init_usecs,
354+
self.config.enable_proof_v2,
354355
);
355356
spawn_named!(
356357
"proof_coordinator",

consensus/src/quorum_store/tests/batch_requester_test.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
};
1212
use aptos_consensus_types::{
1313
common::Author,
14-
proof_of_store::{BatchInfo, ProofOfStore, SignedBatchInfo},
14+
proof_of_store::{BatchInfo, BatchInfoExt, ProofOfStore, SignedBatchInfo},
1515
};
1616
use aptos_crypto::HashValue;
1717
use aptos_infallible::Mutex;
@@ -73,9 +73,16 @@ impl QuorumStoreSender for MockBatchRequester {
7373
unimplemented!()
7474
}
7575

76+
async fn broadcast_proof_of_store_msg_v2(
77+
&mut self,
78+
_proof_of_stores: Vec<ProofOfStore<BatchInfoExt>>,
79+
) {
80+
unimplemented!()
81+
}
82+
7683
async fn send_proof_of_store_msg_to_self(
7784
&mut self,
78-
_proof_of_stores: Vec<ProofOfStore<BatchInfo>>,
85+
_proof_of_stores: Vec<ProofOfStore<BatchInfoExt>>,
7986
) {
8087
unimplemented!()
8188
}

consensus/src/quorum_store/tests/proof_coordinator_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ async fn test_proof_coordinator_basic() {
6060
proof_cache.clone(),
6161
true,
6262
10,
63+
false,
6364
);
6465
let (proof_coordinator_tx, proof_coordinator_rx) = channel(100);
6566
let (tx, mut rx) = channel(100);
@@ -113,6 +114,7 @@ async fn test_proof_coordinator_with_unverified_signatures() {
113114
proof_cache.clone(),
114115
true,
115116
10,
117+
false,
116118
);
117119
let (proof_coordinator_tx, proof_coordinator_rx) = channel(100);
118120
let (tx, mut rx) = channel(100);

consensus/src/test_utils/mock_quorum_store_sender.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
use aptos_consensus_types::{
1010
common::Author,
1111
proof_of_store::{
12-
BatchInfo, ProofOfStore, ProofOfStoreMsg, SignedBatchInfo, SignedBatchInfoMsg,
12+
BatchInfo, BatchInfoExt, ProofOfStore, ProofOfStoreMsg, SignedBatchInfo, SignedBatchInfoMsg,
1313
},
1414
};
1515
use std::time::Duration;
@@ -72,8 +72,21 @@ impl QuorumStoreSender for MockQuorumStoreSender {
7272

7373
async fn send_proof_of_store_msg_to_self(
7474
&mut self,
75-
_proof_of_stores: Vec<ProofOfStore<BatchInfo>>,
75+
_proof_of_stores: Vec<ProofOfStore<BatchInfoExt>>,
7676
) {
7777
unimplemented!()
7878
}
79+
80+
async fn broadcast_proof_of_store_msg_v2(
81+
&mut self,
82+
proof_of_stores: Vec<ProofOfStore<BatchInfoExt>>,
83+
) {
84+
self.tx
85+
.send((
86+
ConsensusMsg::ProofOfStoreMsgV2(Box::new(ProofOfStoreMsg::new(proof_of_stores))),
87+
vec![],
88+
))
89+
.await
90+
.expect("We should be able to send the proof of store message");
91+
}
7992
}

0 commit comments

Comments
 (0)