Skip to content

Commit

Permalink
only store if certificate is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeiannucci committed Oct 8, 2024
1 parent 0f8f8e4 commit 85931e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 8 additions & 3 deletions sequencer/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ mod persistence_tests {
Default::default(),
Default::default(),
);
storage
let res = storage
.store_upgrade_certificate(Some(decide_upgrade_certificate.clone()))
.await
.unwrap();
.await;
assert!(res.is_ok());

let res = storage.load_upgrade_certificate().await.unwrap();
let view_number = res.unwrap().view_number;
Expand All @@ -510,6 +510,11 @@ mod persistence_tests {
let mut new_upgrade_certificate = decide_upgrade_certificate.clone();
new_upgrade_certificate.view_number = new_view_number_for_certificate;

let res = storage
.store_upgrade_certificate(Some(new_upgrade_certificate.clone()))
.await;
assert!(res.is_ok());

let res = storage.load_upgrade_certificate().await.unwrap();
let view_number = res.unwrap().view_number;
assert_eq!(view_number, new_view_number_for_certificate);
Expand Down
8 changes: 6 additions & 2 deletions sequencer/src/persistence/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,19 @@ impl SequencerPersistence for Persistence {
) -> anyhow::Result<()> {
let mut inner = self.inner.write().await;
let path = &inner.upgrade_certificate_dir_path();
let certificate = match decided_upgrade_certificate {
Some(cert) => cert,
None => return Ok(()),
};
inner.replace(
path,
|_| {
// Always overwrite the previous file.
Ok(true)
},
|mut file| {
let bytes = bincode::serialize(&decided_upgrade_certificate)
.context("serializing upgrade certificate")?;
let bytes =
bincode::serialize(&certificate).context("serializing upgrade certificate")?;
file.write_all(&bytes)?;
Ok(())
},
Expand Down
8 changes: 6 additions & 2 deletions sequencer/src/persistence/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,12 @@ impl SequencerPersistence for Persistence {
&self,
decided_upgrade_certificate: Option<UpgradeCertificate<SeqTypes>>,
) -> anyhow::Result<()> {
let upgrade_certificate_bytes = bincode::serialize(&decided_upgrade_certificate)
.context("serializing upgrade certificate")?;
let certificate = match decided_upgrade_certificate {
Some(cert) => cert,
None => return Ok(()),
};
let upgrade_certificate_bytes =
bincode::serialize(&certificate).context("serializing upgrade certificate")?;
let mut tx = self.db.write().await?;
tx.upsert(
"upgrade_certificate",
Expand Down

0 comments on commit 85931e5

Please sign in to comment.