Skip to content

Commit

Permalink
Fix failed unit tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Sep 5, 2023
1 parent bf86f10 commit 921555a
Show file tree
Hide file tree
Showing 53 changed files with 423 additions and 384 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ protoc:
generate-mocks:
go generate mockgen -destination=./tests/bor/mocks/IHeimdallClient.go -package=mocks ./consensus/bor IHeimdallClient
go generate mockgen -destination=./eth/filters/IBackend.go -package=filters ./eth/filters Backend
go generate mockgen -destination=../eth/filters/IDatabase.go -package=filters . Database
go generate mockgen -destination=./eth/filters/IDatabase.go -package=filters ./ethdb Database
go generate mockgen -destination=./consensus/bor/api/caller_mock.go -package=api ./consensus/bor/api Caller

geth:
$(GORUN) build/ci.go install ./cmd/geth
Expand Down
1 change: 1 addition & 0 deletions cmd/evm/blockrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/tests"
"github.com/urfave/cli/v2"
)

var blockTestCommand = &cli.Command{
Expand Down
1 change: 0 additions & 1 deletion cmd/evm/internal/t8ntool/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package t8ntool

import (
"context"
"crypto/ecdsa"
"encoding/json"
"errors"
Expand Down
1 change: 0 additions & 1 deletion cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
"github.com/urfave/cli/v2"
)

var runCommand = &cli.Command{
Expand Down
1 change: 0 additions & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/urfave/cli/v2"
)

var (
Expand Down
4 changes: 0 additions & 4 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
stack, cfg := makeConfigNode(ctx)
// TODO marcello double check
if ctx.IsSet(utils.OverrideShanghai.Name) {
v := ctx.Uint64(utils.OverrideShanghai.Name)
cfg.Eth.OverrideShanghai = &v
}

if ctx.IsSet(utils.OverrideCancun.Name) {
v := ctx.Uint64(utils.OverrideCancun.Name)
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/misccmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/ethereum/go-ethereum/internal/version"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli/v2"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
}
_ = CreateBorEthereum(configs)

engine := ethconfig.CreateConsensusEngine(config, configs, chainDb, nil)
engine := ethconfig.CreateConsensusEngine(config, configs, nil, chainDb, nil)
if err != nil {
Fatalf("%v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions consensus/bor/bor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)

func TestGenesisContractChange(t *testing.T) {
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestGenesisContractChange(t *testing.T) {
}

db := rawdb.NewMemoryDatabase()
genesis := genspec.MustCommit(db)
genesis := genspec.MustCommit(db, trie.NewDatabase(db, trie.HashDefaults))

statedb, err := state.New(genesis.Root(), state.NewDatabase(db), nil)
require.NoError(t, err)
Expand All @@ -71,7 +72,7 @@ func TestGenesisContractChange(t *testing.T) {
b.Finalize(chain, h, statedb, nil, nil, nil)

// write state to database
root, err := statedb.Commit(false)
root, err := statedb.Commit(h.Number.Uint64(), false)
require.NoError(t, err)
require.NoError(t, statedb.Database().TrieDB().Commit(root, true))

Expand Down
6 changes: 3 additions & 3 deletions core/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func testHeaderVerification(t *testing.T, scheme string) {
headers[i] = block.Header()
}
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
defer chain.Stop()

for i := 0; i < len(blocks); i++ {
Expand Down Expand Up @@ -277,11 +277,11 @@ func testHeaderConcurrentVerification(t *testing.T, threads int) {
var results <-chan error

if valid {
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
_, results = chain.engine.VerifyHeaders(chain, headers)
chain.Stop()
} else {
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, ethash.NewFakeFailer(uint64(len(headers)-1)), vm.Config{}, nil, nil)
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, ethash.NewFakeFailer(uint64(len(headers)-1)), vm.Config{}, nil, nil, nil)
_, results = chain.engine.VerifyHeaders(chain, headers)
chain.Stop()
}
Expand Down
9 changes: 6 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
if cacheConfig.TriesInMemory <= 0 {
cacheConfig.TriesInMemory = DefaultCacheConfig.TriesInMemory
}

log.Info("Before")
// Open trie database with provided config
triedb := trie.NewDatabase(db, cacheConfig.TriedbConfig())
log.Info("After")

// Setup the genesis block, commit the provided genesis specification
// to database if the genesis block is not present yet, or load the
Expand Down Expand Up @@ -436,7 +439,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
// The first thing the node will do is reconstruct the verification data for
// the head block (ethash cache or clique voting snapshot). Might as well do
// it in advance.
bc.engine.VerifyHeader(bc, bc.CurrentHeader())
// bc.engine.VerifyHeader(bc, bc.CurrentHeader())

// Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
for hash := range BadHashes {
Expand Down Expand Up @@ -1139,7 +1142,7 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block) {
// OBS! It is generally recommended to use the Stop method!
// This method has been exposed to allow tests to stop the blockchain while simulating
// a crash.
func (bc *BlockChain) stopWithoutSaving() {
func (bc *BlockChain) StopWithoutSaving() {
if !bc.stopping.CompareAndSwap(false, true) {
return
}
Expand All @@ -1164,7 +1167,7 @@ func (bc *BlockChain) stopWithoutSaving() {
// Stop stops the blockchain service. If any imports are currently in progress
// it will abort them using the procInterrupt.
func (bc *BlockChain) Stop() {
bc.stopWithoutSaving()
bc.StopWithoutSaving()

// Ensure that the entirety of the state snapshot is journalled to disk.
var snapBase common.Hash
Expand Down
3 changes: 2 additions & 1 deletion core/blockchain_bor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
)

func TestChain2HeadEvent(t *testing.T) {
Expand All @@ -23,7 +24,7 @@ func TestChain2HeadEvent(t *testing.T) {
Config: params.TestChainConfig,
Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}},
}
genesis = gspec.MustCommit(db)
genesis = gspec.MustCommit(db, trie.NewDatabase(db, trie.HashDefaults))
signer = types.LatestSigner(gspec.Config)
)

Expand Down
12 changes: 12 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,15 @@ func (bc *BlockChain) GetStateSync() []*types.StateSyncData {
func (bc *BlockChain) SubscribeStateSyncEvent(ch chan<- StateSyncEvent) event.Subscription {
return bc.scope.Track(bc.stateSyncFeed.Subscribe(ch))
}

func (bc *BlockChain) SetDB(db ethdb.Database) {
bc.db = db
}

func (bc *BlockChain) SetStateCache(stateCache state.Database) {
bc.stateCache = stateCache
}

func (bc *BlockChain) SetTrieDB(triedb *trie.Database) {
bc.triedb = triedb
}
Loading

0 comments on commit 921555a

Please sign in to comment.