Skip to content

Commit ec2be83

Browse files
committed
mtc_worker: Put landmark checkpoint in object storage
The landmark checkpoint is also part of the landmark bundle, but the landmark bundle is not a standard API and is only intended to be consumed by our internal infrastructure. Relying parties consume the landmark checkpoint as a TLOG note.
1 parent 5fead70 commit ec2be83

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

crates/mtc_api/src/landmark.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ pub struct LandmarkSequence {
99
pub landmarks: VecDeque<u64>,
1010
}
1111

12-
/// The location in object storage for the landmark sequence
12+
/// The location in object storage for the landmark sequence.
1313
pub const LANDMARK_KEY: &str = "landmark";
1414

15-
/// The location in object storage for the landmark bundle. Its serialized form is JSON
15+
/// The location in object storage for the landmark checkpoint.
16+
pub const LANDMARK_CHECKPOINT_KEY: &str = "landmark-checkpoint";
17+
18+
/// The location in object storage for the landmark bundle. Its serialized form is JSON.
1619
pub const LANDMARK_BUNDLE_KEY: &str = "landmark-bundle";
1720

1821
impl LandmarkSequence {

crates/mtc_worker/src/sequencer_do.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use generic_log_worker::{
1212
CachedRoObjectBucket, CheckpointCallbacker, GenericSequencer, ObjectBucket, SequencerConfig,
1313
SEQUENCER_BINDING,
1414
};
15-
use mtc_api::{BootstrapMtcLogEntry, LandmarkSequence, LANDMARK_BUNDLE_KEY, LANDMARK_KEY};
15+
use mtc_api::{
16+
BootstrapMtcLogEntry, LandmarkSequence, LANDMARK_BUNDLE_KEY, LANDMARK_CHECKPOINT_KEY,
17+
LANDMARK_KEY,
18+
};
1619
use serde::{Deserialize, Serialize};
1720
use serde_with::{base64::Base64, serde_as};
1821
use signed_note::Note;
@@ -121,6 +124,13 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
121124
// Time to add a new landmark.
122125
let max_landmarks = params.max_landmarks();
123126

127+
// TODO: the put operations below should all be done as part of the same
128+
// transaction. Otherwise an error that occurs after this point might put us in
129+
// a state where the objects are not in sync with one another, e.g., the
130+
// landmark bundle and checkpoint might have the same value. We need an
131+
// all-or-nothing multi-put operation. Tracking issue here
132+
// https://github.com/cloudflare/workers-rs/issues/876
133+
124134
// Load current landmark sequence.
125135
let mut seq =
126136
if let Some(obj) = bucket_clone.get(LANDMARK_KEY).execute().await? {
@@ -139,6 +149,12 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
139149
.await?;
140150
}
141151

152+
// Update the landmark checkpoint.
153+
bucket_clone
154+
.put(LANDMARK_CHECKPOINT_KEY, new_checkpoint_str.clone())
155+
.execute()
156+
.await?;
157+
142158
// Compute the landmark bundle and save it
143159
let subtrees =
144160
get_landmark_subtrees(&seq, root_hash, tree_size, bucket_clone.clone())
@@ -148,10 +164,6 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
148164
subtrees,
149165
landmarks: seq.landmarks,
150166
};
151-
// TODO: the put operation here should be done with the put operation above.
152-
// Otherwise an error here might put us in a state where the landmark bundle is
153-
// out of sync with the landmark sequence. We need an all-or-nothing multi-put
154-
// operation. Tracking issue here https://github.com/cloudflare/workers-rs/issues/876
155167
bucket_clone
156168
// Can unwrap here because we use the autoderived Serialize impl for LandmarkBundle
157169
.put(LANDMARK_BUNDLE_KEY, serde_json::to_vec(&bundle).unwrap())

0 commit comments

Comments
 (0)