Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Handle unavailable world states #824

Merged
merged 11 commits into from
Feb 12, 2019

Conversation

ajsutton
Copy link
Contributor

@ajsutton ajsutton commented Feb 11, 2019

PR description

Make WorldStateArchive return an Optional<WorldState> and explicitly track which world states are available.

Updates callers to at least reasonably handle cases where the world state they need is not available.

@ajsutton ajsutton changed the title ## PR description Make WorldStateArchive return an Optional<WorldState> and explicitly track which world states are available. Handle unavailable world states Feb 11, 2019
@ajsutton ajsutton added the work in progress Work on this pull request is ongoing label Feb 11, 2019

import java.util.Optional;

public class KeyValueStorageWorldStateStorage implements WorldStateStorage {

private static final BytesValue AVAILABILITY_PREFIX = BytesValue.of("available".getBytes(UTF_8));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could handle this by flipping the approach and saving "provisional" state roots in a separate location. For now, the only provisional root would be from fast sync. When fast sync is done, we could then confirm that provisional state root and move it into regular storage. The advantages of flipping the approach are: no need to migrate existing dbs and more efficient storage (no need to store extra data for every valid root).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to considering a state as available if the root node is present. Fast sync delays committing the root node until the rest of the state has been downloaded. Also realised that when the world state downloader is first started, rather than checking if the world state is empty, it can check if the world state it's after is available and skip downloading if it is (the empty world state is always available).

…es not be available cleanly.

Currently a world state is considered available if it's root node is available.
…ge. Still using presence of root hash as the flag for world state being availalbe.
…ad of assuming the entire world state is available if the root node is.
…is present.

Delay storing the root hash when fast syncing a world state until the download completes so it isn't considered available.
Skip downloading world states that are already available.
@ajsutton ajsutton force-pushed the optional-world-state branch from fab435c to 725ceba Compare February 12, 2019 00:29
@ajsutton ajsutton removed the work in progress Work on this pull request is ongoing label Feb 12, 2019
public WorldState get(final Hash rootHash) {
return getMutable(rootHash);
public Optional<WorldState> get(final Hash rootHash) {
return getMutable(rootHash).map(state -> state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this map here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the compiler happy - it changes the type from Optional<MutableWorldState> to Optional<WorldState>. Since MutableWorldState is an instance of WorldState you don't need to change the object but Optional<MutableWorldState> is not an instance of Optional<WorldState> so you do need to do a mapping.

I'm sure someone can insert an appropriate rant about the limitations of Java generics here. :)

@ajsutton ajsutton merged commit 2770eb3 into PegaSysEng:master Feb 12, 2019
@ajsutton ajsutton deleted the optional-world-state branch February 12, 2019 22:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants