Skip to content
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

Refactoring the public TD management #487

Merged
merged 6 commits into from
Jun 1, 2018
Merged

Conversation

AlexandraRoatis
Copy link
Contributor

Description

Please include a brief summary of the change that this pull request proposes. Include any relevant motivation and context. List any dependencies required for this change.

  • Storing the total difficulty inside the best block at run time to reduce potential mismatches caused by calling separate functions for the best block and total difficulty.

Fixes Issue # .

Type of change

Insert x into the following checkboxes to confirm (eg. [x]):

  • Bug fix.
  • New feature.
  • Breaking change (a fix or feature that causes existing functionality to not work as expected).
  • Requires documentation update.

Testing

Please describe the tests you used to validate this pull request. Provide any relevant details for test configurations as well as any instructions to reproduce these results.

  • Existing suite of unit tests.

Verification

Insert x into the following checkboxes to confirm (eg. [x]):

  • I have self-reviewed my own code and conformed to the style guidelines of this project.
  • New and existing tests pass locally with my changes.
  • I have added tests for my fix or feature.
  • I have made appropriate changes to the corresponding documentation.
  • My code generates no new warnings.
  • Any dependent changes have been made.

@AlexandraRoatis AlexandraRoatis added the enhancement New feature or request label May 16, 2018
@AlexandraRoatis AlexandraRoatis added this to the v0.2.7 - Island Peak milestone May 16, 2018
@qoire
Copy link
Contributor

qoire commented May 21, 2018

In the previous setup on boot, we load the blockchain and that involves setting the total difficulty both privately and publically, with these changes what used to be pubBestTD will now be block.getDifficulty() until the first new block is imported, after which bestBlock() will be set with the correct totalDifficulty(). Suggestion is to set totalDifficulty() when setting the best block.

} catch (Exception e) {
e.printStackTrace();
}
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting error

if (td == null) {
// TODO: currently returning incorrect total difficulty
parseRLP();
return new BigInteger(1, this.header.getDifficulty());
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be confusing (and was confusing before), we only used getCumulativeDifficulty() previously to set difficulty for genesis, and it works out because at genesis cumulativeDiff == diff. Perhaps we should just swap the genesis initialization code to getDifficulty() and return either the cumulative diff (if it is set) or BigInteger.ZERO if it is not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise we may end up in a situation where we retrieve a non-zero difficulty and we cannot be sure whether it is the difficulty or totalDifficulty

@qoire
Copy link
Contributor

qoire commented May 23, 2018

@yulongaion available to review?

@AionJayT AionJayT merged commit 4b5e4f7 into master-pre-merge Jun 1, 2018
@AlexandraRoatis AlexandraRoatis deleted the db-td-refactor branch June 1, 2018 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants