@@ -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+ } ;
1619use serde:: { Deserialize , Serialize } ;
1720use serde_with:: { base64:: Base64 , serde_as} ;
1821use 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