@@ -61,9 +61,10 @@ public SynchronizationServiceImpl(
6161 this .protocolContext = protocolContext ;
6262 this .protocolSchedule = protocolSchedule ;
6363 this .syncState = syncState ;
64- this .worldStateArchive = Optional .ofNullable (worldStateArchive )
65- .filter (z -> z instanceof BonsaiWorldStateProvider )
66- .map (BonsaiWorldStateProvider .class ::cast );
64+ this .worldStateArchive =
65+ Optional .ofNullable (worldStateArchive )
66+ .filter (z -> z instanceof BonsaiWorldStateProvider )
67+ .map (BonsaiWorldStateProvider .class ::cast );
6768 }
6869
6970 @ Override
@@ -102,9 +103,7 @@ public boolean setHeadUnsafe(final BlockHeader blockHeader, final BlockBody bloc
102103
103104 final MutableBlockchain blockchain = protocolContext .getBlockchain ();
104105
105- if (worldStateArchive
106- .flatMap (archive -> archive .getMutable (coreHeader , true ))
107- .isPresent ()) {
106+ if (worldStateArchive .flatMap (archive -> archive .getMutable (coreHeader , true )).isPresent ()) {
108107 if (coreHeader .getParentHash ().equals (blockchain .getChainHeadHash ())) {
109108 LOG .atDebug ()
110109 .setMessage (
@@ -131,20 +130,22 @@ public boolean isInitialSyncPhaseDone() {
131130 @ Override
132131 public void disableWorldStateTrie () {
133132 // TODO MAYBE FIND A BEST WAY TO DELETE AND DISABLE TRIE
134- worldStateArchive .ifPresent (archive -> {
135- archive .getDefaultBonsaiWorldStateConfig ().setTrieDisabled (true );
136- final BonsaiWorldStateKeyValueStorage worldStateStorage = archive .getWorldStateStorage ();
137- final Optional <Hash > worldStateBlockHash = worldStateStorage .getWorldStateBlockHash ();
138- final Optional <Bytes > worldStateRootHash = worldStateStorage .getWorldStateRootHash ();
139- if (worldStateRootHash .isPresent () && worldStateBlockHash .isPresent ()) {
140- worldStateStorage .clearTrie ();
141- // keep root and block hash in the trie branch
142- final BonsaiWorldStateKeyValueStorage .BonsaiUpdater updater = worldStateStorage .updater ();
143- updater .saveWorldState (worldStateBlockHash .get (), Bytes32 .wrap (worldStateRootHash .get ()),
144- Bytes .EMPTY );
145- updater .commit ();
146- worldStateStorage .upgradeToFullFlatDbMode ();
147- }
148- });
133+ worldStateArchive .ifPresent (
134+ archive -> {
135+ archive .getDefaultBonsaiWorldStateConfig ().setTrieDisabled (true );
136+ final BonsaiWorldStateKeyValueStorage worldStateStorage = archive .getWorldStateStorage ();
137+ final Optional <Hash > worldStateBlockHash = worldStateStorage .getWorldStateBlockHash ();
138+ final Optional <Bytes > worldStateRootHash = worldStateStorage .getWorldStateRootHash ();
139+ if (worldStateRootHash .isPresent () && worldStateBlockHash .isPresent ()) {
140+ worldStateStorage .clearTrie ();
141+ // keep root and block hash in the trie branch
142+ final BonsaiWorldStateKeyValueStorage .BonsaiUpdater updater =
143+ worldStateStorage .updater ();
144+ updater .saveWorldState (
145+ worldStateBlockHash .get (), Bytes32 .wrap (worldStateRootHash .get ()), Bytes .EMPTY );
146+ updater .commit ();
147+ worldStateStorage .upgradeToFullFlatDbMode ();
148+ }
149+ });
149150 }
150151}
0 commit comments