linting and test fixes

This commit is contained in:
i-norden 2023-03-30 15:32:21 -05:00
parent 970b7c8581
commit 57188bef8f
7 changed files with 25 additions and 24 deletions

View File

@ -139,7 +139,7 @@ type CacheConfig struct {
SnapshotNoBuild bool // Whether the background generation is allowed SnapshotNoBuild bool // Whether the background generation is allowed
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it
StateDiffing bool // Whether or not the statediffing service is running StateDiffing bool // Whether the statediffing service is running
} }
// defaultCacheConfig are the default caching values if none are specified by the // defaultCacheConfig are the default caching values if none are specified by the
@ -982,8 +982,7 @@ func (bc *BlockChain) Stop() {
} }
} }
for !bc.triegc.Empty() { for !bc.triegc.Empty() {
pruneRootV := bc.triegc.PopItem() pruneRoot := bc.triegc.PopItem()
pruneRoot := (common.Hash)(pruneRootV)
if !bc.TrieLocked(pruneRoot) { if !bc.TrieLocked(pruneRoot) {
triedb.Dereference(pruneRoot) triedb.Dereference(pruneRoot)
} }
@ -1419,10 +1418,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
bc.triegc.Push(root, number) bc.triegc.Push(root, number)
break break
} }
pruneRoot := (common.Hash)(root) if !bc.TrieLocked(root) {
if !bc.TrieLocked(pruneRoot) { log.Debug("Dereferencing", "root", root.Hex())
log.Debug("Dereferencing", "root", (common.Hash)(root).Hex()) bc.triedb.Dereference(root)
bc.triedb.Dereference(pruneRoot)
} }
} }
return nil return nil
@ -2514,7 +2512,7 @@ func (bc *BlockChain) SetTrieFlushInterval(interval time.Duration) {
atomic.StoreInt64(&bc.flushInterval, int64(interval)) atomic.StoreInt64(&bc.flushInterval, int64(interval))
} }
// TrieLocked returns whether the trie associated with the provided root is locked for use // TrieLocked returns whether the trie associated with the provided root is locked for use
func (bc *BlockChain) TrieLocked(root common.Hash) bool { func (bc *BlockChain) TrieLocked(root common.Hash) bool {
bc.trieLock.Lock() bc.trieLock.Lock()
locked, ok := bc.lockedRoots[root] locked, ok := bc.lockedRoots[root]

View File

@ -17,7 +17,7 @@
package ipld package ipld
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -63,7 +63,7 @@ func loadBlockData(t *testing.T) []testCase {
fileDir := "./eip2930_test_data" fileDir := "./eip2930_test_data"
testCases := make([]testCase, len(blockFileNames)) testCases := make([]testCase, len(blockFileNames))
for i, blockFileName := range blockFileNames { for i, blockFileName := range blockFileNames {
blockRLP, err := ioutil.ReadFile(filepath.Join(fileDir, blockFileName)) blockRLP, err := os.ReadFile(filepath.Join(fileDir, blockFileName))
if err != nil { if err != nil {
t.Fatalf("failed to load blockRLP from file, err %v", err) t.Fatalf("failed to load blockRLP from file, err %v", err)
} }
@ -72,7 +72,7 @@ func loadBlockData(t *testing.T) []testCase {
t.Fatalf("failed to decode blockRLP, err %v", err) t.Fatalf("failed to decode blockRLP, err %v", err)
} }
receiptsFileName := receiptsFileNames[i] receiptsFileName := receiptsFileNames[i]
receiptsRLP, err := ioutil.ReadFile(filepath.Join(fileDir, receiptsFileName)) receiptsRLP, err := os.ReadFile(filepath.Join(fileDir, receiptsFileName))
if err != nil { if err != nil {
t.Fatalf("failed to load receiptsRLP from file, err %s", err) t.Fatalf("failed to load receiptsRLP from file, err %s", err)
} }

View File

@ -55,7 +55,6 @@ var (
BaseFee: big.NewInt(params.InitialBaseFee), BaseFee: big.NewInt(params.InitialBaseFee),
Coinbase: common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476777"), Coinbase: common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476777"),
} }
a = trie.Trie{}
MockTransactions, MockReceipts, SenderAddr = createTransactionsAndReceipts(TestConfig, BlockNumber) MockTransactions, MockReceipts, SenderAddr = createTransactionsAndReceipts(TestConfig, BlockNumber)
MockBlock = types.NewBlock(&MockHeader, MockTransactions, nil, MockReceipts, trie.NewEmpty(nil)) MockBlock = types.NewBlock(&MockHeader, MockTransactions, nil, MockReceipts, trie.NewEmpty(nil))
MockHeaderRlp, _ = rlp.EncodeToBytes(MockBlock.Header()) MockHeaderRlp, _ = rlp.EncodeToBytes(MockBlock.Header())

View File

@ -20,15 +20,13 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"math/big" "math/big"
"os" "os"
"sort" "sort"
"testing" "testing"
ipld2 "github.com/ethereum/go-ethereum/statediff/indexer/ipld"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
@ -37,9 +35,9 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/statediff" "github.com/ethereum/go-ethereum/statediff"
ipld2 "github.com/ethereum/go-ethereum/statediff/indexer/ipld"
"github.com/ethereum/go-ethereum/statediff/test_helpers" "github.com/ethereum/go-ethereum/statediff/test_helpers"
sdtypes "github.com/ethereum/go-ethereum/statediff/types" sdtypes "github.com/ethereum/go-ethereum/statediff/types"
) )
@ -467,7 +465,7 @@ func loadBlockFromRLPFile(filename string) (*types.Block, []byte, error) {
return nil, nil, err return nil, nil, err
} }
defer f.Close() defer f.Close()
blockRLP, err := ioutil.ReadAll(f) blockRLP, err := io.ReadAll(f)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -476,7 +474,7 @@ func loadBlockFromRLPFile(filename string) (*types.Block, []byte, error) {
} }
func TestBuilderOnMainnetBlocks(t *testing.T) { func TestBuilderOnMainnetBlocks(t *testing.T) {
chain, _ := core.NewBlockChain(db, nil, params.MainnetChainConfig, ethash.NewFaker(), vm.Config{}, nil, nil) chain, _ := core.NewBlockChain(db, nil, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
_, err := chain.InsertChain([]*types.Block{block1, block2, block3}) _, err := chain.InsertChain([]*types.Block{block1, block2, block3})
if err != nil { if err != nil {
t.Error(err) t.Error(err)

View File

@ -30,8 +30,10 @@ import (
) )
func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance, baseFee *big.Int, initialGasLimit uint64) *types.Block { func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance, baseFee *big.Int, initialGasLimit uint64) *types.Block {
alloc := map[common.Address]core.GenesisAccount{
addr: core.GenesisAccount{Balance: balance}}
g := core.Genesis{ g := core.Genesis{
Alloc: core.GenesisAlloc{addr: {Balance: balance}}, Alloc: alloc,
BaseFee: baseFee, BaseFee: baseFee,
} }
if initialGasLimit != 0 { if initialGasLimit != 0 {

View File

@ -104,7 +104,7 @@ func (gen *prefixGenerator) Next() {
// MakePaths generates paths that cut trie domain into `nbins` uniform conterminous bins (w/ opt. prefix) // MakePaths generates paths that cut trie domain into `nbins` uniform conterminous bins (w/ opt. prefix)
// eg. MakePaths([], 2) => [[0] [8]] // eg. MakePaths([], 2) => [[0] [8]]
// MakePaths([4], 32) => [[4 0 0] [4 0 8] [4 1 0]... [4 f 8]] // MakePaths([4], 32) => [[4 0 0] [4 0 8] [4 1 0]... [4 f 8]]
func MakePaths(prefix []byte, nbins uint) [][]byte { func MakePaths(prefix []byte, nbins uint) [][]byte {
var res [][]byte var res [][]byte
for it := newPrefixGenerator(nbins); it.HasNext(); it.Next() { for it := newPrefixGenerator(nbins); it.HasNext(); it.Next() {

View File

@ -24,10 +24,14 @@ func TestMakePaths(t *testing.T) {
} }
func TestIterator(t *testing.T) { func TestIterator(t *testing.T) {
edb, err := rawdb.NewLevelDBDatabaseWithFreezer( kvdb, ldberr := rawdb.NewLevelDBDatabase(fixt.ChainDataPath, 1024, 256, "vdb-geth", false)
fixt.ChainDataPath, 1024, 256, fixt.AncientDataPath, if ldberr != nil {
"eth-pg-ipfs-state-snapshot", false, t.Fatal(ldberr)
) }
edb, err := rawdb.NewDatabaseWithFreezer(kvdb, fixt.AncientDataPath, "vdb-geth", false)
if err != nil {
t.Fatal(err)
}
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }