@@ -12,7 +12,7 @@ use std::{
1212 } ,
1313} ;
1414
15- use anyhow:: { anyhow, bail, Result } ;
15+ use anyhow:: { anyhow, bail, ensure , Result } ;
1616use async_lock:: RwLock ;
1717use async_trait:: async_trait;
1818use hotshot_types:: {
@@ -28,9 +28,10 @@ use hotshot_types::{
2828 LightClientStateUpdateCertificateV2 , NextEpochQuorumCertificate2 , QuorumCertificate2 ,
2929 UpgradeCertificate ,
3030 } ,
31+ stake_table:: HSStakeTable ,
3132 traits:: {
3233 node_implementation:: { ConsensusTime , NodeType } ,
33- storage:: Storage ,
34+ storage:: { EpochStateStorage , Storage } ,
3435 } ,
3536 vote:: HasViewNumber ,
3637} ;
@@ -174,6 +175,8 @@ impl<TYPES: NodeType> TestStorage<TYPES> {
174175
175176#[ async_trait]
176177impl < TYPES : NodeType > Storage < TYPES > for TestStorage < TYPES > {
178+ type StakeTableMetadata = ( ) ;
179+
177180 async fn append_vid ( & self , proposal : & Proposal < TYPES , ADVZDisperseShare < TYPES > > ) -> Result < ( ) > {
178181 if self . should_return_err . load ( Ordering :: Relaxed ) {
179182 bail ! ( "Failed to append VID proposal to storage" ) ;
@@ -426,41 +429,60 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {
426429
427430 Ok ( ( ) )
428431 }
432+ }
429433
430- async fn store_drb_result ( & self , epoch : TYPES :: Epoch , drb_result : DrbResult ) -> Result < ( ) > {
431- let mut inner = self . inner . write ( ) . await ;
432-
433- inner. drb_results . insert ( epoch, drb_result) ;
434-
435- Ok ( ( ) )
434+ #[ async_trait]
435+ impl < TYPES : NodeType > EpochStateStorage < TYPES > for TestStorage < TYPES > {
436+ async fn load_epoch_root ( & self , epoch : TYPES :: Epoch ) -> Result < Option < TYPES :: BlockHeader > > {
437+ let inner = self . inner . read ( ) . await ;
438+ Ok ( inner. epoch_roots . get ( & epoch) . cloned ( ) )
436439 }
437440
438- async fn store_epoch_root (
441+ async fn load_stake_table (
439442 & self ,
440- epoch : TYPES :: Epoch ,
441- block_header : TYPES :: BlockHeader ,
442- ) -> Result < ( ) > {
443- let mut inner = self . inner . write ( ) . await ;
444-
445- inner. epoch_roots . insert ( epoch, block_header) ;
443+ _epoch : TYPES :: Epoch ,
444+ ) -> Result < Option < ( HSStakeTable < TYPES > , Box < dyn std:: any:: Any + Send + Sync > ) > > {
445+ Ok ( None )
446+ }
446447
447- Ok ( ( ) )
448+ async fn load_drb_result ( & self , epoch : TYPES :: Epoch ) -> Result < DrbResult > {
449+ match self . load_drb_input ( * epoch) . await {
450+ Ok ( drb_input) => {
451+ ensure ! ( drb_input. iteration == drb_input. difficulty_level) ;
452+ Ok ( drb_input. value )
453+ } ,
454+ Err ( e) => Err ( e) ,
455+ }
448456 }
449457
450458 async fn store_drb_input ( & self , drb_input : DrbInput ) -> Result < ( ) > {
451459 let mut inner = self . inner . write ( ) . await ;
452-
453460 inner. drb_inputs . insert ( drb_input. epoch , drb_input) ;
454-
455461 Ok ( ( ) )
456462 }
457463
458464 async fn load_drb_input ( & self , epoch : u64 ) -> Result < DrbInput > {
459465 let inner = self . inner . read ( ) . await ;
466+ inner
467+ . drb_inputs
468+ . get ( & epoch)
469+ . cloned ( )
470+ . ok_or_else ( || anyhow ! ( "DRB input not found for epoch {}" , epoch) )
471+ }
460472
461- match inner. drb_inputs . get ( & epoch) {
462- Some ( drb_input) => Ok ( drb_input. clone ( ) ) ,
463- None => Err ( anyhow ! ( "Missing DrbInput for epoch {}" , epoch) ) ,
464- }
473+ async fn store_drb_result ( & self , epoch : TYPES :: Epoch , drb_result : DrbResult ) -> Result < ( ) > {
474+ let mut inner = self . inner . write ( ) . await ;
475+ inner. drb_results . insert ( epoch, drb_result) ;
476+ Ok ( ( ) )
477+ }
478+
479+ async fn store_epoch_root (
480+ & self ,
481+ epoch : TYPES :: Epoch ,
482+ block_header : TYPES :: BlockHeader ,
483+ ) -> Result < ( ) > {
484+ let mut inner = self . inner . write ( ) . await ;
485+ inner. epoch_roots . insert ( epoch, block_header) ;
486+ Ok ( ( ) )
465487 }
466488}
0 commit comments