Skip to content
Merged
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
7 changes: 5 additions & 2 deletions crates/mtc_api/src/landmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ pub struct LandmarkSequence {
pub landmarks: VecDeque<u64>,
}

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

/// The location in object storage for the landmark bundle. Its serialized form is JSON
/// The location in object storage for the landmark checkpoint.
pub const LANDMARK_CHECKPOINT_KEY: &str = "landmark-checkpoint";

/// The location in object storage for the landmark bundle. Its serialized form is JSON.
pub const LANDMARK_BUNDLE_KEY: &str = "landmark-bundle";

impl LandmarkSequence {
Expand Down
22 changes: 17 additions & 5 deletions crates/mtc_worker/src/sequencer_do.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use generic_log_worker::{
CachedRoObjectBucket, CheckpointCallbacker, GenericSequencer, ObjectBucket, SequencerConfig,
SEQUENCER_BINDING,
};
use mtc_api::{BootstrapMtcLogEntry, LandmarkSequence, LANDMARK_BUNDLE_KEY, LANDMARK_KEY};
use mtc_api::{
BootstrapMtcLogEntry, LandmarkSequence, LANDMARK_BUNDLE_KEY, LANDMARK_CHECKPOINT_KEY,
LANDMARK_KEY,
};
use serde::{Deserialize, Serialize};
use serde_with::{base64::Base64, serde_as};
use signed_note::Note;
Expand Down Expand Up @@ -121,6 +124,13 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
// Time to add a new landmark.
let max_landmarks = params.max_landmarks();

// TODO: the put operations below should all be done as part of the same
// transaction. Otherwise an error that occurs after this point might put us in
// a state where the objects are not in sync with one another, e.g., the
// landmark bundle and checkpoint might have the same value. We need an
// all-or-nothing multi-put operation. Tracking issue here
// https://github.com/cloudflare/workers-rs/issues/876

// Load current landmark sequence.
let mut seq =
if let Some(obj) = bucket_clone.get(LANDMARK_KEY).execute().await? {
Expand All @@ -139,6 +149,12 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
.await?;
}

// Update the landmark checkpoint.
bucket_clone
.put(LANDMARK_CHECKPOINT_KEY, new_checkpoint_str.clone())
.execute()
.await?;

// Compute the landmark bundle and save it
let subtrees =
get_landmark_subtrees(&seq, root_hash, tree_size, bucket_clone.clone())
Expand All @@ -148,10 +164,6 @@ fn checkpoint_callback(env: &Env, name: &str) -> CheckpointCallbacker {
subtrees,
landmarks: seq.landmarks,
};
// TODO: the put operation here should be done with the put operation above.
// Otherwise an error here might put us in a state where the landmark bundle is
// out of sync with the landmark sequence. We need an all-or-nothing multi-put
// operation. Tracking issue here https://github.com/cloudflare/workers-rs/issues/876
bucket_clone
// Can unwrap here because we use the autoderived Serialize impl for LandmarkBundle
.put(LANDMARK_BUNDLE_KEY, serde_json::to_vec(&bundle).unwrap())
Expand Down