fix some tests. relax check that ttd is not nil in IsTTDReached: consensus engine creation ensures this.

This commit is contained in:
Jared Wasinger 2024-10-17 21:20:40 +07:00
parent 6be6b8a520
commit de84a27bcf
4 changed files with 14 additions and 13 deletions

View file

@ -29,7 +29,7 @@ var customGenesisTests = []struct {
query string
result string
}{
// Genesis file with an empty chain configuration (ensure missing fields work)
// Genesis file with a mostly-empty chain configuration (ensure missing fields work)
{
genesis: `{
"alloc" : {},
@ -41,7 +41,9 @@ var customGenesisTests = []struct {
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config": {}
"config": {
"terminalTotalDifficulty": "0xffffffffffffffff"
}
}`,
query: "eth.getBlock(0).nonce",
result: "0x0000000000001338",
@ -61,7 +63,8 @@ var customGenesisTests = []struct {
"config" : {
"homesteadBlock" : 42,
"daoForkBlock" : 141,
"daoForkSupport" : true
"daoForkSupport" : true,
"terminalTotalDifficulty": "0xffffffffffffffff"
}
}`,
query: "eth.getBlock(0).nonce",
@ -111,7 +114,9 @@ func TestCustomBackend(t *testing.T) {
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"config": {}
"config": {
"terminalTotalDifficulty": "0xffffffffffffffff"
}
}`
type backendTest struct {
initArgs []string

View file

@ -8,6 +8,7 @@
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"terminalTotalDifficulty": 0,
"clique": {
"period": 5,
"epoch": 30000
@ -21,4 +22,4 @@
"balance": "300000"
}
}
}
}

View file

@ -19,8 +19,6 @@ package beacon
import (
"errors"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
@ -32,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
"github.com/holiman/uint256"
"math/big"
)
// Proof-of-stake protocol constants.
@ -115,9 +114,6 @@ func errOut(n int, err error) chan error {
func (beacon *Beacon) splitHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) ([]*types.Header, []*types.Header, error) {
// TTD is not defined yet, all headers should be in legacy format.
ttd := chain.Config().TerminalTotalDifficulty
if ttd == nil {
return headers, nil, nil
}
ptd := chain.GetTd(headers[0].ParentHash, headers[0].Number.Uint64()-1)
if ptd == nil {
return nil, nil, consensus.ErrUnknownAncestor
@ -494,9 +490,6 @@ func (beacon *Beacon) SetThreads(threads int) {
// It depends on the parentHash already being stored in the database.
// If the parentHash is not stored in the database a UnknownAncestor error is returned.
func IsTTDReached(chain consensus.ChainHeaderReader, parentHash common.Hash, parentNumber uint64) (bool, error) {
if chain.Config().TerminalTotalDifficulty == nil {
return false, nil
}
td := chain.GetTd(parentHash, parentNumber)
if td == nil {
return false, consensus.ErrUnknownAncestor

View file

@ -115,6 +115,8 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
td := 0
genDb, blocks, _ := GenerateChainWithGenesis(gspec, engine, 8, nil)
gspec.Config.TerminalTotalDifficulty = big.NewInt(1000)
for i, block := range blocks {
header := block.Header()
if i > 0 {