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 } ;
129use 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} ;
1815use mtc_api:: { BootstrapMtcLogEntry , LandmarkSequence , LANDMARK_BUNDLE_KEY , LANDMARK_KEY } ;
16+ use serde:: { Deserialize , Serialize } ;
17+ use serde_with:: { base64:: Base64 , serde_as} ;
1918use signed_note:: Note ;
2019use 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