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

Helper CLI for checking consensus #800

Merged
merged 9 commits into from
Feb 5, 2019
Merged

Conversation

AlexandraRoatis
Copy link
Contributor

@AlexandraRoatis AlexandraRoatis commented Jan 29, 2019

Description

Adding a new CLI option --redo-import / --redo-import <start_height> that imports all the blocks from the genesis block or the given starting block till the top of the chain performing all the consensus checks.

When starting from the genesis block all the other databases are dropped before the reimport starts.

Fixes Issue #560.

Type of change

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

  • Bug fix.
  • New feature.
  • Enhancement.
  • Unit test.
  • 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 unit tests + manual 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.

Copy link
Contributor

@aion-kelvin aion-kelvin left a comment

Choose a reason for hiding this comment

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

Looks pretty good ... have a few small suggestions and a question

modAionImpl/src/org/aion/zero/impl/cli/Arguments.java Outdated Show resolved Hide resolved
modAionImpl/src/org/aion/zero/impl/cli/Cli.java Outdated Show resolved Hide resolved

boolean fail = false;

long start = System.currentTimeMillis();
Copy link
Contributor

Choose a reason for hiding this comment

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

nanoTime is more recommended for calculating time differences, I believe

https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime()

Copy link
Contributor Author

@AlexandraRoatis AlexandraRoatis Feb 4, 2019

Choose a reason for hiding this comment

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

Since the estimates are very inaccurate due to the nature of the operations being timed, I don't think switching to nanoTime would be very useful here. Especially since at best they give a minimum wait time to completion estimate, which is typically overly optimistic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make a note of this suggestion in the initial issue for later enhancement.

modAionImpl/src/org/aion/zero/impl/db/RecoveryUtils.java Outdated Show resolved Hide resolved
@AlexandraRoatis AlexandraRoatis force-pushed the re-import branch 2 times, most recently from 6958dee to c3f5431 Compare February 4, 2019 19:54
@@ -538,9 +538,10 @@ public synchronized void compactState() {

// TEMPORARY: here to support the ConsensusTest
public Pair<ImportResult, AionBlockSummary> tryToConnectAndFetchSummary(
AionBlock block, long currTimeSeconds) {
AionBlock block, long currTimeSeconds, boolean doExistCheck) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR must have branched off when this change was still in there. It's been removed and we should make sure this doesn't go in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're referring to the other boolean constant that disabled the time check. The public tryToConnectAndFetchSummary currently appears on all branches. This boolean flag is needed here, otherwise the block will not get imported because it's already in the database.

for (IByteArrayKeyValueDatabase db : databaseGroup) {
if (!names.contains(db.getName().get())) {
LOG.warn("Dropping database " + db.toString());
db.drop();
Copy link
Contributor

Choose a reason for hiding this comment

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

up to you, but I generally like to perform the action first and then broadcast a message, just in case the action failed then you're not left wondering whether the log is incorrect or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a log after the drop as well. I find the before log useful because if the processing gets stuck, we can know where.

if (currentBlock % stepSize == 0) {
long time = System.currentTimeMillis() - start;

double timePerBlock = time / (currentBlock - startHeight + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

one of the operands should be cast to a double if you actually want to get the precision 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.

done.

try {
result =
chain.tryToConnectAndFetchSummary(
block, System.currentTimeMillis() / THOUSAND_MS, false);
Copy link
Contributor

@aionick aionick Feb 5, 2019

Choose a reason for hiding this comment

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

TimeUnit is a nice alternative to changing between time units; pretty minor & really up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make a note of this suggestion in the initial issue for later enhancement.

@AlexandraRoatis AlexandraRoatis merged commit 8246cd6 into master-pre-merge Feb 5, 2019
@AionJayT AionJayT deleted the re-import branch February 5, 2019 22:52
@AionJayT AionJayT restored the re-import branch February 5, 2019 22:52
@AlexandraRoatis AlexandraRoatis deleted the re-import branch February 6, 2019 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants