-
Notifications
You must be signed in to change notification settings - Fork 130
Conversation
WorldStateArchive
return an Optional<WorldState>
and explicitly track which world states are available.
...e/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java
Outdated
Show resolved
Hide resolved
|
||
import java.util.Optional; | ||
|
||
public class KeyValueStorageWorldStateStorage implements WorldStateStorage { | ||
|
||
private static final BytesValue AVAILABILITY_PREFIX = BytesValue.of("available".getBytes(UTF_8)); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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).
27d1d8a
to
fab435c
Compare
…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.
fab435c
to
725ceba
Compare
public WorldState get(final Hash rootHash) { | ||
return getMutable(rootHash); | ||
public Optional<WorldState> get(final Hash rootHash) { | ||
return getMutable(rootHash).map(state -> state); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. :)
PR description
Make
WorldStateArchive
return anOptional<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.