mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
fix stuff
This commit is contained in:
parent
c2d883321d
commit
3d5672091f
5 changed files with 50 additions and 221 deletions
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/types/bal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = (*executableDataMarshaling)(nil)
|
var _ = (*executableDataMarshaling)(nil)
|
||||||
|
|
@ -35,7 +34,6 @@ func (e ExecutableData) MarshalJSON() ([]byte, error) {
|
||||||
Withdrawals []*types.Withdrawal `json:"withdrawals"`
|
Withdrawals []*types.Withdrawal `json:"withdrawals"`
|
||||||
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"`
|
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"`
|
||||||
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"`
|
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"`
|
||||||
BlockAccessList *bal.BlockAccessList `json:"blockAccessList"`
|
|
||||||
ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"`
|
ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"`
|
||||||
}
|
}
|
||||||
var enc ExecutableData
|
var enc ExecutableData
|
||||||
|
|
@ -61,7 +59,6 @@ func (e ExecutableData) MarshalJSON() ([]byte, error) {
|
||||||
enc.Withdrawals = e.Withdrawals
|
enc.Withdrawals = e.Withdrawals
|
||||||
enc.BlobGasUsed = (*hexutil.Uint64)(e.BlobGasUsed)
|
enc.BlobGasUsed = (*hexutil.Uint64)(e.BlobGasUsed)
|
||||||
enc.ExcessBlobGas = (*hexutil.Uint64)(e.ExcessBlobGas)
|
enc.ExcessBlobGas = (*hexutil.Uint64)(e.ExcessBlobGas)
|
||||||
enc.BlockAccessList = e.BlockAccessList
|
|
||||||
enc.ExecutionWitness = e.ExecutionWitness
|
enc.ExecutionWitness = e.ExecutionWitness
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +83,6 @@ func (e *ExecutableData) UnmarshalJSON(input []byte) error {
|
||||||
Withdrawals []*types.Withdrawal `json:"withdrawals"`
|
Withdrawals []*types.Withdrawal `json:"withdrawals"`
|
||||||
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"`
|
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"`
|
||||||
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"`
|
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"`
|
||||||
BlockAccessList *bal.BlockAccessList `json:"blockAccessList"`
|
|
||||||
ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"`
|
ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"`
|
||||||
}
|
}
|
||||||
var dec ExecutableData
|
var dec ExecutableData
|
||||||
|
|
@ -161,9 +157,6 @@ func (e *ExecutableData) UnmarshalJSON(input []byte) error {
|
||||||
if dec.ExcessBlobGas != nil {
|
if dec.ExcessBlobGas != nil {
|
||||||
e.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
|
e.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
|
||||||
}
|
}
|
||||||
if dec.BlockAccessList != nil {
|
|
||||||
e.BlockAccessList = dec.BlockAccessList
|
|
||||||
}
|
|
||||||
if dec.ExecutionWitness != nil {
|
if dec.ExecutionWitness != nil {
|
||||||
e.ExecutionWitness = dec.ExecutionWitness
|
e.ExecutionWitness = dec.ExecutionWitness
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,13 @@ type Genesis struct {
|
||||||
|
|
||||||
// These fields are used for consensus tests. Please don't use them
|
// These fields are used for consensus tests. Please don't use them
|
||||||
// in actual genesis blocks.
|
// in actual genesis blocks.
|
||||||
Number uint64 `json:"number"`
|
Number uint64 `json:"number"`
|
||||||
GasUsed uint64 `json:"gasUsed"`
|
GasUsed uint64 `json:"gasUsed"`
|
||||||
ParentHash common.Hash `json:"parentHash"`
|
ParentHash common.Hash `json:"parentHash"`
|
||||||
BaseFee *big.Int `json:"baseFeePerGas"` // EIP-1559
|
BaseFee *big.Int `json:"baseFeePerGas"` // EIP-1559
|
||||||
ExcessBlobGas *uint64 `json:"excessBlobGas"` // EIP-4844
|
ExcessBlobGas *uint64 `json:"excessBlobGas"` // EIP-4844
|
||||||
BlobGasUsed *uint64 `json:"blobGasUsed"` // EIP-4844
|
BlobGasUsed *uint64 `json:"blobGasUsed"` // EIP-4844
|
||||||
|
BlockAccessListHash *common.Hash `json:"blockAccessListHash,omitempty"` // EIP-7928
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy copies the genesis.
|
// copy copies the genesis.
|
||||||
|
|
@ -122,6 +123,7 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) {
|
||||||
genesis.BaseFee = genesisHeader.BaseFee
|
genesis.BaseFee = genesisHeader.BaseFee
|
||||||
genesis.ExcessBlobGas = genesisHeader.ExcessBlobGas
|
genesis.ExcessBlobGas = genesisHeader.ExcessBlobGas
|
||||||
genesis.BlobGasUsed = genesisHeader.BlobGasUsed
|
genesis.BlobGasUsed = genesisHeader.BlobGasUsed
|
||||||
|
genesis.BlockAccessListHash = genesisHeader.BlockAccessListHash
|
||||||
|
|
||||||
return &genesis, nil
|
return &genesis, nil
|
||||||
}
|
}
|
||||||
|
|
@ -469,18 +471,19 @@ func (g *Genesis) ToBlock() *types.Block {
|
||||||
// toBlockWithRoot constructs the genesis block with the given genesis state root.
|
// toBlockWithRoot constructs the genesis block with the given genesis state root.
|
||||||
func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block {
|
func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block {
|
||||||
head := &types.Header{
|
head := &types.Header{
|
||||||
Number: new(big.Int).SetUint64(g.Number),
|
Number: new(big.Int).SetUint64(g.Number),
|
||||||
Nonce: types.EncodeNonce(g.Nonce),
|
Nonce: types.EncodeNonce(g.Nonce),
|
||||||
Time: g.Timestamp,
|
Time: g.Timestamp,
|
||||||
ParentHash: g.ParentHash,
|
ParentHash: g.ParentHash,
|
||||||
Extra: g.ExtraData,
|
Extra: g.ExtraData,
|
||||||
GasLimit: g.GasLimit,
|
GasLimit: g.GasLimit,
|
||||||
GasUsed: g.GasUsed,
|
GasUsed: g.GasUsed,
|
||||||
BaseFee: g.BaseFee,
|
BaseFee: g.BaseFee,
|
||||||
Difficulty: g.Difficulty,
|
Difficulty: g.Difficulty,
|
||||||
MixDigest: g.Mixhash,
|
MixDigest: g.Mixhash,
|
||||||
Coinbase: g.Coinbase,
|
Coinbase: g.Coinbase,
|
||||||
Root: root,
|
BlockAccessListHash: g.BlockAccessListHash,
|
||||||
|
Root: root,
|
||||||
}
|
}
|
||||||
if g.GasLimit == 0 {
|
if g.GasLimit == 0 {
|
||||||
head.GasLimit = params.GenesisGasLimit
|
head.GasLimit = params.GenesisGasLimit
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
|
||||||
work.header.RequestsHash = &reqHash
|
work.header.RequestsHash = &reqHash
|
||||||
}
|
}
|
||||||
|
|
||||||
block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts)
|
block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &newPayloadResult{err: err}
|
return &newPayloadResult{err: err}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -68,119 +67,13 @@ func TestBlockchain(t *testing.T) {
|
||||||
bt.skipLoad(`.*\.meta/.*`)
|
bt.skipLoad(`.*\.meta/.*`)
|
||||||
|
|
||||||
bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
|
bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
|
||||||
execBlockTest(t, bt, test, false)
|
execBlockTest(t, bt, test)
|
||||||
})
|
})
|
||||||
// There is also a LegacyTests folder, containing blockchain tests generated
|
// There is also a LegacyTests folder, containing blockchain tests generated
|
||||||
// prior to Istanbul. However, they are all derived from GeneralStateTests,
|
// prior to Istanbul. However, they are all derived from GeneralStateTests,
|
||||||
// which run natively, so there's no reason to run them here.
|
// which run natively, so there's no reason to run them here.
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockchainBAL(t *testing.T) {
|
|
||||||
bt := new(testMatcher)
|
|
||||||
|
|
||||||
// We are running most of GeneralStatetests to tests witness support, even
|
|
||||||
// though they are ran as state tests too. Still, the performance tests are
|
|
||||||
// less about state andmore about EVM number crunching, so skip those.
|
|
||||||
bt.skipLoad(`^GeneralStateTests/VMTests/vmPerformance`)
|
|
||||||
|
|
||||||
// Skip random failures due to selfish mining test
|
|
||||||
bt.skipLoad(`.*bcForgedTest/bcForkUncle\.json`)
|
|
||||||
|
|
||||||
// Slow tests
|
|
||||||
bt.slow(`.*bcExploitTest/DelegateCallSpam.json`)
|
|
||||||
bt.slow(`.*bcExploitTest/ShanghaiLove.json`)
|
|
||||||
bt.slow(`.*bcExploitTest/SuicideIssue.json`)
|
|
||||||
bt.slow(`.*/bcForkStressTest/`)
|
|
||||||
bt.slow(`.*/bcGasPricerTest/RPC_API_Test.json`)
|
|
||||||
bt.slow(`.*/bcWalletTest/`)
|
|
||||||
|
|
||||||
// Very slow test
|
|
||||||
bt.skipLoad(`.*/stTimeConsuming/.*`)
|
|
||||||
// test takes a lot for time and goes easily OOM because of sha3 calculation on a huge range,
|
|
||||||
// using 4.6 TGas
|
|
||||||
bt.skipLoad(`.*randomStatetest94.json.*`)
|
|
||||||
|
|
||||||
// After the merge we would accept side chains as canonical even if they have lower td
|
|
||||||
bt.skipLoad(`.*bcMultiChainTest/ChainAtoChainB_difficultyB.json`)
|
|
||||||
bt.skipLoad(`.*bcMultiChainTest/CallContractFromNotBestBlock.json`)
|
|
||||||
bt.skipLoad(`.*bcTotalDifficultyTest/uncleBlockAtBlock3afterBlock4.json`)
|
|
||||||
bt.skipLoad(`.*bcTotalDifficultyTest/lotsOfBranchesOverrideAtTheMiddle.json`)
|
|
||||||
bt.skipLoad(`.*bcTotalDifficultyTest/sideChainWithMoreTransactions.json`)
|
|
||||||
bt.skipLoad(`.*bcForkStressTest/ForkStressTest.json`)
|
|
||||||
bt.skipLoad(`.*bcMultiChainTest/lotsOfLeafs.json`)
|
|
||||||
bt.skipLoad(`.*bcFrontierToHomestead/blockChainFrontierWithLargerTDvsHomesteadBlockchain.json`)
|
|
||||||
bt.skipLoad(`.*bcFrontierToHomestead/blockChainFrontierWithLargerTDvsHomesteadBlockchain2.json`)
|
|
||||||
|
|
||||||
// With chain history removal, TDs become unavailable, this transition tests based on TTD are unrunnable
|
|
||||||
bt.skipLoad(`.*bcArrowGlacierToParis/powToPosBlockRejection.json`)
|
|
||||||
|
|
||||||
// This directory contains no test.
|
|
||||||
bt.skipLoad(`.*\.meta/.*`)
|
|
||||||
|
|
||||||
bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
|
|
||||||
config, ok := Forks[test.json.Network]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("unsupported fork: %s\n", test.json.Network)
|
|
||||||
}
|
|
||||||
gspec := test.genesis(config)
|
|
||||||
// skip any tests which are not past the cancun fork (selfdestruct removal)
|
|
||||||
if gspec.Config.CancunTime == nil || *gspec.Config.CancunTime != 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
execBlockTest(t, bt, test, true)
|
|
||||||
})
|
|
||||||
// There is also a LegacyTests folder, containing blockchain tests generated
|
|
||||||
// prior to Istanbul. However, they are all derived from GeneralStateTests,
|
|
||||||
// which run natively, so there's no reason to run them here.
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestExecutionSpecBlocktests runs the test fixtures from execution-spec-tests.
|
|
||||||
// TODO: rename this to reflect that it tests creating/verifying BALs on pre-amsterdam tests
|
|
||||||
func TestExecutionSpecBlocktestsBAL(t *testing.T) {
|
|
||||||
if !common.FileExist(executionSpecBlockchainTestDir) {
|
|
||||||
t.Skipf("directory %s does not exist", executionSpecBlockchainTestDir)
|
|
||||||
}
|
|
||||||
bt := new(testMatcher)
|
|
||||||
|
|
||||||
bt.skipLoad(".*prague/eip7251_consolidations/contract_deployment/system_contract_deployment.json")
|
|
||||||
bt.skipLoad(".*prague/eip7002_el_triggerable_withdrawals/contract_deployment/system_contract_deployment.json")
|
|
||||||
|
|
||||||
bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) {
|
|
||||||
config, ok := Forks[test.json.Network]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("unsupported fork: %s\n", test.json.Network)
|
|
||||||
}
|
|
||||||
gspec := test.genesis(config)
|
|
||||||
// skip any tests which are not past the cancun fork (selfdestruct removal)
|
|
||||||
if gspec.Config.CancunTime == nil || *gspec.Config.CancunTime != 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
execBlockTest(t, bt, test, true)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExecutionSpecBlocktestsAmsterdam(t *testing.T) {
|
|
||||||
var executionSpecAmsterdamBlockchainTestDir = filepath.Join(".", "fixtures-amsterdam-bal", "blockchain_tests")
|
|
||||||
if !common.FileExist(executionSpecAmsterdamBlockchainTestDir) {
|
|
||||||
t.Skipf("directory %s does not exist", executionSpecAmsterdamBlockchainTestDir)
|
|
||||||
}
|
|
||||||
bt := new(testMatcher)
|
|
||||||
|
|
||||||
bt.walk(t, executionSpecAmsterdamBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) {
|
|
||||||
config, ok := Forks[test.json.Network]
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("unsupported fork: %s\n", test.json.Network)
|
|
||||||
}
|
|
||||||
gspec := test.genesis(config)
|
|
||||||
// skip any tests which are not past the cancun fork (selfdestruct removal)
|
|
||||||
if gspec.Config.CancunTime == nil || *gspec.Config.CancunTime != 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// TODO: skip any tests that aren't amsterdam
|
|
||||||
execBlockTest(t, bt, test, false)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestExecutionSpecBlocktests runs the test fixtures from execution-spec-tests.
|
// TestExecutionSpecBlocktests runs the test fixtures from execution-spec-tests.
|
||||||
func TestExecutionSpecBlocktests(t *testing.T) {
|
func TestExecutionSpecBlocktests(t *testing.T) {
|
||||||
if !common.FileExist(executionSpecBlockchainTestDir) {
|
if !common.FileExist(executionSpecBlockchainTestDir) {
|
||||||
|
|
@ -193,11 +86,11 @@ func TestExecutionSpecBlocktests(t *testing.T) {
|
||||||
bt.skipLoad(".*prague/eip7002_el_triggerable_withdrawals/test_system_contract_deployment.json")
|
bt.skipLoad(".*prague/eip7002_el_triggerable_withdrawals/test_system_contract_deployment.json")
|
||||||
|
|
||||||
bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) {
|
bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) {
|
||||||
execBlockTest(t, bt, test, false)
|
execBlockTest(t, bt, test)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest, buildAndVerifyBAL bool) {
|
func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest) {
|
||||||
// Define all the different flag combinations we should run the tests with,
|
// Define all the different flag combinations we should run the tests with,
|
||||||
// picking only one for short tests.
|
// picking only one for short tests.
|
||||||
//
|
//
|
||||||
|
|
@ -211,11 +104,9 @@ func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest, buildAndVerif
|
||||||
snapshotConf = []bool{snapshotConf[rand.Int()%2]}
|
snapshotConf = []bool{snapshotConf[rand.Int()%2]}
|
||||||
dbschemeConf = []string{dbschemeConf[rand.Int()%2]}
|
dbschemeConf = []string{dbschemeConf[rand.Int()%2]}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, snapshot := range snapshotConf {
|
for _, snapshot := range snapshotConf {
|
||||||
for _, dbscheme := range dbschemeConf {
|
for _, dbscheme := range dbschemeConf {
|
||||||
//tracer := logger.NewJSONLogger(&logger.Config{}, os.Stdout)
|
if err := bt.checkFailure(t, test.Run(snapshot, dbscheme, true, nil, nil)); err != nil {
|
||||||
if err := bt.checkFailure(t, test.Run(snapshot, dbscheme, false, buildAndVerifyBAL, nil, nil)); err != nil {
|
|
||||||
t.Errorf("test with config {snapshotter:%v, scheme:%v} failed: %v", snapshot, dbscheme, err)
|
t.Errorf("test with config {snapshotter:%v, scheme:%v} failed: %v", snapshot, dbscheme, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/go-ethereum/core/types/bal"
|
|
||||||
stdmath "math"
|
stdmath "math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -72,7 +71,6 @@ type btBlock struct {
|
||||||
ExpectException string
|
ExpectException string
|
||||||
Rlp string
|
Rlp string
|
||||||
UncleHeaders []*btHeader
|
UncleHeaders []*btHeader
|
||||||
AccessList *bal.BlockAccessList `json:"blockAccessList,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run github.com/fjl/gencodec -type btHeader -field-override btHeaderMarshaling -out gen_btheader.go
|
//go:generate go run github.com/fjl/gencodec -type btHeader -field-override btHeaderMarshaling -out gen_btheader.go
|
||||||
|
|
@ -99,7 +97,6 @@ type btHeader struct {
|
||||||
BlobGasUsed *uint64
|
BlobGasUsed *uint64
|
||||||
ExcessBlobGas *uint64
|
ExcessBlobGas *uint64
|
||||||
ParentBeaconBlockRoot *common.Hash
|
ParentBeaconBlockRoot *common.Hash
|
||||||
BlockAccessListHash *common.Hash
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type btHeaderMarshaling struct {
|
type btHeaderMarshaling struct {
|
||||||
|
|
@ -114,7 +111,11 @@ type btHeaderMarshaling struct {
|
||||||
ExcessBlobGas *math.HexOrDecimal64
|
ExcessBlobGas *math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter bool, scheme string, witness, createAndVerifyBAL bool, tracer *tracing.Hooks) (*core.BlockChain, error) {
|
func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, tracer *tracing.Hooks, postCheck func(error, *core.BlockChain)) (result error) {
|
||||||
|
config, ok := Forks[t.json.Network]
|
||||||
|
if !ok {
|
||||||
|
return UnsupportedForkError{t.json.Network}
|
||||||
|
}
|
||||||
// import pre accounts & construct test genesis block & state root
|
// import pre accounts & construct test genesis block & state root
|
||||||
var (
|
var (
|
||||||
db = rawdb.NewMemoryDatabase()
|
db = rawdb.NewMemoryDatabase()
|
||||||
|
|
@ -127,6 +128,7 @@ func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter
|
||||||
} else {
|
} else {
|
||||||
tconf.HashDB = hashdb.Defaults
|
tconf.HashDB = hashdb.Defaults
|
||||||
}
|
}
|
||||||
|
// Commit genesis state
|
||||||
gspec := t.genesis(config)
|
gspec := t.genesis(config)
|
||||||
|
|
||||||
// if ttd is not specified, set an arbitrary huge value
|
// if ttd is not specified, set an arbitrary huge value
|
||||||
|
|
@ -136,15 +138,15 @@ func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter
|
||||||
triedb := triedb.NewDatabase(db, tconf)
|
triedb := triedb.NewDatabase(db, tconf)
|
||||||
gblock, err := gspec.Commit(db, triedb)
|
gblock, err := gspec.Commit(db, triedb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
triedb.Close() // close the db to prevent memory leak
|
triedb.Close() // close the db to prevent memory leak
|
||||||
|
|
||||||
if gblock.Hash() != t.json.Genesis.Hash {
|
if gblock.Hash() != t.json.Genesis.Hash {
|
||||||
return nil, fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6])
|
return fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6])
|
||||||
}
|
}
|
||||||
if gblock.Root() != t.json.Genesis.StateRoot {
|
if gblock.Root() != t.json.Genesis.StateRoot {
|
||||||
return nil, fmt.Errorf("genesis block state root does not match test: computed=%x, test=%x", gblock.Root().Bytes()[:6], t.json.Genesis.StateRoot[:6])
|
return fmt.Errorf("genesis block state root does not match test: computed=%x, test=%x", gblock.Root().Bytes()[:6], t.json.Genesis.StateRoot[:6])
|
||||||
}
|
}
|
||||||
// Wrap the original engine within the beacon-engine
|
// Wrap the original engine within the beacon-engine
|
||||||
engine := beacon.New(ethash.NewFaker())
|
engine := beacon.New(ethash.NewFaker())
|
||||||
|
|
@ -158,28 +160,12 @@ func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter
|
||||||
Tracer: tracer,
|
Tracer: tracer,
|
||||||
StatelessSelfValidation: witness,
|
StatelessSelfValidation: witness,
|
||||||
},
|
},
|
||||||
NoPrefetch: true,
|
|
||||||
EnableBALForTesting: createAndVerifyBAL,
|
|
||||||
}
|
}
|
||||||
if snapshotter {
|
if snapshotter {
|
||||||
options.SnapshotLimit = 1
|
options.SnapshotLimit = 1
|
||||||
options.SnapshotWait = true
|
options.SnapshotWait = true
|
||||||
}
|
}
|
||||||
chain, err := core.NewBlockChain(db, gspec, engine, options)
|
chain, err := core.NewBlockChain(db, gspec, engine, options)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return chain, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, createAndVerifyBAL bool, tracer *tracing.Hooks, postCheck func(error, *core.BlockChain)) (result error) {
|
|
||||||
config, ok := Forks[t.json.Network]
|
|
||||||
if !ok {
|
|
||||||
return UnsupportedForkError{t.json.Network}
|
|
||||||
}
|
|
||||||
// import pre accounts & construct test genesis block & state root
|
|
||||||
|
|
||||||
chain, err := t.createTestBlockChain(config, snapshotter, scheme, witness, createAndVerifyBAL, tracer)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -213,69 +199,25 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, createAnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = t.validateImportedHeaders(chain, validBlocks)
|
return t.validateImportedHeaders(chain, validBlocks)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if createAndVerifyBAL {
|
|
||||||
newChain, _ := t.createTestBlockChain(config, snapshotter, scheme, witness, createAndVerifyBAL, tracer)
|
|
||||||
defer newChain.Stop()
|
|
||||||
|
|
||||||
var blocksWithBAL types.Blocks
|
|
||||||
for i := uint64(1); i <= chain.CurrentBlock().Number.Uint64(); i++ {
|
|
||||||
block := chain.GetBlockByNumber(i)
|
|
||||||
if block.Body().AccessList == nil {
|
|
||||||
return fmt.Errorf("block %d missing BAL", block.NumberU64())
|
|
||||||
}
|
|
||||||
blocksWithBAL = append(blocksWithBAL, block)
|
|
||||||
}
|
|
||||||
|
|
||||||
amt, err := newChain.InsertChain(blocksWithBAL)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_ = amt
|
|
||||||
newDB, err := newChain.State()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err = t.validatePostState(newDB); err != nil {
|
|
||||||
return fmt.Errorf("post state validation failed: %v", err)
|
|
||||||
}
|
|
||||||
// Cross-check the snapshot-to-hash against the trie hash
|
|
||||||
if snapshotter {
|
|
||||||
if newChain.Snapshots() != nil {
|
|
||||||
if err := chain.Snapshots().Verify(chain.CurrentBlock().Root); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = t.validateImportedHeaders(newChain, validBlocks)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
|
func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
|
||||||
return &core.Genesis{
|
return &core.Genesis{
|
||||||
Config: config,
|
Config: config,
|
||||||
Nonce: t.json.Genesis.Nonce.Uint64(),
|
Nonce: t.json.Genesis.Nonce.Uint64(),
|
||||||
Timestamp: t.json.Genesis.Timestamp,
|
Timestamp: t.json.Genesis.Timestamp,
|
||||||
ParentHash: t.json.Genesis.ParentHash,
|
ParentHash: t.json.Genesis.ParentHash,
|
||||||
ExtraData: t.json.Genesis.ExtraData,
|
ExtraData: t.json.Genesis.ExtraData,
|
||||||
GasLimit: t.json.Genesis.GasLimit,
|
GasLimit: t.json.Genesis.GasLimit,
|
||||||
GasUsed: t.json.Genesis.GasUsed,
|
GasUsed: t.json.Genesis.GasUsed,
|
||||||
Difficulty: t.json.Genesis.Difficulty,
|
Difficulty: t.json.Genesis.Difficulty,
|
||||||
Mixhash: t.json.Genesis.MixHash,
|
Mixhash: t.json.Genesis.MixHash,
|
||||||
Coinbase: t.json.Genesis.Coinbase,
|
Coinbase: t.json.Genesis.Coinbase,
|
||||||
Alloc: t.json.Pre,
|
Alloc: t.json.Pre,
|
||||||
BaseFee: t.json.Genesis.BaseFeePerGas,
|
BaseFee: t.json.Genesis.BaseFeePerGas,
|
||||||
BlobGasUsed: t.json.Genesis.BlobGasUsed,
|
BlobGasUsed: t.json.Genesis.BlobGasUsed,
|
||||||
ExcessBlobGas: t.json.Genesis.ExcessBlobGas,
|
ExcessBlobGas: t.json.Genesis.ExcessBlobGas,
|
||||||
BlockAccessListHash: t.json.Genesis.BlockAccessListHash,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue