22package com .hedera .node .app .workflows ;
33
44import static com .hedera .hapi .node .base .ResponseCodeEnum .SUCCESS ;
5+ import static com .hedera .node .app .blocks .schemas .V0560BlockStreamSchema .BLOCK_STREAM_INFO_KEY ;
56import static com .hedera .node .app .records .BlockRecordService .EPOCH ;
67import static com .hedera .node .app .records .schemas .V0490BlockRecordSchema .BLOCK_INFO_STATE_KEY ;
78import static com .hedera .node .app .util .FileUtilities .createFileID ;
89import static com .hedera .node .app .util .FileUtilities .getFileContent ;
910import static com .hedera .node .app .util .FileUtilities .observePropertiesAndPermissions ;
11+ import static com .hedera .node .config .types .StreamMode .RECORDS ;
1012import static java .util .Objects .requireNonNull ;
1113
1214import com .hedera .hapi .node .base .FileID ;
1315import com .hedera .hapi .node .state .blockrecords .BlockInfo ;
16+ import com .hedera .hapi .node .state .blockstream .BlockStreamInfo ;
1417import com .hedera .hapi .node .state .file .File ;
18+ import com .hedera .node .app .blocks .BlockStreamService ;
1519import com .hedera .node .app .config .BootstrapConfigProviderImpl ;
1620import com .hedera .node .app .config .ConfigProviderImpl ;
1721import com .hedera .node .app .fees .ExchangeRateManager ;
2529import com .hedera .node .config .ConfigProvider ;
2630import com .hedera .node .config .data .FilesConfig ;
2731import com .hedera .node .config .data .HederaConfig ;
32+ import com .hedera .node .config .types .StreamMode ;
2833import com .hedera .pbj .runtime .io .buffer .Bytes ;
2934import com .swirlds .state .State ;
3035import dagger .Binds ;
3338import edu .umd .cs .findbugs .annotations .NonNull ;
3439import edu .umd .cs .findbugs .annotations .Nullable ;
3540import java .util .Optional ;
36- import java .util .function .Consumer ;
3741import javax .inject .Singleton ;
3842import org .apache .logging .log4j .LogManager ;
3943import org .apache .logging .log4j .Logger ;
4650public interface FacilityInitModule {
4751 Logger log = LogManager .getLogger (FacilityInitModule .class );
4852
53+ @ FunctionalInterface
54+ interface FacilityInitializer {
55+ void initialize (@ NonNull State state , @ NonNull StreamMode streamMode );
56+ }
57+
4958 @ Binds
5059 @ Singleton
5160 ConfigProvider bindConfigProvider (@ NonNull ConfigProviderImpl configProvider );
@@ -61,16 +70,18 @@ public interface FacilityInitModule {
6170 */
6271 @ Provides
6372 @ Singleton
64- static Consumer < State > initFacilities (
73+ static FacilityInitializer initFacilities (
6574 @ NonNull final FeeManager feeManager ,
6675 @ NonNull final FileServiceImpl fileService ,
6776 @ NonNull final ConfigProviderImpl configProvider ,
6877 @ NonNull final BootstrapConfigProviderImpl bootstrapConfigProvider ,
6978 @ NonNull final ExchangeRateManager exchangeRateManager ,
7079 @ NonNull final ThrottleServiceManager throttleServiceManager ,
7180 @ NonNull final WorkingStateAccessor workingStateAccessor ) {
72- return state -> {
73- if (hasHandledGenesisTxn (state )) {
81+ return (state , streamMode ) -> {
82+ requireNonNull (state );
83+ requireNonNull (streamMode );
84+ if (hasHandledGenesisTxn (state , streamMode )) {
7485 initializeExchangeRateManager (state , configProvider , exchangeRateManager );
7586 initializeFeeManager (state , configProvider , feeManager );
7687 observePropertiesAndPermissions (state , configProvider .getConfiguration (), (properties , permissions ) -> {
@@ -121,13 +132,22 @@ private static void initializeFeeManager(
121132 }
122133 }
123134
124- private static boolean hasHandledGenesisTxn (@ NonNull final State state ) {
125- final var blockInfo = state .getReadableStates (BlockRecordService .NAME )
126- .<BlockInfo >getSingleton (BLOCK_INFO_STATE_KEY )
127- .get ();
128- return !EPOCH .equals (Optional .ofNullable (blockInfo )
129- .map (BlockInfo ::consTimeOfLastHandledTxn )
130- .orElse (EPOCH ));
135+ private static boolean hasHandledGenesisTxn (@ NonNull final State state , @ NonNull final StreamMode streamMode ) {
136+ if (streamMode == RECORDS ) {
137+ final var blockInfo = state .getReadableStates (BlockRecordService .NAME )
138+ .<BlockInfo >getSingleton (BLOCK_INFO_STATE_KEY )
139+ .get ();
140+ return !EPOCH .equals (Optional .ofNullable (blockInfo )
141+ .map (BlockInfo ::consTimeOfLastHandledTxn )
142+ .orElse (EPOCH ));
143+ } else {
144+ final var blockStreamInfo = state .getReadableStates (BlockStreamService .NAME )
145+ .<BlockStreamInfo >getSingleton (BLOCK_STREAM_INFO_KEY )
146+ .get ();
147+ return !EPOCH .equals (Optional .ofNullable (blockStreamInfo )
148+ .map (BlockStreamInfo ::lastHandleTime )
149+ .orElse (EPOCH ));
150+ }
131151 }
132152
133153 private static @ Nullable File getFileFromStorage (
0 commit comments