Adjust import paths and also goimports

pull/250/head
Eugene Kim 6 years ago
parent 82675a2daf
commit 5ad4d5a8f0
  1. 2
      api/client/client.go
  2. 5
      api/client/service/client.go
  3. 5
      api/client/service/server.go
  4. 11
      api/client/service/server_test.go
  5. 2
      api/proto/bcconn/bcconn.go
  6. 4
      api/proto/node/node_test.go
  7. 10
      api/services/explorer/storage.go
  8. 2
      api/services/syncing/syncing.go
  9. 2
      cmd/beaconchain/main.go
  10. 2
      cmd/client/txgen/main.go
  11. 10
      cmd/harmony.go
  12. 2
      consensus/consensus.go
  13. 2
      consensus/consensus_leader.go
  14. 2
      consensus/consensus_leader_msg.go
  15. 2
      consensus/consensus_validator.go
  16. 18
      core/blockchain.go
  17. 8
      core/chain_makers.go
  18. 14
      core/genesis.go
  19. 8
      core/headerchain.go
  20. 10
      core/state/database.go
  21. 4
      core/state/managed_state_test.go
  22. 8
      core/state/state_test.go
  23. 14
      core/state/statedb_test.go
  24. 30
      core/tx_pool_test.go
  25. 6
      core/vm/runtime/runtime.go
  26. 6
      core/vm/runtime/runtime_test.go
  27. 3
      crypto/pki/utils.go
  28. 2
      internal/attack/attack.go
  29. 2
      internal/attack/attack_test.go
  30. 2
      internal/beaconchain/libs/beaconchain.go
  31. 2
      internal/newnode/newnode.go
  32. 2
      internal/profiler/profiler.go
  33. 2
      internal/utils/singleton.go
  34. 7
      node/address_faker.go
  35. 12
      node/node.go
  36. 2
      node/worker/worker.go
  37. 13
      node/worker/worker_test.go
  38. 3
      p2p/helper.go
  39. 2
      p2p/host/hostv1/hostv1.go
  40. 2
      p2p/host/hostv2/hostv2.go
  41. 2
      p2p/host/hostv2/util.go
  42. 2
      p2p/host/message.go
  43. 6
      test/chain/main.go

@ -1,8 +1,8 @@
package client
import (
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
)

@ -3,11 +3,12 @@ package client
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
proto "github.com/harmony-one/harmony/api/client/service/proto"
"log"
"time"
"github.com/ethereum/go-ethereum/common"
proto "github.com/harmony-one/harmony/api/client/service/proto"
"google.golang.org/grpc"
)

@ -2,11 +2,12 @@ package client
import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/core/state"
"log"
"net"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/core/state"
"google.golang.org/grpc"
proto "github.com/harmony-one/harmony/api/client/service/proto"

