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

Upstream: "core/rawdb: freezer batch write" #1908

Merged
merged 6 commits into from
Jul 29, 2022

Conversation

hbandura
Copy link
Contributor

@hbandura hbandura commented Jun 1, 2022

Merging commit ethereum/go-ethereum@794c613#diff-d78b498ba524953c810b53b2f1e866245d052a063863ed820c9b4852f8762d69 from upstream into the 1.10.9 merge PR

It took me a while to make this one work. Had lots of issues with the total difficulty storage. I hacked it by forcing it to write number+1 in the batch write functions.

Opening this PR against the partial 1.10.9 PR since that one hasn't been merged yet.

holiman and others added 2 commits September 7, 2021 12:31
This change is a rewrite of the freezer code.

When writing ancient chain data to the freezer, the previous version first encoded each
individual item to a temporary buffer, then wrote the buffer. For small item sizes (for
example, in the block hash freezer table), this strategy causes a lot of system calls for
writing tiny chunks of data. It also allocated a lot of temporary []byte buffers.

In the new version, we instead encode multiple items into a re-useable batch buffer, which
is then written to the file all at once. This avoids performing a system call for every
inserted item.

To make the internal batching work, the ancient database API had to be changed. While
integrating this new API in BlockChain.InsertReceiptChain, additional optimizations were
also added there.

Co-authored-by: Felix Lange <fjl@twurst.com>
@hbandura hbandura requested a review from a team as a code owner June 1, 2022 04:42
@hbandura hbandura requested review from gastonponti, 37ng and piersy and removed request for a team June 1, 2022 04:42
@piersy
Copy link
Contributor

piersy commented Jun 1, 2022

Coverage from tests in ./e2e_test/... for ./consensus/istanbul/... at commit 62ca7b7

coverage: 46.4% of statements across all listed packages
coverage:  57.3% of statements in consensus/istanbul
coverage:  23.7% of statements in consensus/istanbul/announce
coverage:  54.3% of statements in consensus/istanbul/backend
coverage:   0.0% of statements in consensus/istanbul/backend/backendtest
coverage:  24.3% of statements in consensus/istanbul/backend/internal/replica
coverage:  65.5% of statements in consensus/istanbul/core
coverage:  45.0% of statements in consensus/istanbul/db
coverage:   0.0% of statements in consensus/istanbul/proxy
coverage:  64.4% of statements in consensus/istanbul/uptime
coverage:  51.8% of statements in consensus/istanbul/validator
coverage:  79.2% of statements in consensus/istanbul/validator/random
CommentID: 03ec6ea4e3

@codecov
Copy link

codecov bot commented Jun 1, 2022

Codecov Report

Merging #1908 (62ca7b7) into master (24d3557) will increase coverage by 0.16%.
The diff coverage is 63.82%.

@@            Coverage Diff             @@
##           master    #1908      +/-   ##
==========================================
+ Coverage   54.24%   54.41%   +0.16%     
==========================================
  Files         678      679       +1     
  Lines       89317    89514     +197     
==========================================
+ Hits        48453    48710     +257     
+ Misses      37226    37157      -69     
- Partials     3638     3647       +9     
Impacted Files Coverage Δ
consensus/istanbul/backend/api.go 0.00% <0.00%> (ø)
consensus/istanbul/core/roundchange.go 79.04% <0.00%> (-8.33%) ⬇️
consensus/istanbul/core/types.go 90.47% <ø> (ø)
core/rawdb/table.go 39.08% <0.00%> (ø)
core/rawdb/freezer.go 32.19% <39.24%> (+8.57%) ⬆️
core/rawdb/database.go 9.41% <50.00%> (-0.41%) ⬇️
core/blockchain.go 58.82% <56.81%> (-1.02%) ⬇️
core/rawdb/accessors_chain.go 57.44% <63.63%> (+3.41%) ⬆️
core/rawdb/freezer_batch.go 79.59% <79.59%> (ø)
consensus/istanbul/types.go 26.34% <81.31%> (+13.24%) ⬆️
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e034227...62ca7b7. Read the comment docs.

if first.NumberU64() == 1 {
if frozen, _ := bc.db.Ancients(); frozen == 0 {
b := bc.genesisBlock
writeSize, err := rawdb.WriteAncientBlocks(bc.db, []*types.Block{b}, []types.Receipts{nil}, big.NewInt(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that WriteAncientBlocks is ignoring the td parameter I think we should just remove it from the parameter list, otherwise providing values here is quite confusing

Copy link
Contributor

Choose a reason for hiding this comment

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

@hbandura Is there an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is now #1918

@@ -1204,120 +1183,116 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
}
return false
}

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 makes significant changes to InsertReceiptChain but it is also missing a test that was included in the upstream PR TestInsertReceiptChainRollback. Looking at the results of coverage I can see that none of the error cases of insertReceiptChain are executed so I think it would be good to include a test here that exercises some of the error cases for InsertReceiptChain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new test uses sidechains, which is why we can't run it. But the old test uses a test field/test mechanism "testInsert" to provoke the tests to be tested, which was removed in this refactor. The errors are tested using sidechains, which we don't have.

Re-adding the mechanism to make it testeable was probably a change that should be made in a different PR for the same reason you mentioned the redundant parameter one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@piersy
Copy link
Contributor

piersy commented Jun 22, 2022

Hey @hbandura, I left 2 comments. I think we could leave the removal of the redundant parameter to another PR, because making that change here would complicate understanding this merge.

Further testing of insert receipt chain could however be added without risk of conflict so I think that change should be made here, unless you don't think it should be tested.

Aside from that all the e2e tests on ci are failing.

Also why did you merge the original branch back into this branch? That's going to make for an overly complicated history?

Base automatically changed from hbandura/upstream_1.10.9 to master July 1, 2022 14:03
@hbandura hbandura requested review from piersy and removed request for 37ng July 6, 2022 15:25
Copy link
Contributor

@piersy piersy left a comment

Choose a reason for hiding this comment

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

Lets merge!

@mcortesi mcortesi merged commit a5525dc into master Jul 29, 2022
@mcortesi mcortesi deleted the hbandura/upstream_1.10.9_part2 branch July 29, 2022 03:34
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.

4 participants