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

core: use block difficulty for genesis #23793

Merged
merged 4 commits into from
Oct 26, 2021

Conversation

meowsbits
Copy link
Contributor

Genesis values not having an assigned Difficulty would result in storing TD=0 to the database instead of the default value params.GenesisDifficulty, which is assigned in the ToBlock method (and returned as genesisBlock with that function).

This provides a test to demonstrate the problem, a fix for the problem, and a few follow up fixes to pre-existing tests that used wrong hardcoded data.

See commit messages for more detail.

The ToBlock method applies a default value for an empty
difficulty value. This default is not carried over through the Commit
method because the TotalDifficulty database write writes the
original difficulty value (nil) instead of the defaulty value
present on the genesis Block.

Date: 2021-10-22 08:25:32-07:00
Signed-off-by: meows <b5c6@protonmail.com>
This an issue where a default TD value was not written to
the database, resulting in a 0 value TD at genesis.

A test for this issue was provided at 90e3ffd

Date: 2021-10-22 08:28:00-07:00
Signed-off-by: meows <b5c6@protonmail.com>
See prior two commits.

Date: 2021-10-22 09:16:01-07:00
Signed-off-by: meows <b5c6@protonmail.com>
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM

@holiman holiman changed the title Fix stored TD for genesis block when using defaults core: use block difficulty for genesis Oct 25, 2021
@holiman holiman added this to the 1.10.12 milestone Oct 25, 2021
@holiman holiman merged commit c72b16c into ethereum:master Oct 26, 2021
sidhujag pushed a commit to syscoin/go-ethereum that referenced this pull request Oct 26, 2021
* core: write test showing that TD is not stored properly at genesis

The ToBlock method applies a default value for an empty
difficulty value. This default is not carried over through the Commit
method because the TotalDifficulty database write writes the
original difficulty value (nil) instead of the defaulty value
present on the genesis Block.

Date: 2021-10-22 08:25:32-07:00
Signed-off-by: meows <b5c6@protonmail.com>

* core: write TD value from Block, not original genesis value

This an issue where a default TD value was not written to
the database, resulting in a 0 value TD at genesis.

A test for this issue was provided at 90e3ffd

Date: 2021-10-22 08:28:00-07:00
Signed-off-by: meows <b5c6@protonmail.com>

* core: fix tests by adding GenesisDifficulty to expected result

See prior two commits.

Date: 2021-10-22 09:16:01-07:00
Signed-off-by: meows <b5c6@protonmail.com>

* les: fix test with genesis change

Co-authored-by: Martin Holst Swende <martin@swende.se>
meowsbits added a commit to etclabscore/core-geth that referenced this pull request Oct 27, 2021
ethereum/go-ethereum uses, as of 1.10.9, a new API for writing
ancient blocks to the freezer.
This change required corresponding changes in the core-geth
featured Remote Freezer implementation.

Along the way, a bug was uncovered that cause the difficulty
value to be miswritten for genesis blocks, although its practical
effect was limited mostly to test scenarios. See
ethereum/go-ethereum#23793

Squashed commit messages are preserved below.

core/rawdb: REVERTME: notes on ancient ModifyAncients interface

Date: 2021-10-13 11:14:53-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core/rawdb,ethdb: rename AncientWriteOp -> AncientWriteOperator

Interfaces are do-ers.
This interfaces defines an operator,
not an operation.

Date: 2021-10-14 05:58:35-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core/rawdb: add init impl for ModifyAncients method for client RemoteFreezer

Date: 2021-10-14 06:51:40-07:00
Signed-off-by: meows <b5c6@protonmail.com>

cmd/ancient-store-mem/lib,core/rawdb: implement Append and AppendRaw for test freezer store mock

Date: 2021-10-14 08:30:09-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: REVERTME: debug 'hereX' statements

Date: 2021-10-14 08:44:27-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core/rawdb: Append should encode to RLP before sending to server

Date: 2021-10-14 09:23:33-07:00
Signed-off-by: meows <b5c6@protonmail.com>

cmd/ancient-store-mem/lib: same as previous commit

Date: 2021-10-14 09:23:55-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: REVERTME: debugging lines for SetHead

Date: 2021-10-14 09:24:11-07:00
Signed-off-by: meows <b5c6@protonmail.com>

