@@ -11,6 +11,7 @@ use crate::append_only_zks::{Azks, InsertMode};
11
11
use crate :: ecvrf:: { VRFKeyStorage , VRFPublicKey } ;
12
12
use crate :: errors:: { AkdError , DirectoryError , StorageError } ;
13
13
use crate :: helper_structs:: LookupInfo ;
14
+ use crate :: log_shim:: { error, info} ;
14
15
use crate :: storage:: manager:: StorageManager ;
15
16
use crate :: storage:: types:: { DbRecord , ValueState , ValueStateRetrievalFlag } ;
16
17
use crate :: storage:: Database ;
@@ -23,11 +24,12 @@ use crate::VersionFreshness;
23
24
use akd_core:: configuration:: Configuration ;
24
25
use akd_core:: utils:: get_marker_versions;
25
26
use akd_core:: verify:: history:: HistoryParams ;
26
- use log:: { error, info} ;
27
27
use std:: collections:: { HashMap , HashSet } ;
28
28
use std:: marker:: PhantomData ;
29
29
use std:: sync:: Arc ;
30
30
use tokio:: sync:: RwLock ;
31
+ #[ cfg( feature = "tracing" ) ]
32
+ use tracing:: Instrument ;
31
33
32
34
/// The representation of a auditable key directory
33
35
pub struct Directory < TC , S : Database , V > {
64
66
/// Creates a new (stateless) instance of a auditable key directory.
65
67
/// Takes as input a pointer to the storage being used for this instance.
66
68
/// The state is stored in the storage.
69
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
67
70
pub async fn new ( storage : StorageManager < S > , vrf : V ) -> Result < Self , AkdError > {
68
71
let azks = Directory :: < TC , S , V > :: get_azks_from_storage ( & storage, false ) . await ;
69
72
90
93
///
91
94
/// Note that the vector of label-value pairs should not contain any entries with duplicate labels. This
92
95
/// condition is explicitly checked, and an error will be returned if this is the case.
96
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all, fields( num_updates = updates. len( ) ) ) ) ]
93
97
pub async fn publish ( & self , updates : Vec < ( AkdLabel , AkdValue ) > ) -> Result < EpochHash , AkdError > {
94
- // The guard will be dropped at the end of the publish
98
+ // The guard will be dropped at the end of the publish operation
95
99
let _guard = self . cache_lock . read ( ) . await ;
96
100
97
101
// Check for duplicate labels and return an error if any are encountered
@@ -254,6 +258,7 @@ where
254
258
///
255
259
/// Returns [Ok((LookupProof, EpochHash))] upon successful generation for the latest version
256
260
/// of the target label's state. [Err(_)] otherwise
261
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
257
262
pub async fn lookup ( & self , akd_label : AkdLabel ) -> Result < ( LookupProof , EpochHash ) , AkdError > {
258
263
// The guard will be dropped at the end of the proof generation
259
264
let _guard = self . cache_lock . read ( ) . await ;
@@ -281,6 +286,7 @@ where
281
286
/// from bulk lookup proof generation, as it has its own preloading operation
282
287
///
283
288
/// Returns [Ok(LookupProof)] if the proof generation succeeded, [Err(_)] otherwise
289
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
284
290
async fn lookup_with_info (
285
291
& self ,
286
292
current_azks : & Azks ,
@@ -351,6 +357,7 @@ where
351
357
352
358
// TODO(eoz): Call proof generations async
353
359
/// Allows efficient batch lookups by preloading necessary nodes for the lookups.
360
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
354
361
pub async fn batch_lookup (
355
362
& self ,
356
363
akd_labels : & [ AkdLabel ] ,
@@ -392,6 +399,7 @@ where
392
399
Ok ( ( lookup_proofs, root_hash) )
393
400
}
394
401
402
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
395
403
async fn build_lookup_info ( & self , latest_st : & ValueState ) -> Result < LookupInfo , AkdError > {
396
404
let akd_label = & latest_st. username ;
397
405
// Need to account for the case where the latest state is
@@ -419,6 +427,7 @@ where
419
427
} )
420
428
}
421
429
430
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
422
431
async fn get_lookup_info (
423
432
& self ,
424
433
akd_label : AkdLabel ,
@@ -449,13 +458,21 @@ where
449
458
/// this function returns all the values ever associated with it,
450
459
/// and the epoch at which each value was first committed to the server state.
451
460
/// It also returns the proof of the latest version being served at all times.
461
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
452
462
pub async fn key_history (
453
463
& self ,
454
464
akd_label : & AkdLabel ,
455
465
params : HistoryParams ,
456
466
) -> Result < ( HistoryProof , EpochHash ) , AkdError > {
457
467
// The guard will be dropped at the end of the proof generation
468
+ #[ cfg( not( feature = "tracing" ) ) ]
458
469
let _guard = self . cache_lock . read ( ) . await ;
470
+ #[ cfg( feature = "tracing" ) ]
471
+ let _guard = self
472
+ . cache_lock
473
+ . read ( )
474
+ . instrument ( tracing:: trace_span!( "cache_lock.read" ) )
475
+ . await ;
459
476
460
477
let current_azks = self . retrieve_azks ( ) . await ?;
461
478
let current_epoch = current_azks. get_latest_epoch ( ) ;
@@ -616,9 +633,24 @@ where
616
633
{
617
634
// acquire a singleton lock prior to flushing the cache to assert that no
618
635
// cache accesses are underway (i.e. publish/proof generations/etc)
636
+ #[ cfg( not( feature = "tracing" ) ) ]
619
637
let _guard = self . cache_lock . write ( ) . await ;
638
+ #[ cfg( feature = "tracing" ) ]
639
+ let _guard = self
640
+ . cache_lock
641
+ . write ( )
642
+ . instrument ( tracing:: trace_span!( "cache_lock.write" ) )
643
+ . await ;
644
+
620
645
// flush the cache in its entirety
646
+ #[ cfg( not( feature = "tracing" ) ) ]
621
647
self . storage . flush_cache ( ) . await ;
648
+ #[ cfg( feature = "tracing" ) ]
649
+ self . storage
650
+ . flush_cache ( )
651
+ . instrument ( tracing:: trace_span!( "flush_cache" ) )
652
+ . await ;
653
+
622
654
// re-fetch the azks to load it into cache so when we release the cache lock
623
655
// others will see the new AZKS loaded up and ready
624
656
last =
@@ -643,13 +675,21 @@ where
643
675
644
676
/// Returns an [AppendOnlyProof] for the leaves inserted into the underlying tree between
645
677
/// the epochs `audit_start_ep` and `audit_end_ep`.
678
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all, fields( start_epoch = audit_start_ep, end_epoch = audit_end_ep) ) ) ]
646
679
pub async fn audit (
647
680
& self ,
648
681
audit_start_ep : u64 ,
649
682
audit_end_ep : u64 ,
650
683
) -> Result < AppendOnlyProof , AkdError > {
651
684
// The guard will be dropped at the end of the proof generation
685
+ #[ cfg( not( feature = "tracing" ) ) ]
652
686
let _guard = self . cache_lock . read ( ) . await ;
687
+ #[ cfg( feature = "tracing" ) ]
688
+ let _guard = self
689
+ . cache_lock
690
+ . read ( )
691
+ . instrument ( tracing:: trace_span!( "cache_lock.read" ) )
692
+ . await ;
653
693
654
694
let current_azks = self . retrieve_azks ( ) . await ?;
655
695
let current_epoch = current_azks. get_latest_epoch ( ) ;
@@ -673,10 +713,12 @@ where
673
713
}
674
714
675
715
/// Retrieves the [Azks]
716
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
676
717
pub ( crate ) async fn retrieve_azks ( & self ) -> Result < Azks , crate :: errors:: AkdError > {
677
718
Directory :: < TC , S , V > :: get_azks_from_storage ( & self . storage , false ) . await
678
719
}
679
720
721
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all, fields( ignore_cache = ignore_cache) ) ) ]
680
722
async fn get_azks_from_storage (
681
723
storage : & StorageManager < S > ,
682
724
ignore_cache : bool ,
@@ -704,10 +746,12 @@ where
704
746
/// HELPERS ///
705
747
706
748
/// Use this function to retrieve the [VRFPublicKey] for this AKD.
749
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
707
750
pub async fn get_public_key ( & self ) -> Result < VRFPublicKey , AkdError > {
708
751
Ok ( self . vrf . get_vrf_public_key ( ) . await ?)
709
752
}
710
753
754
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
711
755
async fn create_single_update_proof (
712
756
& self ,
713
757
akd_label : & AkdLabel ,
@@ -770,6 +814,7 @@ where
770
814
}
771
815
772
816
/// Gets the root hash at the current epoch.
817
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
773
818
pub async fn get_epoch_hash ( & self ) -> Result < EpochHash , AkdError > {
774
819
let current_azks = self . retrieve_azks ( ) . await ?;
775
820
let latest_epoch = current_azks. get_latest_epoch ( ) ;
@@ -823,11 +868,13 @@ where
823
868
}
824
869
825
870
/// Read-only access to [Directory::lookup](Directory::lookup).
871
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
826
872
pub async fn lookup ( & self , uname : AkdLabel ) -> Result < ( LookupProof , EpochHash ) , AkdError > {
827
873
self . 0 . lookup ( uname) . await
828
874
}
829
875
830
876
/// Read-only access to [Directory::batch_lookup](Directory::batch_lookup).
877
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
831
878
pub async fn batch_lookup (
832
879
& self ,
833
880
unames : & [ AkdLabel ] ,
@@ -836,6 +883,7 @@ where
836
883
}
837
884
838
885
/// Read-only access to [Directory::key_history](Directory::key_history).
886
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
839
887
pub async fn key_history (
840
888
& self ,
841
889
uname : & AkdLabel ,
@@ -845,6 +893,7 @@ where
845
893
}
846
894
847
895
/// Read-only access to [Directory::poll_for_azks_changes](Directory::poll_for_azks_changes).
896
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
848
897
pub async fn poll_for_azks_changes (
849
898
& self ,
850
899
period : tokio:: time:: Duration ,
@@ -854,6 +903,7 @@ where
854
903
}
855
904
856
905
/// Read-only access to [Directory::audit](Directory::audit).
906
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
857
907
pub async fn audit (
858
908
& self ,
859
909
audit_start_ep : u64 ,
@@ -863,11 +913,13 @@ where
863
913
}
864
914
865
915
/// Read-only access to [Directory::get_epoch_hash].
916
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
866
917
pub async fn get_epoch_hash ( & self ) -> Result < EpochHash , AkdError > {
867
918
self . 0 . get_epoch_hash ( ) . await
868
919
}
869
920
870
921
/// Read-only access to [Directory::get_public_key](Directory::get_public_key).
922
+ #[ cfg_attr( feature = "tracing" , tracing:: instrument( skip_all) ) ]
871
923
pub async fn get_public_key ( & self ) -> Result < VRFPublicKey , AkdError > {
872
924
self . 0 . get_public_key ( ) . await
873
925
}
0 commit comments