From 4c080bb40aa44c77a6225edd8205c8b264706a11 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 22 Mar 2023 11:30:55 +0100 Subject: [PATCH 1/3] eth/catalyst: fix races --- eth/catalyst/api_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index fb6e6935ee46..6af054136082 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -1240,9 +1240,10 @@ func TestNilWithdrawals(t *testing.T) { func setupBodies(t *testing.T) (*node.Node, *eth.Ethereum, []*types.Block) { genesis, blocks := generateMergeChain(10, true) - n, ethservice := startEthService(t, genesis, blocks) // enable shanghai on the last block - ethservice.BlockChain().Config().ShanghaiTime = &blocks[len(blocks)-1].Header().Time + time := blocks[len(blocks)-1].Header().Time + 1 + genesis.Config.ShanghaiTime = &time + n, ethservice := startEthService(t, genesis, blocks) var ( parent = ethservice.BlockChain().CurrentBlock() From 146af0aead2b4bae740603f1f48e6048ca310d97 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 22 Mar 2023 12:57:21 +0100 Subject: [PATCH 2/3] eth/catalyst: fix race --- eth/catalyst/api_test.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 6af054136082..86e8a26172fc 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -879,15 +879,11 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) { genesis, preMergeBlocks := generateMergeChain(100, false) n, ethservice := startEthService(t, genesis, preMergeBlocks) defer n.Close() - - ethservice.BlockChain().Config().TerminalTotalDifficulty = preMergeBlocks[0].Difficulty() //.Sub(genesis.Config.TerminalTotalDifficulty, preMergeBlocks[len(preMergeBlocks)-1].Difficulty()) - - var ( - api = NewConsensusAPI(ethservice) - parent = preMergeBlocks[len(preMergeBlocks)-1] - ) + api := NewConsensusAPI(ethservice) + setupBlocks(t, ethservice, 10, ethservice.BlockChain().CurrentBlock(), func(parent *types.Header) {}, nil) // Test parent already post TTD in FCU + parent := preMergeBlocks[len(preMergeBlocks)-2] fcState := engine.ForkchoiceStateV1{ HeadBlockHash: parent.Hash(), SafeBlockHash: common.Hash{}, @@ -913,6 +909,28 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) { t.Fatalf("error preparing payload, err=%v", err) } data := *payload.Resolve().ExecutionPayload + // We need to recompute the blockhash, since the miner computes a wrong (correct) blockhash + txs, _ := decodeTransactions(data.Transactions) + header := &types.Header{ + ParentHash: data.ParentHash, + UncleHash: types.EmptyUncleHash, + Coinbase: data.FeeRecipient, + Root: data.StateRoot, + TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), + ReceiptHash: data.ReceiptsRoot, + Bloom: types.BytesToBloom(data.LogsBloom), + Difficulty: common.Big0, + Number: new(big.Int).SetUint64(data.Number), + GasLimit: data.GasLimit, + GasUsed: data.GasUsed, + Time: data.Timestamp, + BaseFee: data.BaseFeePerGas, + Extra: data.ExtraData, + MixDigest: data.Random, + } + block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */) + data.BlockHash = block.Hash() + // Send the new payload resp2, err := api.NewPayloadV1(data) if err != nil { t.Fatalf("error sending NewPayload, err=%v", err) From fd90169e9651a5727b8006ac46daff6c32b0fa41 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Wed, 22 Mar 2023 13:02:20 +0100 Subject: [PATCH 3/3] eth/catalyst: reduce diff --- eth/catalyst/api_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 86e8a26172fc..f38122200233 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -880,7 +880,6 @@ func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) { n, ethservice := startEthService(t, genesis, preMergeBlocks) defer n.Close() api := NewConsensusAPI(ethservice) - setupBlocks(t, ethservice, 10, ethservice.BlockChain().CurrentBlock(), func(parent *types.Header) {}, nil) // Test parent already post TTD in FCU parent := preMergeBlocks[len(preMergeBlocks)-2]