Skip to content

Commit

Permalink
log and return Optional.empty on failed log rolling
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Oct 24, 2022
1 parent 39ae004 commit a9df9b3
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.hyperledger.besu.ethereum.chain.BlockAddedEvent;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.SnapshotMutableWorldState;
import org.hyperledger.besu.ethereum.proof.WorldStateProof;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
Expand Down Expand Up @@ -118,7 +119,7 @@ private void blockAddedHandler(final BlockAddedEvent event) {

@Override
public Optional<WorldState> get(final Hash rootHash, final Hash blockHash) {
final Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> layeredWorldState =
final Optional<MutableWorldState> layeredWorldState =
trieLogManager.getBonsaiLayeredWorldState(blockHash);
if (layeredWorldState.isPresent()) {
return Optional.of(layeredWorldState.get());
Expand All @@ -136,8 +137,7 @@ public boolean isWorldStateAvailable(final Hash rootHash, final Hash blockHash)
|| worldStateStorage.isWorldStateAvailable(rootHash, blockHash);
}

public Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> getMutableSnapshot(
final Hash blockHash) {
public Optional<MutableWorldState> getMutableSnapshot(final Hash blockHash) {
// TODO: decide whether we want to use BonsaiSnapshotWorldState or
// BonsaiSnapshotPersistedWorldState
return rollMutableStateToBlockHash(
Expand All @@ -147,7 +147,7 @@ public Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> getMutable
}

@Override
public Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> getMutable(
public Optional<MutableWorldState> getMutable(
final Hash rootHash, final Hash blockHash, final boolean shouldPersistState) {
if (!shouldPersistState) {
return blockchain
Expand All @@ -170,15 +170,15 @@ public Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> getMutable
}
}

private Function<Hash, Optional<org.hyperledger.besu.ethereum.core.MutableWorldState>>
snapshotOrLayeredWorldState(final boolean useSnapshots) {
private Function<Hash, Optional<MutableWorldState>> snapshotOrLayeredWorldState(
final boolean useSnapshots) {
if (useSnapshots) {
// use snapshots:
return this::getMutableSnapshot;
} else {
// otherwise use layered worldstate:
return blockHash -> {
final Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> layeredWorldState =
final Optional<MutableWorldState> layeredWorldState =
trieLogManager.getBonsaiLayeredWorldState(blockHash);
if (layeredWorldState.isPresent()) {
return layeredWorldState;
Expand Down Expand Up @@ -208,14 +208,12 @@ public Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> getMutable
}

@Override
public Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> getMutable(
final Hash rootHash, final Hash blockHash) {
public Optional<MutableWorldState> getMutable(final Hash rootHash, final Hash blockHash) {
return rollMutableStateToBlockHash(persistedState, blockHash);
}

private Optional<org.hyperledger.besu.ethereum.core.MutableWorldState>
rollMutableStateToBlockHash(
final BonsaiPersistedWorldState mutableState, final Hash blockHash) {
private Optional<MutableWorldState> rollMutableStateToBlockHash(
final BonsaiPersistedWorldState mutableState, final Hash blockHash) {
if (blockHash.equals(mutableState.blockHash())) {
return Optional.of(mutableState);
} else {
Expand Down Expand Up @@ -283,10 +281,11 @@ public Optional<org.hyperledger.besu.ethereum.core.MutableWorldState> getMutable
} catch (final Exception e) {
// if we fail we must clean up the updater
bonsaiUpdater.reset();
throw new RuntimeException(e);
LOG.debug("Archive rolling failed for block hash " + blockHash, e);
return Optional.empty();
}
} catch (final RuntimeException re) {
re.printStackTrace(System.out);
LOG.debug("Archive rolling failed for block hash " + blockHash, e);
return Optional.empty();
}
}
Expand All @@ -298,7 +297,7 @@ BonsaiWorldStateUpdater getUpdaterFromPersistedState(
}

@Override
public org.hyperledger.besu.ethereum.core.MutableWorldState getMutable() {
public MutableWorldState getMutable() {
return persistedState;
}

Expand Down

0 comments on commit a9df9b3

Please sign in to comment.