@ -2,18 +2,19 @@ package client
import (
"bytes"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/harmony-one/harmony/api/client/service/proto"
client "github.com/harmony-one/harmony/api/client/service/proto"
"github.com/harmony-one/harmony/core/state"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/db"
)
var (
@ -48,7 +49,7 @@ func TestGetFreeToken(test *testing.T) {
func TestFetchAccountState(test *testing.T) {
var (
database = db.NewMemDatabase()
database = ethdb.NewMemDatabase()
gspec = core.Genesis{
Config: chainConfig,
Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},

@ -4,7 +4,7 @@ import (
"bytes"
"encoding/gob"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/p2p"
)

@ -3,10 +3,10 @@ package node
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
hdb "github.com/harmony-one/harmony/internal/db"
// "fmt"
"math/big"
@ -75,7 +75,7 @@ func TestConstructStopMessage(t *testing.T) {
func TestConstructBlocksSyncMessage(t *testing.T) {
db := hdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
root := statedb.IntermediateRoot(false)

@ -6,10 +6,10 @@ import (
"strconv"
"sync"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/db"
"github.com/harmony-one/harmony/log"
)
// Constants for storage.
@ -49,7 +49,7 @@ var once sync.Once
// Storage dump the block info into leveldb.
type Storage struct {
db *db.LDBDatabase
db *ethdb.LDBDatabase
}
// GetStorageInstance returns attack model by using singleton pattern.
@ -71,13 +71,13 @@ func (storage *Storage) Init(ip, port string, remove bool) {
Log.Error(err.Error())
}
}
if storage.db, err = db.NewLDBDatabase(dbFileName, 0, 0); err != nil {
if storage.db, err = ethdb.NewLDBDatabase(dbFileName, 0, 0); err != nil {
Log.Error(err.Error())
}
}
// GetDB returns the LDBDatabase of the storage.
func (storage *Storage) GetDB() *db.LDBDatabase {
func (storage *Storage) GetDB() *ethdb.LDBDatabase {
return storage.db
}

@ -10,8 +10,8 @@ import (
"github.com/harmony-one/harmony/core"
"github.com/Workiva/go-datastructures/queue"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/api/services/syncing/downloader"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/p2p"
)

@ -6,8 +6,8 @@ import (
"os"
"path"
"github.com/ethereum/go-ethereum/log"
beaconchain "github.com/harmony-one/harmony/internal/beaconchain/libs"
"github.com/harmony-one/harmony/log"
)
var (

@ -9,6 +9,7 @@ import (
"sync"
"time"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/api/client"
proto_node "github.com/harmony-one/harmony/api/proto/node"
"github.com/harmony-one/harmony/cmd/client/txgen/txgen"
@ -16,7 +17,6 @@ import (
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/newnode"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"

@ -9,12 +9,12 @@ import (
"runtime"
"time"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/internal/attack"
"github.com/harmony-one/harmony/internal/db"
pkg_newnode "github.com/harmony-one/harmony/internal/newnode"
"github.com/harmony-one/harmony/internal/profiler"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
@ -45,14 +45,14 @@ func attackDetermination(attackedMode int) bool {
}
// InitLDBDatabase initializes a LDBDatabase.
func InitLDBDatabase(ip string, port string) (*db.LDBDatabase, error) {
func InitLDBDatabase(ip string, port string) (*ethdb.LDBDatabase, error) {
// TODO(minhdoan): Refactor this.
dbFileName := "/tmp/harmony_" + ip + port + ".dat"
var err = os.RemoveAll(dbFileName)
if err != nil {
fmt.Println(err.Error())
}
return db.NewLDBDatabase(dbFileName, 0, 0)
return ethdb.NewLDBDatabase(dbFileName, 0, 0)
}
func printVersion(me string) {
@ -136,7 +136,7 @@ func main() {
loggingInit(*logFolder, role, *ip, *port, *onlyLogTps)
// Initialize leveldb if dbSupported.
var ldb *db.LDBDatabase
var ldb *ethdb.LDBDatabase
if *dbSupported {
ldb, _ = InitLDBDatabase(*ip, *port)

@ -10,6 +10,7 @@ import (
"github.com/dedis/kyber"
"github.com/dedis/kyber/sign/schnorr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/core/state"
@ -17,7 +18,6 @@ import (
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/crypto/pki"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
"golang.org/x/crypto/sha3"

@ -11,12 +11,12 @@ import (
"github.com/dedis/kyber/sign/schnorr"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/log"
consensus_proto "github.com/harmony-one/harmony/api/consensus"
"github.com/harmony-one/harmony/api/services/explorer"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/internal/profiler"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
)

@ -4,10 +4,10 @@ import (
"bytes"
"github.com/dedis/kyber"
"github.com/ethereum/go-ethereum/log"
consensus_proto "github.com/harmony-one/harmony/api/consensus"
"github.com/harmony-one/harmony/api/proto"
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/log"
)
// Constructs the announce message

@ -4,13 +4,13 @@ import (
"bytes"
"github.com/dedis/kyber/sign/schnorr"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
consensus_proto "github.com/harmony-one/harmony/api/consensus"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/internal/attack"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/log"
)
// ProcessMessageValidator dispatches validator's consensus message.

@ -31,19 +31,19 @@ import (
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
hdb "github.com/harmony-one/harmony/internal/db"
"github.com/harmony-one/harmony/internal/trie"
"github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru"
)
var (
@ -93,9 +93,9 @@ type BlockChain struct {
chainConfig *params.ChainConfig // Chain & network configuration
cacheConfig *CacheConfig // Cache configuration for pruning
db hdb.Database // Low level persistent database to store final content in
triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
gcproc time.Duration // Accumulates canonical block processing for trie dumping
db ethdb.Database // Low level persistent database to store final content in
triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
gcproc time.Duration // Accumulates canonical block processing for trie dumping
hc *HeaderChain
rmLogsFeed event.Feed
@ -139,7 +139,7 @@ type BlockChain struct {
// NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator and
// Processor.
func NewBlockChain(db hdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool) (*BlockChain, error) {
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool) (*BlockChain, error) {
if cacheConfig == nil {
cacheConfig = &CacheConfig{
TrieNodeLimit: 256 * 1024 * 1024,
@ -855,7 +855,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
stats.processed++
if batch.ValueSize() >= hdb.IdealBatchSize {
if batch.ValueSize() >= ethdb.IdealBatchSize {
if err := batch.Write(); err != nil {
return 0, err
}
@ -961,7 +961,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
limit = common.StorageSize(bc.cacheConfig.TrieNodeLimit) * 1024 * 1024
)
if nodes > limit || imgs > 4*1024*1024 {
triedb.Cap(limit - hdb.IdealBatchSize)
triedb.Cap(limit - ethdb.IdealBatchSize)
}
// Find the next state trie we need to commit
header := bc.GetHeaderByNumber(current - triesInMemory)

@ -21,12 +21,12 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
hdb "github.com/harmony-one/harmony/internal/db"
)
// BlockGen creates blocks for testing.
@ -161,7 +161,7 @@ func (b *BlockGen) PrevBlock(index int) *types.Block {
// Blocks created by GenerateChain do not contain valid proof of work
// values. Inserting them into BlockChain requires use of FakePow or
// a similar non-validating proof of work implementation.
func GenerateChain(config *params.ChainConfig, parent *types.Block, engine consensus.Engine, db hdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) {
func GenerateChain(config *params.ChainConfig, parent *types.Block, engine consensus.Engine, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) {
if config == nil {
config = params.TestChainConfig
}
@ -241,7 +241,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
}
// makeHeaderChain creates a deterministic chain of headers rooted at parent.
func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db hdb.Database, seed int) []*types.Header {
func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Header {
blocks := makeBlockChain(types.NewBlockWithHeader(parent), n, engine, db, seed)
headers := make([]*types.Header, len(blocks))
for i, block := range blocks {
@ -251,7 +251,7 @@ func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db hd
}
// makeBlockChain creates a deterministic chain of blocks rooted at parent.
func makeBlockChain(parent *types.Block, n int, engine consensus.Engine, db hdb.Database, seed int) []*types.Block {
func makeBlockChain(parent *types.Block, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Block {
blocks, _ := GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *BlockGen) {
b.SetCoinbase(common.Address{0: byte(seed), 19: byte(i)})
})

@ -27,12 +27,12 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
hdb "github.com/harmony-one/harmony/internal/db"
)
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
@ -149,7 +149,7 @@ func (e *GenesisMismatchError) Error() string {
// error is a *params.ConfigCompatError and the new, unwritten config is returned.
//
// The returned chain configuration is never nil.
func SetupGenesisBlock(db hdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
if genesis != nil && genesis.Config == nil {
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
}
@ -219,9 +219,9 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
// ToBlock creates the genesis block and writes state of a genesis specification
// to the given database (or discards it if nil).
func (g *Genesis) ToBlock(db hdb.Database) *types.Block {
func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
if db == nil {
db = hdb.NewMemDatabase()
db = ethdb.NewMemDatabase()
}
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
for addr, account := range g.Alloc {
@ -261,7 +261,7 @@ func (g *Genesis) ToBlock(db hdb.Database) *types.Block {
// Commit writes the block and state of a genesis specification to the database.
// The block is committed as the canonical head block.
func (g *Genesis) Commit(db hdb.Database) (*types.Block, error) {
func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
block := g.ToBlock(db)
if block.Number().Sign() != 0 {
return nil, fmt.Errorf("can't commit genesis block with number > 0")
@ -283,7 +283,7 @@ func (g *Genesis) Commit(db hdb.Database) (*types.Block, error) {
// MustCommit writes the genesis block and state to db, panicking on error.
// The block is committed as the canonical head block.
func (g *Genesis) MustCommit(db hdb.Database) *types.Block {
func (g *Genesis) MustCommit(db ethdb.Database) *types.Block {
block, err := g.Commit(db)
if err != nil {
panic(err)
@ -292,7 +292,7 @@ func (g *Genesis) MustCommit(db hdb.Database) *types.Block {
}
// GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
func GenesisBlockForTesting(db hdb.Database, addr common.Address, balance *big.Int) *types.Block {
func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block {
g := Genesis{Alloc: GenesisAlloc{addr: {Balance: balance}}}
return g.MustCommit(db)
}

@ -27,13 +27,13 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/db"
"github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru"
)
const (
@ -50,7 +50,7 @@ const (
type HeaderChain struct {
config *params.ChainConfig
chainDb db.Database
chainDb ethdb.Database
genesisHeader *types.Header
currentHeader atomic.Value // Current head of the header chain (may be above the block chain!)
@ -70,7 +70,7 @@ type HeaderChain struct {
// getValidator should return the parent's validator
// procInterrupt points to the parent's interrupt semaphore
// wg points to the parent's shutdown wait group
func NewHeaderChain(chainDb db.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
headerCache, _ := lru.New(headerCacheLimit)
tdCache, _ := lru.New(tdCacheLimit)
numberCache, _ := lru.New(numberCacheLimit)

@ -21,8 +21,8 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/internal/db"
"github.com/harmony-one/harmony/internal/trie"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
lru "github.com/hashicorp/golang-lru"
)
@ -68,14 +68,14 @@ type Trie interface {
Hash() common.Hash
NodeIterator(startKey []byte) trie.NodeIterator
GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed
Prove(key []byte, fromLevel uint, proofDb db.Putter) error
Prove(key []byte, fromLevel uint, proofDb ethdb.Putter) error
}
// NewDatabase creates a backing store for state. The returned database is safe for
// concurrent use and retains cached trie nodes in memory. The pool is an optional
// intermediate trie-node memory pool between the low level storage layer and the
// high level trie abstraction.
func NewDatabase(db db.Database) Database {
func NewDatabase(db ethdb.Database) Database {
csc, _ := lru.New(codeSizeCacheSize)
return &cachingDB{
db: trie.NewDatabase(db),
@ -173,6 +173,6 @@ func (m cachedTrie) Commit(onleaf trie.LeafCallback) (common.Hash, error) {
return root, err
}
func (m cachedTrie) Prove(key []byte, fromLevel uint, proofDb db.Putter) error {
func (m cachedTrie) Prove(key []byte, fromLevel uint, proofDb ethdb.Putter) error {
return m.SecureTrie.Prove(key, fromLevel, proofDb)
}

@ -20,13 +20,13 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/internal/db"
"github.com/ethereum/go-ethereum/ethdb"
)
var addr = common.BytesToAddress([]byte("test"))
func create() (*ManagedState, *account) {
statedb, _ := New(common.Hash{}, NewDatabase(db.NewMemDatabase()))
statedb, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
ms := ManageState(statedb)
ms.StateDB.SetNonce(addr, 100)
ms.accounts[addr] = newAccount(ms.StateDB.getStateObject(addr))

@ -23,12 +23,12 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/harmony-one/harmony/internal/db"
"github.com/ethereum/go-ethereum/ethdb"
checker "gopkg.in/check.v1"
)
type StateSuite struct {
db *db.MemDatabase
db *ethdb.MemDatabase
state *StateDB
}
@ -87,7 +87,7 @@ func (s *StateSuite) TestDump(c *checker.C) {
}
func (s *StateSuite) SetUpTest(c *checker.C) {
s.db = db.NewMemDatabase()
s.db = ethdb.NewMemDatabase()
s.state, _ = New(common.Hash{}, NewDatabase(s.db))
}
@ -141,7 +141,7 @@ func (s *StateSuite) TestSnapshotEmpty(c *checker.C) {
// use testing instead of checker because checker does not support
// printing/logging in tests (-check.vv does not work)
func TestSnapshot2(t *testing.T) {
state, _ := New(common.Hash{}, NewDatabase(db.NewMemDatabase()))
state, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
stateobjaddr0 := toAddr([]byte("so0"))
stateobjaddr1 := toAddr([]byte("so1"))

@ -31,15 +31,15 @@ import (
check "gopkg.in/check.v1"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/db"
)
// Tests that updating a state trie does not leak any database writes prior to
// actually committing the state.
func TestUpdateLeaks(t *testing.T) {
// Create an empty state database
db := db.NewMemDatabase()
db := ethdb.NewMemDatabase()
state, _ := New(common.Hash{}, NewDatabase(db))
// Update it with some accounts
@ -66,8 +66,8 @@ func TestUpdateLeaks(t *testing.T) {
// only the one right before the commit.
func TestIntermediateLeaks(t *testing.T) {
// Create two state databases, one transitioning to the final state, the other final from the beginning
transDb := db.NewMemDatabase()
finalDb := db.NewMemDatabase()
transDb := ethdb.NewMemDatabase()
finalDb := ethdb.NewMemDatabase()
transState, _ := New(common.Hash{}, NewDatabase(transDb))
finalState, _ := New(common.Hash{}, NewDatabase(finalDb))
@ -122,7 +122,7 @@ func TestIntermediateLeaks(t *testing.T) {
// https://github.com/ethereum/go-ethereum/pull/15549.
func TestCopy(t *testing.T) {
// Create a random state test to copy and modify "independently"
orig, _ := New(common.Hash{}, NewDatabase(db.NewMemDatabase()))
orig, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
for i := byte(0); i < 255; i++ {
obj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
@ -333,7 +333,7 @@ func (test *snapshotTest) String() string {
func (test *snapshotTest) run() bool {
// Run all actions and create snapshots.
var (
state, _ = New(common.Hash{}, NewDatabase(db.NewMemDatabase()))
state, _ = New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
snapshotRevs = make([]int, len(test.snapshots))
sindex = 0
)
@ -424,7 +424,7 @@ func (s *StateSuite) TestTouchDelete(c *check.C) {
// TestCopyOfCopy tests that modified objects are carried over to the copy, and the copy of the copy.
// See https://github.com/ethereum/go-ethereum/pull/15225#issuecomment-380191512
func TestCopyOfCopy(t *testing.T) {
sdb, _ := New(common.Hash{}, NewDatabase(db.NewMemDatabase()))
sdb, _ := New(common.Hash{}, NewDatabase(ethdb.NewMemDatabase()))
addr := common.HexToAddress("aaaa")
sdb.SetBalance(addr, big.NewInt(42))

@ -28,11 +28,11 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/db"
)
// testTxPoolConfig is a transaction pool configuration without stateful disk
@ -78,7 +78,7 @@ func pricedTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ec
}
func setupTxPool() (*TxPool, *ecdsa.PrivateKey) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
key, _ := crypto.GenerateKey()
@ -163,7 +163,7 @@ func (c *testChain) State() (*state.StateDB, error) {
// a state change between those fetches.
stdb := c.statedb
if *c.trigger {
c.statedb, _ = state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
c.statedb, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
// simulate that the new head block included tx0 and tx1
c.statedb.SetNonce(c.address, 2)
c.statedb.SetBalance(c.address, new(big.Int).SetUint64(params.Ether))
@ -181,7 +181,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
var (
key, _ = crypto.GenerateKey()
address = crypto.PubkeyToAddress(key.PublicKey)
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
trigger = false
)
@ -335,7 +335,7 @@ func TestTransactionChainFork(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey)
resetState := func() {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
statedb.AddBalance(addr, big.NewInt(100000000000000))
pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
@ -364,7 +364,7 @@ func TestTransactionDoubleNonce(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey)
resetState := func() {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
statedb.AddBalance(addr, big.NewInt(100000000000000))
pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
@ -554,7 +554,7 @@ func TestTransactionPostponing(t *testing.T) {
t.Parallel()
// Create the pool to test the postponing with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
@ -712,7 +712,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
t.Parallel()
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
@ -800,7 +800,7 @@ func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {
evictionInterval = time.Second
// Create the pool to test the non-expiration enforcement
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
@ -913,7 +913,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
t.Parallel()
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
@ -959,7 +959,7 @@ func TestTransactionCapClearsFromAll(t *testing.T) {
t.Parallel()
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
@ -993,7 +993,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
t.Parallel()
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
@ -1038,7 +1038,7 @@ func TestTransactionPoolRepricingKeepsLocals(t *testing.T) {
t.Parallel()
// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
@ -1112,7 +1112,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
os.Remove(journal)
// Create the original pool to inject transaction into the journal
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
@ -1210,7 +1210,7 @@ func TestTransactionStatusCheck(t *testing.T) {
t.Parallel()
// Create the pool to test the status retrievals with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)

@ -23,10 +23,10 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/db"
)
// Config is a basic type specifying certain configuration flags for running
@ -99,7 +99,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
setDefaults(cfg)
if cfg.State == nil {
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
}
var (
address = common.BytesToAddress([]byte("contract"))
@ -129,7 +129,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
setDefaults(cfg)
if cfg.State == nil {
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
}
var (
vmenv = NewEnv(cfg)

@ -23,10 +23,10 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/db"
)
func TestDefaults(t *testing.T) {
@ -95,7 +95,7 @@ func TestExecute(t *testing.T) {
}
func TestCall(t *testing.T) {
state, _ := state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
state, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
address := common.HexToAddress("0x0a")
state.SetCode(address, []byte{
byte(vm.PUSH1), 10,
@ -152,7 +152,7 @@ func BenchmarkCall(b *testing.B) {
func benchmarkEVMCreate(bench *testing.B, code string) {
var (
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
statedb, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
sender = common.BytesToAddress([]byte("sender"))
receiver = common.BytesToAddress([]byte("receiver"))
)

@ -2,9 +2,10 @@ package pki
import (
"crypto/sha256"
"github.com/dedis/kyber"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/log"
)
// GetAddressFromPublicKey returns address given a public key.

@ -6,7 +6,7 @@ import (
"sync"
"time"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
)
// Constants used for attack model.

@ -3,7 +3,7 @@ package attack
import (
"testing"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/assert"
)

@ -7,12 +7,12 @@ import (
"github.com/dedis/kyber"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/api/proto/bcconn"
proto_identity "github.com/harmony-one/harmony/api/proto/identity"
"github.com/harmony-one/harmony/crypto/pki"
"github.com/harmony-one/harmony/internal/beaconchain/rpc"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
"github.com/harmony-one/harmony/p2p/p2pimpl"

@ -9,11 +9,11 @@ import (
"github.com/dedis/kyber"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/api/proto/bcconn"
proto_identity "github.com/harmony-one/harmony/api/proto/identity"
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
"github.com/harmony-one/harmony/p2p/p2pimpl"

@ -8,7 +8,7 @@ import (
"sync"
"time"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
"github.com/shirou/gopsutil/process"
)

@ -6,7 +6,7 @@ import (
"sync"
"sync/atomic"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
)
// UniqueValidatorID defines the structure of unique validator ID

@ -2,12 +2,13 @@ package node
import (
"crypto/ecdsa"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core"
"math/big"
"math/rand"
"strings"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/core"
)
// CreateGenesisAllocWithTestingAddresses create the genesis block allocation that contains deterministically

@ -16,6 +16,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/api/client"
@ -30,8 +32,6 @@ import (
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/pki"
hdb "github.com/harmony-one/harmony/internal/db"
"github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/node/worker"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
@ -99,8 +99,8 @@ type Node struct {
transactionInConsensus []*types.Transaction // The transactions selected into the new block and under Consensus process
pendingTxMutex sync.Mutex
blockchain *core.BlockChain // The blockchain for the shard where this node belongs
db *hdb.LDBDatabase // LevelDB to store blockchain.
blockchain *core.BlockChain // The blockchain for the shard where this node belongs
db *ethdb.LDBDatabase // LevelDB to store blockchain.
log log.Logger // Log utility
@ -209,7 +209,7 @@ func DeserializeNode(d []byte) *NetworkNode {
}
// New creates a new node.
func New(host host.Host, consensus *bft.Consensus, db *hdb.LDBDatabase) *Node {
func New(host host.Host, consensus *bft.Consensus, db *ethdb.LDBDatabase) *Node {
node := Node{}
if host != nil {
@ -236,7 +236,7 @@ func New(host host.Host, consensus *bft.Consensus, db *hdb.LDBDatabase) *Node {
genesisAlloc[contractAddress] = core.GenesisAccount{Balance: contractFunds}
node.ContractKeys = append(node.ContractKeys, contractKey)
database := hdb.NewMemDatabase()
database := ethdb.NewMemDatabase()
chainConfig := params.TestChainConfig
chainConfig.ChainID = big.NewInt(int64(node.Consensus.ShardID)) // Use ChainID as piggybacked ShardID
gspec := core.Genesis{

@ -4,7 +4,7 @@ import (
"math/big"
"time"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"

@ -1,16 +1,17 @@
package worker
import (
"math/big"
"math/rand"
"testing"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/db"
"math/big"
"math/rand"
"testing"
)
var (
@ -25,7 +26,7 @@ var (
func TestNewWorker(t *testing.T) {
// Setup a new blockchain with genesis block containing test token on test address
var (
database = db.NewMemDatabase()
database = ethdb.NewMemDatabase()
gspec = core.Genesis{
Config: chainConfig,
Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
@ -48,7 +49,7 @@ func TestNewWorker(t *testing.T) {
func TestCommitTransactions(t *testing.T) {
// Setup a new blockchain with genesis block containing test token on test address
var (
database = db.NewMemDatabase()
database = ethdb.NewMemDatabase()
gspec = core.Genesis{
Config: chainConfig,
Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},

@ -4,9 +4,10 @@ import (
"bufio"
"bytes"
"encoding/binary"
"github.com/harmony-one/harmony/log"
"io"
"time"
"github.com/ethereum/go-ethereum/log"
)
/*

@ -6,7 +6,7 @@ import (
"net"
"time"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/p2p"
)

@ -5,7 +5,7 @@ import (
"context"
"fmt"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/p2p"
libp2p "github.com/libp2p/go-libp2p"
libp2phost "github.com/libp2p/go-libp2p-host"

@ -3,7 +3,7 @@ package hostv2
import (
"bufio"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
)
func catchError(err error) {

@ -7,7 +7,7 @@ import (
"runtime"
"time"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/p2p"
)

@ -8,12 +8,12 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/db"
"github.com/harmony-one/harmony/node/worker"
)
@ -45,14 +45,14 @@ func init() {
}
type testWorkerBackend struct {
db db.Database
db ethdb.Database
txPool *core.TxPool
chain *core.BlockChain
}
func main() {
var (
database = db.NewMemDatabase()
database = ethdb.NewMemDatabase()
gspec = core.Genesis{
Config: chainConfig,
Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},

Loading…
Cancel
Save