Skip to content

Commit 9f2a55a

Browse files
Alenarghubertpalojpraynaud
committed
Suffix open message database type with "record"
Co-authored-by: Grégoire HUBERT <[email protected]> Co-authored-by: Jean-Philippe Raynaud <[email protected]>
1 parent 0a209ca commit 9f2a55a

File tree

7 files changed

+51
-48
lines changed

7 files changed

+51
-48
lines changed

mithril-aggregator/src/certifier_service.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use thiserror::Error;
2020
use tokio::sync::RwLock;
2121

2222
use crate::database::provider::{
23-
CertificateRepository, OpenMessage, OpenMessageRepository, OpenMessageWithSingleSignatures,
24-
SingleSignatureRepository,
23+
CertificateRepository, OpenMessageRecord, OpenMessageRepository,
24+
OpenMessageWithSingleSignaturesRecord, SingleSignatureRepository,
2525
};
2626
use crate::MultiSigner;
2727

@@ -88,14 +88,14 @@ pub trait CertifierService: Sync + Send {
8888
&self,
8989
signed_entity_type: &SignedEntityType,
9090
protocol_message: &ProtocolMessage,
91-
) -> StdResult<OpenMessage>;
91+
) -> StdResult<OpenMessageRecord>;
9292

9393
/// Return the open message at the given Beacon. If the message does not
9494
/// exist, None is returned.
9595
async fn get_open_message(
9696
&self,
9797
signed_entity_type: &SignedEntityType,
98-
) -> StdResult<Option<OpenMessageWithSingleSignatures>>;
98+
) -> StdResult<Option<OpenMessageWithSingleSignaturesRecord>>;
9999

