Skip to content

Commit db93ab6

Browse files
committed
opt proposal
1 parent 7ff4f18 commit db93ab6

18 files changed

+974
-31
lines changed

config/src/config/consensus_config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use serde::{Deserialize, Serialize};
1414
use std::path::PathBuf;
1515

1616
// NOTE: when changing, make sure to update QuorumStoreBackPressureConfig::backlog_txn_limit_count as well.
17-
const MAX_SENDING_BLOCK_TXNS_AFTER_FILTERING: u64 = 3000;
18-
const MAX_SENDING_BLOCK_TXNS: u64 = 7000;
17+
const MAX_SENDING_BLOCK_TXNS_AFTER_FILTERING: u64 = 1700;
18+
const MAX_SENDING_BLOCK_TXNS: u64 = 4000;
1919
pub(crate) static MAX_RECEIVING_BLOCK_TXNS: Lazy<u64> =
2020
Lazy::new(|| 10000.max(2 * MAX_SENDING_BLOCK_TXNS));
2121
// stop reducing size at this point, so 1MB transactions can still go through
@@ -324,7 +324,7 @@ impl Default for ConsensusConfig {
324324
max_pending_rounds_in_commit_vote_cache: 100,
325325
optimistic_sig_verification: true,
326326
enable_round_timeout_msg: true,
327-
enable_pipeline: false,
327+
enable_pipeline: true,
328328
}
329329
}
330330
}

consensus/consensus-types/src/block.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
use crate::{
66
block_data::{BlockData, BlockType},
77
common::{Author, Payload, Round},
8+
opt_block_data::OptBlockData,
89
quorum_cert::QuorumCert,
910
};
10-
use anyhow::{bail, ensure, format_err};
11+
use anyhow::{bail, ensure, format_err, Result};
1112
use aptos_bitvec::BitVec;
1213
use aptos_crypto::{bls12381, hash::CryptoHash, HashValue};
1314
use aptos_infallible::duration_since_epoch;
@@ -168,6 +169,10 @@ impl Block {
168169
self.block_data.is_nil_block()
169170
}
170171

172+
pub fn is_opt_block(&self) -> bool {
173+
self.block_data.is_opt_block()
174+
}
175+
171176
#[cfg(any(test, feature = "fuzzing"))]
172177
pub fn make_genesis_block() -> Self {
173178
Self::make_genesis_block_from_ledger_info(&LedgerInfo::mock_genesis(None))
@@ -308,6 +313,19 @@ impl Block {
308313
}
309314
}
310315

