Skip to content

Conversation

@frolosofsky
Copy link
Member

@frolosofsky frolosofsky commented Jan 10, 2019

This PR prepares finalization state for commits based full sync implementation. There are some interconnected changes:

  • Use individual finalization state per block index (it's still possible to process several blocks by single state though, for keeping old tests, mostly);
  • Add cache of finalization states. It stores a small window of unfinalized states only;
  • Split ProcessNewTip on several functions: ProcessNewTip, ProcessNewCommits, ProcessNewCommit;
  • Cache also supposed to fix Starting node with -reindex does not work #421 (or a major part of it).

Implementation of finalization states restoring isn't final. Currently, it restores from blocks on the disk. It's slow for large blockchains but still fine for our tests. I'm about to implement proper finalization states serialization on every checkpoint with ability to fall back to reading blocks for any missing data. For example, let's restore finalization state of the following blockchain:

b0 - b1 - ... - b49 - b50 - b51 

b49 is a checkpoint and we will have serialized finalization state for it. The algorithm is:

  1. Restore state for b49 from serialized data,
  2. Restore state for b50 and b51 from blocks.

It's only one of possible solutions. Let's discuss it the #432.

Signed-off-by: Stanislav Frolov stanislav@thirdhash.com

@frolosofsky frolosofsky added refactoring Changes which clean up code but don't change the user-visible behavior wip Work in progress which is not supposed to be merged yet finalization labels Jan 10, 2019
@frolosofsky frolosofsky self-assigned this Jan 10, 2019
@frolosofsky
Copy link
Member Author

frolosofsky commented Jan 10, 2019

Snapshot functional tests fail as they try to fork before last finalized checkpoint. @kostyantyn and I are looking at it — a reason for WIP.

Copy link
Member Author

Choose a reason for hiding this comment

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

This diff looks like a mess, however, it's only code moving here. The split view can help a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed this test as it checks C++ standard behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

This test can randomly create forks behind last finalization point, workaround it (fallback to default bitcoin behavior).

Copy link
Member Author

Choose a reason for hiding this comment

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

whitelist is default option for ComparisonTestFramework

Copy link
Member

@Gnappuraz Gnappuraz left a comment

Choose a reason for hiding this comment

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

I really don't think that reading every time the whole blockchain from disk is a good idea, my intuition is that it will make startup time grow linearly with the blockchain and thus potentially taking a long time with disk being a big bottleneck.

Copy link
Member

Choose a reason for hiding this comment

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

Here it seems to me is more a reset to Genesis than a reset to anything else.

Copy link
Member Author

Choose a reason for hiding this comment

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

It resets tip's finalization to the fresh state.

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, it's an incorrect and temporary solution until I implement full-sync based on commits, and this PR is a base for that. I don't want to present too large PR at once.

@frolosofsky
Copy link
Member Author

@Gnappuraz I understand your concern. I'm about to implement finalization states serialization on every checkpoint, but it would be a different PR, and anyway I think to fall back to reading the whole blockchain in case of serialized data isn't presented for any reason.

This implementation allows passing all the tests and works fine for regtest. I'd appreciate if you remove your reject as I don't want to mix too many changes in a single PR. I will add serialization next.

@frolosofsky frolosofsky requested review from a team, AM5800, Gnappuraz and scravy January 11, 2019 10:53
@thothd
Copy link
Member

thothd commented Jan 11, 2019

@Gnappuraz I understand your concern. I'm about to implement finalization states serialization on every checkpoint, but it would be a different PR, and anyway I think to fall back to reading the whole blockchain in case of serialized data isn't presented for any reason.

This implementation allows passing all the tests and works fine for regtest. I'd appreciate if you remove your reject as I don't want to mix too many changes in a single PR. I will add serialization next.

@frolosofsky, what is passing tests on a new code enabling us? if we know it's not the solution we wanna have, I mean it's not that master is currently red and we're looking for a quick fix.
also by looking at the PR it's not clear for me that there was supposed to be a next step of reading the serialized state from disk other than from the blocks

@frolosofsky
Copy link
Member Author

@Gnappuraz The primary purpose of this PR is adding finalization states cache. Once I implemented it I faced with the similar issue as described in #421: if node starts with some blocks presented on the disk, the cache is empty for that blocks, and it's impossible to accept new blocks further. So that, I implemented restoring finalization state from presented blocks.

And I'd point it one more time. After we implement proper serialization of finalization states, I think to keep the possibility to fall back to restoring finalization states from blocks on disk for case serialized data isn't presented for any reason.

Sure, I missed this description in the PR, updated.

@Gnappuraz Gnappuraz dismissed their stale review January 11, 2019 13:57

Removing for the sake of moving forward and with the conditional that a proper solution for handling state serialization and recovery to/from disk

@kostyantyn kostyantyn self-assigned this Jan 15, 2019
frolosofsky and others added 9 commits January 15, 2019 14:58
…lized checkpoint

Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Kostiantyn Stepaniuk <kostia@thirdhash.com>
Signed-off-by: Kostiantyn Stepaniuk <kostia@thirdhash.com>
Signed-off-by: Kostiantyn Stepaniuk <kostia@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
@frolosofsky frolosofsky removed the wip Work in progress which is not supposed to be merged yet label Jan 15, 2019
@frolosofsky frolosofsky requested a review from a team January 15, 2019 15:30
@frolosofsky
Copy link
Member Author

A lot of thanks to @kostyantyn for fixing snapshot tests.

Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Copy link
Member

@kostyantyn kostyantyn left a comment

Choose a reason for hiding this comment

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

utACK 60e7a70

Copy link
Member

@Gnappuraz Gnappuraz left a comment

Choose a reason for hiding this comment

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

utACK 60e7a70

@frolosofsky frolosofsky merged commit 3d9a195 into dtr-org:master Jan 16, 2019
@frolosofsky frolosofsky deleted the fin-state branch January 16, 2019 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

finalization refactoring Changes which clean up code but don't change the user-visible behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants