From b8798c3ff5c188f3e80a593e052257ea2da29e30 Mon Sep 17 00:00:00 2001 From: Edgar Aroutiounian Date: Mon, 13 Apr 2020 12:43:09 -0700 Subject: [PATCH] [project] Dead fields, staticcheck, update deprecated libp2p usages (#2825) * [project] Dead fields, staticcheck, update deprecated libp2p usages * [project] Dead gas fild in test --- api/proto/node/node.go | 4 ++-- api/service/networkinfo/service.go | 6 ++--- core/state/journal.go | 4 +--- core/state/state_object.go | 5 +--- core/vm/contracts_test.go | 1 - core/vm/jump_table.go | 3 --- internal/genesis/genesis_test.go | 37 ------------------------------ 7 files changed, 7 insertions(+), 53 deletions(-) diff --git a/api/proto/node/node.go b/api/proto/node/node.go index 5b86dae95..6cade0946 100644 --- a/api/proto/node/node.go +++ b/api/proto/node/node.go @@ -15,7 +15,7 @@ import ( "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/staking/slash" staking "github.com/harmony-one/harmony/staking/types" - peer "github.com/libp2p/go-libp2p-peer" + libp2p_peer "github.com/libp2p/go-libp2p-core/peer" ) // MessageType is to indicate the specific type of message under Node category @@ -84,7 +84,7 @@ type Info struct { Port string PubKey []byte Role RoleType - PeerID peer.ID // Peerstore ID + PeerID libp2p_peer.ID // Peerstore ID } func (info Info) String() string { diff --git a/api/service/networkinfo/service.go b/api/service/networkinfo/service.go index 07e6ef6ca..db2d5d036 100644 --- a/api/service/networkinfo/service.go +++ b/api/service/networkinfo/service.go @@ -14,10 +14,10 @@ import ( "github.com/harmony-one/harmony/p2p" badger "github.com/ipfs/go-ds-badger" coredis "github.com/libp2p/go-libp2p-core/discovery" + libp2p_peer "github.com/libp2p/go-libp2p-core/peer" libp2pdis "github.com/libp2p/go-libp2p-discovery" libp2pdht "github.com/libp2p/go-libp2p-kad-dht" libp2pdhtopts "github.com/libp2p/go-libp2p-kad-dht/opts" - peerstore "github.com/libp2p/go-libp2p-peerstore" manet "github.com/multiformats/go-multiaddr-net" "github.com/pkg/errors" ) @@ -32,7 +32,7 @@ type Service struct { stopChan chan struct{} stoppedChan chan struct{} peerChan chan p2p.Peer - peerInfo <-chan peerstore.PeerInfo + peerInfo <-chan libp2p_peer.AddrInfo discovery *libp2pdis.RoutingDiscovery messageChan chan *msg_pb.Message started bool @@ -138,7 +138,7 @@ func (s *Service) Init() error { connected := false for _, peerAddr := range s.bootnodes { - peerinfo, _ := peerstore.InfoFromP2pAddr(peerAddr) + peerinfo, _ := libp2p_peer.AddrInfoFromP2pAddr(peerAddr) wg.Add(1) go func() { defer wg.Done() diff --git a/core/state/journal.go b/core/state/journal.go index 56392e442..4f94753c8 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -127,9 +127,7 @@ type ( hash common.Hash } touchChange struct { - account *common.Address - prev bool - prevDirty bool + account *common.Address } ) diff --git a/core/state/state_object.go b/core/state/state_object.go index a766c7e76..8edc2e373 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -397,8 +397,5 @@ func (so *Object) Value() *big.Int { // IsValidator checks whether it is a validator object func (so *Object) IsValidator(db Database) bool { value := so.GetState(db, staking.IsValidatorKey) - if value == (common.Hash{}) { - return false - } - return true + return value != (common.Hash{}) } diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 96083337c..c4c06dd89 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -27,7 +27,6 @@ import ( // precompiledTest defines the input/output pairs for precompiled contract tests. type precompiledTest struct { input, expected string - gas uint64 name string noBenchmark bool // Benchmark primarily the worst-cases } diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 4aba84fd9..ed77083f8 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -51,9 +51,6 @@ type operation struct { } var ( - frontierInstructionSet = newFrontierInstructionSet() - homesteadInstructionSet = newHomesteadInstructionSet() - byzantiumInstructionSet = newByzantiumInstructionSet() constantinopleInstructionSet = newConstantinopleInstructionSet() ) diff --git a/internal/genesis/genesis_test.go b/internal/genesis/genesis_test.go index 2eadda931..4ae5f8a42 100644 --- a/internal/genesis/genesis_test.go +++ b/internal/genesis/genesis_test.go @@ -1,9 +1,6 @@ package genesis import ( - "bufio" - "fmt" - "os" "strconv" "strings" "testing" @@ -11,7 +8,6 @@ import ( "github.com/btcsuite/btcutil/bech32" ethCommon "github.com/ethereum/go-ethereum/common" "github.com/harmony-one/bls/ffi/go/bls" - "github.com/harmony-one/harmony/internal/common" ) @@ -19,39 +15,6 @@ func TestString(t *testing.T) { _ = BeaconAccountPriKey() } -func fileToLines(filePath string) (lines []string, err error) { - f, err := os.Open(filePath) - if err != nil { - return - } - defer f.Close() - - scanner := bufio.NewScanner(f) - for scanner.Scan() { - lines = append(lines, scanner.Text()) - } - err = scanner.Err() - return -} - -func testGenesisccounts(t *testing.T) { - ones, err := fileToLines("one-acc.txt") - if err != nil { - t.Fatal("ReadFile failed", err) - } - - bls, err := fileToLines("bls-pub.txt") - if err != nil { - t.Fatal("ReadFile failed", err) - } - - index := 404 - for i, one := range ones { - fmt.Printf(" {Index: \" %v \", Address: \"%v\", BLSPublicKey: \"%v\"},\n", index, one, bls[i]) - index++ - } -} - func TestCommitteeAccounts(test *testing.T) { testAccounts(test, FoundationalNodeAccounts) testAccounts(test, FoundationalNodeAccountsV1)