Skip to content

Commit

Permalink
Remove Owner from BlockProposal. (#3371)
Browse files Browse the repository at this point in the history
## Motivation

`Owner` in `BlockProposal` is redundant information (derived from public
key that's already part of the `BlockProposal`).

## Proposal

Remove `owner` field from `BlockProposal`.

## Test Plan

CI.

## Release Plan


- Nothing to do / These changes follow the usual release cycle.

## Links


- [reviewer
checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
  • Loading branch information
deuszx authored Feb 19, 2025
1 parent a18d2df commit 1505022
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
7 changes: 0 additions & 7 deletions linera-chain/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ pub enum Medium {
#[cfg_attr(with_testing, derive(Eq, PartialEq))]
pub struct BlockProposal {
pub content: ProposalContent,
pub owner: Owner,
pub public_key: AccountPublicKey,
pub signature: AccountSignature,
#[debug(skip_if = Option::is_none)]
Expand Down Expand Up @@ -747,7 +746,6 @@ impl BlockProposal {
Self {
content,
public_key: secret.public(),
owner: secret.public().into(),
signature,
validated_block_certificate: None,
}
Expand All @@ -770,7 +768,6 @@ impl BlockProposal {
Self {
content,
public_key: secret.public(),
owner: secret.public().into(),
signature,
validated_block_certificate: Some(lite_cert),
}
Expand All @@ -792,10 +789,6 @@ impl BlockProposal {
/// Checks that the public key matches the owner and that the optional certificate matches
/// the outcome.
pub fn check_invariants(&self) -> Result<(), &'static str> {
ensure!(
self.owner == Owner::from(&self.public_key),
"Public key does not match owner"
);
match (&self.validated_block_certificate, &self.content.outcome) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
Expand Down
4 changes: 2 additions & 2 deletions linera-chain/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ where
// If the fast round has not timed out yet, only a super owner is allowed to open
// a later round by making a proposal.
ensure!(
self.is_super(&proposal.owner) || !current_round.is_fast(),
self.is_super(&proposal.public_key.into()) || !current_round.is_fast(),
ChainError::WrongRound(current_round)
);
// After the fast round, proposals older than the current round are obsolete.
Expand Down Expand Up @@ -582,7 +582,7 @@ where
/// Returns whether the signer is a valid owner and allowed to propose a block in the
/// proposal's round.
pub fn verify_owner(&self, proposal: &BlockProposal) -> bool {
let owner = &proposal.owner;
let owner = &proposal.public_key.into();
if self.ownership.get().super_owners.contains(owner) {
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions linera-core/src/chain_worker/state/attempted_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::future::Either;
use linera_base::{
data_types::{Blob, BlockHeight, Timestamp},
ensure,
identifiers::ChainId,
identifiers::{ChainId, Owner},
};
use linera_chain::{
data_types::{
Expand Down Expand Up @@ -128,12 +128,12 @@ where
round,
outcome: _,
},
public_key: _,
owner,
public_key,
validated_block_certificate,
signature: _,
} = proposal;

let owner: Owner = public_key.into();
let chain = &self.state.chain;
// Check the epoch.
let (epoch, committee) = chain.current_committee()?;
Expand All @@ -150,7 +150,7 @@ where
lite_certificate.check(committee)?;
} else if let Some(signer) = block.authenticated_signer {
// Check the authentication of the operations in the new block.
ensure!(signer == *owner, WorkerError::InvalidSigner(signer));
ensure!(signer == owner, WorkerError::InvalidSigner(signer));
}
// Check if the chain is ready for this new block proposal.
chain.tip_state.get().verify_block_chaining(block)?;
Expand All @@ -170,7 +170,7 @@ where
}
chain
.pending_proposed_blobs
.try_load_entry_mut(owner)
.try_load_entry_mut(&owner)
.await?
.update(*round, validated_block_certificate.is_some(), maybe_blobs)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ where
}
}
for proposal in proposals {
let owner = proposal.owner;
let owner: Owner = proposal.public_key.into();
if let Err(mut err) = self
.client
.local_node
Expand Down
4 changes: 1 addition & 3 deletions linera-rpc/src/grpc/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl TryFrom<BlockProposal> for api::BlockProposal {
chain_id: Some(block_proposal.content.block.chain_id.into()),
content: bincode::serialize(&block_proposal.content)?,
public_key: Some(block_proposal.public_key.into()),
owner: Some(block_proposal.owner.into()),
owner: Some(Owner::from(block_proposal.public_key).into()),
signature: Some(block_proposal.signature.into()),
validated_block_certificate: block_proposal
.validated_block_certificate
Expand All @@ -219,7 +219,6 @@ impl TryFrom<api::BlockProposal> for BlockProposal {
Ok(Self {
content,
public_key: try_proto_convert(block_proposal.public_key)?,
owner: try_proto_convert(block_proposal.owner)?,
signature: try_proto_convert(block_proposal.signature)?,
validated_block_certificate: block_proposal
.validated_block_certificate
Expand Down Expand Up @@ -1222,7 +1221,6 @@ pub mod tests {
round: Round::SingleLeader(4),
outcome: Some(outcome),
},
owner: Owner::from(key_pair.public()),
public_key: key_pair.public(),
signature: AccountSignature::new(&Foo("test".into()), &key_pair),
validated_block_certificate: Some(cert),
Expand Down
2 changes: 0 additions & 2 deletions linera-rpc/tests/snapshots/format__format.yaml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ BlockProposal:
STRUCT:
- content:
TYPENAME: ProposalContent
- owner:
TYPENAME: Owner
- public_key:
TYPENAME: Ed25519PublicKey
- signature:
Expand Down

0 comments on commit 1505022

Please sign in to comment.