mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
f66c118cad
* cmd, core, eth: init tx lookup in background * core/rawdb: tiny log fixes to make it clearer what's happening * core, eth: fix rebase errors * core/rawdb: make reindexing less generic, but more optimal * rlp: implement rlp list iterator * core/rawdb: new implementation of tx indexing/unindex using generic tx iterator and hashing rlp-data * core/rawdb, cmd/utils: fix review concerns * cmd/utils: fix merge issue * core/rawdb: add some log formatting polishes Co-authored-by: rjl493456442 <garyrong0905@gmail.com> Co-authored-by: Péter Szilágyi <peterke@gmail.com> # Conflicts: # accounts/abi/bind/backends/simulated.go # cmd/geth/main.go # cmd/geth/usage.go # cmd/utils/flags.go # consensus/clique/snapshot_test.go # core/bench_test.go # core/block_validator_test.go # core/blockchain.go # core/blockchain_test.go # core/chain_makers_test.go # core/dao_test.go # core/rawdb/accessors_indexes.go # core/rawdb/schema.go # eth/config.go # eth/helper_test.go # eth/sync.go # light/odr_test.go # light/trie_test.go # light/txpool_test.go # miner/worker_test.go # tests/block_test_util.go
172 lines
6.3 KiB
Go
172 lines
6.3 KiB
Go
// Copyright 2017 The go-ethereum Authors
|
|
// 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 core
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/consensus/ethash"
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
|
"github.com/ledgerwatch/turbo-geth/core/state"
|
|
"github.com/ledgerwatch/turbo-geth/core/vm"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/params"
|
|
)
|
|
|
|
func TestDefaultGenesisBlock(t *testing.T) {
|
|
block, _, _, _ := DefaultGenesisBlock().ToBlock(nil, true)
|
|
if block.Hash() != params.MainnetGenesisHash {
|
|
t.Errorf("wrong mainnet genesis hash, got %v, want %v", block.Hash(), params.MainnetGenesisHash)
|
|
}
|
|
var err error
|
|
block, _, _, err = DefaultRopstenGenesisBlock().ToBlock(nil, true)
|
|
if err != nil {
|
|
t.Errorf("error: %w", err)
|
|
}
|
|
if block.Hash() != params.RopstenGenesisHash {
|
|
t.Errorf("wrong ropsten genesis hash, got %v, want %v", block.Hash(), params.RopstenGenesisHash)
|
|
}
|
|
}
|
|
|
|
func TestSetupGenesis(t *testing.T) {
|
|
var (
|
|
customghash = common.HexToHash("0x89c99d90b79719238d2645c7642f2c9295246e80775b38cfd162b696817fbd50")
|
|
customg = Genesis{
|
|
Config: ¶ms.ChainConfig{HomesteadBlock: big.NewInt(3)},
|
|
Alloc: GenesisAlloc{
|
|
{1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
|
|
},
|
|
}
|
|
oldcustomg = customg
|
|
)
|
|
oldcustomg.Config = ¶ms.ChainConfig{HomesteadBlock: big.NewInt(2)}
|
|
tests := []struct {
|
|
name string
|
|
fn func(ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error)
|
|
wantConfig *params.ChainConfig
|
|
wantHash common.Hash
|
|
wantErr error
|
|
}{
|
|
{
|
|
name: "genesis without ChainConfig",
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error) {
|
|
return SetupGenesisBlock(db, new(Genesis), true /* history */)
|
|
},
|
|
wantErr: errGenesisNoConfig,
|
|
wantConfig: params.AllEthashProtocolChanges,
|
|
},
|
|
{
|
|
name: "no block in DB, genesis == nil",
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error) {
|
|
return SetupGenesisBlock(db, nil, true /* history */)
|
|
},
|
|
wantHash: params.MainnetGenesisHash,
|
|
wantConfig: params.MainnetChainConfig,
|
|
},
|
|
{
|
|
name: "mainnet block in DB, genesis == nil",
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error) {
|
|
DefaultGenesisBlock().MustCommit(db)
|
|
return SetupGenesisBlock(db, nil, true /* history */)
|
|
},
|
|
wantHash: params.MainnetGenesisHash,
|
|
wantConfig: params.MainnetChainConfig,
|
|
},
|
|
{
|
|
name: "custom block in DB, genesis == nil",
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error) {
|
|
customg.MustCommit(db)
|
|
return SetupGenesisBlock(db, nil, true /* history */)
|
|
},
|
|
wantHash: customghash,
|
|
wantConfig: customg.Config,
|
|
},
|
|
{
|
|
name: "custom block in DB, genesis == ropsten",
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error) {
|
|
customg.MustCommit(db)
|
|
return SetupGenesisBlock(db, DefaultRopstenGenesisBlock(), true /* history */)
|
|
},
|
|
wantErr: &GenesisMismatchError{Stored: customghash, New: params.RopstenGenesisHash},
|
|
wantHash: params.RopstenGenesisHash,
|
|
wantConfig: params.RopstenChainConfig,
|
|
},
|
|
{
|
|
name: "compatible config in DB",
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error) {
|
|
oldcustomg.MustCommit(db)
|
|
return SetupGenesisBlock(db, &customg, true /* history */)
|
|
},
|
|
wantHash: customghash,
|
|
wantConfig: customg.Config,
|
|
},
|
|
{
|
|
name: "incompatible config in DB",
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *state.IntraBlockState, error) {
|
|
// Commit the 'old' genesis block with Homestead transition at #2.
|
|
// Advance to block #4, past the homestead transition block of customg.
|
|
genesis := oldcustomg.MustCommit(db)
|
|
|
|
bc, _ := NewBlockChain(db, nil, oldcustomg.Config, ethash.NewFullFaker(), vm.Config{}, nil, nil)
|
|
defer bc.Stop()
|
|
ctx := bc.WithContext(context.Background(), big.NewInt(genesis.Number().Int64()+1))
|
|
|
|
blocks, _ := GenerateChain(ctx, oldcustomg.Config, genesis, ethash.NewFaker(), db.MemCopy(), 4, nil)
|
|
_, _ = bc.InsertChain(context.Background(), blocks)
|
|
bc.CurrentBlock()
|
|
// This should return a compatibility error.
|
|
return SetupGenesisBlock(db, &customg, true /* history */)
|
|
},
|
|
wantHash: customghash,
|
|
wantConfig: customg.Config,
|
|
wantErr: ¶ms.ConfigCompatError{
|
|
What: "Homestead fork block",
|
|
StoredConfig: big.NewInt(2),
|
|
NewConfig: big.NewInt(3),
|
|
RewindTo: 1,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
db := ethdb.NewMemDatabase()
|
|
config, hash, _, err := test.fn(db)
|
|
// Check the return values.
|
|
if !reflect.DeepEqual(err, test.wantErr) {
|
|
spew := spew.ConfigState{DisablePointerAddresses: true, DisableCapacities: true}
|
|
t.Errorf("%s: returned error %#v, want %#v", test.name, spew.NewFormatter(err), spew.NewFormatter(test.wantErr))
|
|
}
|
|
if !reflect.DeepEqual(config, test.wantConfig) {
|
|
t.Errorf("%s:\nreturned %v\nwant %v", test.name, config, test.wantConfig)
|
|
}
|
|
if hash != test.wantHash {
|
|
t.Errorf("%s: returned hash %s, want %s", test.name, hash.Hex(), test.wantHash.Hex())
|
|
} else if err == nil {
|
|
// Check database content.
|
|
stored := rawdb.ReadBlock(db, test.wantHash, 0)
|
|
if stored.Hash() != test.wantHash {
|
|
t.Errorf("%s: block in DB has hash %s, want %s", test.name, stored.Hash(), test.wantHash)
|
|
}
|
|
}
|
|
}
|
|
}
|