-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FastSync with skipHistory fixes #1060
Conversation
zilm13
commented
Apr 25, 2018
- modified structure of headers store used in FastSync
- if skipHistory is used, headers store is used for getBlockHeaders message answer, so fixing Lack of commonly validating blocks if sync.fast.skipHistory = true #1058
- total difficulty recalculated if skipHistory used, fixing Incorrect totalDifficulty after FastSync in skipHistory mode #1041
- migration added to modify DB for those who already did sync with skipHistory
- if skipHistory was not used, headers store is removed, because it's not used at all (1.6GB currently on MainNet)
… skipped during fast sync
…kipHistory is used
public HeaderStore headerStore() { | ||
DbSource<byte[]> dataSource = keyValueDataSource("headers"); | ||
|
||
WriteCache.BytesKey<byte[]> cache = new WriteCache.BytesKey<>( |
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'd suggest to simplify source pipeline in following way:
xorSource("header")
\
cachedSource -> kvSource("headers")
/
xorSource("index")
/** | ||
* Dummy serializer (doesn't change anything) | ||
*/ | ||
public final static Serializer<byte[], byte[]> DummySerializer = new Serializer<byte[], byte[]>() { |
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.
Maybe IdentitySerializer
is better? dummy
pretty equals to stub
@@ -874,6 +898,10 @@ private BlockHeader getPivotHeaderByHash(byte[] pivotBlockHash) throws Exception | |||
return null; | |||
} | |||
|
|||
public boolean isEndedOrNotStarted() { |
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.
Isn't isInProgress()
a better name?
for (int i = 1; i < headerSource.size(); ++i) { | ||
BlockHeader curHeader = headerSource.get(i); | ||
headerStore.saveHeader(curHeader); | ||
headerSource.set(i, null); |
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.
Won't two sources with same physical source collide 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.
The same chance that two xor sources in one db will collide. Very small.
* @deprecated | ||
* Remove alone with migration from {@link org.ethereum.manager.WorldManager} | ||
*/ | ||
@Deprecated | ||
@Bean | ||
@Lazy | ||
public DataSourceArray<BlockHeader> headerSource() { |
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.
Let's get rid of this. It can be created manually to run a migration
* adds additional headerSource to Blockchain | ||
* as Blockstore is incomplete in this mode | ||
*/ | ||
private void fastSyncDbJobs() { |
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.
Seems WorldManager is not the best place for that code. Let's move it to separate class.
/** | ||
* No change serializer (doesn't change anything) | ||
*/ | ||
public final static Serializer<byte[], byte[]> NoChangeSerializer = new Serializer<byte[], byte[]>() { |
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.
AsIs
maybe? :)
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'm fine with it