Skip to content

Commit 2053b61

Browse files
authored
Rename Proposal back to ProposedBlock. (#3169)
## Motivation The discussion #3101 (comment) was never resolved; a proposal has a content, which has a proposal. ## Proposal Rename `Proposal` to `ProposedBlock`, to distinguish it from the outer type. (I also added some destructuring in `Block::new`, because I ran into a naming conflict and this way the compiler will warn us if we add any fields and forget them there.) ## Test Plan Only renaming. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - Related to #3101 - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 903b975 commit 2053b61

File tree

25 files changed

+192
-160
lines changed

25 files changed

+192
-160
lines changed

linera-chain/src/block.rs

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use thiserror::Error;
2121
use crate::{
2222
data_types::{
2323
BlockExecutionOutcome, EventRecord, ExecutedBlock, IncomingBundle, Medium, MessageBundle,
24-
OutgoingMessage, Proposal,
24+
OutgoingMessage, ProposedBlock,
2525
},
2626
ChainError,
2727
};
@@ -34,7 +34,7 @@ pub struct ValidatedBlock(Hashed<Block>);
3434
impl ValidatedBlock {
3535
/// Creates a new `ValidatedBlock` from an `ExecutedBlock`.
3636
pub fn new(block: ExecutedBlock) -> Self {
37-
Self(Hashed::new(Block::new(block.proposal, block.outcome)))
37+
Self(Hashed::new(Block::new(block.block, block.outcome)))
3838
}
3939

4040
pub fn from_hashed(block: Hashed<Block>) -> Self {
@@ -95,7 +95,7 @@ impl<'de> BcsHashable<'de> for ConfirmedBlock {}
9595

9696
impl ConfirmedBlock {
9797
pub fn new(block: ExecutedBlock) -> Self {
98-
Self(Hashed::new(Block::new(block.proposal, block.outcome)))
98+
Self(Hashed::new(Block::new(block.block, block.outcome)))
9999
}
100100

101101
pub fn from_hashed(block: Hashed<Block>) -> Self {
@@ -333,21 +333,21 @@ pub struct BlockBody {
333333
}
334334

335335
impl Block {
336-
pub fn new(proposal: Proposal, outcome: BlockExecutionOutcome) -> Self {
337-
let bundles_hash = hashing::hash_vec(&proposal.incoming_bundles);
336+
pub fn new(block: ProposedBlock, outcome: BlockExecutionOutcome) -> Self {
337+
let bundles_hash = hashing::hash_vec(&block.incoming_bundles);
338338
let messages_hash = hashing::hash_vec_vec(&outcome.messages);
339-
let operations_hash = hashing::hash_vec(&proposal.operations);
339+
let operations_hash = hashing::hash_vec(&block.operations);
340340
let oracle_responses_hash = hashing::hash_vec_vec(&outcome.oracle_responses);
341341
let events_hash = hashing::hash_vec_vec(&outcome.events);
342342

343343
let header = BlockHeader {
344-
chain_id: proposal.chain_id,
345-
epoch: proposal.epoch,
346-
height: proposal.height,
347-
timestamp: proposal.timestamp,
344+
chain_id: block.chain_id,
345+
epoch: block.epoch,
346+
height: block.height,
347+
timestamp: block.timestamp,
348348
state_hash: outcome.state_hash,
349-
previous_block_hash: proposal.previous_block_hash,
350-
authenticated_signer: proposal.authenticated_signer,
349+
previous_block_hash: block.previous_block_hash,
350+
authenticated_signer: block.authenticated_signer,
351351
bundles_hash,
352352
operations_hash,
353353
messages_hash,
@@ -356,8 +356,8 @@ impl Block {
356356
};
357357

358358
let body = BlockBody {
359-
incoming_bundles: proposal.incoming_bundles,
360-
operations: proposal.operations,
359+
incoming_bundles: block.incoming_bundles,
360+
operations: block.operations,
361361
messages: outcome.messages,
362362
oracle_responses: outcome.oracle_responses,
363363
events: outcome.events,
@@ -510,25 +510,51 @@ impl Block {
510510

511511
impl From<Block> for ExecutedBlock {
512512
fn from(block: Block) -> Self {
513-
let proposal = Proposal {
514-
chain_id: block.header.chain_id,
515-
epoch: block.header.epoch,
516-
height: block.header.height,
517-
timestamp: block.header.timestamp,
518-
incoming_bundles: block.body.incoming_bundles,
519-
operations: block.body.operations,
520-
authenticated_signer: block.header.authenticated_signer,
521-
previous_block_hash: block.header.previous_block_hash,
513+
let Block {
514+
header:
515+
BlockHeader {
516+
chain_id,
517+
epoch,
518+
height,
519+
timestamp,
520+
state_hash,
521+
previous_block_hash,
522+
authenticated_signer,
523+
bundles_hash: _,
524+
operations_hash: _,
525+
messages_hash: _,
526+
oracle_responses_hash: _,
527+
events_hash: _,
528+
},
529+
body:
530+
BlockBody {
531+
incoming_bundles,
532+
operations,
533+
messages,
534+
oracle_responses,
535+
events,
536+
},
537+
} = block;
538+
539+
let block = ProposedBlock {
540+
chain_id,
541+
epoch,
542+
height,
543+
timestamp,
544+
incoming_bundles,
545+
operations,
546+
authenticated_signer,
547+
previous_block_hash,
522548
};
523549

524550
let outcome = BlockExecutionOutcome {
525-
state_hash: block.header.state_hash,
526-
messages: block.body.messages,
527-
oracle_responses: block.body.oracle_responses,
528-
events: block.body.events,
551+
state_hash,
552+
messages,
553+
oracle_responses,
554+
events,
529555
};
530556

531-
ExecutedBlock { proposal, outcome }
557+
ExecutedBlock { block, outcome }
532558
}
533559
}
534560

linera-chain/src/chain.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ use serde::{Deserialize, Serialize};
4343
use crate::{
4444
data_types::{
4545
BlockExecutionOutcome, ChainAndHeight, ChannelFullName, EventRecord, IncomingBundle,
46-
MessageAction, MessageBundle, Origin, OutgoingMessage, PostedMessage, Proposal, Target,
47-
Transaction,
46+
MessageAction, MessageBundle, Origin, OutgoingMessage, PostedMessage, ProposedBlock,
47+
Target, Transaction,
4848
},
4949
inbox::{Cursor, InboxError, InboxStateView},
5050
manager::ChainManager,
@@ -247,7 +247,7 @@ pub struct ChainTipState {
247247
impl ChainTipState {
248248
/// Checks that the proposed block is suitable, i.e. at the expected height and with the
249249
/// expected parent.
250-
pub fn verify_block_chaining(&self, new_block: &Proposal) -> Result<(), ChainError> {
250+
pub fn verify_block_chaining(&self, new_block: &ProposedBlock) -> Result<(), ChainError> {
251251
ensure!(
252252
new_block.height == self.next_block_height,
253253
ChainError::UnexpectedBlockHeight {
@@ -282,7 +282,7 @@ impl ChainTipState {
282282
/// Checks if the measurement counters would be valid.
283283
pub fn verify_counters(
284284
&self,
285-
new_block: &Proposal,
285+
new_block: &ProposedBlock,
286286
outcome: &BlockExecutionOutcome,
287287
) -> Result<(), ChainError> {
288288
let num_incoming_bundles = u32::try_from(new_block.incoming_bundles.len())
@@ -664,7 +664,7 @@ where
664664
/// * Returns the outcome of the execution.
665665
pub async fn execute_block(
666666
&mut self,
667-
block: &Proposal,
667+
block: &ProposedBlock,
668668
local_time: Timestamp,
669669
replaying_oracle_responses: Option<Vec<Vec<OracleResponse>>>,
670670
) -> Result<BlockExecutionOutcome, ChainError> {
@@ -934,7 +934,7 @@ where
934934
message_id: MessageId,
935935
posted_message: &PostedMessage,
936936
incoming_bundle: &IncomingBundle,
937-
block: &Proposal,
937+
block: &ProposedBlock,
938938
txn_index: u32,
939939
local_time: Timestamp,
940940
txn_tracker: &mut TransactionTracker,
@@ -1247,11 +1247,11 @@ where
12471247
#[test]
12481248
fn empty_block_size() {
12491249
let executed_block = crate::data_types::ExecutedBlock {
1250-
proposal: crate::test::make_first_block(ChainId::root(0)),
1250+
block: crate::test::make_first_block(ChainId::root(0)),
12511251
outcome: crate::data_types::BlockExecutionOutcome::default(),
12521252
};
12531253
let size = bcs::serialized_size(&crate::block::Block::new(
1254-
executed_block.proposal,
1254+
executed_block.block,
12551255
executed_block.outcome,
12561256
))
12571257
.unwrap();

linera-chain/src/data_types.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod data_types_tests;
4848
/// received ahead of time in the inbox of the chain.
4949
/// * This constraint does not apply to the execution of confirmed blocks.
5050
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, SimpleObject)]
51-
pub struct Proposal {
51+
pub struct ProposedBlock {
5252
/// The chain to which this block belongs.
5353
pub chain_id: ChainId,
5454
/// The number identifying the current configuration.
@@ -76,7 +76,7 @@ pub struct Proposal {
7676
pub previous_block_hash: Option<CryptoHash>,
7777
}
7878

79-
impl Proposal {
79+
impl ProposedBlock {
8080
/// Returns all the published blob IDs in this block's operations.
8181
pub fn published_blob_ids(&self) -> BTreeSet<BlobId> {
8282
let mut blob_ids = BTreeSet::new();
@@ -400,14 +400,14 @@ impl OutgoingMessage {
400400
}
401401
}
402402

403-
/// A [`Proposal`], together with the outcome from its execution.
403+
/// A [`ProposedBlock`], together with the outcome from its execution.
404404
#[derive(Debug, PartialEq, Eq, Hash, Clone, SimpleObject)]
405405
pub struct ExecutedBlock {
406-
pub proposal: Proposal,
406+
pub block: ProposedBlock,
407407
pub outcome: BlockExecutionOutcome,
408408
}
409409

410-
/// The messages and the state hash resulting from a [`Proposal`]'s execution.
410+
/// The messages and the state hash resulting from a [`ProposedBlock`]'s execution.
411411
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, SimpleObject)]
412412
#[cfg_attr(with_testing, derive(Default))]
413413
pub struct BlockExecutionOutcome {
@@ -643,9 +643,9 @@ impl ExecutedBlock {
643643
certificate_hash: CryptoHash,
644644
) -> impl Iterator<Item = (Epoch, MessageBundle)> + 'a {
645645
let mut index = 0u32;
646-
let block_height = self.proposal.height;
647-
let block_timestamp = self.proposal.timestamp;
648-
let block_epoch = self.proposal.epoch;
646+
let block_height = self.block.height;
647+
let block_timestamp = self.block.timestamp;
648+
let block_epoch = self.block.epoch;
649649

650650
(0u32..)
651651
.zip(self.messages())
@@ -676,7 +676,7 @@ impl ExecutedBlock {
676676
operation_index: usize,
677677
message_index: u32,
678678
) -> Option<MessageId> {
679-
let block = &self.proposal;
679+
let block = &self.block;
680680
let transaction_index = block.incoming_bundles.len().checked_add(operation_index)?;
681681
if message_index
682682
>= u32::try_from(self.outcome.messages.get(transaction_index)?.len()).ok()?
@@ -702,7 +702,7 @@ impl ExecutedBlock {
702702
height,
703703
index,
704704
} = message_id;
705-
if self.proposal.chain_id != *chain_id || self.proposal.height != *height {
705+
if self.block.chain_id != *chain_id || self.block.height != *height {
706706
return None;
707707
}
708708
let mut index = usize::try_from(*index).ok()?;
@@ -718,28 +718,28 @@ impl ExecutedBlock {
718718
/// Returns the message ID belonging to the `index`th outgoing message in this block.
719719
pub fn message_id(&self, index: u32) -> MessageId {
720720
MessageId {
721-
chain_id: self.proposal.chain_id,
722-
height: self.proposal.height,
721+
chain_id: self.block.chain_id,
722+
height: self.block.height,
723723
index,
724724
}
725725
}
726726

727727
pub fn required_blob_ids(&self) -> HashSet<BlobId> {
728728
let mut blob_ids = self.outcome.oracle_blob_ids();
729-
blob_ids.extend(self.proposal.published_blob_ids());
729+
blob_ids.extend(self.block.published_blob_ids());
730730
blob_ids
731731
}
732732

733733
pub fn requires_blob(&self, blob_id: &BlobId) -> bool {
734734
self.outcome.oracle_blob_ids().contains(blob_id)
735-
|| self.proposal.published_blob_ids().contains(blob_id)
735+
|| self.block.published_blob_ids().contains(blob_id)
736736
}
737737
}
738738

739739
impl BlockExecutionOutcome {
740-
pub fn with(self, block: Proposal) -> ExecutedBlock {
740+
pub fn with(self, block: ProposedBlock) -> ExecutedBlock {
741741
ExecutedBlock {
742-
proposal: block,
742+
block,
743743
outcome: self,
744744
}
745745
}
@@ -768,7 +768,7 @@ impl BlockExecutionOutcome {
768768
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
769769
pub struct ProposalContent {
770770
/// The proposed block.
771-
pub proposal: Proposal,
771+
pub block: ProposedBlock,
772772
/// The consensus round in which this proposal is made.
773773
pub round: Round,
774774
/// If this is a retry from an earlier round, the execution outcome.
@@ -779,13 +779,13 @@ pub struct ProposalContent {
779779
impl BlockProposal {
780780
pub fn new_initial(
781781
round: Round,
782-
proposal: Proposal,
782+
block: ProposedBlock,
783783
secret: &KeyPair,
784784
blobs: Vec<Blob>,
785785
) -> Self {
786786
let content = ProposalContent {
787787
round,
788-
proposal,
788+
block,
789789
outcome: None,
790790
};
791791
let signature = Signature::new(&content, secret);
@@ -809,7 +809,7 @@ impl BlockProposal {
809809
let block = validated_block_certificate.into_inner().into_inner();
810810
let executed_block: ExecutedBlock = block.into();
811811
let content = ProposalContent {
812-
proposal: executed_block.proposal,
812+
block: executed_block.block,
813813
round,
814814
outcome: Some(executed_block.outcome),
815815
};

linera-chain/src/manager.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use serde::{Deserialize, Serialize};
9494

9595
use crate::{
9696
block::{ConfirmedBlock, Timeout, ValidatedBlock},
97-
data_types::{BlockProposal, ExecutedBlock, LiteVote, Proposal, Vote},
97+
data_types::{BlockProposal, ExecutedBlock, LiteVote, ProposedBlock, Vote},
9898
types::{TimeoutCertificate, ValidatedBlockCertificate},
9999
ChainError,
100100
};
@@ -131,7 +131,7 @@ impl LockedBlock {
131131

132132
pub fn chain_id(&self) -> ChainId {
133133
match self {
134-
Self::Fast(proposal) => proposal.content.proposal.chain_id,
134+
Self::Fast(proposal) => proposal.content.block.chain_id,
135135
Self::Regular(certificate) => certificate.value().inner().chain_id(),
136136
}
137137
}
@@ -285,7 +285,7 @@ where
285285

286286
/// Verifies the safety of a proposed block with respect to voting rules.
287287
pub fn check_proposed_block(&self, proposal: &BlockProposal) -> Result<Outcome, ChainError> {
288-
let new_block = &proposal.content.proposal;
288+
let new_block = &proposal.content.block;
289289
if let Some(old_proposal) = self.proposed.get() {
290290
if old_proposal.content == proposal.content {
291291
return Ok(Outcome::Skip); // We already voted for this proposal; nothing to do.
@@ -304,7 +304,7 @@ where
304304
// validated block certificate, or it must propose the same block.
305305
ensure!(
306306
proposal.validated_block_certificate.is_some()
307-
|| new_block == &old_proposal.content.proposal,
307+
|| new_block == &old_proposal.content.block,
308308
ChainError::HasLockedBlock(new_block.height, Round::Fast)
309309
);
310310
}
@@ -811,9 +811,9 @@ impl ChainManagerInfo {
811811
}
812812

813813
/// Returns whether a proposal with this content was already handled.
814-
pub fn already_handled_proposal(&self, round: Round, block: &Proposal) -> bool {
814+
pub fn already_handled_proposal(&self, round: Round, block: &ProposedBlock) -> bool {
815815
self.requested_proposed.as_ref().is_some_and(|proposal| {
816-
proposal.content.round == round && proposal.content.proposal == *block
816+
proposal.content.round == round && proposal.content.block == *block
817817
})
818818
}
819819

0 commit comments

Comments
 (0)