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

feat: batch block database inserts when syncing #2500

Merged
merged 7 commits into from
Apr 29, 2019

Conversation

air1one
Copy link
Contributor

@air1one air1one commented Apr 29, 2019

Summary

Batch block database inserts. Resolves #1945.

Did some benchmark for testnet sync (on potato server) : 7-8min to sync to 540k blocks vs a bit more than 20min non-batching.

What kind of change does this PR introduce?

  • New feature

Does this PR release a new version?

  • No

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works

@ghost
Copy link

ghost commented Apr 29, 2019

The ci/circleci: test-node10-e2e job is failing as of c59d771ea7478f037c6e774549ddb695cd39fdae. Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

} catch (exceptionSaveBlocks) {
logger.error(`Could not save ${acceptedBlocks.length} blocks to database : ${exceptionSaveBlocks.stack}`);

const resetToHeight = async height => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const resetToHeight = async height => {
const resetToHeight = async height => {
try {
return await this.removeTopBlocks(
app
.resolvePlugin<State.IStateService>("state")
.getStore()
.getLastHeight() - height,
);
} catch (e) {
logger.error(`Could not remove top blocks from database : ${e.stack}`);
return resetToHeight(height); // keep trying, we can't do anything while this fails
}
};

* @param {Function} callback
* @return {(Function|void)}
*/
processBlock(block: Interfaces.IBlock, callback: any): Promise<any>;
processBlocks(block: Interfaces.IBlock[], callback: any): Promise<any>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
processBlocks(block: Interfaces.IBlock[], callback: any): Promise<any>;
processBlocks(blocks: Interfaces.IBlock[], callback: any): Promise<any>;

}

try {
// save accepted blocks to db
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment can be removed.

// broadcast only current block
const blocktime: number = config.getMilestone(block.data.height).blocktime;
const blocktime: number = config.getMilestone(blocks[blocks.length - 1].data.height).blocktime;
Copy link
Contributor

Choose a reason for hiding this comment

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

Store blocks[blocks.length - 1] in a variable named currentBlock so it is more clear what the value is.

@faustbrian faustbrian merged commit ca74c46 into develop Apr 29, 2019
@ghost ghost deleted the feat/batch-block-db branch April 29, 2019 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants