Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl<T: CertificateValue> From<&Hashed<T>> for LiteValue #3068

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linera-chain/src/certificate/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<T> GenericCertificate<T> {
T: CertificateValue,
{
crate::certificate::LiteCertificate {
value: LiteValue::new(&self.value),
value: LiteValue::from(&self.value),
round: self.round,
signatures: std::borrow::Cow::Borrowed(&self.signatures),
}
Expand Down
6 changes: 3 additions & 3 deletions linera-chain/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ pub struct LiteValue {
pub kind: CertificateKind,
}

impl LiteValue {
pub fn new<T: CertificateValue>(value: &Hashed<T>) -> Self {
impl<T: CertificateValue> From<&Hashed<T>> for LiteValue {
fn from(value: &Hashed<T>) -> Self {
LiteValue {
value_hash: value.hash(),
chain_id: value.inner().chain_id(),
Expand Down Expand Up @@ -486,7 +486,7 @@ impl<T> Vote<T> {
T: CertificateValue,
{
LiteVote {
value: LiteValue::new(&self.value),
value: LiteValue::from(&self.value),
round: self.round,
validator: self.validator,
signature: self.signature,
Expand Down
12 changes: 6 additions & 6 deletions linera-chain/src/unit_tests/data_types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ fn test_signed_values() {
.with(block);
let confirmed_value = Hashed::new(ConfirmedBlock::new(executed_block.clone()));

let confirmed_vote = LiteVote::new(LiteValue::new(&confirmed_value), Round::Fast, &key1);
let confirmed_vote = LiteVote::new(LiteValue::from(&confirmed_value), Round::Fast, &key1);
assert!(confirmed_vote.check().is_ok());

let validated_value = Hashed::new(ValidatedBlock::new(executed_block));
let validated_vote = LiteVote::new(LiteValue::new(&validated_value), Round::Fast, &key1);
let validated_vote = LiteVote::new(LiteValue::from(&validated_value), Round::Fast, &key1);
assert!(validated_vote.check().is_ok());
assert_ne!(
confirmed_vote.value, validated_vote.value,
"Confirmed and validated votes should be different, even if for the same executed block"
);

let mut v = LiteVote::new(LiteValue::new(&confirmed_value), Round::Fast, &key2);
let mut v = LiteVote::new(LiteValue::from(&confirmed_value), Round::Fast, &key2);
v.validator = name1;
assert!(v.check().is_err());
}
Expand Down Expand Up @@ -83,9 +83,9 @@ fn test_certificates() {
.with(block);
let value = Hashed::new(ConfirmedBlock::new(executed_block));

let v1 = LiteVote::new(LiteValue::new(&value), Round::Fast, &key1);
let v2 = LiteVote::new(LiteValue::new(&value), Round::Fast, &key2);
let v3 = LiteVote::new(LiteValue::new(&value), Round::Fast, &key3);
let v1 = LiteVote::new(LiteValue::from(&value), Round::Fast, &key1);
let v2 = LiteVote::new(LiteValue::from(&value), Round::Fast, &key2);
let v3 = LiteVote::new(LiteValue::from(&value), Round::Fast, &key3);

let mut builder = SignatureAggregator::new(value.clone(), Round::Fast, &committee);
assert!(builder
Expand Down
8 changes: 4 additions & 4 deletions linera-core/src/unit_tests/worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ where
T: CertificateValue,
{
let vote = LiteVote::new(
LiteValue::new(&value),
LiteValue::from(&value),
round,
worker.chain_worker_config.key_pair().unwrap(),
);
Expand Down Expand Up @@ -3332,7 +3332,7 @@ where
.await?;
let vote = response.info.manager.pending.as_ref().unwrap();
let value = Hashed::new(ConfirmedBlock::new(executed_block1.clone()));
assert_eq!(vote.value, LiteValue::new(&value));
assert_eq!(vote.value, LiteValue::from(&value));

// Instead of submitting the confirmed block certificate, let rounds 2 to 4 time out, too.
let certificate_timeout = make_certificate_with_round(
Expand Down Expand Up @@ -3386,7 +3386,7 @@ where
&key_pairs[1],
Vec::new(),
);
let lite_value2 = LiteValue::new(&value2);
let lite_value2 = LiteValue::from(&value2);
let (_, _) = worker.handle_block_proposal(proposal).await?;
let (response, _) = worker.handle_chain_info_query(query_values.clone()).await?;
assert_eq!(
Expand Down Expand Up @@ -3618,7 +3618,7 @@ where
&key_pairs[1],
Vec::new(),
);
let lite_value2 = LiteValue::new(&value2);
let lite_value2 = LiteValue::from(&value2);
let (_, _) = worker.handle_block_proposal(proposal).await?;
let query_values = ChainInfoQuery::new(chain_id).with_manager_values();
let (response, _) = worker.handle_chain_info_query(query_values).await?;
Expand Down
2 changes: 1 addition & 1 deletion linera-sdk/src/test/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl BlockBuilder {

let value = Hashed::new(ConfirmedBlock::new(executed_block));
let vote = LiteVote::new(
LiteValue::new(&value),
LiteValue::from(&value),
Round::Fast,
self.validator.key_pair(),
);
Expand Down
Loading