Skip to content

Commit

Permalink
Include the outcome in a re-proposal instead of re-executing. (#3016)
Browse files Browse the repository at this point in the history
  • Loading branch information
afck authored Dec 6, 2024
1 parent 5ff44e3 commit adb6aea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
9 changes: 4 additions & 5 deletions linera-chain/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,18 +743,17 @@ pub struct ProposalContent {
pub block: Block,
/// The consensus round in which this proposal is made.
pub round: Round,
/// If this is a retry from an earlier round, the oracle responses from when the block was
/// first validated. These are reused so the execution outcome remains the same.
/// If this is a retry from an earlier round, the execution outcome.
#[debug(skip_if = Option::is_none)]
pub forced_oracle_responses: Option<Vec<Vec<OracleResponse>>>,
pub outcome: Option<BlockExecutionOutcome>,
}

impl BlockProposal {
pub fn new_initial(round: Round, block: Block, secret: &KeyPair, blobs: Vec<Blob>) -> Self {
let content = ProposalContent {
round,
block,
forced_oracle_responses: None,
outcome: None,
};
let signature = Signature::new(&content, secret);
Self {
Expand All @@ -777,7 +776,7 @@ impl BlockProposal {
let content = ProposalContent {
block: executed_block.block,
round,
forced_oracle_responses: Some(executed_block.outcome.oracle_responses),
outcome: Some(executed_block.outcome),
};
let signature = Signature::new(&content, secret);
Self {
Expand Down
17 changes: 8 additions & 9 deletions linera-core/src/chain_worker/state/temporary_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ where
ProposalContent {
block,
round,
forced_oracle_responses,
outcome,
},
owner,
blobs,
validated_block_certificate,
signature: _,
} = proposal;
ensure!(
validated_block_certificate.is_some() == forced_oracle_responses.is_some(),
validated_block_certificate.is_some() == outcome.is_some(),
WorkerError::InvalidBlockProposal(
"Must contain a validation certificate if and only if \
oracle responses are forced from a previous round"
it contains the execution outcome from a previous round"
.to_string()
)
);
Expand Down Expand Up @@ -226,12 +226,11 @@ where
);
self.0.storage.clock().sleep_until(block.timestamp).await;
let local_time = self.0.storage.clock().current_time();
let outcome = Box::pin(self.0.chain.execute_block(
block,
local_time,
forced_oracle_responses.clone(),
))
.await?;
let outcome = if let Some(outcome) = outcome {
outcome.clone()
} else {
Box::pin(self.0.chain.execute_block(block, local_time, None)).await?
};

let executed_block = outcome.with(block.clone());
let required_blobs = self
Expand Down
14 changes: 6 additions & 8 deletions linera-rpc/src/grpc/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,14 +1104,12 @@ pub mod tests {
#[test]
pub fn test_block_proposal() {
let key_pair = KeyPair::generate();
let outcome = BlockExecutionOutcome {
state_hash: CryptoHash::new(&Foo("validated".into())),
..BlockExecutionOutcome::default()
};
let cert = ValidatedBlockCertificate::new(
Hashed::new(ValidatedBlock::new(
BlockExecutionOutcome {
state_hash: CryptoHash::new(&Foo("validated".into())),
..BlockExecutionOutcome::default()
}
.with(get_block()),
)),
Hashed::new(ValidatedBlock::new(outcome.clone().with(get_block()))),
Round::SingleLeader(2),
vec![(
ValidatorName::from(key_pair.public()),
Expand All @@ -1124,7 +1122,7 @@ pub mod tests {
content: ProposalContent {
block: get_block(),
round: Round::SingleLeader(4),
forced_oracle_responses: Some(Vec::new()),
outcome: Some(outcome),
},
owner: Owner::from(KeyPair::generate().public()),
signature: Signature::new(&Foo("test".into()), &KeyPair::generate()),
Expand Down
6 changes: 2 additions & 4 deletions linera-rpc/tests/snapshots/format__format.yaml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,9 @@ ProposalContent:
TYPENAME: Block
- round:
TYPENAME: Round
- forced_oracle_responses:
- outcome:
OPTION:
SEQ:
SEQ:
TYPENAME: OracleResponse
TYPENAME: BlockExecutionOutcome
PublicKey:
NEWTYPESTRUCT:
TUPLEARRAY:
Expand Down

0 comments on commit adb6aea

Please sign in to comment.