316+
pub fn new_from_opt(
317+
block_data: OptBlockData,
318+
quorum_cert: QuorumCert,
319+
failed_authors: Vec<(Round, Author)>,
320+
) -> Result<Self> {
321+
let block_data = BlockData::new_from_opt(block_data, quorum_cert, failed_authors)?;
322+
Ok(Block {
323+
id: block_data.hash(),
324+
block_data,
325+
signature: None,
326+
})
327+
}
328+
311329
pub fn validator_txns(&self) -> Option<&Vec<ValidatorTransaction>> {
312330
self.block_data.validator_txns()
313331
}
@@ -334,6 +352,13 @@ impl Block {
334352
validator.verify(*proposal_ext.author(), &self.block_data, signature)?;
335353
self.quorum_cert().verify(validator)
336354
},
355+
BlockType::OptProposal { .. } => {
356+
// Optimistic proposal is not signed by proposer
357+
self.block_data()
358+
.grandparent_qc()
359+
.map_or(Ok(()), |qc| qc.verify(validator))?;
360+
self.quorum_cert().verify(validator)
361+
},
337362
BlockType::DAGBlock { .. } => bail!("We should not accept DAG block from others"),
338363
}
339364
}
@@ -442,6 +467,8 @@ impl Block {
442467
fn previous_bitvec(&self) -> BitVec {
443468
if let BlockType::DAGBlock { parents_bitvec, .. } = self.block_data.block_type() {
444469
parents_bitvec.clone()
470+
} else if let BlockType::OptProposal { grandparent_qc, .. } = self.block_data.block_type() {
471+
grandparent_qc.ledger_info().get_voters_bitvec().clone()
445472
} else {
446473
self.quorum_cert().ledger_info().get_voters_bitvec().clone()
447474
}

consensus/consensus-types/src/block_data.rs

+106-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
use crate::{
66
common::{Author, Payload, Round},
7+
opt_block_data::OptBlockData,
78
proposal_ext::ProposalExt,
89
quorum_cert::QuorumCert,
910
vote_data::VoteData,
1011
};
12+
use anyhow::{bail, Result};
1113
use aptos_bitvec::BitVec;
12-
use aptos_crypto::hash::HashValue;
13-
use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher};
14+
use aptos_crypto::{
15+
hash::{CryptoHash, CryptoHasher},
16+
HashValue,
17+
};
18+
use aptos_crypto_derive::CryptoHasher;
1419
use aptos_types::{
1520
aggregate_signature::AggregateSignature,
1621
block_info::BlockInfo,
@@ -49,6 +54,21 @@ pub enum BlockType {
4954
/// Proposal with extensions (e.g. system transactions).
5055
ProposalExt(ProposalExt),
5156

57+
/// Optimistic proposal
58+
OptProposal {
59+
validator_txns: Vec<ValidatorTransaction>,
60+
/// T of the block (e.g. one or more transaction(s)
61+
payload: Payload,
62+
/// Author of the block that can be validated by the author's public key and the signature
63+
author: Author,
64+
/// Failed authors from the parent's block to this block.
65+
/// I.e. the list of consecutive proposers from the
66+
/// immediately preceeding rounds that didn't produce a successful block.
67+
failed_authors: Vec<(Round, Author)>,
68+
/// Grandparent QC, used to generate previous_bitvec
69+
grandparent_qc: QuorumCert,
70+
},
71+
5272
/// A virtual block that's constructed by nodes from DAG, this is purely a local thing so
5373
/// we hide it from serde
5474
#[serde(skip_deserializing)]
@@ -63,7 +83,7 @@ pub enum BlockType {
6383
},
6484
}
6585

66-
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, CryptoHasher, BCSCryptoHash)]
86+
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, CryptoHasher)]
6787
/// Block has the core data of a consensus block that should be persistent when necessary.
6888
/// Each block must know the id of its parent and keep the QuorurmCertificate to that parent.
6989
pub struct BlockData {
@@ -96,12 +116,34 @@ pub struct BlockData {
96116
block_type: BlockType,
97117
}
98118

119+
impl CryptoHash for BlockData {
120+
type Hasher = BlockDataHasher;
121+
122+
fn hash(&self) -> HashValue {
123+
let mut state = Self::Hasher::default();
124+
if self.is_opt_block() {
125+
state.update(&self.epoch.to_be_bytes());
126+
state.update(&self.round.to_be_bytes());
127+
state.update(&self.timestamp_usecs.to_be_bytes());
128+
state.update(
129+
&bcs::to_bytes(self.quorum_cert().vote_data())
130+
.expect("Unable to serialize quorum cert vote data"),
131+
);
132+
state
133+
.update(&bcs::to_bytes(self.block_type()).expect("Unable to serialize block type"));
134+
} else {
135+
state.update(&bcs::to_bytes(self).expect("Failed to serialize BlockData"));
136+
}
137+
state.finish()
138+
}
139+
}
140+
99141
impl BlockData {
100142
pub fn author(&self) -> Option<Author> {
101143
match &self.block_type {
102-
BlockType::Proposal { author, .. } | BlockType::DAGBlock { author, .. } => {
103-
Some(*author)
104-
},
144+
BlockType::Proposal { author, .. }
145+
| BlockType::OptProposal { author, .. }
146+
| BlockType::DAGBlock { author, .. } => Some(*author),
105147
BlockType::ProposalExt(p) => Some(*p.author()),
106148
_ => None,
107149
}
@@ -126,11 +168,18 @@ impl BlockData {
126168
}
127169
}
128170

171+
pub fn grandparent_qc(&self) -> Result<QuorumCert> {
172+
match &self.block_type {
173+
BlockType::OptProposal { grandparent_qc, .. } => Ok(grandparent_qc.clone()),
174+
_ => bail!("Invalid block type"),
175+
}
176+
}
177+
129178
pub fn payload(&self) -> Option<&Payload> {
130179
match &self.block_type {
131-
BlockType::Proposal { payload, .. } | BlockType::DAGBlock { payload, .. } => {
132-
Some(payload)
133-
},
180+
BlockType::Proposal { payload, .. }
181+
| BlockType::DAGBlock { payload, .. }
182+
| BlockType::OptProposal { payload, .. } => Some(payload),
134183
BlockType::ProposalExt(p) => p.payload(),
135184
_ => None,
136185
}
@@ -141,6 +190,9 @@ impl BlockData {
141190
BlockType::ProposalExt(proposal_ext) => proposal_ext.validator_txns(),
142191
BlockType::Proposal { .. } | BlockType::NilBlock { .. } | BlockType::Genesis => None,
143192
BlockType::DAGBlock { validator_txns, .. } => Some(validator_txns),
193+
BlockType::OptProposal { validator_txns, .. } => {
194+
(!validator_txns.is_empty()).then_some(validator_txns)
195+
},
144196
}
145197
}
146198

@@ -176,13 +228,18 @@ impl BlockData {
176228
matches!(self.block_type, BlockType::NilBlock { .. })
177229
}
178230

231+
pub fn is_opt_block(&self) -> bool {
232+
matches!(self.block_type, BlockType::OptProposal { .. })
233+
}
234+
179235
/// the list of consecutive proposers from the immediately preceeding
180236
/// rounds that didn't produce a successful block
181237
pub fn failed_authors(&self) -> Option<&Vec<(Round, Author)>> {
182238
match &self.block_type {
183239
BlockType::Proposal { failed_authors, .. }
184240
| BlockType::NilBlock { failed_authors, .. }
185-
| BlockType::DAGBlock { failed_authors, .. } => Some(failed_authors),
241+
| BlockType::DAGBlock { failed_authors, .. }
242+
| BlockType::OptProposal { failed_authors, .. } => Some(failed_authors),
186243
BlockType::ProposalExt(p) => Some(p.failed_authors()),
187244
BlockType::Genesis => None,
188245
}
@@ -353,6 +410,45 @@ impl BlockData {
353410
}
354411
}
355412

413+
// Converting OptBlockData to BlockData
414+
// by adding QC and failed_authors
415+
pub fn new_from_opt(
416+
opt_block_data: OptBlockData,
417+
quorum_cert: QuorumCert,
418+
new_failed_authors: Vec<(Round, Author)>,
419+
) -> Result<Self> {
420+
let OptBlockData {
421+
epoch,
422+
round,
423+
timestamp_usecs,
424+
parent_id: _,
425+
block_type,
426+
} = opt_block_data;
427+
let block_type = match block_type {
428+
BlockType::OptProposal {
429+
validator_txns,
430+
payload,
431+
author,
432+
failed_authors: _,
433+
grandparent_qc,
434+
} => BlockType::OptProposal {
435+
validator_txns,
436+
payload,
437+
author,
438+
failed_authors: new_failed_authors,
439+
grandparent_qc,
440+
},
441+
_ => bail!("Invalid block type"),
442+
};
443+
Ok(Self {
444+
epoch,
445+
round,
446+
timestamp_usecs,
447+
quorum_cert,
448+
block_type,
449+
})
450+
}
451+
356452
/// It's a reconfiguration suffix block if the parent block's executed state indicates next epoch.
357453
pub fn is_reconfiguration_suffix(&self) -> bool {
358454
self.quorum_cert.certified_block().has_reconfiguration()

consensus/consensus-types/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub mod block_data;
99
pub mod block_retrieval;
1010
pub mod common;
1111
pub mod epoch_retrieval;
12+
pub mod opt_block_data;
13+
pub mod opt_proposal_msg;
1214
pub mod order_vote;
1315
pub mod order_vote_msg;
1416
pub mod order_vote_proposal;

0 commit comments

Comments
 (0)