Clean up unused functions (#8403)

* Clean ups

* Gazelle
This commit is contained in:
terence tsao
2021-02-05 10:39:15 -08:00
committed by GitHub
parent 4c25fe978a
commit f9303ca2e4
18 changed files with 8 additions and 213 deletions

View File

@@ -14,10 +14,6 @@ import (
"go.opencensus.io/trace"
)
// ErrTargetRootNotInDB returns when the target block root of an attestation cannot be found in the
// beacon database.
var ErrTargetRootNotInDB = errors.New("target root does not exist in db")
// onAttestation is called whenever an attestation is received, verifies the attestation is valid and saves
// it to the DB. As a stateless function, this does not hold nor delay attestation based on the spec descriptions.
// The delay is handled by the caller in `processAttestations`.

View File

@@ -466,7 +466,7 @@ func TestProcessChainStartTime_ReceivedFeed(t *testing.T) {
service.processChainStartTime(context.Background(), time.Now())
stateEvent := <-stateChannel
require.Equal(t, int(stateEvent.Type), int(statefeed.Initialized))
require.Equal(t, int(stateEvent.Type), statefeed.Initialized)
_, ok := stateEvent.Data.(*statefeed.InitializedData)
require.Equal(t, true, ok)
}

View File

@@ -396,10 +396,10 @@ func TestPeerCount(t *testing.T) {
s := Server{PeersFetcher: peerFetcher}
resp, err := s.PeerCount(context.Background(), &ptypes.Empty{})
require.NoError(t, err)
assert.Equal(t, uint64(1), uint64(resp.Data.Connecting), "Wrong number of connecting peers")
assert.Equal(t, uint64(2), uint64(resp.Data.Connected), "Wrong number of connected peers")
assert.Equal(t, uint64(3), uint64(resp.Data.Disconnecting), "Wrong number of disconnecting peers")
assert.Equal(t, uint64(4), uint64(resp.Data.Disconnected), "Wrong number of disconnected peers")
assert.Equal(t, uint64(1), resp.Data.Connecting, "Wrong number of connecting peers")
assert.Equal(t, uint64(2), resp.Data.Connected, "Wrong number of connected peers")
assert.Equal(t, uint64(3), resp.Data.Disconnecting, "Wrong number of disconnecting peers")
assert.Equal(t, uint64(4), resp.Data.Disconnected, "Wrong number of disconnected peers")
}
func BenchmarkListPeers(b *testing.B) {

View File

@@ -126,7 +126,7 @@ func TestToogleAfterOverflow(t *testing.T) {
}
// make sure overflow happened
var valueAfterToggle int32 = *(*int32)(v)
var valueAfterToggle = *(*int32)(v)
if valueAfterToggle >= valueBeforeToggle {
t.Fatalf("Overflow does not happen as expected, before %d, after: %d", valueBeforeToggle, valueAfterToggle)
}

View File

@@ -102,19 +102,3 @@ func RandKey() (common.SecretKey, error) {
}
return herumi.RandKey()
}
// VerifyCompressed signature.
func VerifyCompressed(signature, pub, msg []byte) bool {
if featureconfig.Get().EnableBlst {
return blst.VerifyCompressed(signature, pub, msg)
}
sig, err := SignatureFromBytes(signature)
if err != nil {
return false
}
pk, err := PublicKeyFromBytes(pub)
if err != nil {
return false
}
return sig.Verify(pk, msg)
}

View File

@@ -11,6 +11,3 @@ var ErrSecretUnmarshal = errors.New("could not unmarshal bytes into secret key")
// ErrInfinitePubKey describes an error due to an infinite public key.
var ErrInfinitePubKey = errors.New("received an infinite public key")
// ErrInfiniteSignature describes an error due to an infinite signature.
var ErrInfiniteSignature = errors.New("received an infinite signature")

View File

@@ -1,17 +1,7 @@
package bls
import (
"github.com/prysmaticlabs/prysm/shared/bls/common"
)
// DomainByteLength length of domain byte array.
const DomainByteLength = 4
// CurveOrder for the BLS12-381 curve.
const CurveOrder = "52435875175126190479447740508185965837690552500527637822603658699938581184513"
// ZeroSecretKey represents a zero secret key.
var ZeroSecretKey = common.ZeroSecretKey
// InfinitePublicKey represents an infinite public key.
var InfinitePublicKey = common.InfinitePublicKey

View File

@@ -1,11 +1 @@
package bls
import (
"github.com/prysmaticlabs/prysm/shared/bls/common"
)
// ErrZeroKey describes an error due to a zero secret key.
var ErrZeroKey = common.ErrZeroKey
// ErrInfinitePubKey describes an error due to an infinite public key.
var ErrInfinitePubKey = common.ErrInfinitePubKey

View File

@@ -7,21 +7,11 @@ package browser
import (
"os"
"os/exec"
"runtime"
"strings"
"github.com/google/shlex"
)
// Command produces an exec.Cmd respecting runtime.GOOS and $BROWSER environment variable
func Command(url string) (*exec.Cmd, error) {
launcher := os.Getenv("BROWSER")
if launcher != "" {
return FromLauncher(launcher, url)
}
return ForOS(runtime.GOOS, url), nil
}
// ForOS produces an exec.Cmd to open the web browser for different OS
func ForOS(goos, url string) *exec.Cmd {
exe := "open"

View File

@@ -94,15 +94,6 @@ func ToBytes32(x []byte) [32]byte {
return y
}
// ToBytes96 is a convenience method for converting a byte slice to a fix
// sized 96 byte array. This method will truncate the input if it is larger
// than 96 bytes.
func ToBytes96(x []byte) [96]byte {
var y [96]byte
copy(y[:], x)
return y
}
// ToBytes48 is a convenience method for converting a byte slice to a fix
// sized 48 byte array. This method will truncate the input if it is larger
// than 48 bytes.
@@ -142,12 +133,6 @@ func FromBool(x bool) byte {
return 0
}
// FromBytes32 is a convenience method for converting a fixed-size byte array
// to a byte slice.
func FromBytes32(x [32]byte) []byte {
return x[:]
}
// FromBytes48 is a convenience method for converting a fixed-size byte array
// to a byte slice.
func FromBytes48(x [48]byte) []byte {

View File

@@ -9,13 +9,11 @@ go_library(
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state:go_default_library",
"//contracts/deposit-contract:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bls:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
],

View File

@@ -3,12 +3,10 @@
package depositutil
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
contract "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -117,31 +115,3 @@ func VerifyDepositSignature(dd *ethpb.Deposit_Data, domain []byte) error {
}
return nil
}
// GenerateDepositTransaction uses the provided validating key and withdrawal key to
// create a transaction object for the deposit contract.
func GenerateDepositTransaction(validatingKey, withdrawalKey bls.SecretKey) (*types.Transaction, *ethpb.Deposit_Data, error) {
depositData, depositRoot, err := DepositInput(
validatingKey, withdrawalKey, params.BeaconConfig().MaxEffectiveBalance,
)
if err != nil {
return nil, nil, errors.Wrap(err, "could not generate deposit input")
}
testAcc, err := contract.Setup()
if err != nil {
return nil, nil, errors.Wrap(err, "could not load deposit contract")
}
testAcc.TxOpts.GasLimit = 1000000
tx, err := testAcc.Contract.Deposit(
testAcc.TxOpts,
depositData.PublicKey,
depositData.WithdrawalCredentials,
depositData.Signature,
depositRoot,
)
if err != nil {
return nil, nil, err
}
return tx, depositData, nil
}

View File

@@ -25,28 +25,6 @@ func ExternalIPv4() (string, error) {
return "127.0.0.1", nil
}
// ExternalIPv6 retrieves any allocated IPv6 addresses
// from the accessible network interfaces.
func ExternalIPv6() (string, error) {
ips, err := ipAddrs()
if err != nil {
return "", err
}
if len(ips) == 0 {
return "127.0.0.1", nil
}
for _, ip := range ips {
if ip.To4() != nil {
continue // not an ipv6 address
}
if ip.To16() == nil {
continue
}
return ip.String(), nil
}
return "127.0.0.1", nil
}
// ExternalIP returns the first IPv4/IPv6 available.
func ExternalIP() (string, error) {
ips, err := ipAddrs()

View File

@@ -52,15 +52,6 @@ type Keystore struct {
scryptP int
}
// New creates a new keystore from a directory.
func New(directory string) Keystore {
return Keystore{
keysDirPath: directory,
scryptN: StandardScryptN,
scryptP: StandardScryptP,
}
}
// GetKey from file using the filename path and a decryption password.
func (ks Keystore) GetKey(filename, password string) (*Key, error) {
// Load the key from the keystore and decrypt its contents

View File

@@ -1,10 +1,8 @@
package cache
import (
lru "github.com/hashicorp/golang-lru"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
)
var (
@@ -20,63 +18,3 @@ var (
Help: "The total number of cache misses on the epoch spans cache.",
})
)
// EpochSpansCache is used to store the spans needed on a per-epoch basis for slashing detection.
type EpochSpansCache struct {
cache *lru.Cache
}
// NewEpochSpansCache initializes the map and underlying cache.
func NewEpochSpansCache(size int, onEvicted func(key interface{}, value interface{})) (*EpochSpansCache, error) {
if size != 0 {
epochSpansCacheSize = size
}
cache, err := lru.NewWithEvict(epochSpansCacheSize, onEvicted)
if err != nil {
return nil, err
}
return &EpochSpansCache{cache: cache}, nil
}
// Get returns an ok bool and the cached value for the requested epoch key, if any.
func (c *EpochSpansCache) Get(epoch uint64) (map[uint64]types.Span, bool) {
item, exists := c.cache.Get(epoch)
if exists && item != nil {
epochSpansCacheHit.Inc()
return item.(map[uint64]types.Span), true
}
epochSpansCacheMiss.Inc()
return make(map[uint64]types.Span), false
}
// Set the response in the cache.
func (c *EpochSpansCache) Set(epoch uint64, epochSpans map[uint64]types.Span) {
_ = c.cache.Add(epoch, epochSpans)
}
// Delete removes an epoch from the cache and returns if it existed or not.
// Performs the onEviction function before removal.
func (c *EpochSpansCache) Delete(epoch uint64) bool {
return c.cache.Remove(epoch)
}
// PruneOldest removes the oldest key from the span cache, calling its OnEvict function.
func (c *EpochSpansCache) PruneOldest() uint64 {
if c.cache.Len() == epochSpansCacheSize {
epoch, _, _ := c.cache.RemoveOldest()
return epoch.(uint64)
}
return 0
}
// Has returns true if the key exists in the cache.
func (c *EpochSpansCache) Has(epoch uint64) bool {
return c.cache.Contains(epoch)
}
// Purge removes all keys from the SpanCache and evicts all current data.
func (c *EpochSpansCache) Purge() {
log.Info("Saving all cached data to DB, please wait for completion.")
c.cache.Purge()
}

View File

@@ -24,13 +24,3 @@ func setupDB(t testing.TB) *Store {
})
return db
}
func setupDBDiffCacheSize(t testing.TB, cacheSize int) *Store {
cfg := &Config{SpanCacheSize: cacheSize}
db, err := NewKVStore(t.TempDir(), cfg)
require.NoError(t, err, "Failed to instantiate DB")
t.Cleanup(func() {
require.NoError(t, db.Close(), "Failed to close database")
})
return db
}

View File

@@ -13,8 +13,6 @@ import (
logTest "github.com/sirupsen/logrus/hooks/test"
)
var walletPassword = "OhWOWthisisatest42!$"
func cancelledContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
cancel()

View File

@@ -10,8 +10,8 @@ type migration func(*bolt.Tx) error
var (
migrationCompleted = []byte("done")
upMigrations = []migration{}
downMigrations = []migration{}
upMigrations []migration
downMigrations []migration
)
// RunUpMigrations defined in the upMigrations list.