Skip to content

Commit 32191e5

Browse files
author
Michael Rosenberg
committed
Address comments
1 parent 82b0691 commit 32191e5

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

crates/mtc_worker/src/frontend_worker.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use mtc_api::{
2323
use serde::{Deserialize, Serialize};
2424
use serde_with::{base64::Base64, serde_as};
2525
use signed_note::VerifierList;
26-
use std::{collections::VecDeque, time::Duration};
26+
use std::time::Duration;
2727
use tlog_tiles::{
2828
open_checkpoint, CheckpointSigner, CheckpointText, LeafIndex, PendingLogEntry,
2929
PendingLogEntryBlob,
@@ -70,23 +70,6 @@ pub struct GetCertificateResponse {
7070
pub landmark_id: usize,
7171
}
7272

73-
/// GET response structure for the `/get-landmark-bundle` endpoint
74-
#[derive(Serialize, Deserialize)]
75-
pub struct LandmarkBundle {
76-
pub checkpoint: String,
77-
pub subtrees: Vec<SubtreeWithConsistencyProof>,
78-
pub landmarks: VecDeque<u64>,
79-
}
80-
81-
#[serde_as]
82-
#[derive(Serialize, Deserialize)]
83-
pub struct SubtreeWithConsistencyProof {
84-
#[serde_as(as = "Base64")]
85-
pub hash: [u8; 32],
86-
#[serde_as(as = "Vec<Base64>")]
87-
pub consistency_proof: Vec<[u8; 32]>,
88-
}
89-
9073
/// Start is the first code run when the Wasm module is loaded.
9174
#[event(start)]
9275
fn start() {

crates/mtc_worker/src/sequencer_do.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33

44
//! Sequencer is the 'brain' of the CT log, responsible for sequencing entries and maintaining log state.
55
6-
use std::{future::Future, pin::Pin, time::Duration};
6+
use std::{collections::VecDeque, time::Duration};
77

8-
use crate::{
9-
frontend_worker::{LandmarkBundle, SubtreeWithConsistencyProof},
10-
load_checkpoint_cosigner, load_origin, CONFIG,
11-
};
8+
use crate::{load_checkpoint_cosigner, load_origin, CONFIG};
129
use generic_log_worker::{
1310
get_durable_object_name, load_public_bucket,
1411
log_ops::{prove_subtree_consistency, ProofError},
1512
CachedRoObjectBucket, CheckpointCallbacker, GenericSequencer, ObjectBucket, SequencerConfig,
1613
SEQUENCER_BINDING,
1714
};
1815
use mtc_api::{BootstrapMtcLogEntry, LandmarkSequence, LANDMARK_BUNDLE_KEY, LANDMARK_KEY};
16+
use serde::{Deserialize, Serialize};
17+
use serde_with::{base64::Base64, serde_as};
1918
use signed_note::Note;
2019
use tlog_tiles::{CheckpointText, Hash, UnixTimestamp};
2120
#[allow(clippy::wildcard_imports)]
@@ -59,6 +58,23 @@ impl DurableObject for Sequencer {
5958
}
6059
}
6160

61+
#[serde_as]
62+
#[derive(Serialize, Deserialize)]
63+
pub struct SubtreeWithConsistencyProof {
64+
#[serde_as(as = "Base64")]
65+
pub hash: [u8; 32],
66+
#[serde_as(as = "Vec<Base64>")]
67+
pub consistency_proof: Vec<[u8; 32]>,
68+
}
69+
70+
/// GET response structure for the `/get-landmark-bundle` endpoint
71+
#[derive(Serialize, Deserialize)]
72+
pub struct LandmarkBundle {
73+
pub checkpoint: String,
74+
pub subtrees: Vec<SubtreeWithConsistencyProof>,
75+
pub landmarks: VecDeque<u64>,
76+
}
77+
6278
/// Return a callback function that gets passed into the generic sequencer and
6379
/// called each time a new checkpoint is created. For MTC, this is used to
6480
/// periodically update the landmark checkpoint sequence.
@@ -68,14 +84,18 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
6884
Box::new(
6985
move |old_time: UnixTimestamp, new_time: UnixTimestamp, new_checkpoint_bytes: &[u8]| {
7086
let new_checkpoint = {
71-
// TODO: Make more efficient. There are two unnecessary allocations here
87+
// TODO: Make more efficient. There are two unnecessary allocations here.
88+
89+
// We can unwrap because the checkpoint provided is the checkpoint that the
90+
// sequencer just created, so it must be well formed.
7291
let note = Note::from_bytes(new_checkpoint_bytes)
7392
.expect("freshly created checkpoint is not a note");
7493
CheckpointText::from_bytes(note.text())
7594
.expect("freshly created checkpoint is not a checkpoint")
7695
};
7796
let tree_size = new_checkpoint.size();
7897
let root_hash = *new_checkpoint.hash();
98+
// We can unwrap here for the same reason as above
7999
let new_checkpoint_str = String::from_utf8(new_checkpoint_bytes.to_vec())
80100
.expect("freshly created checkpoint is not UTF-8");
81101

0 commit comments

Comments
 (0)