2022-05-24 21:39:40 +03:00
|
|
|
// Copyright 2021 The go-ethereum Authors
|
2021-04-16 22:29:22 +03:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package catalyst
|
|
|
|
|
|
|
|
import (
|
2022-05-20 11:12:12 +03:00
|
|
|
"bytes"
|
2023-01-25 17:32:25 +03:00
|
|
|
"context"
|
2023-03-07 18:30:04 +03:00
|
|
|
crand "crypto/rand"
|
2024-10-09 13:24:58 +03:00
|
|
|
"errors"
|
2022-01-20 14:29:06 +03:00
|
|
|
"fmt"
|
2021-04-16 22:29:22 +03:00
|
|
|
"math/big"
|
2023-03-07 18:30:04 +03:00
|
|
|
"math/rand"
|
|
|
|
"reflect"
|
2022-09-21 14:48:09 +03:00
|
|
|
"sync"
|
2021-04-16 22:29:22 +03:00
|
|
|
"testing"
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
"time"
|
2021-04-16 22:29:22 +03:00
|
|
|
|
2023-02-06 18:37:58 +03:00
|
|
|
"github.com/ethereum/go-ethereum/beacon/engine"
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2022-03-17 18:20:03 +03:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2023-01-25 17:32:25 +03:00
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
|
|
beaconConsensus "github.com/ethereum/go-ethereum/consensus/beacon"
|
2021-04-16 22:29:22 +03:00
|
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
|
|
|
"github.com/ethereum/go-ethereum/core"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2023-07-18 10:44:16 +03:00
|
|
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
2021-04-16 22:29:22 +03:00
|
|
|
"github.com/ethereum/go-ethereum/eth"
|
2022-05-20 11:12:12 +03:00
|
|
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
2021-04-16 22:29:22 +03:00
|
|
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
2024-10-20 19:28:39 +03:00
|
|
|
"github.com/ethereum/go-ethereum/internal/version"
|
2022-11-02 12:32:20 +03:00
|
|
|
"github.com/ethereum/go-ethereum/miner"
|
2021-04-16 22:29:22 +03:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
2022-05-20 11:12:12 +03:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2021-04-16 22:29:22 +03:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2023-01-25 17:32:25 +03:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2022-05-20 11:12:12 +03:00
|
|
|
"github.com/ethereum/go-ethereum/trie"
|
2021-04-16 22:29:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// testKey is a private key to use for funding a tester account.
|
|
|
|
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
|
|
|
|
|
|
// testAddr is the Ethereum address of the tester account.
|
|
|
|
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
|
|
|
|
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
testBalance = big.NewInt(2e18)
|
2021-04-16 22:29:22 +03:00
|
|
|
)
|
|
|
|
|
2023-01-25 17:32:25 +03:00
|
|
|
func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) {
|
2022-09-07 21:21:59 +03:00
|
|
|
config := *params.AllEthashProtocolChanges
|
2023-01-25 17:32:25 +03:00
|
|
|
engine := consensus.Engine(beaconConsensus.New(ethash.NewFaker()))
|
|
|
|
if merged {
|
|
|
|
config.TerminalTotalDifficulty = common.Big0
|
|
|
|
engine = beaconConsensus.NewFaker()
|
|
|
|
}
|
2021-04-16 22:29:22 +03:00
|
|
|
genesis := &core.Genesis{
|
2023-08-26 05:52:12 +03:00
|
|
|
Config: &config,
|
2024-02-16 21:05:33 +03:00
|
|
|
Alloc: types.GenesisAlloc{
|
2024-03-15 11:14:31 +03:00
|
|
|
testAddr: {Balance: testBalance},
|
|
|
|
params.BeaconRootsAddress: {Balance: common.Big0, Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500")},
|
2024-09-04 15:33:51 +03:00
|
|
|
config.DepositContractAddress: {
|
|
|
|
// Simple deposit generator, source: https://gist.github.com/lightclient/54abb2af2465d6969fa6d1920b9ad9d7
|
|
|
|
Code: common.Hex2Bytes("6080604052366103aa575f603067ffffffffffffffff811115610025576100246103ae565b5b6040519080825280601f01601f1916602001820160405280156100575781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f8151811061007d5761007c6103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f602067ffffffffffffffff8111156100c7576100c66103ae565b5b6040519080825280601f01601f1916602001820160405280156100f95781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f8151811061011f5761011e6103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f600867ffffffffffffffff811115610169576101686103ae565b5b6040519080825280601f01601f19166020018201604052801561019b5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f815181106101c1576101c06103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f606067ffffffffffffffff81111561020b5761020a6103ae565b5b6040519080825280601f01601f19166020018201604052801561023d5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f81518110610263576102626103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f600867ffffffffffffffff8111156102ad576102ac6103ae565b5b6040519080825280601f01601f1916602001820160405280156102df5781602001600182028036833780820191505090505b5090505f8054906101000a900460ff1660f81b815f81518110610305576103046103db565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f8081819054906101000a900460ff168092919061035090610441565b91906101000a81548160ff021916908360ff160217905550507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c585858585856040516103a09594939291906104d9565b60405180910390a1005b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f60ff82169050919050565b5f61044b82610435565b915060ff820361045e5761045d610408565b5b600182019050919050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6104ab82610469565b6104b58185610473565b93506104c5818560208601610483565b6104ce81610491565b840191505092915050565b5f60a0820190508181035f8301526104f181886104a1565b9050818103602083015261050581876104a1565b9050818103604083015261051981866104a1565b9050818103606083015261052d81856104a1565b9050818103608083015261054181846104a1565b9050969550505050505056fea26469706673582212208569967e58690162d7d6fe3513d07b393b4c15e70f41505cbbfd08f53eba739364736f6c63430008190033"),
|
|
|
|
Nonce: 0,
|
|
|
|
Balance: big.NewInt(0),
|
|
|
|
},
|
2023-08-26 05:52:12 +03:00
|
|
|
},
|
2022-03-17 18:20:03 +03:00
|
|
|
ExtraData: []byte("test genesis"),
|
|
|
|
Timestamp: 9000,
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee),
|
|
|
|
Difficulty: big.NewInt(0),
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
testNonce := uint64(0)
|
2021-04-16 22:29:22 +03:00
|
|
|
generate := func(i int, g *core.BlockGen) {
|
|
|
|
g.OffsetTime(5)
|
|
|
|
g.SetExtra([]byte("test"))
|
2022-09-07 21:21:59 +03:00
|
|
|
tx, _ := types.SignTx(types.NewTransaction(testNonce, common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"), big.NewInt(1), params.TxGas, big.NewInt(params.InitialBaseFee*2), nil), types.LatestSigner(&config), testKey)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
g.AddTx(tx)
|
|
|
|
testNonce++
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
2023-01-25 17:32:25 +03:00
|
|
|
_, blocks, _ := core.GenerateChainWithGenesis(genesis, engine, n, generate)
|
|
|
|
|
|
|
|
if !merged {
|
|
|
|
totalDifficulty := big.NewInt(0)
|
|
|
|
for _, b := range blocks {
|
|
|
|
totalDifficulty.Add(totalDifficulty, b.Difficulty())
|
|
|
|
}
|
|
|
|
config.TerminalTotalDifficulty = totalDifficulty
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
}
|
2023-01-25 17:32:25 +03:00
|
|
|
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
return genesis, blocks
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth2AssembleBlock(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, blocks := generateMergeChain(10, false)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, blocks)
|
2021-04-16 22:29:22 +03:00
|
|
|
defer n.Close()
|
|
|
|
|
2022-01-31 15:22:35 +03:00
|
|
|
api := NewConsensusAPI(ethservice)
|
2021-04-16 22:29:22 +03:00
|
|
|
signer := types.NewEIP155Signer(ethservice.BlockChain().Config().ChainID)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
tx, err := types.SignTx(types.NewTransaction(uint64(10), blocks[9].Coinbase(), big.NewInt(1000), params.TxGas, big.NewInt(params.InitialBaseFee), nil), signer, testKey)
|
2021-04-16 22:29:22 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error signing transaction, err=%v", err)
|
|
|
|
}
|
2024-04-23 11:33:36 +03:00
|
|
|
ethservice.TxPool().Add([]*types.Transaction{tx}, true, true)
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams := engine.PayloadAttributes{
|
2021-12-03 18:26:28 +03:00
|
|
|
Timestamp: blocks[9].Time() + 5,
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
2022-11-21 11:52:12 +03:00
|
|
|
// The miner needs to pick up on the txs in the pool, so a few retries might be
|
|
|
|
// needed.
|
|
|
|
if _, testErr := assembleWithTransactions(api, blocks[9].Hash(), &blockParams, 1); testErr != nil {
|
2022-10-06 14:39:20 +03:00
|
|
|
t.Fatal(testErr)
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 11:52:12 +03:00
|
|
|
// assembleWithTransactions tries to assemble a block, retrying until it has 'want',
|
|
|
|
// number of transactions in it, or it has retried three times.
|
2023-02-06 18:37:58 +03:00
|
|
|
func assembleWithTransactions(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes, want int) (execData *engine.ExecutableData, err error) {
|
2022-11-21 11:52:12 +03:00
|
|
|
for retries := 3; retries > 0; retries-- {
|
|
|
|
execData, err = assembleBlock(api, parentHash, params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if have, want := len(execData.Transactions), want; have != want {
|
|
|
|
err = fmt.Errorf("invalid number of transactions, have %d want %d", have, want)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return execData, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-04-16 22:29:22 +03:00
|
|
|
func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, blocks := generateMergeChain(10, false)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, blocks[:9])
|
2021-04-16 22:29:22 +03:00
|
|
|
defer n.Close()
|
|
|
|
|
2022-01-31 15:22:35 +03:00
|
|
|
api := NewConsensusAPI(ethservice)
|
2021-04-16 22:29:22 +03:00
|
|
|
|
|
|
|
// Put the 10th block's tx in the pool and produce a new block
|
2023-06-16 15:29:40 +03:00
|
|
|
txs := blocks[9].Transactions()
|
core/types: support for optional blob sidecar in BlobTx (#27841)
This PR removes the newly added txpool.Transaction wrapper type, and instead adds a way
of keeping the blob sidecar within types.Transaction. It's better this way because most
code in go-ethereum does not care about blob transactions, and probably never will. This
will start mattering especially on the client side of RPC, where all APIs are based on
types.Transaction. Users need to be able to use the same signing flows they already
have.
However, since blobs are only allowed in some places but not others, we will now need to
add checks to avoid creating invalid blocks. I'm still trying to figure out the best place
to do some of these. The way I have it currently is as follows:
- In block validation (import), txs are verified not to have a blob sidecar.
- In miner, we strip off the sidecar when committing the transaction into the block.
- In TxPool validation, txs must have a sidecar to be added into the blobpool.
- Note there is a special case here: when transactions are re-added because of a chain
reorg, we cannot use the transactions gathered from the old chain blocks as-is,
because they will be missing their blobs. This was previously handled by storing the
blobs into the 'blobpool limbo'. The code has now changed to store the full
transaction in the limbo instead, but it might be confusing for code readers why we're
not simply adding the types.Transaction we already have.
Code changes summary:
- txpool.Transaction removed and all uses replaced by types.Transaction again
- blobpool now stores types.Transaction instead of defining its own blobTx format for storage
- the blobpool limbo now stores types.Transaction instead of storing only the blobs
- checks to validate the presence/absence of the blob sidecar added in certain critical places
2023-08-14 11:13:34 +03:00
|
|
|
api.eth.TxPool().Add(txs, false, true)
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams := engine.PayloadAttributes{
|
2021-12-03 18:26:28 +03:00
|
|
|
Timestamp: blocks[8].Time() + 5,
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
2022-11-21 11:52:12 +03:00
|
|
|
// The miner needs to pick up on the txs in the pool, so a few retries might be
|
|
|
|
// needed.
|
|
|
|
if _, err := assembleWithTransactions(api, blocks[8].Hash(), &blockParams, blocks[9].Transactions().Len()); err != nil {
|
|
|
|
t.Fatal(err)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
}
|
|
|
|
}
|
2021-04-16 22:29:22 +03:00
|
|
|
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
func TestSetHeadBeforeTotalDifficulty(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, blocks := generateMergeChain(10, false)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, blocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
2022-01-31 15:22:35 +03:00
|
|
|
api := NewConsensusAPI(ethservice)
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2021-12-03 18:26:28 +03:00
|
|
|
HeadBlockHash: blocks[5].Hash(),
|
|
|
|
SafeBlockHash: common.Hash{},
|
|
|
|
FinalizedBlockHash: common.Hash{},
|
|
|
|
}
|
2022-03-17 18:20:03 +03:00
|
|
|
if resp, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil {
|
|
|
|
t.Errorf("fork choice updated should not error: %v", err)
|
2023-02-06 18:37:58 +03:00
|
|
|
} else if resp.PayloadStatus.Status != engine.INVALID_TERMINAL_BLOCK.Status {
|
2022-03-17 18:20:03 +03:00
|
|
|
t.Errorf("fork choice updated before total terminal difficulty should be INVALID")
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth2PrepareAndGetPayload(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, blocks := generateMergeChain(10, false)
|
2022-05-20 11:12:12 +03:00
|
|
|
// We need to properly set the terminal total difficulty
|
|
|
|
genesis.Config.TerminalTotalDifficulty.Sub(genesis.Config.TerminalTotalDifficulty, blocks[9].Difficulty())
|
|
|
|
n, ethservice := startEthService(t, genesis, blocks[:9])
|
|
|
|
defer n.Close()
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
|
2022-05-20 11:12:12 +03:00
|
|
|
api := NewConsensusAPI(ethservice)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
|
2022-05-20 11:12:12 +03:00
|
|
|
// Put the 10th block's tx in the pool and produce a new block
|
2023-06-16 15:29:40 +03:00
|
|
|
txs := blocks[9].Transactions()
|
2024-04-23 11:33:36 +03:00
|
|
|
ethservice.TxPool().Add(txs, true, true)
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams := engine.PayloadAttributes{
|
2022-05-20 11:12:12 +03:00
|
|
|
Timestamp: blocks[8].Time() + 5,
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2022-05-20 11:12:12 +03:00
|
|
|
HeadBlockHash: blocks[8].Hash(),
|
|
|
|
SafeBlockHash: common.Hash{},
|
|
|
|
FinalizedBlockHash: common.Hash{},
|
|
|
|
}
|
|
|
|
_, err := api.ForkchoiceUpdatedV1(fcState, &blockParams)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
2022-11-02 12:32:20 +03:00
|
|
|
// give the payload some time to be built
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
2022-11-07 17:30:54 +03:00
|
|
|
payloadID := (&miner.BuildPayloadArgs{
|
|
|
|
Parent: fcState.HeadBlockHash,
|
|
|
|
Timestamp: blockParams.Timestamp,
|
|
|
|
FeeRecipient: blockParams.SuggestedFeeRecipient,
|
|
|
|
Random: blockParams.Random,
|
2023-08-26 05:52:12 +03:00
|
|
|
BeaconRoot: blockParams.BeaconRoot,
|
2024-01-24 10:39:12 +03:00
|
|
|
Version: engine.PayloadV1,
|
2022-11-07 17:30:54 +03:00
|
|
|
}).Id()
|
2022-05-20 11:12:12 +03:00
|
|
|
execData, err := api.GetPayloadV1(payloadID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting payload, err=%v", err)
|
|
|
|
}
|
|
|
|
if len(execData.Transactions) != blocks[9].Transactions().Len() {
|
|
|
|
t.Fatalf("invalid number of transactions %d != 1", len(execData.Transactions))
|
|
|
|
}
|
|
|
|
// Test invalid payloadID
|
2023-02-06 18:37:58 +03:00
|
|
|
var invPayload engine.PayloadID
|
2022-05-20 11:12:12 +03:00
|
|
|
copy(invPayload[:], payloadID[:])
|
|
|
|
invPayload[0] = ^invPayload[0]
|
|
|
|
_, err = api.GetPayloadV1(invPayload)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error retrieving invalid payload")
|
|
|
|
}
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
|
|
|
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
func checkLogEvents(t *testing.T, logsCh <-chan []*types.Log, rmLogsCh <-chan core.RemovedLogsEvent, wantNew, wantRemoved int) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
if len(logsCh) != wantNew {
|
|
|
|
t.Fatalf("wrong number of log events: got %d, want %d", len(logsCh), wantNew)
|
|
|
|
}
|
|
|
|
if len(rmLogsCh) != wantRemoved {
|
|
|
|
t.Fatalf("wrong number of removed log events: got %d, want %d", len(rmLogsCh), wantRemoved)
|
|
|
|
}
|
|
|
|
// Drain events.
|
|
|
|
for i := 0; i < len(logsCh); i++ {
|
|
|
|
<-logsCh
|
|
|
|
}
|
|
|
|
for i := 0; i < len(rmLogsCh); i++ {
|
|
|
|
<-rmLogsCh
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 14:29:06 +03:00
|
|
|
func TestInvalidPayloadTimestamp(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-01-20 14:29:06 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
|
|
|
var (
|
2022-01-31 15:22:35 +03:00
|
|
|
api = NewConsensusAPI(ethservice)
|
2022-01-20 14:29:06 +03:00
|
|
|
parent = ethservice.BlockChain().CurrentBlock()
|
|
|
|
)
|
|
|
|
tests := []struct {
|
|
|
|
time uint64
|
|
|
|
shouldErr bool
|
|
|
|
}{
|
|
|
|
{0, true},
|
2023-03-02 09:29:15 +03:00
|
|
|
{parent.Time, true},
|
|
|
|
{parent.Time - 1, true},
|
2024-02-26 12:59:03 +03:00
|
|
|
{parent.Time + 1, false},
|
|
|
|
{uint64(time.Now().Unix()) + uint64(time.Minute), false},
|
2022-01-20 14:29:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
t.Run(fmt.Sprintf("Timestamp test: %v", i), func(t *testing.T) {
|
2023-02-06 18:37:58 +03:00
|
|
|
params := engine.PayloadAttributes{
|
2022-01-20 14:29:06 +03:00
|
|
|
Timestamp: test.time,
|
|
|
|
Random: crypto.Keccak256Hash([]byte{byte(123)}),
|
2023-03-02 09:29:15 +03:00
|
|
|
SuggestedFeeRecipient: parent.Coinbase,
|
2022-01-20 14:29:06 +03:00
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2022-01-20 14:29:06 +03:00
|
|
|
HeadBlockHash: parent.Hash(),
|
|
|
|
SafeBlockHash: common.Hash{},
|
|
|
|
FinalizedBlockHash: common.Hash{},
|
|
|
|
}
|
|
|
|
_, err := api.ForkchoiceUpdatedV1(fcState, ¶ms)
|
|
|
|
if test.shouldErr && err == nil {
|
|
|
|
t.Fatalf("expected error preparing payload with invalid timestamp, err=%v", err)
|
|
|
|
} else if !test.shouldErr && err != nil {
|
|
|
|
t.Fatalf("error preparing payload with valid timestamp, err=%v", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 22:29:22 +03:00
|
|
|
func TestEth2NewBlock(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
2021-04-16 22:29:22 +03:00
|
|
|
defer n.Close()
|
|
|
|
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
var (
|
2022-01-31 15:22:35 +03:00
|
|
|
api = NewConsensusAPI(ethservice)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
parent = preMergeBlocks[len(preMergeBlocks)-1]
|
|
|
|
|
|
|
|
// This EVM code generates a log when the contract is created.
|
|
|
|
logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00")
|
|
|
|
)
|
|
|
|
// The event channels.
|
|
|
|
newLogCh := make(chan []*types.Log, 10)
|
|
|
|
rmLogsCh := make(chan core.RemovedLogsEvent, 10)
|
|
|
|
ethservice.BlockChain().SubscribeLogsEvent(newLogCh)
|
|
|
|
ethservice.BlockChain().SubscribeRemovedLogsEvent(rmLogsCh)
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
statedb, _ := ethservice.BlockChain().StateAt(parent.Root())
|
|
|
|
nonce := statedb.GetNonce(testAddr)
|
|
|
|
tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey)
|
2024-04-23 11:33:36 +03:00
|
|
|
ethservice.TxPool().Add([]*types.Transaction{tx}, true, true)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
|
2023-02-06 18:37:58 +03:00
|
|
|
execData, err := assembleWithTransactions(api, parent.Hash(), &engine.PayloadAttributes{
|
2021-12-03 18:26:28 +03:00
|
|
|
Timestamp: parent.Time() + 5,
|
2022-11-21 11:52:12 +03:00
|
|
|
}, 1)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
if err != nil {
|
2024-04-23 11:33:36 +03:00
|
|
|
t.Fatalf("Failed to create the executable data, block %d: %v", i, err)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
block, err := engine.ExecutableDataToBlock(*execData, nil, nil, nil)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to convert executable data to block %v", err)
|
|
|
|
}
|
2022-03-17 18:20:03 +03:00
|
|
|
newResp, err := api.NewPayloadV1(*execData)
|
2022-09-21 14:48:09 +03:00
|
|
|
switch {
|
|
|
|
case err != nil:
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Failed to insert block: %v", err)
|
2022-09-21 14:48:09 +03:00
|
|
|
case newResp.Status != "VALID":
|
|
|
|
t.Fatalf("Failed to insert block: %v", newResp.Status)
|
2023-03-02 09:29:15 +03:00
|
|
|
case ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64()-1:
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Chain head shouldn't be updated")
|
|
|
|
}
|
|
|
|
checkLogEvents(t, newLogCh, rmLogsCh, 0, 0)
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2021-12-03 18:26:28 +03:00
|
|
|
HeadBlockHash: block.Hash(),
|
|
|
|
SafeBlockHash: block.Hash(),
|
|
|
|
FinalizedBlockHash: block.Hash(),
|
|
|
|
}
|
|
|
|
if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil {
|
2021-04-16 22:29:22 +03:00
|
|
|
t.Fatalf("Failed to insert block: %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if have, want := ethservice.BlockChain().CurrentBlock().Number.Uint64(), block.NumberU64(); have != want {
|
2022-09-21 14:48:09 +03:00
|
|
|
t.Fatalf("Chain head should be updated, have %d want %d", have, want)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
}
|
|
|
|
checkLogEvents(t, newLogCh, rmLogsCh, 1, 0)
|
|
|
|
|
|
|
|
parent = block
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
|
|
|
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
// Introduce fork chain
|
|
|
|
var (
|
2023-03-02 09:29:15 +03:00
|
|
|
head = ethservice.BlockChain().CurrentBlock().Number.Uint64()
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
)
|
|
|
|
parent = preMergeBlocks[len(preMergeBlocks)-1]
|
|
|
|
for i := 0; i < 10; i++ {
|
2023-02-06 18:37:58 +03:00
|
|
|
execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{
|
2021-12-03 18:26:28 +03:00
|
|
|
Timestamp: parent.Time() + 6,
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
})
|
2021-04-16 22:29:22 +03:00
|
|
|
if err != nil {
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Failed to create the executable data %v", err)
|
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
block, err := engine.ExecutableDataToBlock(*execData, nil, nil, nil)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to convert executable data to block %v", err)
|
|
|
|
}
|
2022-03-17 18:20:03 +03:00
|
|
|
newResp, err := api.NewPayloadV1(*execData)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
if err != nil || newResp.Status != "VALID" {
|
|
|
|
t.Fatalf("Failed to insert block: %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentBlock().Number.Uint64() != head {
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Chain head shouldn't be updated")
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
|
|
|
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2021-12-03 18:26:28 +03:00
|
|
|
HeadBlockHash: block.Hash(),
|
|
|
|
SafeBlockHash: block.Hash(),
|
|
|
|
FinalizedBlockHash: block.Hash(),
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
}
|
2021-12-03 18:26:28 +03:00
|
|
|
if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil {
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Failed to insert block: %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64() {
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Chain head should be updated")
|
|
|
|
}
|
|
|
|
parent, head = block, block.NumberU64()
|
2021-04-16 22:29:22 +03:00
|
|
|
}
|
|
|
|
}
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
|
|
|
|
func TestEth2DeepReorg(t *testing.T) {
|
|
|
|
// TODO (MariusVanDerWijden) TestEth2DeepReorg is currently broken, because it tries to reorg
|
|
|
|
// before the totalTerminalDifficulty threshold
|
|
|
|
/*
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(core.TriesInMemory * 2, false)
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
var (
|
|
|
|
api = NewConsensusAPI(ethservice, nil)
|
|
|
|
parent = preMergeBlocks[len(preMergeBlocks)-core.TriesInMemory-1]
|
2023-03-02 09:29:15 +03:00
|
|
|
head = ethservice.BlockChain().CurrentBlock().Number.Uint64()()
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
)
|
|
|
|
if ethservice.BlockChain().HasBlockAndState(parent.Hash(), parent.NumberU64()) {
|
|
|
|
t.Errorf("Block %d not pruned", parent.NumberU64())
|
|
|
|
}
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
execData, err := api.assembleBlock(AssembleBlockParams{
|
|
|
|
ParentHash: parent.Hash(),
|
|
|
|
Timestamp: parent.Time() + 5,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create the executable data %v", err)
|
|
|
|
}
|
|
|
|
block, err := ExecutableDataToBlock(ethservice.BlockChain().Config(), parent.Header(), *execData)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to convert executable data to block %v", err)
|
|
|
|
}
|
|
|
|
newResp, err := api.ExecutePayload(*execData)
|
|
|
|
if err != nil || newResp.Status != "VALID" {
|
|
|
|
t.Fatalf("Failed to insert block: %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentBlock().Number.Uint64()() != head {
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Chain head shouldn't be updated")
|
|
|
|
}
|
|
|
|
if err := api.setHead(block.Hash()); err != nil {
|
|
|
|
t.Fatalf("Failed to set head: %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentBlock().Number.Uint64()() != block.NumberU64() {
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
t.Fatalf("Chain head should be updated")
|
|
|
|
}
|
|
|
|
parent, head = block, block.NumberU64()
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2021-04-16 22:29:22 +03:00
|
|
|
|
|
|
|
// startEthService creates a full node instance for testing.
|
|
|
|
func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block) (*node.Node, *eth.Ethereum) {
|
|
|
|
t.Helper()
|
|
|
|
|
2022-05-20 11:12:12 +03:00
|
|
|
n, err := node.New(&node.Config{
|
|
|
|
P2P: p2p.Config{
|
|
|
|
ListenAddr: "0.0.0.0:0",
|
|
|
|
NoDiscovery: true,
|
|
|
|
MaxPeers: 25,
|
|
|
|
}})
|
2021-04-16 22:29:22 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("can't create node:", err)
|
|
|
|
}
|
2022-05-20 11:12:12 +03:00
|
|
|
|
2024-03-06 15:45:03 +03:00
|
|
|
mcfg := miner.DefaultConfig
|
|
|
|
mcfg.PendingFeeRecipient = testAddr
|
|
|
|
ethcfg := ðconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: mcfg}
|
2021-04-16 22:29:22 +03:00
|
|
|
ethservice, err := eth.New(n, ethcfg)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("can't create eth service:", err)
|
|
|
|
}
|
|
|
|
if err := n.Start(); err != nil {
|
|
|
|
t.Fatal("can't start node:", err)
|
|
|
|
}
|
|
|
|
if _, err := ethservice.BlockChain().InsertChain(blocks); err != nil {
|
|
|
|
n.Close()
|
|
|
|
t.Fatal("can't import test blocks:", err)
|
|
|
|
}
|
2022-05-17 11:19:51 +03:00
|
|
|
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
ethservice.SetSynced()
|
2021-04-16 22:29:22 +03:00
|
|
|
return n, ethservice
|
|
|
|
}
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
|
|
|
|
func TestFullAPI(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-03-17 18:20:03 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
|
|
|
var (
|
|
|
|
parent = ethservice.BlockChain().CurrentBlock()
|
|
|
|
// This EVM code generates a log when the contract is created.
|
|
|
|
logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00")
|
|
|
|
)
|
2022-05-20 11:12:12 +03:00
|
|
|
|
2023-03-02 09:29:15 +03:00
|
|
|
callback := func(parent *types.Header) {
|
|
|
|
statedb, _ := ethservice.BlockChain().StateAt(parent.Root)
|
2022-03-17 18:20:03 +03:00
|
|
|
nonce := statedb.GetNonce(testAddr)
|
|
|
|
tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey)
|
core/types: support for optional blob sidecar in BlobTx (#27841)
This PR removes the newly added txpool.Transaction wrapper type, and instead adds a way
of keeping the blob sidecar within types.Transaction. It's better this way because most
code in go-ethereum does not care about blob transactions, and probably never will. This
will start mattering especially on the client side of RPC, where all APIs are based on
types.Transaction. Users need to be able to use the same signing flows they already
have.
However, since blobs are only allowed in some places but not others, we will now need to
add checks to avoid creating invalid blocks. I'm still trying to figure out the best place
to do some of these. The way I have it currently is as follows:
- In block validation (import), txs are verified not to have a blob sidecar.
- In miner, we strip off the sidecar when committing the transaction into the block.
- In TxPool validation, txs must have a sidecar to be added into the blobpool.
- Note there is a special case here: when transactions are re-added because of a chain
reorg, we cannot use the transactions gathered from the old chain blocks as-is,
because they will be missing their blobs. This was previously handled by storing the
blobs into the 'blobpool limbo'. The code has now changed to store the full
transaction in the limbo instead, but it might be confusing for code readers why we're
not simply adding the types.Transaction we already have.
Code changes summary:
- txpool.Transaction removed and all uses replaced by types.Transaction again
- blobpool now stores types.Transaction instead of defining its own blobTx format for storage
- the blobpool limbo now stores types.Transaction instead of storing only the blobs
- checks to validate the presence/absence of the blob sidecar added in certain critical places
2023-08-14 11:13:34 +03:00
|
|
|
ethservice.TxPool().Add([]*types.Transaction{tx}, true, false)
|
2022-05-20 11:12:12 +03:00
|
|
|
}
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
|
2024-09-04 15:33:51 +03:00
|
|
|
setupBlocks(t, ethservice, 10, parent, callback, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 15:33:51 +03:00
|
|
|
func setupBlocks(t *testing.T, ethservice *eth.Ethereum, n int, parent *types.Header, callback func(parent *types.Header), withdrawals [][]*types.Withdrawal, beaconRoots []common.Hash) []*types.Header {
|
2022-05-20 11:12:12 +03:00
|
|
|
api := NewConsensusAPI(ethservice)
|
2023-03-02 09:29:15 +03:00
|
|
|
var blocks []*types.Header
|
2022-05-20 11:12:12 +03:00
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
callback(parent)
|
2023-03-07 18:30:04 +03:00
|
|
|
var w []*types.Withdrawal
|
|
|
|
if withdrawals != nil {
|
|
|
|
w = withdrawals[i]
|
|
|
|
}
|
2024-09-04 15:33:51 +03:00
|
|
|
var h *common.Hash
|
|
|
|
if beaconRoots != nil {
|
|
|
|
h = &beaconRoots[i]
|
|
|
|
}
|
2022-05-20 11:12:12 +03:00
|
|
|
|
2024-10-09 13:24:58 +03:00
|
|
|
envelope := getNewEnvelope(t, api, parent, w, h)
|
|
|
|
execResp, err := api.newPayload(*envelope.ExecutionPayload, []common.Hash{}, h, envelope.Requests, false)
|
2022-03-17 18:20:03 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("can't execute payload: %v", err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if execResp.Status != engine.VALID {
|
2024-09-04 15:33:51 +03:00
|
|
|
t.Fatalf("invalid status: %v %s", execResp.Status, *execResp.ValidationError)
|
2022-03-17 18:20:03 +03:00
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
payload := envelope.ExecutionPayload
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2022-03-17 18:20:03 +03:00
|
|
|
HeadBlockHash: payload.BlockHash,
|
|
|
|
SafeBlockHash: payload.ParentHash,
|
|
|
|
FinalizedBlockHash: payload.ParentHash,
|
|
|
|
}
|
|
|
|
if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil {
|
|
|
|
t.Fatalf("Failed to insert block: %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentBlock().Number.Uint64() != payload.Number {
|
2022-05-18 17:30:42 +03:00
|
|
|
t.Fatal("Chain head should be updated")
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentFinalBlock().Number.Uint64() != payload.Number-1 {
|
2022-05-18 17:30:42 +03:00
|
|
|
t.Fatal("Finalized block should be updated")
|
2022-03-17 18:20:03 +03:00
|
|
|
}
|
|
|
|
parent = ethservice.BlockChain().CurrentBlock()
|
2023-02-06 12:21:40 +03:00
|
|
|
blocks = append(blocks, parent)
|
2022-03-17 18:20:03 +03:00
|
|
|
}
|
2023-02-06 12:21:40 +03:00
|
|
|
return blocks
|
2022-03-17 18:20:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestExchangeTransitionConfig(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-03-17 18:20:03 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
2022-10-03 15:10:00 +03:00
|
|
|
|
2022-03-17 18:20:03 +03:00
|
|
|
// invalid ttd
|
2022-10-03 15:10:00 +03:00
|
|
|
api := NewConsensusAPI(ethservice)
|
2023-02-06 18:37:58 +03:00
|
|
|
config := engine.TransitionConfigurationV1{
|
2022-03-17 18:20:03 +03:00
|
|
|
TerminalTotalDifficulty: (*hexutil.Big)(big.NewInt(0)),
|
|
|
|
TerminalBlockHash: common.Hash{},
|
|
|
|
TerminalBlockNumber: 0,
|
|
|
|
}
|
|
|
|
if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil {
|
|
|
|
t.Fatal("expected error on invalid config, invalid ttd")
|
|
|
|
}
|
|
|
|
// invalid terminal block hash
|
2023-02-06 18:37:58 +03:00
|
|
|
config = engine.TransitionConfigurationV1{
|
2022-03-17 18:20:03 +03:00
|
|
|
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
|
|
|
|
TerminalBlockHash: common.Hash{1},
|
|
|
|
TerminalBlockNumber: 0,
|
|
|
|
}
|
|
|
|
if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil {
|
|
|
|
t.Fatal("expected error on invalid config, invalid hash")
|
|
|
|
}
|
|
|
|
// valid config
|
2023-02-06 18:37:58 +03:00
|
|
|
config = engine.TransitionConfigurationV1{
|
2022-03-17 18:20:03 +03:00
|
|
|
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
|
|
|
|
TerminalBlockHash: common.Hash{},
|
|
|
|
TerminalBlockNumber: 0,
|
|
|
|
}
|
|
|
|
if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil {
|
|
|
|
t.Fatalf("expected no error on valid config, got %v", err)
|
|
|
|
}
|
|
|
|
// valid config
|
2023-02-06 18:37:58 +03:00
|
|
|
config = engine.TransitionConfigurationV1{
|
2022-03-17 18:20:03 +03:00
|
|
|
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
|
|
|
|
TerminalBlockHash: preMergeBlocks[5].Hash(),
|
|
|
|
TerminalBlockNumber: 6,
|
|
|
|
}
|
|
|
|
if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil {
|
|
|
|
t.Fatalf("expected no error on valid config, got %v", err)
|
|
|
|
}
|
all: core rework for the merge transition (#23761)
* 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>
2021-11-26 14:23:02 +03:00
|
|
|
}
|
2022-05-18 17:33:37 +03:00
|
|
|
|
2022-05-20 11:12:12 +03:00
|
|
|
/*
|
|
|
|
TestNewPayloadOnInvalidChain sets up a valid chain and tries to feed blocks
|
|
|
|
from an invalid chain to test if latestValidHash (LVH) works correctly.
|
|
|
|
|
2022-09-10 14:25:40 +03:00
|
|
|
We set up the following chain where P1 ... Pn and P1” are valid while
|
2022-05-20 11:12:12 +03:00
|
|
|
P1' is invalid.
|
|
|
|
We expect
|
|
|
|
(1) The LVH to point to the current inserted payload if it was valid.
|
|
|
|
(2) The LVH to point to the valid parent on an invalid payload (if the parent is available).
|
|
|
|
(3) If the parent is unavailable, the LVH should not be set.
|
|
|
|
|
2022-09-10 14:25:40 +03:00
|
|
|
CommonAncestor◄─▲── P1 ◄── P2 ◄─ P3 ◄─ ... ◄─ Pn
|
|
|
|
│
|
|
|
|
└── P1' ◄─ P2' ◄─ P3' ◄─ ... ◄─ Pn'
|
|
|
|
│
|
|
|
|
└── P1''
|
2022-05-20 11:12:12 +03:00
|
|
|
*/
|
|
|
|
func TestNewPayloadOnInvalidChain(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-05-18 17:33:37 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
2022-05-20 11:12:12 +03:00
|
|
|
|
2022-05-18 17:33:37 +03:00
|
|
|
var (
|
|
|
|
api = NewConsensusAPI(ethservice)
|
|
|
|
parent = ethservice.BlockChain().CurrentBlock()
|
2022-11-11 15:22:54 +03:00
|
|
|
signer = types.LatestSigner(ethservice.BlockChain().Config())
|
2022-05-18 17:33:37 +03:00
|
|
|
// This EVM code generates a log when the contract is created.
|
|
|
|
logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00")
|
|
|
|
)
|
|
|
|
for i := 0; i < 10; i++ {
|
2023-03-02 09:29:15 +03:00
|
|
|
statedb, _ := ethservice.BlockChain().StateAt(parent.Root)
|
2022-11-11 15:22:54 +03:00
|
|
|
tx := types.MustSignNewTx(testKey, signer, &types.LegacyTx{
|
|
|
|
Nonce: statedb.GetNonce(testAddr),
|
|
|
|
Value: new(big.Int),
|
|
|
|
Gas: 1000000,
|
|
|
|
GasPrice: big.NewInt(2 * params.InitialBaseFee),
|
|
|
|
Data: logCode,
|
|
|
|
})
|
core/types: support for optional blob sidecar in BlobTx (#27841)
This PR removes the newly added txpool.Transaction wrapper type, and instead adds a way
of keeping the blob sidecar within types.Transaction. It's better this way because most
code in go-ethereum does not care about blob transactions, and probably never will. This
will start mattering especially on the client side of RPC, where all APIs are based on
types.Transaction. Users need to be able to use the same signing flows they already
have.
However, since blobs are only allowed in some places but not others, we will now need to
add checks to avoid creating invalid blocks. I'm still trying to figure out the best place
to do some of these. The way I have it currently is as follows:
- In block validation (import), txs are verified not to have a blob sidecar.
- In miner, we strip off the sidecar when committing the transaction into the block.
- In TxPool validation, txs must have a sidecar to be added into the blobpool.
- Note there is a special case here: when transactions are re-added because of a chain
reorg, we cannot use the transactions gathered from the old chain blocks as-is,
because they will be missing their blobs. This was previously handled by storing the
blobs into the 'blobpool limbo'. The code has now changed to store the full
transaction in the limbo instead, but it might be confusing for code readers why we're
not simply adding the types.Transaction we already have.
Code changes summary:
- txpool.Transaction removed and all uses replaced by types.Transaction again
- blobpool now stores types.Transaction instead of defining its own blobTx format for storage
- the blobpool limbo now stores types.Transaction instead of storing only the blobs
- checks to validate the presence/absence of the blob sidecar added in certain critical places
2023-08-14 11:13:34 +03:00
|
|
|
ethservice.TxPool().Add([]*types.Transaction{tx}, false, true)
|
2022-11-11 15:22:54 +03:00
|
|
|
var (
|
2023-02-06 18:37:58 +03:00
|
|
|
params = engine.PayloadAttributes{
|
2023-03-02 09:29:15 +03:00
|
|
|
Timestamp: parent.Time + 1,
|
2022-11-11 15:22:54 +03:00
|
|
|
Random: crypto.Keccak256Hash([]byte{byte(i)}),
|
2023-03-02 09:29:15 +03:00
|
|
|
SuggestedFeeRecipient: parent.Coinbase,
|
2022-11-11 15:22:54 +03:00
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState = engine.ForkchoiceStateV1{
|
2022-11-11 15:22:54 +03:00
|
|
|
HeadBlockHash: parent.Hash(),
|
|
|
|
SafeBlockHash: common.Hash{},
|
|
|
|
FinalizedBlockHash: common.Hash{},
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
payload *engine.ExecutableData
|
|
|
|
resp engine.ForkChoiceResponse
|
2022-11-11 15:22:54 +03:00
|
|
|
err error
|
|
|
|
)
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
if resp, err = api.ForkchoiceUpdatedV1(fcState, ¶ms); err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if resp.PayloadStatus.Status != engine.VALID {
|
2022-11-11 15:22:54 +03:00
|
|
|
t.Fatalf("error preparing payload, invalid status: %v", resp.PayloadStatus.Status)
|
|
|
|
}
|
|
|
|
// give the payload some time to be built
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
if payload, err = api.GetPayloadV1(*resp.PayloadID); err != nil {
|
|
|
|
t.Fatalf("can't get payload: %v", err)
|
|
|
|
}
|
|
|
|
if len(payload.Transactions) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
// No luck this time we need to update the params and try again.
|
|
|
|
params.Timestamp = params.Timestamp + 1
|
|
|
|
if i > 10 {
|
|
|
|
t.Fatalf("payload should not be empty")
|
|
|
|
}
|
2022-05-18 17:33:37 +03:00
|
|
|
}
|
|
|
|
execResp, err := api.NewPayloadV1(*payload)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("can't execute payload: %v", err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if execResp.Status != engine.VALID {
|
2022-05-18 17:33:37 +03:00
|
|
|
t.Fatalf("invalid status: %v", execResp.Status)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState = engine.ForkchoiceStateV1{
|
2022-05-18 17:33:37 +03:00
|
|
|
HeadBlockHash: payload.BlockHash,
|
|
|
|
SafeBlockHash: payload.ParentHash,
|
|
|
|
FinalizedBlockHash: payload.ParentHash,
|
|
|
|
}
|
|
|
|
if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil {
|
|
|
|
t.Fatalf("Failed to insert block: %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentBlock().Number.Uint64() != payload.Number {
|
2022-05-18 17:33:37 +03:00
|
|
|
t.Fatalf("Chain head should be updated")
|
|
|
|
}
|
|
|
|
parent = ethservice.BlockChain().CurrentBlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-09 13:24:58 +03:00
|
|
|
func assembleEnvelope(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes) (*engine.ExecutionPayloadEnvelope, error) {
|
2022-11-02 12:32:20 +03:00
|
|
|
args := &miner.BuildPayloadArgs{
|
|
|
|
Parent: parentHash,
|
|
|
|
Timestamp: params.Timestamp,
|
|
|
|
FeeRecipient: params.SuggestedFeeRecipient,
|
|
|
|
Random: params.Random,
|
2023-01-25 17:32:25 +03:00
|
|
|
Withdrawals: params.Withdrawals,
|
2023-08-26 05:52:12 +03:00
|
|
|
BeaconRoot: params.BeaconRoot,
|
2022-11-02 12:32:20 +03:00
|
|
|
}
|
beacon, core, eth, miner: integrate witnesses into production Geth (#30069)
This PR integrates witness-enabled block production, witness-creating
payload execution and stateless cross-validation into the `engine` API.
The purpose of the PR is to enable the following use-cases (for API
details, please see next section):
- Cross validating locally created blocks:
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Cross validating locally processed blocks:
- Call `newPayloadWithWitness` instead of `newPayload` to trigger
witness creation too.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Block production for stateless clients (local or MEV builders):
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Propagate witnesses across the consensus libp2p network for stateless
Ethereum.
- Stateless validator validation:
- Call `executeStatelessPayload` with the propagated witness to
statelessly validate the block.
*Note, the various `WithWitness` methods could also *just be* an
additional boolean flag on the base methods, but this PR wanted to keep
the methods separate until a final consensus is reached on how to
integrate in production.*
---
The following `engine` API types are introduced:
```go
// StatelessPayloadStatusV1 is the result of a stateless payload execution.
type StatelessPayloadStatusV1 struct {
Status string `json:"status"`
StateRoot common.Hash `json:"stateRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
ValidationError *string `json:"validationError"`
}
```
- Add `forkchoiceUpdatedWithWitnessV1,2,3` with same params and returns
as `forkchoiceUpdatedV1,2,3`, but triggering a stateless witness
building if block production is requested.
- Extend `getPayloadV2,3` to return `executionPayloadEnvelope` with an
additional `witness` field of type `bytes` iff created via
`forkchoiceUpdatedWithWitnessV2,3`.
- Add `newPayloadWithWitnessV1,2,3,4` with same params and returns as
`newPayloadV1,2,3,4`, but triggering a stateless witness creation during
payload execution to allow cross validating it.
- Extend `payloadStatusV1` with a `witness` field of type `bytes` if
returned by `newPayloadWithWitnessV1,2,3,4`.
- Add `executeStatelessPayloadV1,2,3,4` with same base params as
`newPayloadV1,2,3,4` and one more additional param (`witness`) of type
`bytes`. The method returns `statelessPayloadStatusV1`, which mirrors
`payloadStatusV1` but replaces `latestValidHash` with `stateRoot` and
`receiptRoot`.
2024-09-20 16:43:42 +03:00
|
|
|
payload, err := api.eth.Miner().BuildPayload(args, false)
|
2022-05-18 17:33:37 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
return payload.ResolveFull(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func assembleBlock(api *ConsensusAPI, parentHash common.Hash, params *engine.PayloadAttributes) (*engine.ExecutableData, error) {
|
|
|
|
envelope, err := assembleEnvelope(api, parentHash, params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return envelope.ExecutionPayload, nil
|
2022-05-18 17:33:37 +03:00
|
|
|
}
|
2022-05-20 11:12:12 +03:00
|
|
|
|
|
|
|
func TestEmptyBlocks(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-05-20 11:12:12 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
commonAncestor := ethservice.BlockChain().CurrentBlock()
|
|
|
|
api := NewConsensusAPI(ethservice)
|
|
|
|
|
|
|
|
// Setup 10 blocks on the canonical chain
|
2024-09-04 15:33:51 +03:00
|
|
|
setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Header) {}, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
|
|
|
|
// (1) check LatestValidHash by sending a normal payload (P1'')
|
2024-09-04 15:33:51 +03:00
|
|
|
payload := getNewPayload(t, api, commonAncestor, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
|
|
|
|
status, err := api.NewPayloadV1(*payload)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if status.Status != engine.VALID {
|
2022-05-20 11:12:12 +03:00
|
|
|
t.Errorf("invalid status: expected VALID got: %v", status.Status)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(status.LatestValidHash[:], payload.BlockHash[:]) {
|
|
|
|
t.Fatalf("invalid LVH: got %v want %v", status.LatestValidHash, payload.BlockHash)
|
|
|
|
}
|
|
|
|
|
|
|
|
// (2) Now send P1' which is invalid
|
2024-09-04 15:33:51 +03:00
|
|
|
payload = getNewPayload(t, api, commonAncestor, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
payload.GasUsed += 1
|
|
|
|
payload = setBlockhash(payload)
|
|
|
|
// Now latestValidHash should be the common ancestor
|
|
|
|
status, err = api.NewPayloadV1(*payload)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if status.Status != engine.INVALID {
|
2022-05-20 11:12:12 +03:00
|
|
|
t.Errorf("invalid status: expected INVALID got: %v", status.Status)
|
|
|
|
}
|
2022-06-02 14:15:17 +03:00
|
|
|
// Expect 0x0 on INVALID block on top of PoW block
|
|
|
|
expected := common.Hash{}
|
2022-05-20 11:12:12 +03:00
|
|
|
if !bytes.Equal(status.LatestValidHash[:], expected[:]) {
|
|
|
|
t.Fatalf("invalid LVH: got %v want %v", status.LatestValidHash, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// (3) Now send a payload with unknown parent
|
2024-09-04 15:33:51 +03:00
|
|
|
payload = getNewPayload(t, api, commonAncestor, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
payload.ParentHash = common.Hash{1}
|
|
|
|
payload = setBlockhash(payload)
|
|
|
|
// Now latestValidHash should be the common ancestor
|
|
|
|
status, err = api.NewPayloadV1(*payload)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if status.Status != engine.SYNCING {
|
2022-07-28 16:01:35 +03:00
|
|
|
t.Errorf("invalid status: expected SYNCING got: %v", status.Status)
|
2022-05-20 11:12:12 +03:00
|
|
|
}
|
|
|
|
if status.LatestValidHash != nil {
|
|
|
|
t.Fatalf("invalid LVH: got %v wanted nil", status.LatestValidHash)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-09 13:24:58 +03:00
|
|
|
func getNewEnvelope(t *testing.T, api *ConsensusAPI, parent *types.Header, withdrawals []*types.Withdrawal, beaconRoot *common.Hash) *engine.ExecutionPayloadEnvelope {
|
2023-02-06 18:37:58 +03:00
|
|
|
params := engine.PayloadAttributes{
|
2023-03-02 09:29:15 +03:00
|
|
|
Timestamp: parent.Time + 1,
|
2022-05-20 11:12:12 +03:00
|
|
|
Random: crypto.Keccak256Hash([]byte{byte(1)}),
|
2023-03-02 09:29:15 +03:00
|
|
|
SuggestedFeeRecipient: parent.Coinbase,
|
2023-03-07 18:30:04 +03:00
|
|
|
Withdrawals: withdrawals,
|
2024-09-04 15:33:51 +03:00
|
|
|
BeaconRoot: beaconRoot,
|
2022-05-20 11:12:12 +03:00
|
|
|
}
|
|
|
|
|
2024-10-09 13:24:58 +03:00
|
|
|
envelope, err := assembleEnvelope(api, parent.Hash(), ¶ms)
|
2022-05-20 11:12:12 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
return envelope
|
|
|
|
}
|
|
|
|
|
|
|
|
func getNewPayload(t *testing.T, api *ConsensusAPI, parent *types.Header, withdrawals []*types.Withdrawal, beaconRoot *common.Hash) *engine.ExecutableData {
|
|
|
|
return getNewEnvelope(t, api, parent, withdrawals, beaconRoot).ExecutionPayload
|
2022-05-20 11:12:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// setBlockhash sets the blockhash of a modified ExecutableData.
|
|
|
|
// Can be used to make modified payloads look valid.
|
2023-02-06 18:37:58 +03:00
|
|
|
func setBlockhash(data *engine.ExecutableData) *engine.ExecutableData {
|
2022-05-20 11:12:12 +03:00
|
|
|
txs, _ := decodeTransactions(data.Transactions)
|
|
|
|
number := big.NewInt(0)
|
|
|
|
number.SetUint64(data.Number)
|
|
|
|
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: number,
|
|
|
|
GasLimit: data.GasLimit,
|
|
|
|
GasUsed: data.GasUsed,
|
|
|
|
Time: data.Timestamp,
|
|
|
|
BaseFee: data.BaseFeePerGas,
|
|
|
|
Extra: data.ExtraData,
|
|
|
|
MixDigest: data.Random,
|
|
|
|
}
|
2024-04-30 15:55:08 +03:00
|
|
|
block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs})
|
2022-05-20 11:12:12 +03:00
|
|
|
data.BlockHash = block.Hash()
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
|
|
|
|
var txs = make([]*types.Transaction, len(enc))
|
|
|
|
for i, encTx := range enc {
|
|
|
|
var tx types.Transaction
|
|
|
|
if err := tx.UnmarshalBinary(encTx); err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid transaction %d: %v", i, err)
|
|
|
|
}
|
|
|
|
txs[i] = &tx
|
|
|
|
}
|
|
|
|
return txs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTrickRemoteBlockCache(t *testing.T) {
|
|
|
|
// Setup two nodes
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-05-20 11:12:12 +03:00
|
|
|
nodeA, ethserviceA := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
nodeB, ethserviceB := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer nodeA.Close()
|
|
|
|
defer nodeB.Close()
|
|
|
|
for nodeB.Server().NodeInfo().Ports.Listener == 0 {
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
}
|
|
|
|
nodeA.Server().AddPeer(nodeB.Server().Self())
|
|
|
|
nodeB.Server().AddPeer(nodeA.Server().Self())
|
|
|
|
apiA := NewConsensusAPI(ethserviceA)
|
|
|
|
apiB := NewConsensusAPI(ethserviceB)
|
|
|
|
|
|
|
|
commonAncestor := ethserviceA.BlockChain().CurrentBlock()
|
|
|
|
|
|
|
|
// Setup 10 blocks on the canonical chain
|
2024-09-04 15:33:51 +03:00
|
|
|
setupBlocks(t, ethserviceA, 10, commonAncestor, func(parent *types.Header) {}, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
commonAncestor = ethserviceA.BlockChain().CurrentBlock()
|
|
|
|
|
2023-02-06 18:37:58 +03:00
|
|
|
var invalidChain []*engine.ExecutableData
|
2022-05-20 11:12:12 +03:00
|
|
|
// create a valid payload (P1)
|
|
|
|
//payload1 := getNewPayload(t, apiA, commonAncestor)
|
|
|
|
//invalidChain = append(invalidChain, payload1)
|
|
|
|
|
|
|
|
// create an invalid payload2 (P2)
|
2024-09-04 15:33:51 +03:00
|
|
|
payload2 := getNewPayload(t, apiA, commonAncestor, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
//payload2.ParentHash = payload1.BlockHash
|
|
|
|
payload2.GasUsed += 1
|
|
|
|
payload2 = setBlockhash(payload2)
|
|
|
|
invalidChain = append(invalidChain, payload2)
|
|
|
|
|
|
|
|
head := payload2
|
|
|
|
// create some valid payloads on top
|
|
|
|
for i := 0; i < 10; i++ {
|
2024-09-04 15:33:51 +03:00
|
|
|
payload := getNewPayload(t, apiA, commonAncestor, nil, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
payload.ParentHash = head.BlockHash
|
|
|
|
payload = setBlockhash(payload)
|
|
|
|
invalidChain = append(invalidChain, payload)
|
|
|
|
head = payload
|
|
|
|
}
|
|
|
|
|
|
|
|
// feed the payloads to node B
|
|
|
|
for _, payload := range invalidChain {
|
|
|
|
status, err := apiB.NewPayloadV1(*payload)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if status.Status == engine.VALID {
|
2022-07-25 16:51:04 +03:00
|
|
|
t.Error("invalid status: VALID on an invalid chain")
|
2022-05-20 11:12:12 +03:00
|
|
|
}
|
|
|
|
// Now reorg to the head of the invalid chain
|
2023-02-06 18:37:58 +03:00
|
|
|
resp, err := apiB.ForkchoiceUpdatedV1(engine.ForkchoiceStateV1{HeadBlockHash: payload.BlockHash, SafeBlockHash: payload.BlockHash, FinalizedBlockHash: payload.ParentHash}, nil)
|
2022-05-20 11:12:12 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if resp.PayloadStatus.Status == engine.VALID {
|
2022-07-25 16:51:04 +03:00
|
|
|
t.Error("invalid status: VALID on an invalid chain")
|
2022-05-20 11:12:12 +03:00
|
|
|
}
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
2022-05-30 14:28:15 +03:00
|
|
|
|
2022-05-31 12:11:50 +03:00
|
|
|
func TestInvalidBloom(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-05-31 12:11:50 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
commonAncestor := ethservice.BlockChain().CurrentBlock()
|
|
|
|
api := NewConsensusAPI(ethservice)
|
|
|
|
|
|
|
|
// Setup 10 blocks on the canonical chain
|
2024-09-04 15:33:51 +03:00
|
|
|
setupBlocks(t, ethservice, 10, commonAncestor, func(parent *types.Header) {}, nil, nil)
|
2022-05-31 12:11:50 +03:00
|
|
|
|
|
|
|
// (1) check LatestValidHash by sending a normal payload (P1'')
|
2024-09-04 15:33:51 +03:00
|
|
|
payload := getNewPayload(t, api, commonAncestor, nil, nil)
|
2022-05-31 12:11:50 +03:00
|
|
|
payload.LogsBloom = append(payload.LogsBloom, byte(1))
|
|
|
|
status, err := api.NewPayloadV1(*payload)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-02-17 13:25:09 +03:00
|
|
|
if status.Status != engine.INVALID {
|
|
|
|
t.Errorf("invalid status: expected INVALID got: %v", status.Status)
|
2022-05-31 12:11:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-30 14:28:15 +03:00
|
|
|
func TestNewPayloadOnInvalidTerminalBlock(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(100, false)
|
2022-05-30 14:28:15 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
2023-03-22 20:36:26 +03:00
|
|
|
api := NewConsensusAPI(ethservice)
|
2022-05-30 14:28:15 +03:00
|
|
|
|
|
|
|
// Test parent already post TTD in FCU
|
2023-03-22 20:36:26 +03:00
|
|
|
parent := preMergeBlocks[len(preMergeBlocks)-2]
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2022-05-30 14:28:15 +03:00
|
|
|
HeadBlockHash: parent.Hash(),
|
|
|
|
SafeBlockHash: common.Hash{},
|
|
|
|
FinalizedBlockHash: common.Hash{},
|
|
|
|
}
|
|
|
|
resp, err := api.ForkchoiceUpdatedV1(fcState, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error sending forkchoice, err=%v", err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if resp.PayloadStatus != engine.INVALID_TERMINAL_BLOCK {
|
2022-05-30 14:28:15 +03:00
|
|
|
t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test parent already post TTD in NewPayload
|
2022-11-02 12:32:20 +03:00
|
|
|
args := &miner.BuildPayloadArgs{
|
|
|
|
Parent: parent.Hash(),
|
|
|
|
Timestamp: parent.Time() + 1,
|
|
|
|
Random: crypto.Keccak256Hash([]byte{byte(1)}),
|
|
|
|
FeeRecipient: parent.Coinbase(),
|
2022-05-30 14:28:15 +03:00
|
|
|
}
|
beacon, core, eth, miner: integrate witnesses into production Geth (#30069)
This PR integrates witness-enabled block production, witness-creating
payload execution and stateless cross-validation into the `engine` API.
The purpose of the PR is to enable the following use-cases (for API
details, please see next section):
- Cross validating locally created blocks:
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Cross validating locally processed blocks:
- Call `newPayloadWithWitness` instead of `newPayload` to trigger
witness creation too.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Block production for stateless clients (local or MEV builders):
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Propagate witnesses across the consensus libp2p network for stateless
Ethereum.
- Stateless validator validation:
- Call `executeStatelessPayload` with the propagated witness to
statelessly validate the block.
*Note, the various `WithWitness` methods could also *just be* an
additional boolean flag on the base methods, but this PR wanted to keep
the methods separate until a final consensus is reached on how to
integrate in production.*
---
The following `engine` API types are introduced:
```go
// StatelessPayloadStatusV1 is the result of a stateless payload execution.
type StatelessPayloadStatusV1 struct {
Status string `json:"status"`
StateRoot common.Hash `json:"stateRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
ValidationError *string `json:"validationError"`
}
```
- Add `forkchoiceUpdatedWithWitnessV1,2,3` with same params and returns
as `forkchoiceUpdatedV1,2,3`, but triggering a stateless witness
building if block production is requested.
- Extend `getPayloadV2,3` to return `executionPayloadEnvelope` with an
additional `witness` field of type `bytes` iff created via
`forkchoiceUpdatedWithWitnessV2,3`.
- Add `newPayloadWithWitnessV1,2,3,4` with same params and returns as
`newPayloadV1,2,3,4`, but triggering a stateless witness creation during
payload execution to allow cross validating it.
- Extend `payloadStatusV1` with a `witness` field of type `bytes` if
returned by `newPayloadWithWitnessV1,2,3,4`.
- Add `executeStatelessPayloadV1,2,3,4` with same base params as
`newPayloadV1,2,3,4` and one more additional param (`witness`) of type
`bytes`. The method returns `statelessPayloadStatusV1`, which mirrors
`payloadStatusV1` but replaces `latestValidHash` with `stateRoot` and
`receiptRoot`.
2024-09-20 16:43:42 +03:00
|
|
|
payload, err := api.eth.Miner().BuildPayload(args, false)
|
2022-05-30 14:28:15 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
2023-01-25 17:32:25 +03:00
|
|
|
data := *payload.Resolve().ExecutionPayload
|
2023-03-22 20:36:26 +03:00
|
|
|
// 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,
|
|
|
|
}
|
2024-04-30 15:55:08 +03:00
|
|
|
block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs})
|
2023-03-22 20:36:26 +03:00
|
|
|
data.BlockHash = block.Hash()
|
|
|
|
// Send the new payload
|
2022-05-30 14:28:15 +03:00
|
|
|
resp2, err := api.NewPayloadV1(data)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error sending NewPayload, err=%v", err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if resp2 != engine.INVALID_TERMINAL_BLOCK {
|
2022-05-30 14:28:15 +03:00
|
|
|
t.Fatalf("error sending invalid forkchoice, invalid status: %v", resp.PayloadStatus.Status)
|
|
|
|
}
|
|
|
|
}
|
2022-09-21 14:48:09 +03:00
|
|
|
|
|
|
|
// TestSimultaneousNewBlock does several parallel inserts, both as
|
|
|
|
// newPayLoad and forkchoiceUpdate. This is to test that the api behaves
|
|
|
|
// well even of the caller is not being 'serial'.
|
|
|
|
func TestSimultaneousNewBlock(t *testing.T) {
|
2023-01-25 17:32:25 +03:00
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
2022-09-21 14:48:09 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
var (
|
|
|
|
api = NewConsensusAPI(ethservice)
|
|
|
|
parent = preMergeBlocks[len(preMergeBlocks)-1]
|
|
|
|
)
|
|
|
|
for i := 0; i < 10; i++ {
|
2023-02-06 18:37:58 +03:00
|
|
|
execData, err := assembleBlock(api, parent.Hash(), &engine.PayloadAttributes{
|
2022-09-21 14:48:09 +03:00
|
|
|
Timestamp: parent.Time() + 5,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to create the executable data %v", err)
|
|
|
|
}
|
|
|
|
// Insert it 10 times in parallel. Should be ignored.
|
|
|
|
{
|
|
|
|
var (
|
|
|
|
wg sync.WaitGroup
|
|
|
|
testErr error
|
|
|
|
errMu sync.Mutex
|
|
|
|
)
|
|
|
|
wg.Add(10)
|
|
|
|
for ii := 0; ii < 10; ii++ {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
if newResp, err := api.NewPayloadV1(*execData); err != nil {
|
|
|
|
errMu.Lock()
|
2024-05-28 14:44:40 +03:00
|
|
|
testErr = fmt.Errorf("failed to insert block: %w", err)
|
2022-09-21 14:48:09 +03:00
|
|
|
errMu.Unlock()
|
|
|
|
} else if newResp.Status != "VALID" {
|
|
|
|
errMu.Lock()
|
2024-05-28 14:44:40 +03:00
|
|
|
testErr = fmt.Errorf("failed to insert block: %v", newResp.Status)
|
2022-09-21 14:48:09 +03:00
|
|
|
errMu.Unlock()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
if testErr != nil {
|
|
|
|
t.Fatal(testErr)
|
|
|
|
}
|
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
block, err := engine.ExecutableDataToBlock(*execData, nil, nil, nil)
|
2022-09-21 14:48:09 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to convert executable data to block %v", err)
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if ethservice.BlockChain().CurrentBlock().Number.Uint64() != block.NumberU64()-1 {
|
2022-09-21 14:48:09 +03:00
|
|
|
t.Fatalf("Chain head shouldn't be updated")
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2022-09-21 14:48:09 +03:00
|
|
|
HeadBlockHash: block.Hash(),
|
|
|
|
SafeBlockHash: block.Hash(),
|
|
|
|
FinalizedBlockHash: block.Hash(),
|
|
|
|
}
|
|
|
|
{
|
|
|
|
var (
|
|
|
|
wg sync.WaitGroup
|
|
|
|
testErr error
|
|
|
|
errMu sync.Mutex
|
|
|
|
)
|
|
|
|
wg.Add(10)
|
|
|
|
// Do each FCU 10 times
|
|
|
|
for ii := 0; ii < 10; ii++ {
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
if _, err := api.ForkchoiceUpdatedV1(fcState, nil); err != nil {
|
|
|
|
errMu.Lock()
|
2024-05-28 14:44:40 +03:00
|
|
|
testErr = fmt.Errorf("failed to insert block: %w", err)
|
2022-09-21 14:48:09 +03:00
|
|
|
errMu.Unlock()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
if testErr != nil {
|
|
|
|
t.Fatal(testErr)
|
|
|
|
}
|
|
|
|
}
|
2023-03-02 09:29:15 +03:00
|
|
|
if have, want := ethservice.BlockChain().CurrentBlock().Number.Uint64(), block.NumberU64(); have != want {
|
2022-09-21 14:48:09 +03:00
|
|
|
t.Fatalf("Chain head should be updated, have %d want %d", have, want)
|
|
|
|
}
|
|
|
|
parent = block
|
|
|
|
}
|
|
|
|
}
|
2023-01-25 17:32:25 +03:00
|
|
|
|
|
|
|
// TestWithdrawals creates and verifies two post-Shanghai blocks. The first
|
|
|
|
// includes zero withdrawals and the second includes two.
|
|
|
|
func TestWithdrawals(t *testing.T) {
|
|
|
|
genesis, blocks := generateMergeChain(10, true)
|
|
|
|
// Set shanghai time to last block + 5 seconds (first post-merge block)
|
|
|
|
time := blocks[len(blocks)-1].Time() + 5
|
|
|
|
genesis.Config.ShanghaiTime = &time
|
|
|
|
|
|
|
|
n, ethservice := startEthService(t, genesis, blocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
api := NewConsensusAPI(ethservice)
|
|
|
|
|
|
|
|
// 10: Build Shanghai block with no withdrawals.
|
|
|
|
parent := ethservice.BlockChain().CurrentHeader()
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams := engine.PayloadAttributes{
|
2023-01-25 17:32:25 +03:00
|
|
|
Timestamp: parent.Time + 5,
|
|
|
|
Withdrawals: make([]*types.Withdrawal, 0),
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2023-01-25 17:32:25 +03:00
|
|
|
HeadBlockHash: parent.Hash(),
|
|
|
|
}
|
|
|
|
resp, err := api.ForkchoiceUpdatedV2(fcState, &blockParams)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
2023-02-06 18:37:58 +03:00
|
|
|
if resp.PayloadStatus.Status != engine.VALID {
|
|
|
|
t.Fatalf("unexpected status (got: %s, want: %s)", resp.PayloadStatus.Status, engine.VALID)
|
2023-01-25 17:32:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 10: verify state root is the same as parent
|
|
|
|
payloadID := (&miner.BuildPayloadArgs{
|
|
|
|
Parent: fcState.HeadBlockHash,
|
|
|
|
Timestamp: blockParams.Timestamp,
|
|
|
|
FeeRecipient: blockParams.SuggestedFeeRecipient,
|
|
|
|
Random: blockParams.Random,
|
2023-02-07 21:16:53 +03:00
|
|
|
Withdrawals: blockParams.Withdrawals,
|
2023-08-26 05:52:12 +03:00
|
|
|
BeaconRoot: blockParams.BeaconRoot,
|
2024-01-24 10:39:12 +03:00
|
|
|
Version: engine.PayloadV2,
|
2023-01-25 17:32:25 +03:00
|
|
|
}).Id()
|
|
|
|
execData, err := api.GetPayloadV2(payloadID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting payload, err=%v", err)
|
|
|
|
}
|
|
|
|
if execData.ExecutionPayload.StateRoot != parent.Root {
|
|
|
|
t.Fatalf("mismatch state roots (got: %s, want: %s)", execData.ExecutionPayload.StateRoot, blocks[8].Root())
|
|
|
|
}
|
|
|
|
|
|
|
|
// 10: verify locally built block
|
|
|
|
if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil {
|
|
|
|
t.Fatalf("error validating payload: %v", err)
|
2023-02-06 18:37:58 +03:00
|
|
|
} else if status.Status != engine.VALID {
|
2023-01-25 17:32:25 +03:00
|
|
|
t.Fatalf("invalid payload")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: build shanghai block with withdrawal
|
|
|
|
aa := common.Address{0xaa}
|
|
|
|
bb := common.Address{0xbb}
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams = engine.PayloadAttributes{
|
2023-01-25 17:32:25 +03:00
|
|
|
Timestamp: execData.ExecutionPayload.Timestamp + 5,
|
|
|
|
Withdrawals: []*types.Withdrawal{
|
|
|
|
{
|
|
|
|
Index: 0,
|
|
|
|
Address: aa,
|
|
|
|
Amount: 32,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Index: 1,
|
|
|
|
Address: bb,
|
|
|
|
Amount: 33,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
fcState.HeadBlockHash = execData.ExecutionPayload.BlockHash
|
|
|
|
_, err = api.ForkchoiceUpdatedV2(fcState, &blockParams)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: verify locally build block.
|
|
|
|
payloadID = (&miner.BuildPayloadArgs{
|
|
|
|
Parent: fcState.HeadBlockHash,
|
|
|
|
Timestamp: blockParams.Timestamp,
|
|
|
|
FeeRecipient: blockParams.SuggestedFeeRecipient,
|
|
|
|
Random: blockParams.Random,
|
2023-02-07 21:16:53 +03:00
|
|
|
Withdrawals: blockParams.Withdrawals,
|
2023-08-26 05:52:12 +03:00
|
|
|
BeaconRoot: blockParams.BeaconRoot,
|
2024-01-24 10:39:12 +03:00
|
|
|
Version: engine.PayloadV2,
|
2023-01-25 17:32:25 +03:00
|
|
|
}).Id()
|
|
|
|
execData, err = api.GetPayloadV2(payloadID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting payload, err=%v", err)
|
|
|
|
}
|
|
|
|
if status, err := api.NewPayloadV2(*execData.ExecutionPayload); err != nil {
|
|
|
|
t.Fatalf("error validating payload: %v", err)
|
2023-02-06 18:37:58 +03:00
|
|
|
} else if status.Status != engine.VALID {
|
2023-01-25 17:32:25 +03:00
|
|
|
t.Fatalf("invalid payload")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: set block as head.
|
|
|
|
fcState.HeadBlockHash = execData.ExecutionPayload.BlockHash
|
|
|
|
_, err = api.ForkchoiceUpdatedV2(fcState, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: verify withdrawals were processed.
|
|
|
|
db, _, err := ethservice.APIBackend.StateAndHeaderByNumber(context.Background(), rpc.BlockNumber(execData.ExecutionPayload.Number))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to load db: %v", err)
|
|
|
|
}
|
|
|
|
for i, w := range blockParams.Withdrawals {
|
|
|
|
// w.Amount is in gwei, balance in wei
|
|
|
|
if db.GetBalance(w.Address).Uint64() != w.Amount*params.GWei {
|
|
|
|
t.Fatalf("failed to process withdrawal %d", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-27 13:42:14 +03:00
|
|
|
|
|
|
|
func TestNilWithdrawals(t *testing.T) {
|
|
|
|
genesis, blocks := generateMergeChain(10, true)
|
|
|
|
// Set shanghai time to last block + 4 seconds (first post-merge block)
|
|
|
|
time := blocks[len(blocks)-1].Time() + 4
|
|
|
|
genesis.Config.ShanghaiTime = &time
|
|
|
|
|
|
|
|
n, ethservice := startEthService(t, genesis, blocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
api := NewConsensusAPI(ethservice)
|
|
|
|
parent := ethservice.BlockChain().CurrentHeader()
|
|
|
|
aa := common.Address{0xaa}
|
|
|
|
|
|
|
|
type test struct {
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams engine.PayloadAttributes
|
2023-01-27 13:42:14 +03:00
|
|
|
wantErr bool
|
|
|
|
}
|
|
|
|
tests := []test{
|
|
|
|
// Before Shanghai
|
|
|
|
{
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams: engine.PayloadAttributes{
|
2023-01-27 13:42:14 +03:00
|
|
|
Timestamp: parent.Time + 2,
|
|
|
|
Withdrawals: nil,
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams: engine.PayloadAttributes{
|
2023-01-27 13:42:14 +03:00
|
|
|
Timestamp: parent.Time + 2,
|
|
|
|
Withdrawals: make([]*types.Withdrawal, 0),
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams: engine.PayloadAttributes{
|
2023-01-27 13:42:14 +03:00
|
|
|
Timestamp: parent.Time + 2,
|
|
|
|
Withdrawals: []*types.Withdrawal{
|
|
|
|
{
|
|
|
|
Index: 0,
|
|
|
|
Address: aa,
|
|
|
|
Amount: 32,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
// After Shanghai
|
|
|
|
{
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams: engine.PayloadAttributes{
|
2023-01-27 13:42:14 +03:00
|
|
|
Timestamp: parent.Time + 5,
|
|
|
|
Withdrawals: nil,
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams: engine.PayloadAttributes{
|
2023-01-27 13:42:14 +03:00
|
|
|
Timestamp: parent.Time + 5,
|
|
|
|
Withdrawals: make([]*types.Withdrawal, 0),
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
2023-02-06 18:37:58 +03:00
|
|
|
blockParams: engine.PayloadAttributes{
|
2023-01-27 13:42:14 +03:00
|
|
|
Timestamp: parent.Time + 5,
|
|
|
|
Withdrawals: []*types.Withdrawal{
|
|
|
|
{
|
|
|
|
Index: 0,
|
|
|
|
Address: aa,
|
|
|
|
Amount: 32,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-02-06 18:37:58 +03:00
|
|
|
fcState := engine.ForkchoiceStateV1{
|
2023-01-27 13:42:14 +03:00
|
|
|
HeadBlockHash: parent.Hash(),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2024-01-23 18:02:08 +03:00
|
|
|
var (
|
2024-01-24 10:39:12 +03:00
|
|
|
err error
|
|
|
|
payloadVersion engine.PayloadVersion
|
|
|
|
shanghai = genesis.Config.IsShanghai(genesis.Config.LondonBlock, test.blockParams.Timestamp)
|
2024-01-23 18:02:08 +03:00
|
|
|
)
|
|
|
|
if !shanghai {
|
2024-01-24 10:39:12 +03:00
|
|
|
payloadVersion = engine.PayloadV1
|
2024-01-23 18:02:08 +03:00
|
|
|
_, err = api.ForkchoiceUpdatedV1(fcState, &test.blockParams)
|
|
|
|
} else {
|
2024-01-24 10:39:12 +03:00
|
|
|
payloadVersion = engine.PayloadV2
|
2024-01-23 18:02:08 +03:00
|
|
|
_, err = api.ForkchoiceUpdatedV2(fcState, &test.blockParams)
|
|
|
|
}
|
2023-01-27 13:42:14 +03:00
|
|
|
if test.wantErr {
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("wanted error on fcuv2 with invalid withdrawals")
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: verify locally build block.
|
|
|
|
payloadID := (&miner.BuildPayloadArgs{
|
|
|
|
Parent: fcState.HeadBlockHash,
|
|
|
|
Timestamp: test.blockParams.Timestamp,
|
|
|
|
FeeRecipient: test.blockParams.SuggestedFeeRecipient,
|
|
|
|
Random: test.blockParams.Random,
|
2024-01-24 10:39:12 +03:00
|
|
|
Version: payloadVersion,
|
2023-01-27 13:42:14 +03:00
|
|
|
}).Id()
|
|
|
|
execData, err := api.GetPayloadV2(payloadID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting payload, err=%v", err)
|
|
|
|
}
|
2024-01-23 18:02:08 +03:00
|
|
|
var status engine.PayloadStatusV1
|
|
|
|
if !shanghai {
|
|
|
|
status, err = api.NewPayloadV1(*execData.ExecutionPayload)
|
|
|
|
} else {
|
|
|
|
status, err = api.NewPayloadV2(*execData.ExecutionPayload)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error validating payload: %v", err.(*engine.EngineAPIError).ErrorData())
|
2023-02-06 18:37:58 +03:00
|
|
|
} else if status.Status != engine.VALID {
|
2023-01-27 13:42:14 +03:00
|
|
|
t.Fatalf("invalid payload")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-06 12:21:40 +03:00
|
|
|
|
|
|
|
func setupBodies(t *testing.T) (*node.Node, *eth.Ethereum, []*types.Block) {
|
2023-03-07 18:30:04 +03:00
|
|
|
genesis, blocks := generateMergeChain(10, true)
|
2024-09-04 15:33:51 +03:00
|
|
|
|
|
|
|
// Enable next forks on the last block.
|
2023-03-22 20:36:26 +03:00
|
|
|
time := blocks[len(blocks)-1].Header().Time + 1
|
|
|
|
genesis.Config.ShanghaiTime = &time
|
2024-09-04 15:33:51 +03:00
|
|
|
genesis.Config.CancunTime = &time
|
|
|
|
genesis.Config.PragueTime = &time
|
|
|
|
|
2023-03-22 20:36:26 +03:00
|
|
|
n, ethservice := startEthService(t, genesis, blocks)
|
2023-02-06 12:21:40 +03:00
|
|
|
|
|
|
|
var (
|
|
|
|
// This EVM code generates a log when the contract is created.
|
|
|
|
logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00")
|
2024-09-04 15:33:51 +03:00
|
|
|
parent = ethservice.BlockChain().CurrentBlock()
|
2023-02-06 12:21:40 +03:00
|
|
|
)
|
|
|
|
|
2024-09-04 15:33:51 +03:00
|
|
|
// Each block, this callback will include two txs that generate body values like logs and requests.
|
2023-03-02 09:29:15 +03:00
|
|
|
callback := func(parent *types.Header) {
|
2024-09-04 15:33:51 +03:00
|
|
|
var (
|
|
|
|
statedb, _ = ethservice.BlockChain().StateAt(parent.Root)
|
|
|
|
// Create tx to trigger log generator.
|
|
|
|
tx1, _ = types.SignTx(types.NewContractCreation(statedb.GetNonce(testAddr), new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey)
|
|
|
|
// Create tx to trigger deposit generator.
|
|
|
|
tx2, _ = types.SignTx(types.NewTransaction(statedb.GetNonce(testAddr)+1, ethservice.APIBackend.ChainConfig().DepositContractAddress, new(big.Int), 500000, big.NewInt(2*params.InitialBaseFee), nil), types.LatestSigner(ethservice.BlockChain().Config()), testKey)
|
|
|
|
)
|
|
|
|
ethservice.TxPool().Add([]*types.Transaction{tx1}, false, false)
|
|
|
|
ethservice.TxPool().Add([]*types.Transaction{tx2}, false, false)
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 15:33:51 +03:00
|
|
|
// Make some withdrawals to include.
|
2023-03-07 18:30:04 +03:00
|
|
|
withdrawals := make([][]*types.Withdrawal, 10)
|
|
|
|
withdrawals[0] = nil // should be filtered out by miner
|
|
|
|
withdrawals[1] = make([]*types.Withdrawal, 0)
|
|
|
|
for i := 2; i < len(withdrawals); i++ {
|
|
|
|
addr := make([]byte, 20)
|
|
|
|
crand.Read(addr)
|
|
|
|
withdrawals[i] = []*types.Withdrawal{
|
|
|
|
{Index: rand.Uint64(), Validator: rand.Uint64(), Amount: rand.Uint64(), Address: common.BytesToAddress(addr)},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 15:33:51 +03:00
|
|
|
// Make beacon root update for each block.
|
|
|
|
beaconRoots := make([]common.Hash, 10)
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
beaconRoots[i] = common.Hash{byte(i)}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the blocks.
|
|
|
|
newHeaders := setupBlocks(t, ethservice, 10, parent, callback, withdrawals, beaconRoots)
|
|
|
|
newBlocks := make([]*types.Block, len(newHeaders))
|
|
|
|
for i, header := range newHeaders {
|
|
|
|
newBlocks[i] = ethservice.BlockChain().GetBlock(header.Hash(), header.Number.Uint64())
|
2023-03-02 09:29:15 +03:00
|
|
|
}
|
2024-09-04 15:33:51 +03:00
|
|
|
|
|
|
|
return n, ethservice, append(blocks, newBlocks...)
|
2023-03-07 18:30:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func allHashes(blocks []*types.Block) []common.Hash {
|
|
|
|
var hashes []common.Hash
|
|
|
|
for _, b := range blocks {
|
|
|
|
hashes = append(hashes, b.Hash())
|
|
|
|
}
|
|
|
|
return hashes
|
|
|
|
}
|
|
|
|
func allBodies(blocks []*types.Block) []*types.Body {
|
|
|
|
var bodies []*types.Body
|
|
|
|
for _, b := range blocks {
|
|
|
|
bodies = append(bodies, b.Body())
|
|
|
|
}
|
|
|
|
return bodies
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetBlockBodiesByHash(t *testing.T) {
|
|
|
|
node, eth, blocks := setupBodies(t)
|
|
|
|
api := NewConsensusAPI(eth)
|
|
|
|
defer node.Close()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
results []*types.Body
|
|
|
|
hashes []common.Hash
|
|
|
|
}{
|
|
|
|
// First pow block
|
|
|
|
{
|
|
|
|
results: []*types.Body{eth.BlockChain().GetBlockByNumber(0).Body()},
|
|
|
|
hashes: []common.Hash{eth.BlockChain().GetBlockByNumber(0).Hash()},
|
|
|
|
},
|
|
|
|
// Last pow block
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[9].Body()},
|
|
|
|
hashes: []common.Hash{blocks[9].Hash()},
|
|
|
|
},
|
|
|
|
// First post-merge block
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[10].Body()},
|
|
|
|
hashes: []common.Hash{blocks[10].Hash()},
|
|
|
|
},
|
|
|
|
// Pre & post merge blocks
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[0].Body(), blocks[9].Body(), blocks[14].Body()},
|
|
|
|
hashes: []common.Hash{blocks[0].Hash(), blocks[9].Hash(), blocks[14].Hash()},
|
|
|
|
},
|
|
|
|
// unavailable block
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[0].Body(), nil, blocks[14].Body()},
|
|
|
|
hashes: []common.Hash{blocks[0].Hash(), {1, 2}, blocks[14].Hash()},
|
|
|
|
},
|
|
|
|
// same block multiple times
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[0].Body(), nil, blocks[0].Body(), blocks[0].Body()},
|
|
|
|
hashes: []common.Hash{blocks[0].Hash(), {1, 2}, blocks[0].Hash(), blocks[0].Hash()},
|
|
|
|
},
|
2023-03-07 18:30:04 +03:00
|
|
|
// all blocks
|
|
|
|
{
|
|
|
|
results: allBodies(blocks),
|
|
|
|
hashes: allHashes(blocks),
|
|
|
|
},
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, test := range tests {
|
2024-09-04 15:33:51 +03:00
|
|
|
result := api.GetPayloadBodiesByHashV2(test.hashes)
|
2023-02-06 12:21:40 +03:00
|
|
|
for i, r := range result {
|
2024-10-09 13:24:58 +03:00
|
|
|
if err := checkEqualBody(test.results[i], r); err != nil {
|
|
|
|
t.Fatalf("test %v: invalid response: %v\nexpected %+v\ngot %+v", k, err, test.results[i], r)
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetBlockBodiesByRange(t *testing.T) {
|
|
|
|
node, eth, blocks := setupBodies(t)
|
|
|
|
api := NewConsensusAPI(eth)
|
|
|
|
defer node.Close()
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
results []*types.Body
|
2023-02-08 18:04:40 +03:00
|
|
|
start hexutil.Uint64
|
|
|
|
count hexutil.Uint64
|
2023-02-06 12:21:40 +03:00
|
|
|
}{
|
2023-02-08 18:04:40 +03:00
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[9].Body()},
|
|
|
|
start: 10,
|
|
|
|
count: 1,
|
|
|
|
},
|
2023-02-06 12:21:40 +03:00
|
|
|
// Genesis
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[0].Body()},
|
|
|
|
start: 1,
|
|
|
|
count: 1,
|
|
|
|
},
|
|
|
|
// First post-merge block
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[9].Body()},
|
|
|
|
start: 10,
|
|
|
|
count: 1,
|
|
|
|
},
|
|
|
|
// Pre & post merge blocks
|
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[7].Body(), blocks[8].Body(), blocks[9].Body(), blocks[10].Body()},
|
|
|
|
start: 8,
|
|
|
|
count: 4,
|
|
|
|
},
|
|
|
|
// unavailable block
|
|
|
|
{
|
2023-02-08 18:04:40 +03:00
|
|
|
results: []*types.Body{blocks[18].Body(), blocks[19].Body()},
|
2023-02-06 12:21:40 +03:00
|
|
|
start: 19,
|
|
|
|
count: 3,
|
|
|
|
},
|
2023-02-08 18:04:40 +03:00
|
|
|
// unavailable block
|
2023-02-06 12:21:40 +03:00
|
|
|
{
|
2023-02-08 18:04:40 +03:00
|
|
|
results: []*types.Body{blocks[19].Body()},
|
2023-02-06 12:21:40 +03:00
|
|
|
start: 20,
|
|
|
|
count: 2,
|
|
|
|
},
|
2023-02-08 18:04:40 +03:00
|
|
|
{
|
|
|
|
results: []*types.Body{blocks[19].Body()},
|
|
|
|
start: 20,
|
|
|
|
count: 1,
|
|
|
|
},
|
|
|
|
// whole range unavailable
|
|
|
|
{
|
|
|
|
results: make([]*types.Body, 0),
|
|
|
|
start: 22,
|
|
|
|
count: 2,
|
|
|
|
},
|
2023-03-07 18:30:04 +03:00
|
|
|
// allBlocks
|
|
|
|
{
|
|
|
|
results: allBodies(blocks),
|
|
|
|
start: 1,
|
|
|
|
count: hexutil.Uint64(len(blocks)),
|
|
|
|
},
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, test := range tests {
|
2024-09-04 15:33:51 +03:00
|
|
|
result, err := api.GetPayloadBodiesByRangeV2(test.start, test.count)
|
2023-02-06 12:21:40 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(result) == len(test.results) {
|
|
|
|
for i, r := range result {
|
2024-10-09 13:24:58 +03:00
|
|
|
if err := checkEqualBody(test.results[i], r); err != nil {
|
|
|
|
t.Fatalf("test %d: invalid response: %v\nexpected %+v\ngot %+v", k, err, test.results[i], r)
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-08 18:04:40 +03:00
|
|
|
t.Fatalf("test %d: invalid length want %v got %v", k, len(test.results), len(result))
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
|
|
|
|
node, eth, _ := setupBodies(t)
|
|
|
|
api := NewConsensusAPI(eth)
|
|
|
|
defer node.Close()
|
|
|
|
tests := []struct {
|
2023-02-08 18:04:40 +03:00
|
|
|
start hexutil.Uint64
|
|
|
|
count hexutil.Uint64
|
2023-02-17 21:30:38 +03:00
|
|
|
want *engine.EngineAPIError
|
2023-02-06 12:21:40 +03:00
|
|
|
}{
|
|
|
|
// Genesis
|
|
|
|
{
|
|
|
|
start: 0,
|
|
|
|
count: 1,
|
2023-02-17 21:30:38 +03:00
|
|
|
want: engine.InvalidParams,
|
2023-02-06 12:21:40 +03:00
|
|
|
},
|
|
|
|
// No block requested
|
|
|
|
{
|
|
|
|
start: 1,
|
|
|
|
count: 0,
|
2023-02-17 21:30:38 +03:00
|
|
|
want: engine.InvalidParams,
|
2023-02-06 12:21:40 +03:00
|
|
|
},
|
|
|
|
// Genesis & no block
|
|
|
|
{
|
|
|
|
start: 0,
|
|
|
|
count: 0,
|
2023-02-17 21:30:38 +03:00
|
|
|
want: engine.InvalidParams,
|
2023-02-06 12:21:40 +03:00
|
|
|
},
|
|
|
|
// More than 1024 blocks
|
|
|
|
{
|
|
|
|
start: 1,
|
|
|
|
count: 1025,
|
2023-02-17 21:30:38 +03:00
|
|
|
want: engine.TooLargeRequest,
|
2023-02-06 12:21:40 +03:00
|
|
|
},
|
|
|
|
}
|
2023-02-17 21:30:38 +03:00
|
|
|
for i, tc := range tests {
|
2024-09-04 15:33:51 +03:00
|
|
|
result, err := api.GetPayloadBodiesByRangeV2(tc.start, tc.count)
|
2023-02-06 12:21:40 +03:00
|
|
|
if err == nil {
|
2023-02-17 21:30:38 +03:00
|
|
|
t.Fatalf("test %d: expected error, got %v", i, result)
|
|
|
|
}
|
|
|
|
if have, want := err.Error(), tc.want.Error(); have != want {
|
|
|
|
t.Fatalf("test %d: have %s, want %s", i, have, want)
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-09 13:24:58 +03:00
|
|
|
func checkEqualBody(a *types.Body, b *engine.ExecutionPayloadBody) error {
|
2023-02-06 12:21:40 +03:00
|
|
|
if a == nil && b == nil {
|
2024-10-09 13:24:58 +03:00
|
|
|
return nil
|
2023-02-06 12:21:40 +03:00
|
|
|
} else if a == nil || b == nil {
|
2024-10-09 13:24:58 +03:00
|
|
|
return errors.New("nil vs. non-nil")
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
2023-03-07 18:30:04 +03:00
|
|
|
if len(a.Transactions) != len(b.TransactionData) {
|
2024-10-09 13:24:58 +03:00
|
|
|
return errors.New("transactions length mismatch")
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
2023-03-07 18:30:04 +03:00
|
|
|
for i, tx := range a.Transactions {
|
|
|
|
data, _ := tx.MarshalBinary()
|
|
|
|
if !bytes.Equal(data, b.TransactionData[i]) {
|
2024-10-09 13:24:58 +03:00
|
|
|
return fmt.Errorf("transaction %d mismatch", i)
|
2023-03-07 18:30:04 +03:00
|
|
|
}
|
|
|
|
}
|
2024-09-04 15:33:51 +03:00
|
|
|
if !reflect.DeepEqual(a.Withdrawals, b.Withdrawals) {
|
2024-10-09 13:24:58 +03:00
|
|
|
return fmt.Errorf("withdrawals mismatch")
|
2024-09-04 15:33:51 +03:00
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
return nil
|
2023-02-06 12:21:40 +03:00
|
|
|
}
|
2023-07-18 10:44:16 +03:00
|
|
|
|
|
|
|
func TestBlockToPayloadWithBlobs(t *testing.T) {
|
|
|
|
header := types.Header{}
|
|
|
|
var txs []*types.Transaction
|
|
|
|
|
|
|
|
inner := types.BlobTx{
|
|
|
|
BlobHashes: make([]common.Hash, 1),
|
|
|
|
}
|
|
|
|
|
|
|
|
txs = append(txs, types.NewTx(&inner))
|
2023-08-24 00:16:14 +03:00
|
|
|
sidecars := []*types.BlobTxSidecar{
|
|
|
|
{
|
|
|
|
Blobs: make([]kzg4844.Blob, 1),
|
|
|
|
Commitments: make([]kzg4844.Commitment, 1),
|
|
|
|
Proofs: make([]kzg4844.Proof, 1),
|
|
|
|
},
|
|
|
|
}
|
2023-07-18 10:44:16 +03:00
|
|
|
|
2024-04-30 15:55:08 +03:00
|
|
|
block := types.NewBlock(&header, &types.Body{Transactions: txs}, nil, trie.NewStackTrie(nil))
|
2024-10-14 22:43:35 +03:00
|
|
|
envelope := engine.BlockToExecutableData(block, nil, sidecars, nil)
|
2023-07-18 10:44:16 +03:00
|
|
|
var want int
|
|
|
|
for _, tx := range txs {
|
|
|
|
want += len(tx.BlobHashes())
|
|
|
|
}
|
|
|
|
if got := len(envelope.BlobsBundle.Commitments); got != want {
|
|
|
|
t.Fatalf("invalid number of commitments: got %v, want %v", got, want)
|
|
|
|
}
|
|
|
|
if got := len(envelope.BlobsBundle.Proofs); got != want {
|
|
|
|
t.Fatalf("invalid number of proofs: got %v, want %v", got, want)
|
|
|
|
}
|
|
|
|
if got := len(envelope.BlobsBundle.Blobs); got != want {
|
|
|
|
t.Fatalf("invalid number of blobs: got %v, want %v", got, want)
|
|
|
|
}
|
2024-10-09 13:24:58 +03:00
|
|
|
_, err := engine.ExecutableDataToBlock(*envelope.ExecutionPayload, make([]common.Hash, 1), nil, nil)
|
2023-07-18 10:44:16 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2023-08-26 05:52:12 +03:00
|
|
|
|
|
|
|
// This checks that beaconRoot is applied to the state from the engine API.
|
|
|
|
func TestParentBeaconBlockRoot(t *testing.T) {
|
2024-10-10 08:54:07 +03:00
|
|
|
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), log.LevelTrace, true)))
|
2023-08-26 05:52:12 +03:00
|
|
|
|
|
|
|
genesis, blocks := generateMergeChain(10, true)
|
|
|
|
|
|
|
|
// Set cancun time to last block + 5 seconds
|
|
|
|
time := blocks[len(blocks)-1].Time() + 5
|
|
|
|
genesis.Config.ShanghaiTime = &time
|
|
|
|
genesis.Config.CancunTime = &time
|
|
|
|
|
|
|
|
n, ethservice := startEthService(t, genesis, blocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
api := NewConsensusAPI(ethservice)
|
|
|
|
|
|
|
|
// 11: Build Shanghai block with no withdrawals.
|
|
|
|
parent := ethservice.BlockChain().CurrentHeader()
|
|
|
|
blockParams := engine.PayloadAttributes{
|
|
|
|
Timestamp: parent.Time + 5,
|
|
|
|
Withdrawals: make([]*types.Withdrawal, 0),
|
|
|
|
BeaconRoot: &common.Hash{42},
|
|
|
|
}
|
|
|
|
fcState := engine.ForkchoiceStateV1{
|
|
|
|
HeadBlockHash: parent.Hash(),
|
|
|
|
}
|
2024-01-23 18:02:08 +03:00
|
|
|
resp, err := api.ForkchoiceUpdatedV3(fcState, &blockParams)
|
2023-08-26 05:52:12 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err.(*engine.EngineAPIError).ErrorData())
|
|
|
|
}
|
|
|
|
if resp.PayloadStatus.Status != engine.VALID {
|
|
|
|
t.Fatalf("unexpected status (got: %s, want: %s)", resp.PayloadStatus.Status, engine.VALID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: verify state root is the same as parent
|
|
|
|
payloadID := (&miner.BuildPayloadArgs{
|
|
|
|
Parent: fcState.HeadBlockHash,
|
|
|
|
Timestamp: blockParams.Timestamp,
|
|
|
|
FeeRecipient: blockParams.SuggestedFeeRecipient,
|
|
|
|
Random: blockParams.Random,
|
|
|
|
Withdrawals: blockParams.Withdrawals,
|
|
|
|
BeaconRoot: blockParams.BeaconRoot,
|
2024-01-24 10:39:12 +03:00
|
|
|
Version: engine.PayloadV3,
|
2023-08-26 05:52:12 +03:00
|
|
|
}).Id()
|
|
|
|
execData, err := api.GetPayloadV3(payloadID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting payload, err=%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: verify locally built block
|
|
|
|
if status, err := api.NewPayloadV3(*execData.ExecutionPayload, []common.Hash{}, &common.Hash{42}); err != nil {
|
|
|
|
t.Fatalf("error validating payload: %v", err)
|
|
|
|
} else if status.Status != engine.VALID {
|
|
|
|
t.Fatalf("invalid payload")
|
|
|
|
}
|
|
|
|
|
|
|
|
fcState.HeadBlockHash = execData.ExecutionPayload.BlockHash
|
|
|
|
resp, err = api.ForkchoiceUpdatedV3(fcState, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err.(*engine.EngineAPIError).ErrorData())
|
|
|
|
}
|
|
|
|
if resp.PayloadStatus.Status != engine.VALID {
|
|
|
|
t.Fatalf("unexpected status (got: %s, want: %s)", resp.PayloadStatus.Status, engine.VALID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 11: verify beacon root was processed.
|
|
|
|
db, _, err := ethservice.APIBackend.StateAndHeaderByNumber(context.Background(), rpc.BlockNumber(execData.ExecutionPayload.Number))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to load db: %v", err)
|
|
|
|
}
|
|
|
|
var (
|
|
|
|
timeIdx = common.BigToHash(big.NewInt(int64(execData.ExecutionPayload.Timestamp % 98304)))
|
|
|
|
rootIdx = common.BigToHash(big.NewInt(int64((execData.ExecutionPayload.Timestamp % 98304) + 98304)))
|
|
|
|
)
|
|
|
|
|
2024-03-15 11:14:31 +03:00
|
|
|
if num := db.GetState(params.BeaconRootsAddress, timeIdx); num != timeIdx {
|
2023-08-26 05:52:12 +03:00
|
|
|
t.Fatalf("incorrect number stored: want %s, got %s", timeIdx, num)
|
|
|
|
}
|
2024-03-15 11:14:31 +03:00
|
|
|
if root := db.GetState(params.BeaconRootsAddress, rootIdx); root != *blockParams.BeaconRoot {
|
2023-08-26 05:52:12 +03:00
|
|
|
t.Fatalf("incorrect root stored: want %s, got %s", *blockParams.BeaconRoot, root)
|
|
|
|
}
|
|
|
|
}
|
2024-02-15 14:01:30 +03:00
|
|
|
|
beacon, core, eth, miner: integrate witnesses into production Geth (#30069)
This PR integrates witness-enabled block production, witness-creating
payload execution and stateless cross-validation into the `engine` API.
The purpose of the PR is to enable the following use-cases (for API
details, please see next section):
- Cross validating locally created blocks:
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Cross validating locally processed blocks:
- Call `newPayloadWithWitness` instead of `newPayload` to trigger
witness creation too.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Block production for stateless clients (local or MEV builders):
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Propagate witnesses across the consensus libp2p network for stateless
Ethereum.
- Stateless validator validation:
- Call `executeStatelessPayload` with the propagated witness to
statelessly validate the block.
*Note, the various `WithWitness` methods could also *just be* an
additional boolean flag on the base methods, but this PR wanted to keep
the methods separate until a final consensus is reached on how to
integrate in production.*
---
The following `engine` API types are introduced:
```go
// StatelessPayloadStatusV1 is the result of a stateless payload execution.
type StatelessPayloadStatusV1 struct {
Status string `json:"status"`
StateRoot common.Hash `json:"stateRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
ValidationError *string `json:"validationError"`
}
```
- Add `forkchoiceUpdatedWithWitnessV1,2,3` with same params and returns
as `forkchoiceUpdatedV1,2,3`, but triggering a stateless witness
building if block production is requested.
- Extend `getPayloadV2,3` to return `executionPayloadEnvelope` with an
additional `witness` field of type `bytes` iff created via
`forkchoiceUpdatedWithWitnessV2,3`.
- Add `newPayloadWithWitnessV1,2,3,4` with same params and returns as
`newPayloadV1,2,3,4`, but triggering a stateless witness creation during
payload execution to allow cross validating it.
- Extend `payloadStatusV1` with a `witness` field of type `bytes` if
returned by `newPayloadWithWitnessV1,2,3,4`.
- Add `executeStatelessPayloadV1,2,3,4` with same base params as
`newPayloadV1,2,3,4` and one more additional param (`witness`) of type
`bytes`. The method returns `statelessPayloadStatusV1`, which mirrors
`payloadStatusV1` but replaces `latestValidHash` with `stateRoot` and
`receiptRoot`.
2024-09-20 16:43:42 +03:00
|
|
|
func TestWitnessCreationAndConsumption(t *testing.T) {
|
2024-10-10 08:54:07 +03:00
|
|
|
//log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), log.LevelTrace, true)))
|
beacon, core, eth, miner: integrate witnesses into production Geth (#30069)
This PR integrates witness-enabled block production, witness-creating
payload execution and stateless cross-validation into the `engine` API.
The purpose of the PR is to enable the following use-cases (for API
details, please see next section):
- Cross validating locally created blocks:
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Cross validating locally processed blocks:
- Call `newPayloadWithWitness` instead of `newPayload` to trigger
witness creation too.
- Call `executeStatelessPayload` against another client to
cross-validate the block.
- Block production for stateless clients (local or MEV builders):
- Call `forkchoiceUpdatedWithWitness` instead of `forkchoiceUpdated` to
trigger witness creation too.
- Call `getPayload` as before to retrieve the new block and also the
above created witness.
- Propagate witnesses across the consensus libp2p network for stateless
Ethereum.
- Stateless validator validation:
- Call `executeStatelessPayload` with the propagated witness to
statelessly validate the block.
*Note, the various `WithWitness` methods could also *just be* an
additional boolean flag on the base methods, but this PR wanted to keep
the methods separate until a final consensus is reached on how to
integrate in production.*
---
The following `engine` API types are introduced:
```go
// StatelessPayloadStatusV1 is the result of a stateless payload execution.
type StatelessPayloadStatusV1 struct {
Status string `json:"status"`
StateRoot common.Hash `json:"stateRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
ValidationError *string `json:"validationError"`
}
```
- Add `forkchoiceUpdatedWithWitnessV1,2,3` with same params and returns
as `forkchoiceUpdatedV1,2,3`, but triggering a stateless witness
building if block production is requested.
- Extend `getPayloadV2,3` to return `executionPayloadEnvelope` with an
additional `witness` field of type `bytes` iff created via
`forkchoiceUpdatedWithWitnessV2,3`.
- Add `newPayloadWithWitnessV1,2,3,4` with same params and returns as
`newPayloadV1,2,3,4`, but triggering a stateless witness creation during
payload execution to allow cross validating it.
- Extend `payloadStatusV1` with a `witness` field of type `bytes` if
returned by `newPayloadWithWitnessV1,2,3,4`.
- Add `executeStatelessPayloadV1,2,3,4` with same base params as
`newPayloadV1,2,3,4` and one more additional param (`witness`) of type
`bytes`. The method returns `statelessPayloadStatusV1`, which mirrors
`payloadStatusV1` but replaces `latestValidHash` with `stateRoot` and
`receiptRoot`.
2024-09-20 16:43:42 +03:00
|
|
|
|
|
|
|
genesis, blocks := generateMergeChain(10, true)
|
|
|
|
|
|
|
|
// Set cancun time to semi-last block + 5 seconds
|
|
|
|
timestamp := blocks[len(blocks)-2].Time() + 5
|
|
|
|
genesis.Config.ShanghaiTime = ×tamp
|
|
|
|
genesis.Config.CancunTime = ×tamp
|
|
|
|
|
|
|
|
n, ethservice := startEthService(t, genesis, blocks[:9])
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
api := NewConsensusAPI(ethservice)
|
|
|
|
|
|
|
|
// Put the 10th block's tx in the pool and produce a new block
|
|
|
|
txs := blocks[9].Transactions()
|
|
|
|
|
|
|
|
ethservice.TxPool().Add(txs, true, true)
|
|
|
|
blockParams := engine.PayloadAttributes{
|
|
|
|
Timestamp: blocks[8].Time() + 5,
|
|
|
|
Withdrawals: make([]*types.Withdrawal, 0),
|
|
|
|
BeaconRoot: &common.Hash{42},
|
|
|
|
}
|
|
|
|
fcState := engine.ForkchoiceStateV1{
|
|
|
|
HeadBlockHash: blocks[8].Hash(),
|
|
|
|
SafeBlockHash: common.Hash{},
|
|
|
|
FinalizedBlockHash: common.Hash{},
|
|
|
|
}
|
|
|
|
_, err := api.ForkchoiceUpdatedWithWitnessV3(fcState, &blockParams)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error preparing payload, err=%v", err)
|
|
|
|
}
|
|
|
|
// Give the payload some time to be built
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
payloadID := (&miner.BuildPayloadArgs{
|
|
|
|
Parent: fcState.HeadBlockHash,
|
|
|
|
Timestamp: blockParams.Timestamp,
|
|
|
|
FeeRecipient: blockParams.SuggestedFeeRecipient,
|
|
|
|
Random: blockParams.Random,
|
|
|
|
Withdrawals: blockParams.Withdrawals,
|
|
|
|
BeaconRoot: blockParams.BeaconRoot,
|
|
|
|
Version: engine.PayloadV3,
|
|
|
|
}).Id()
|
|
|
|
envelope, err := api.GetPayloadV3(payloadID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting payload, err=%v", err)
|
|
|
|
}
|
|
|
|
if len(envelope.ExecutionPayload.Transactions) != blocks[9].Transactions().Len() {
|
|
|
|
t.Fatalf("invalid number of transactions %d != %d", len(envelope.ExecutionPayload.Transactions), blocks[9].Transactions().Len())
|
|
|
|
}
|
|
|
|
if envelope.Witness == nil {
|
|
|
|
t.Fatalf("witness missing from payload")
|
|
|
|
}
|
|
|
|
// Test stateless execution of the created witness
|
|
|
|
wantStateRoot := envelope.ExecutionPayload.StateRoot
|
|
|
|
wantReceiptRoot := envelope.ExecutionPayload.ReceiptsRoot
|
|
|
|
|
|
|
|
envelope.ExecutionPayload.StateRoot = common.Hash{}
|
|
|
|
envelope.ExecutionPayload.ReceiptsRoot = common.Hash{}
|
|
|
|
|
|
|
|
res, err := api.ExecuteStatelessPayloadV3(*envelope.ExecutionPayload, []common.Hash{}, &common.Hash{42}, *envelope.Witness)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error executing stateless payload witness: %v", err)
|
|
|
|
}
|
|
|
|
if res.StateRoot != wantStateRoot {
|
|
|
|
t.Fatalf("stateless state root mismatch: have %v, want %v", res.StateRoot, wantStateRoot)
|
|
|
|
}
|
|
|
|
if res.ReceiptsRoot != wantReceiptRoot {
|
|
|
|
t.Fatalf("stateless receipt root mismatch: have %v, want %v", res.ReceiptsRoot, wantReceiptRoot)
|
|
|
|
}
|
|
|
|
// Test block insertion with witness creation
|
|
|
|
envelope.ExecutionPayload.StateRoot = wantStateRoot
|
|
|
|
envelope.ExecutionPayload.ReceiptsRoot = wantReceiptRoot
|
|
|
|
|
|
|
|
res2, err := api.NewPayloadWithWitnessV3(*envelope.ExecutionPayload, []common.Hash{}, &common.Hash{42})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error executing stateless payload witness: %v", err)
|
|
|
|
}
|
|
|
|
if res2.Witness == nil {
|
|
|
|
t.Fatalf("witness missing from payload")
|
|
|
|
}
|
|
|
|
// Test stateless execution of the created witness
|
|
|
|
wantStateRoot = envelope.ExecutionPayload.StateRoot
|
|
|
|
wantReceiptRoot = envelope.ExecutionPayload.ReceiptsRoot
|
|
|
|
|
|
|
|
envelope.ExecutionPayload.StateRoot = common.Hash{}
|
|
|
|
envelope.ExecutionPayload.ReceiptsRoot = common.Hash{}
|
|
|
|
|
|
|
|
res, err = api.ExecuteStatelessPayloadV3(*envelope.ExecutionPayload, []common.Hash{}, &common.Hash{42}, *res2.Witness)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error executing stateless payload witness: %v", err)
|
|
|
|
}
|
|
|
|
if res.StateRoot != wantStateRoot {
|
|
|
|
t.Fatalf("stateless state root mismatch: have %v, want %v", res.StateRoot, wantStateRoot)
|
|
|
|
}
|
|
|
|
if res.ReceiptsRoot != wantReceiptRoot {
|
|
|
|
t.Fatalf("stateless receipt root mismatch: have %v, want %v", res.ReceiptsRoot, wantReceiptRoot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-15 14:01:30 +03:00
|
|
|
// TestGetClientVersion verifies the expected version info is returned.
|
|
|
|
func TestGetClientVersion(t *testing.T) {
|
|
|
|
genesis, preMergeBlocks := generateMergeChain(10, false)
|
|
|
|
n, ethservice := startEthService(t, genesis, preMergeBlocks)
|
|
|
|
defer n.Close()
|
|
|
|
|
|
|
|
api := NewConsensusAPI(ethservice)
|
|
|
|
info := engine.ClientVersionV1{
|
|
|
|
Code: "TT",
|
|
|
|
Name: "test",
|
|
|
|
Version: "1.1.1",
|
|
|
|
Commit: "0x12345678",
|
|
|
|
}
|
|
|
|
infos := api.GetClientVersionV1(info)
|
|
|
|
if len(infos) != 1 {
|
|
|
|
t.Fatalf("expected only one returned client version, got %d", len(infos))
|
|
|
|
}
|
|
|
|
info = infos[0]
|
2024-10-20 19:28:39 +03:00
|
|
|
if info.Code != engine.ClientCode || info.Name != engine.ClientName || info.Version != version.WithMeta {
|
2024-02-15 14:01:30 +03:00
|
|
|
t.Fatalf("client info does match expected, got %s", info.String())
|
|
|
|
}
|
|
|
|
}
|