-
Notifications
You must be signed in to change notification settings - Fork 285
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
Conversation
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 => { |
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.
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>; |
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.
processBlocks(block: Interfaces.IBlock[], callback: any): Promise<any>; | |
processBlocks(blocks: Interfaces.IBlock[], callback: any): Promise<any>; |
} | ||
|
||
try { | ||
// save accepted blocks to db |
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.
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; |
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.
Store blocks[blocks.length - 1]
in a variable named currentBlock
so it is more clear what the value is.
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?
Does this PR release a new version?
Checklist