Skip to content

Commit

Permalink
ut: fix some broken ut;
Browse files Browse the repository at this point in the history
lint: fix some golang lint;
  • Loading branch information
0xbundler committed Nov 27, 2023
1 parent c75f24b commit 1c75ad6
Show file tree
Hide file tree
Showing 49 changed files with 123 additions and 132 deletions.
3 changes: 3 additions & 0 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ func inspectTrie(ctx *cli.Context) error {
return err
}
theInspect, err := trie.NewInspector(trieDB, theTrie, blockNumber, jobnum)
if err != nil {
return err
}
theInspect.Run()
theInspect.DisplayResult()
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/core"
"os"
"path/filepath"
"strings"
"time"

"github.com/ethereum/go-ethereum/core"

"github.com/prometheus/tsdb/fileutil"

"github.com/ethereum/go-ethereum/cmd/utils"
Expand Down
5 changes: 3 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"math"
"math/big"
"net"
Expand All @@ -37,6 +35,9 @@ import (
"strings"
"time"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"

"github.com/fatih/structs"
pcsclite "github.com/gballet/go-libpcsclite"
gopsutil "github.com/shirou/gopsutil/mem"
Expand Down
3 changes: 2 additions & 1 deletion core/rawdb/accessors_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package rawdb

import (
"fmt"
"github.com/ethereum/go-ethereum/core/types"
"sync"

"github.com/ethereum/go-ethereum/core/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
Expand Down
7 changes: 4 additions & 3 deletions core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/params"
bloomfilter "github.com/holiman/bloomfilter/v2"
"math"
"math/big"
"os"
Expand All @@ -32,6 +30,9 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/params"
bloomfilter "github.com/holiman/bloomfilter/v2"

"github.com/prometheus/tsdb/fileutil"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -683,7 +684,7 @@ func (p *Pruner) Prune(root common.Hash) error {

// find target header
header := p.chainHeader
for header != nil && header.Number.Uint64() >= 0 && header.Root != root {
for header != nil && header.Root != root {
header = rawdb.ReadHeader(p.db, header.ParentHash, header.Number.Uint64()-1)
}
if header == nil || header.Root != root {
Expand Down
2 changes: 1 addition & 1 deletion core/state/snapshot/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TraverseContractTrie(snaptree *Tree, root common.Hash, pruneExpiredTrieCh c
// Start to feed leaves
for acctIt.Next() {
// Fetch the next account and process it concurrently
account, err = types.FullAccount(acctIt.(AccountIterator).Account())
account, err = types.FullAccount(acctIt.Account())
if err != nil {
break
}
Expand Down
1 change: 0 additions & 1 deletion core/state/snapshot/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) {
rawdb.WriteStorageSnapshot(helper.diskdb, key, hashData([]byte("b-key-2")), val)
val, _ = rlp.EncodeToBytes([]byte("b-val-3"))
rawdb.WriteStorageSnapshot(helper.diskdb, key, hashData([]byte("b-key-3")), val)

}
root := helper.Commit()

Expand Down
10 changes: 4 additions & 6 deletions core/state/snapshot/snapshot_expire_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package snapshot

import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/stretchr/testify/assert"
"testing"
)

var (
accountHash = common.HexToHash("0x31b67165f56d0ac50814cafa06748fb3b8fccd3c611a8117350e7a49b44ce130")
storageHash1 = common.HexToHash("0x0bb2f3e66816c6fd12513f053d5ee034b1fa2d448a1dc8ee7f56e4c87d6c53fe")
storageHash2 = common.HexToHash("0x0bb2f3e66816c93e142cd336c411ebd5576a90739bad7ec1ec0d4a63ea0ec1dc")
storageShrink1 = common.FromHex("0x0bb2f3e66816c")
storageNodeHash1 = common.HexToHash("0xcf0e24cb9417a38ff61d11def23fb0ec041257c81c04dec6156d5e6b30f4ec28")
accountHash = common.HexToHash("0x31b67165f56d0ac50814cafa06748fb3b8fccd3c611a8117350e7a49b44ce130")
storageHash1 = common.HexToHash("0x0bb2f3e66816c6fd12513f053d5ee034b1fa2d448a1dc8ee7f56e4c87d6c53fe")
)

func TestShrinkExpiredLeaf(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions core/state/snapshot/snapshot_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package snapshot
import (
"bytes"
"errors"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
)
Expand Down
6 changes: 3 additions & 3 deletions core/state/snapshot/snapshot_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package snapshot

import (
"encoding/hex"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/assert"
"testing"
)

var (
val, _ = hex.DecodeString("0000f9eef0150e074b32e3b3b6d34d2534222292e3953019a41d714d135763a6")
hash, _ = hex.DecodeString("2b6fad2e1335b0b4debd3de01c91f3f45d2b88465ff42ae2c53900f2f702101d")
val, _ = hex.DecodeString("0000f9eef0150e074b32e3b3b6d34d2534222292e3953019a41d714d135763a6")
)

func TestRawValueEncode(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/state/state_expiry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package state
import (
"bytes"
"fmt"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/trie"
"time"
)

var (
Expand Down Expand Up @@ -103,7 +104,6 @@ func batchFetchExpiredFromRemote(expiryMeta *stateExpiryMeta, addr common.Addres
for i, key := range expiredKeys {
keysStr[i] = common.Bytes2Hex(key[:])
}

} else {
for i, prefix := range prefixKeys {
prefixKeysStr[i] = common.Bytes2Hex(prefix)
Expand Down
16 changes: 0 additions & 16 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,22 +337,6 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
return value
}

// needLoadFromTrie If not found in snap when EnableExpire(), need check insert duplication from trie.
func (s *stateObject) needLoadFromTrie(err error, sv snapshot.SnapValue) bool {
if s.db.snap == nil {
return true
}
if !s.db.EnableExpire() {
return err != nil
}

if err != nil || sv == nil {
return true
}

return false
}

// SetState updates a value in account storage.
func (s *stateObject) SetState(key, value common.Hash) {
// If the new value is the same as old, don't set
Expand Down
14 changes: 2 additions & 12 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
package state

import (
"bytes"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/ethdb"
"math/big"
"runtime"
"sort"
"sync"
"time"

"github.com/ethereum/go-ethereum/ethdb"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/gopool"
"github.com/ethereum/go-ethereum/core/rawdb"
Expand Down Expand Up @@ -1899,16 +1899,6 @@ func (s *StateDB) Commit(block uint64, failPostCommitFunc func(), postCommitFunc
return root, diffLayer, nil
}

func stringfyEpochMeta(meta map[common.Hash]map[string][]byte) string {
buf := bytes.NewBuffer(nil)
for hash, m := range meta {
for k, v := range m {
buf.WriteString(fmt.Sprintf("%v: %v|%v, ", hash, []byte(k), common.Bytes2Hex(v)))
}
}
return buf.String()
}

func (s *StateDB) SnapToDiffLayer() ([]common.Address, []types.DiffAccount, []types.DiffStorage) {
destructs := make([]common.Address, 0, len(s.stateObjectsDestruct))
for account := range s.stateObjectsDestruct {
Expand Down
3 changes: 2 additions & 1 deletion core/txpool/blobpool/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package blobpool

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"math/big"
)

// BlockChain defines the minimal set of methods needed to back a blob pool with
Expand Down
7 changes: 5 additions & 2 deletions core/types/gen_account_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions core/types/gen_header_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions core/types/gen_log_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions core/types/gen_withdrawal_rlp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion core/types/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package types

import (
"encoding/hex"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestMetaEncodeDecode(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion core/types/state_expiry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package types
import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/log"
"strings"

"github.com/ethereum/go-ethereum/log"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion core/types/typed_trie_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package types
import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/rlp"
"io"

"github.com/ethereum/go-ethereum/rlp"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package ethconfig

import (
"errors"
"github.com/ethereum/go-ethereum/core/types"
"time"

"github.com/ethereum/go-ethereum/core/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/beacon"
Expand Down
4 changes: 2 additions & 2 deletions ethclient/gethclient/gethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (ec *Client) GetProof(ctx context.Context, account common.Address, keys []s
func (ec *Client) GetStorageReviveProof(ctx context.Context, stateRoot common.Hash, account common.Address, root common.Hash, keys []string, prefixKeys []string) (*types.ReviveResult, error) {
type reviveResult struct {
StorageProof []types.ReviveStorageProof `json:"storageProof"`
BlockNum hexutil.Uint64 `json:"blockNum"`
BlockNum uint64 `json:"blockNum"`
}

var err error
Expand All @@ -140,7 +140,7 @@ func (ec *Client) GetStorageReviveProof(ctx context.Context, stateRoot common.Ha

return &types.ReviveResult{
StorageProof: res.StorageProof,
BlockNum: uint64(res.BlockNum),
BlockNum: res.BlockNum,
}, err
}

Expand Down
5 changes: 3 additions & 2 deletions ethdb/fullstatedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rpc"
lru "github.com/hashicorp/golang-lru"
"strings"
"time"
)

var (
Expand Down
Loading

0 comments on commit 1c75ad6

Please sign in to comment.