:hammer:

Signed-off-by: meows <b5c6@protonmail.com>

wip/debug: log lines, another non-freezer test for comparison

Signed-off-by: meows <b5c6@protonmail.com>

cmd/ancient-store-mem/lib,core/rawdb: unit test for mock freezer (in mem) Append method

Date: 2021-10-15 07:43:33-07:00
Signed-off-by: meows <b5c6@protonmail.com>

cmd/ancient-store-mem/lib,core,core/rawdb: wip/debug: TestFreezerRemoteConcise passes

Date: 2021-10-15 08:18:14-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: set difficulty for genesis block; fixes mismatch difficulty vals Error

Date: 2021-10-18 09:24:46-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: change difficulty assignment for genesis

Date: 2021-10-18 09:29:05-07:00
Signed-off-by: meows <b5c6@protonmail.com>

:hammer:

Signed-off-by: meows <b5c6@protonmail.com>

core/rawdb,test.out.difficulty: turn off logging at db accessor

Date: 2021-10-21 09:11:03-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: set genesis.difficutly at remotefreezer_test, rest difficulty assignment at CommitGenesis

This fixes most tests.
I'm not sure yet exactly why.
One remaining failing test: TestIncompleteAncientReceiptChainInsertion_RemoteFreezer

Date: 2021-10-21 09:14:10-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: remove useless test now

InsertReceiptChain calls the db accessor directly,
and the terminateInsert function got ill-formed for the job.

We're going to limit our responsibility for the remote freezer
(client) implementations; other tests show that the server side
of the API is functioning correctly.

Date: 2021-10-21 09:54:12-07:00
Signed-off-by: meows <b5c6@protonmail.com>

test.out.difficulty: remove test log

Date: 2021-10-21 10:39:36-07:00
Signed-off-by: meows <b5c6@protonmail.com>

cmd/ancient-store-mem/lib,core: clean up debugging

Date: 2021-10-21 10:51:17-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: more cleanup

Date: 2021-10-21 10:56:20-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core,core/rawdb: cleaup time

Date: 2021-10-21 11:03:37-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: fix total difficulty assignment to block from genesis

In core/genesis.go a default value for difficulty
is provided in GenesisToBlock, the vars.GenesisDifficulty value.

This value was not used in CommitGenesis, where instead
genesis.Difficulty (instead of block.Difficulty()) was used.

As you can see in the diff, the vars.GenesisDifficulty.Int64() value
is added to the preexisting expected TD outcomes for Short and Long reorg
tests.

Date: 2021-10-21 13:00:04-07:00
Signed-off-by: meows <b5c6@protonmail.com>

cmd/ancient-store-mem/lib,core: fix freezer count record and associated errOutOfOrder conditions

Date: 2021-10-26 08:43:53-07:00
Signed-off-by: meows <b5c6@protonmail.com>

les: fix LES test by using fixed total difficulty for announce

Date: 2021-10-26 10:31:24-07:00
Signed-off-by: meows <b5c6@protonmail.com>

core: (lint) and small touch ups

Date: 2021-10-27 08:48:50-07:00
Signed-off-by: meows <b5c6@protonmail.com>
yongjun925 pushed a commit to DODOEX/go-ethereum that referenced this pull request Dec 3, 2022
* core: write test showing that TD is not stored properly at genesis

The ToBlock method applies a default value for an empty
difficulty value. This default is not carried over through the Commit
method because the TotalDifficulty database write writes the
original difficulty value (nil) instead of the defaulty value
present on the genesis Block.

Date: 2021-10-22 08:25:32-07:00
Signed-off-by: meows <b5c6@protonmail.com>

* core: write TD value from Block, not original genesis value

This an issue where a default TD value was not written to
the database, resulting in a 0 value TD at genesis.

A test for this issue was provided at 90e3ffd

Date: 2021-10-22 08:28:00-07:00
Signed-off-by: meows <b5c6@protonmail.com>

* core: fix tests by adding GenesisDifficulty to expected result

See prior two commits.

Date: 2021-10-22 09:16:01-07:00
Signed-off-by: meows <b5c6@protonmail.com>

* les: fix test with genesis change

Co-authored-by: Martin Holst Swende <martin@swende.se>
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.

None yet

2 participants