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

ChainDB: pass new block to ledger validation #1398

Merged
merged 1 commit into from Jan 30, 2020

Conversation

mrBliss
Copy link
Contributor

@mrBliss mrBliss commented Jan 6, 2020

In ChainDB.addBlock, we receive a new block and use it to try switch to a longer chain. This will require applying the block to the ledger, which requires reading the block from disk and parsing it again. This is right in the critical path of (bulk) chain sync.

Since we have the block in memory, we can avoid the redundant read and pass it to the validation code directly.

Note that when switching to a fork or when we can extend the new chain with more blocks after the new block, we'll still have to read blocks from disk in order to validate them, but not the new block.

@mrBliss mrBliss added consensus issues related to ouroboros-consensus optimisation Performance optimisation chain db labels Jan 6, 2020
@mrBliss mrBliss requested a review from edsko January 6, 2020 10:08
@mrBliss mrBliss force-pushed the mrBliss/pass-new-block-to-ledger-validation branch from 3739d62 to 3bed5e0 Compare January 6, 2020 10:08
Copy link
Contributor

@edsko edsko left a comment

Choose a reason for hiding this comment

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

Discussed over meet. Let's introduce a BlockCache and take another look.

@mrBliss mrBliss force-pushed the mrBliss/pass-new-block-to-ledger-validation branch from 3bed5e0 to a3d2ec4 Compare January 23, 2020 11:49
@mrBliss mrBliss requested a review from edsko January 23, 2020 11:52
@mrBliss mrBliss force-pushed the mrBliss/pass-new-block-to-ledger-validation branch 2 times, most recently from ae956ec to 79018a0 Compare January 29, 2020 13:23
@mrBliss mrBliss force-pushed the mrBliss/pass-new-block-to-ledger-validation branch from 79018a0 to 1def1ad Compare January 30, 2020 11:03
In `ChainDB.addBlock`, we receive a new block and use it to try switch to a
longer chain. This will require applying the block to the ledger, which
requires reading the block from disk and parsing it again. This is right in
the critical path of (bulk) chain sync.

Since we have the block in memory, we can avoid the redundant read and pass it
to the validation code directly in the form of a `BlockCache`. We can later
use this cache for caching more/other blocks.

Note that when switching to a fork or when we can extend the new chain with
more blocks after the new block, we'll still have to read blocks from disk in
order to validate them, but not the new block.
@mrBliss mrBliss force-pushed the mrBliss/pass-new-block-to-ledger-validation branch from 1def1ad to ab17e61 Compare January 30, 2020 11:15
@mrBliss
Copy link
Contributor Author

mrBliss commented Jan 30, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Jan 30, 2020
1398: ChainDB: pass new block to ledger validation r=mrBliss a=mrBliss

In `ChainDB.addBlock`, we receive a new block and use it to try switch to a longer chain. This will require applying the block to the ledger, which requires reading the block from disk and parsing it again. This is right in the critical path of (bulk) chain sync.

Since we have the block in memory, we can avoid the redundant read and pass it to the validation code directly.

Note that when switching to a fork or when we can extend the new chain with more blocks after the new block, we'll still have to read blocks from disk in order to validate them, but not the new block.

Co-authored-by: Thomas Winant <thomas@well-typed.com>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 30, 2020

@iohk-bors iohk-bors bot merged commit ab17e61 into master Jan 30, 2020
@iohk-bors iohk-bors bot deleted the mrBliss/pass-new-block-to-ledger-validation branch January 30, 2020 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chain db consensus issues related to ouroboros-consensus optimisation Performance optimisation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants