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

Minimized changes for the merge #23761

Merged
merged 33 commits into from Nov 26, 2021
Merged

Conversation

MariusVanDerWijden
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden commented Oct 18, 2021

This PR aims to provide the changes needed for running geth as an execution layer.
If you want to run a node on the current network, please use #23607
In this PR, the reverse header sync is disabled, so it can't be used to join the testnets

cmd/geth/config.go Outdated Show resolved Hide resolved
consensus/beacon/consensus.go Outdated Show resolved Hide resolved
consensus/beacon/consensus.go Outdated Show resolved Hide resolved
consensus/beacon/consensus.go Outdated Show resolved Hide resolved
consensus/beacon/consensus.go Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/forkchoice.go Outdated Show resolved Hide resolved
@@ -103,9 +173,100 @@ func (api *consensusAPI) makeEnv(parent *types.Block, header *types.Header) (*bl
return env, nil
}

func (api *ConsensusAPI) PreparePayload(params AssembleBlockParams) (*PayloadResponse, error) {
data, err := api.assembleBlock(params)
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: clear unused payloads after a certain time

Copy link
Member

Choose a reason for hiding this comment

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

Just want to say this. The generated data is basically block. Accumulate the blocks non-stop is very bad.
Do we have any guarantee that when can we clean some cached blocks from the consensus layer?

Copy link
Member

Choose a reason for hiding this comment

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

Previously I enabled the "transition" in this catalyst package by default, so that all the block creation via catalyst API are using the new rules.

But now we pass the merger into the consensus engine, engine = beacon.New(b.InnerEngine(), eth.Merger()). So that it can happen:

for the first block creation, the TTDReached is still false, block is created with old rule.

eth/catalyst/api.go Outdated Show resolved Hide resolved
@MariusVanDerWijden MariusVanDerWijden marked this pull request as ready for review October 21, 2021 07:54
@MariusVanDerWijden MariusVanDerWijden changed the title [WIP] Minimized changes for the merge Minimized changes for the merge Oct 26, 2021
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
consensus/beacon/consensus.go Show resolved Hide resolved
Comment on lines +142 to +144
oldDone, oldResult = beacon.ethone.VerifyHeaders(chain, preHeaders, preSeals)
newDone, newResult = beacon.verifyHeaders(chain, postHeaders, preHeaders[len(preHeaders)-1])
Copy link
Contributor

Choose a reason for hiding this comment

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

The results here can lie a bit. The last of the Pow-headers will be fed as the 'ancestor' to the first PoS block. So the PoS block can be deemed 'valid', even if the parent block is later found to be invalid.
So the results can be [valid, valid, valid.. invalid, pos:valid, pos:valid..].
Might not matter 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Hehe, it's interesting! Maybe we can invalidate all the children in case one parent header is invalid. Or we can choose to add this scenario to comment if we think in practice it's impossible?

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK the same can happen even now in ethash. I can make the middle header invalid, it will still leave the headers after it potentially valid since we're evaluating each header individually from the rest.

consensus/beacon/consensus.go Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
consensus/beacon/consensus.go Outdated Show resolved Hide resolved
core/forkchoice.go Outdated Show resolved Hide resolved
core/headerchain.go Outdated Show resolved Hide resolved
core/forkchoice.go Outdated Show resolved Hide resolved
consensus/merger.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
eth/handler_eth.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
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.

Some remaining nits, but generally LGTM

core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
eth/catalyst/api_types.go Show resolved Hide resolved
eth/catalyst/api_types.go Show resolved Hide resolved
eth/catalyst/api_types.go Show resolved Hide resolved
// a results channel to retrieve the async verifications.
// VerifyHeaders expect the headers to be ordered and continuous.
func (beacon *Beacon) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
if !beacon.IsPoSHeader(headers[len(headers)-1]) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we also use IsTTDReached to distinguish pow headers and pos headers?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to implement this change, but it fails in different places.
The biggest one is during VerifyHeaders, the TD of the last parenthash is not in the db, thus verification of it will fail.
During Author we don't have access to the chain reader.
Also the GenerateChain which is used throughout the tests is very opinionated about this as it uses a fakeChainReader which has no idea about the td. Hacking it in is not super easy

}

// NewMerger creates a new Merger which stores its transition status in the provided db.
func NewMerger(db ethdb.KeyValueStore) *Merger {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick, can ignore it right now. The Merger object I think can be moved to core package since it's irrelevant with consensus anymore.

It's totally fine to leave it here, we can do it in the following PR.

inserted []numberHash // Ephemeral lookup of number/hash for the chain
firstInserted = -1 // Index of the first non-ignored header
newTD = new(big.Int).Set(ptd) // Total difficulty of inserted chain
inserted []rawdb.NumberHash // Ephemeral lookup of number/hash for the chain
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a slice and not a simple number if we only care about how many header we've inserted?

@karalabe karalabe added this to the 1.10.14 milestone Nov 26, 2021
@karalabe karalabe merged commit 3038e48 into ethereum:master Nov 26, 2021
JacekGlen pushed a commit to JacekGlen/go-ethereum that referenced this pull request May 26, 2022
* all: work for eth1/2 transtition

* consensus/beacon, eth: change beacon difficulty to 0

* eth: updates

* all: add terminalBlockDifficulty config, fix rebasing issues

* eth: implemented merge interop spec

* internal/ethapi: update to v1.0.0.alpha.2

                                                                 This commit updates the code to the new spec, moving payloadId into
                                                                 it's own object. It also fixes an issue with finalizing an empty blockhash.
                                                                 It also properly sets the basefee

* all: sync polishes, other fixes + refactors

* core, eth: correct semantics for LeavePoW, EnterPoS

* core: fixed rebasing artifacts

* core: light: performance improvements

* core: use keyed field (f)

* core: eth: fix compilation issues + tests

* eth/catalyst: dbetter error codes

* all: move Merger to consensus/, remove reliance on it in bc

* all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS

* core: make mergelogs a function

* core: use InsertChain instead of InsertBlock

* les: drop merger from lightchain object

* consensus: add merger

* core: recoverAncestors in catalyst mode

* core: fix nitpick

* all: removed merger from beacon, use TTD, nitpicks

* consensus: eth: add docstring, removed unnecessary code duplication

* consensus/beacon: better comment

* all: easy to fix nitpicks by karalabe

* consensus/beacon: verify known headers to be sure

* core: comments

* core: eth: don't drop peers who advertise blocks, nitpicks

* core: never add beacon blocks to the future queue

* core: fixed nitpicks

* consensus/beacon: simplify IsTTDReached check

* consensus/beacon: correct IsTTDReached check

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
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

4 participants