100100
/// Create a certificate if possible. If the pointed open message does
101101
/// not exist or has been already certified, an error is raised. If a multi
@@ -209,7 +209,7 @@ impl CertifierService for MithrilCertifierService {
209209
&self,
210210
signed_entity_type: &SignedEntityType,
211211
protocol_message: &ProtocolMessage,
212-
) -> StdResult<OpenMessage> {
212+
) -> StdResult<OpenMessageRecord> {
213213
debug!("CertifierService::create_open_message(signed_entity_type: {signed_entity_type:?}, protocol_message: {protocol_message:?})");
214214
let current_epoch = self.current_epoch.read().await;
215215

@@ -229,7 +229,7 @@ impl CertifierService for MithrilCertifierService {
229229
async fn get_open_message(
230230
&self,
231231
signed_entity_type: &SignedEntityType,
232-
) -> StdResult<Option<OpenMessageWithSingleSignatures>> {
232+
) -> StdResult<Option<OpenMessageWithSingleSignaturesRecord>> {
233233
debug!("CertifierService::get_open_message(signed_entity_type: {signed_entity_type:?})");
234234

235235
self.open_message_repository
@@ -325,7 +325,7 @@ impl CertifierService for MithrilCertifierService {
325325
.create_certificate(certificate)
326326
.await?;
327327

328-
let mut open_message_certified: OpenMessage = open_message.into();
328+
let mut open_message_certified: OpenMessageRecord = open_message.into();
329329
open_message_certified.is_certified = true;
330330
self.open_message_repository
331331
.update_open_message(&open_message_certified)

mithril-aggregator/src/database/provider/open_message.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type StdResult<T> = Result<T, StdError>;
2525
/// generated if possible.
2626
#[allow(dead_code)]
2727
#[derive(Debug, Clone, PartialEq, Eq)]
28-
pub struct OpenMessage {
28+
pub struct OpenMessageRecord {
2929
/// OpenMessage unique identifier
3030
pub open_message_id: Uuid,
3131

@@ -45,7 +45,7 @@ pub struct OpenMessage {
4545
pub created_at: NaiveDateTime,
4646
}
4747

48-
impl OpenMessage {
48+
impl OpenMessageRecord {
4949
#[cfg(test)]
5050
/// Create a dumb OpenMessage instance mainly for test purposes
5151
pub fn dummy() -> Self {
@@ -64,8 +64,8 @@ impl OpenMessage {
6464
}
6565
}
6666

67-
impl From<OpenMessageWithSingleSignatures> for OpenMessage {
68-
fn from(value: OpenMessageWithSingleSignatures) -> Self {
67+
impl From<OpenMessageWithSingleSignaturesRecord> for OpenMessageRecord {
68+
fn from(value: OpenMessageWithSingleSignaturesRecord) -> Self {
6969
Self {
7070
open_message_id: value.open_message_id,
7171
epoch: value.epoch,
@@ -77,7 +77,7 @@ impl From<OpenMessageWithSingleSignatures> for OpenMessage {
7777
}
7878
}
7979

80-
impl SqLiteEntity for OpenMessage {
80+
impl SqLiteEntity for OpenMessageRecord {
8181
fn hydrate(row: Row) -> Result<Self, HydrationError>
8282
where
8383
Self: Sized,
@@ -199,7 +199,7 @@ impl<'client> OpenMessageProvider<'client> {
199199
}
200200

201201
impl<'client> Provider<'client> for OpenMessageProvider<'client> {
202-
type Entity = OpenMessage;
202+
type Entity = OpenMessageRecord;
203203

204204
fn get_definition(&self, condition: &str) -> String {
205205
let aliases = SourceAlias::new(&[
@@ -245,7 +245,7 @@ impl<'client> InsertOpenMessageProvider<'client> {
245245
}
246246

247247
impl<'client> Provider<'client> for InsertOpenMessageProvider<'client> {
248-
type Entity = OpenMessage;
248+
type Entity = OpenMessageRecord;
249249

250250
fn get_connection(&'client self) -> &'client Connection {
251251
self.connection
@@ -267,7 +267,7 @@ impl<'client> UpdateOpenMessageProvider<'client> {
267267
Self { connection }
268268
}
269269

270-
fn get_update_condition(&self, open_message: &OpenMessage) -> StdResult<WhereCondition> {
270+
fn get_update_condition(&self, open_message: &OpenMessageRecord) -> StdResult<WhereCondition> {
271271
let expression = "(open_message_id, epoch_setting_id, beacon, signed_entity_type_id, protocol_message, is_certified) values (?*, ?*, ?*, ?*, ?*, ?*)";
272272
let beacon_str = open_message.signed_entity_type.get_json_beacon()?;
273273
let parameters = vec![
@@ -284,7 +284,7 @@ impl<'client> UpdateOpenMessageProvider<'client> {
284284
}
285285

286286
impl<'client> Provider<'client> for UpdateOpenMessageProvider<'client> {
287-
type Entity = OpenMessage;
287+
type Entity = OpenMessageRecord;
288288

289289
fn get_connection(&'client self) -> &'client Connection {
290290
self.connection
@@ -316,7 +316,7 @@ impl<'client> DeleteOpenMessageProvider<'client> {
316316
}
317317

318318
impl<'client> Provider<'client> for DeleteOpenMessageProvider<'client> {
319-
type Entity = OpenMessage;
319+
type Entity = OpenMessageRecord;
320320

321321
fn get_connection(&'client self) -> &'client Connection {
322322
self.connection
@@ -332,7 +332,7 @@ impl<'client> Provider<'client> for DeleteOpenMessageProvider<'client> {
332332

333333
/// Open Message with associated single signatures if any.
334334
#[derive(Debug, Clone)]
335-
pub struct OpenMessageWithSingleSignatures {
335+
pub struct OpenMessageWithSingleSignaturesRecord {
336336
/// OpenMessage unique identifier
337337
pub open_message_id: Uuid,
338338

@@ -355,7 +355,7 @@ pub struct OpenMessageWithSingleSignatures {
355355
pub created_at: NaiveDateTime,
356356
}
357357

358-
impl OpenMessageWithSingleSignatures {
358+
impl OpenMessageWithSingleSignaturesRecord {
359359
/// Gather all signers party_id for this open message
360360
pub fn get_signers_id(&self) -> Vec<PartyId> {
361361
self.single_signatures
@@ -365,7 +365,7 @@ impl OpenMessageWithSingleSignatures {
365365
}
366366
}
367367

368-
impl SqLiteEntity for OpenMessageWithSingleSignatures {
368+
impl SqLiteEntity for OpenMessageWithSingleSignaturesRecord {
369369
fn hydrate(row: Row) -> Result<Self, HydrationError>
370370
where
371371
Self: Sized,
@@ -378,7 +378,7 @@ impl SqLiteEntity for OpenMessageWithSingleSignatures {
378378
))
379379
})?;
380380

381-
let open_message = OpenMessage::hydrate(row)?;
381+
let open_message = OpenMessageRecord::hydrate(row)?;
382382

383383
let open_message = Self {
384384
open_message_id: open_message.open_message_id,
@@ -440,7 +440,7 @@ impl<'client> OpenMessageWithSingleSignaturesProvider<'client> {
440440
}
441441

442442
impl<'client> Provider<'client> for OpenMessageWithSingleSignaturesProvider<'client> {
443-
type Entity = OpenMessageWithSingleSignatures;
443+
type Entity = OpenMessageWithSingleSignaturesRecord;
444444

445445
fn get_definition(&self, condition: &str) -> String {
446446
let aliases = SourceAlias::new(&[
@@ -485,7 +485,7 @@ impl OpenMessageRepository {
485485
pub async fn get_open_message(
486486
&self,
487487
signed_entity_type: &SignedEntityType,
488-
) -> StdResult<Option<OpenMessage>> {
488+
) -> StdResult<Option<OpenMessageRecord>> {
489489
let lock = self.connection.lock().await;
490490
let provider = OpenMessageProvider::new(&lock);
491491
let filters = provider
@@ -502,7 +502,7 @@ impl OpenMessageRepository {
502502
epoch: Epoch,
503503
signed_entity_type: &SignedEntityType,
504504
protocol_message: &ProtocolMessage,
505-
) -> StdResult<OpenMessage> {
505+
) -> StdResult<OpenMessageRecord> {
506506
let lock = self.connection.lock().await;
507507
let provider = InsertOpenMessageProvider::new(&lock);
508508
let filters = provider.get_insert_condition(epoch, signed_entity_type, protocol_message)?;
@@ -514,7 +514,10 @@ impl OpenMessageRepository {
514514
}
515515

516516
/// Updates an [OpenMessage] in the database.
517-
pub async fn update_open_message(&self, open_message: &OpenMessage) -> StdResult<OpenMessage> {
517+
pub async fn update_open_message(
518+
&self,
519+
open_message: &OpenMessageRecord,
520+
) -> StdResult<OpenMessageRecord> {
518521
let lock = self.connection.lock().await;
519522
let provider = UpdateOpenMessageProvider::new(&lock);
520523
let filters = provider.get_update_condition(open_message)?;
@@ -540,7 +543,7 @@ impl OpenMessageRepository {
540543
pub async fn get_open_message_with_single_signatures(
541544
&self,
542545
signed_entity_type: &SignedEntityType,
543-
) -> StdResult<Option<OpenMessageWithSingleSignatures>> {
546+
) -> StdResult<Option<OpenMessageWithSingleSignaturesRecord>> {
544547
let lock = self.connection.lock().await;
545548
let provider = OpenMessageWithSingleSignaturesProvider::new(&lock);
546549
let filters = provider.get_signed_entity_type_condition(signed_entity_type);
@@ -564,7 +567,7 @@ mod tests {
564567

565568
#[test]
566569
fn open_message_with_single_signature_projection() {
567-
let projection = OpenMessageWithSingleSignatures::get_projection();
570+
let projection = OpenMessageWithSingleSignaturesRecord::get_projection();
568571
let aliases = SourceAlias::new(&[
569572
("{:open_message:}", "open_message"),
570573
("{:single_signature:}", "single_signature"),
@@ -578,7 +581,7 @@ mod tests {
578581

579582
#[test]
580583
fn open_message_projection() {
581-
let projection = OpenMessage::get_projection();
584+
let projection = OpenMessageRecord::get_projection();
582585
let aliases = SourceAlias::new(&[("{:open_message:}", "open_message")]);
583586

584587
assert_eq!(
@@ -659,7 +662,7 @@ mod tests {
659662
fn update_provider_condition() {
660663
let connection = Connection::open(":memory:").unwrap();
661664
let provider = UpdateOpenMessageProvider::new(&connection);
662-
let open_message = OpenMessage {
665+
let open_message = OpenMessageRecord {
663666
open_message_id: Uuid::new_v4(),
664667
epoch: Epoch(12),
665668
signed_entity_type: SignedEntityType::dummy(),
@@ -836,7 +839,7 @@ mod tests {
836839
setup_single_signature_db(&connection, single_signature_records.clone()).unwrap();
837840
let repository = OpenMessageRepository::new(Arc::new(Mutex::new(connection)));
838841

839-
let mut open_message = OpenMessage::dummy();
842+
let mut open_message = OpenMessageRecord::dummy();
840843
open_message.open_message_id = single_signature_records[0].open_message_id;
841844
repository.update_open_message(&open_message).await.unwrap();
842845

@@ -857,7 +860,7 @@ mod tests {
857860
setup_single_signature_db(&connection, Vec::new()).unwrap();
858861
let repository = OpenMessageRepository::new(Arc::new(Mutex::new(connection)));
859862

860-
let open_message = OpenMessage::dummy();
863+
let open_message = OpenMessageRecord::dummy();
861864
repository
862865
.create_open_message(
863866
open_message.epoch,

mithril-aggregator/src/database/provider/single_signature.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use mithril_common::StdError;
1616
use tokio::sync::Mutex;
1717
use uuid::Uuid;
1818

19-
use super::OpenMessage;
19+
use super::OpenMessageRecord;
2020

2121
/// SingleSignature record is the representation of a stored single_signature.
2222
#[derive(Debug, PartialEq, Clone)]
@@ -285,7 +285,7 @@ impl SingleSignatureRepository {
285285
pub async fn create_single_signature(
286286
&self,
287287
single_signature: &SingleSignatures,
288-
open_message: &OpenMessage,
288+
open_message: &OpenMessageRecord,
289289
) -> Result<SingleSignatureRecord, StdError> {
290290
let connection = self.connection.lock().await;
291291
let single_signature = SingleSignatureRecord::from_single_signatures(

mithril-aggregator/src/multi_signer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use mithril_common::{
1414
};
1515

1616
use crate::{
17-
database::provider::OpenMessageWithSingleSignatures, store::VerificationKeyStorer,
17+
database::provider::OpenMessageWithSingleSignaturesRecord, store::VerificationKeyStorer,
1818
ProtocolParametersStore, ProtocolParametersStorer, VerificationKeyStore,
1919
};
2020

@@ -184,7 +184,7 @@ pub trait MultiSigner: Sync + Send {
184184
/// Creates a multi signature from single signatures
185185
async fn create_multi_signature(
186186
&self,
187-
open_message: &OpenMessageWithSingleSignatures,
187+
open_message: &OpenMessageWithSingleSignaturesRecord,
188188
) -> Result<Option<ProtocolMultiSignature>, ProtocolError>;
189189
}
190190

@@ -539,7 +539,7 @@ impl MultiSigner for MultiSignerImpl {
539539
/// Creates a multi signature from single signatures
540540
async fn create_multi_signature(
541541
&self,
542-
open_message: &OpenMessageWithSingleSignatures,
542+
open_message: &OpenMessageWithSingleSignaturesRecord,
543543
) -> Result<Option<ProtocolMultiSignature>, ProtocolError> {
544544
debug!("MultiSigner:create_multi_signature({open_message:?})");
545545
let protocol_parameters = self
@@ -805,7 +805,7 @@ mod tests {
805805
"they should be at least one signature that can be registered without reaching the quorum"
806806
);
807807

808-
let mut open_message = OpenMessageWithSingleSignatures {
808+
let mut open_message = OpenMessageWithSingleSignaturesRecord {
809809
open_message_id: Uuid::parse_str("193d1442-e89b-43cf-9519-04d8db9a12ff").unwrap(),
810810
epoch: start_epoch,
811811
signed_entity_type: SignedEntityType::CardanoImmutableFilesFull(

mithril-aggregator/src/runtime/runner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::path::Path;
1616
use std::path::PathBuf;
1717
use std::sync::Arc;
1818

19-
use crate::database::provider::OpenMessage;
19+
use crate::database::provider::OpenMessageRecord;
2020
use crate::snapshot_uploaders::SnapshotLocation;
2121
use crate::snapshotter::OngoingSnapshot;
2222
use crate::RuntimeError;
@@ -172,7 +172,7 @@ pub trait AggregatorRunnerTrait: Sync + Send {
172172
&self,
173173
signed_entity_type: &SignedEntityType,
174174
protocol_message: &ProtocolMessage,
175-
) -> Result<OpenMessage, Box<dyn StdError + Sync + Send>>;
175+
) -> Result<OpenMessageRecord, Box<dyn StdError + Sync + Send>>;
176176
}
177177

178178
/// The runner responsibility is to expose a code API for the state machine. It
@@ -614,7 +614,7 @@ impl AggregatorRunnerTrait for AggregatorRunner {
614614
&self,
615615
signed_entity_type: &SignedEntityType,
616616
protocol_message: &ProtocolMessage,
617-
) -> Result<OpenMessage, Box<dyn StdError + Sync + Send>> {
617+
) -> Result<OpenMessageRecord, Box<dyn StdError + Sync + Send>> {
618618
self.dependencies
619619
.certifier_service
620620
.create_open_message(signed_entity_type, protocol_message)

mithril-aggregator/src/runtime/state_machine.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
database::provider::OpenMessage,
2+
database::provider::OpenMessageRecord,
33
runtime::{AggregatorRunnerTrait, RuntimeError},
44
};
55

@@ -22,7 +22,7 @@ pub struct ReadyState {
2222
#[derive(Clone, Debug, PartialEq)]
2323
pub struct SigningState {
2424
current_beacon: Beacon,
25-
open_message: OpenMessage,
25+
open_message: OpenMessageRecord,
2626
}
2727

2828
#[derive(Clone, Debug, PartialEq)]
@@ -359,7 +359,7 @@ impl AggregatorRuntime {
359359
#[cfg(test)]
360360
mod tests {
361361

362-
use crate::database::provider::OpenMessage;
362+
use crate::database::provider::OpenMessageRecord;
363363

364364
use super::super::runner::MockAggregatorRunner;
365365
use super::*;
@@ -607,7 +607,7 @@ mod tests {
607607
runner
608608
.expect_create_open_message()
609609
.once()
610-
.returning(|_, _| Ok(OpenMessage::dummy()));
610+
.returning(|_, _| Ok(OpenMessageRecord::dummy()));
611611

612612
let mut runtime = init_runtime(
613613
Some(AggregatorState::Ready(ReadyState {
@@ -642,7 +642,7 @@ mod tests {
642642

643643
beacon
644644
},
645-
open_message: OpenMessage::dummy(),
645+
open_message: OpenMessageRecord::dummy(),
646646
};
647647
let mut runtime = init_runtime(Some(AggregatorState::Signing(state)), runner).await;
648648
runtime.cycle().await.unwrap();
@@ -663,7 +663,7 @@ mod tests {
663663
.returning(|_| Ok(None));
664664
let state = SigningState {
665665
current_beacon: fake_data::beacon(),
666-
open_message: OpenMessage::dummy(),
666+
open_message: OpenMessageRecord::dummy(),
667667
};
668668
let mut runtime = init_runtime(Some(AggregatorState::Signing(state)), runner).await;
669669
runtime

0 commit comments

Comments
 (0)