@@ -12,7 +12,9 @@ use crate::{
1212 } ,
1313} ;
1414use anyhow:: bail;
15- use aptos_consensus_types:: proof_of_store:: { BatchInfo , BatchInfoExt , SignedBatchInfo } ;
15+ use aptos_consensus_types:: proof_of_store:: {
16+ BatchInfo , BatchInfoExt , BatchKind , ExtraBatchInfo , SignedBatchInfo , TBatchInfo ,
17+ } ;
1618use aptos_crypto:: { CryptoMaterialError , HashValue } ;
1719use aptos_executor_types:: { ExecutorError , ExecutorResult } ;
1820use aptos_infallible:: Mutex ;
@@ -26,6 +28,7 @@ use fail::fail_point;
2628use futures:: { future:: Shared , FutureExt } ;
2729use once_cell:: sync:: OnceCell ;
2830use std:: {
31+ any:: TypeId ,
2932 collections:: { BTreeSet , HashMap } ,
3033 future:: Future ,
3134 pin:: Pin ,
@@ -378,10 +381,10 @@ impl BatchStore {
378381 ret
379382 }
380383
381- fn generate_signed_batch_info (
384+ fn generate_signed_batch_info < T : TBatchInfo > (
382385 & self ,
383- batch_info : BatchInfo ,
384- ) -> Result < SignedBatchInfo < BatchInfo > , CryptoMaterialError > {
386+ batch_info : T ,
387+ ) -> Result < SignedBatchInfo < T > , CryptoMaterialError > {
385388 fail_point ! ( "quorum_store::create_invalid_signed_batch_info" , |_| {
386389 Ok ( SignedBatchInfo :: new_with_signature(
387390 batch_info. clone( ) ,
@@ -392,10 +395,17 @@ impl BatchStore {
392395 SignedBatchInfo :: new ( batch_info, & self . validator_signer )
393396 }
394397
395- fn persist_inner ( & self , persist_request : PersistedValue ) -> Option < SignedBatchInfo < BatchInfo > > {
398+ fn persist_inner < T : TBatchInfo > (
399+ & self ,
400+ batch_info : T ,
401+ persist_request : PersistedValue ,
402+ ) -> Option < SignedBatchInfo < T > > {
403+ assert ! (
404+ batch_info. as_batch_info( ) == persist_request. batch_info( ) ,
405+ "Provided batch info doesn't match persist request batch info"
406+ ) ;
396407 match self . save ( & persist_request) {
397408 Ok ( needs_db) => {
398- let batch_info = persist_request. batch_info ( ) . clone ( ) ;
399409 trace ! ( "QS: sign digest {}" , persist_request. digest( ) ) ;
400410 if needs_db {
401411 #[ allow( clippy:: unwrap_in_result) ]
@@ -405,7 +415,6 @@ impl BatchStore {
405415 }
406416 self . generate_signed_batch_info ( batch_info) . ok ( )
407417 } ,
408-
409418 Err ( e) => {
410419 debug ! ( "QS: failed to store to cache {:?}" , e) ;
411420 None
@@ -486,7 +495,37 @@ impl BatchWriter for BatchStore {
486495 fn persist ( & self , persist_requests : Vec < PersistedValue > ) -> Vec < SignedBatchInfo < BatchInfo > > {
487496 let mut signed_infos = vec ! [ ] ;
488497 for persist_request in persist_requests. into_iter ( ) {
489- if let Some ( signed_info) = self . persist_inner ( persist_request. clone ( ) ) {
498+ let batch_info = persist_request. batch_info ( ) . clone ( ) ;
499+ if let Some ( signed_info) = self . persist_inner ( batch_info, persist_request. clone ( ) ) {
500+ self . notify_subscribers ( persist_request) ;
501+ signed_infos. push ( signed_info) ;
502+ }
503+ }
504+ signed_infos
505+ }
506+
507+ fn persist_v2 (
508+ & self ,
509+ persist_requests : Vec < PersistedValue > ,
510+ ) -> Vec < SignedBatchInfo < BatchInfoExt > > {
511+ let mut signed_infos = vec ! [ ] ;
512+ for persist_request in persist_requests. into_iter ( ) {
513+ let is_encrypted_batch = persist_request
514+ . payload ( )
515+ . as_ref ( )
516+ . expect ( "Payload must be available for persistence" )
517+ . iter ( )
518+ . any ( |txn| txn. is_encrypted ( ) ) ;
519+ let batch_kind = if is_encrypted_batch {
520+ BatchKind :: Encrypted
521+ } else {
522+ BatchKind :: Normal
523+ } ;
524+ let batch_info = BatchInfoExt :: V2 {
525+ info : persist_request. batch_info ( ) . clone ( ) ,
526+ extra : ExtraBatchInfo { batch_kind } ,
527+ } ;
528+ if let Some ( signed_info) = self . persist_inner ( batch_info, persist_request. clone ( ) ) {
490529 self . notify_subscribers ( persist_request) ;
491530 signed_infos. push ( signed_info) ;
492531 }
@@ -611,4 +650,9 @@ impl<T: QuorumStoreSender + Clone + Send + Sync + 'static> BatchReader for Batch
611650
612651pub trait BatchWriter : Send + Sync {
613652 fn persist ( & self , persist_requests : Vec < PersistedValue > ) -> Vec < SignedBatchInfo < BatchInfo > > ;
653+
654+ fn persist_v2 (
655+ & self ,
656+ persist_requests : Vec < PersistedValue > ,
657+ ) -> Vec < SignedBatchInfo < BatchInfoExt > > ;
614658}
0 commit comments