mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 22:07:59 -05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f8d9c59dd | ||
|
|
021d777b5e | ||
|
|
dc3fb018fe | ||
|
|
2ab4b86f9b | ||
|
|
b30a089548 | ||
|
|
271938202e | ||
|
|
6fe814c5aa | ||
|
|
a9f4d1d02d | ||
|
|
7c110e54f0 |
64
WORKSPACE
64
WORKSPACE
@@ -292,12 +292,10 @@ go_repository(
|
||||
name = "com_github_prysmaticlabs_go_ssz",
|
||||
commit = "e24db4d9e9637cf88ee9e4a779e339a1686a84ee",
|
||||
importpath = "github.com/prysmaticlabs/go-ssz",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_urfave_cli",
|
||||
commit = "e6cf83ec39f6e1158ced1927d4ed14578fda8edb", # v1.21.0
|
||||
importpath = "github.com/urfave/cli",
|
||||
patch_args = ["-p1"],
|
||||
patches = [
|
||||
"//third_party:com_github_prysmaticlabs_go_ssz.patch",
|
||||
],
|
||||
)
|
||||
|
||||
go_repository(
|
||||
@@ -1296,7 +1294,7 @@ go_repository(
|
||||
|
||||
go_repository(
|
||||
name = "com_github_prysmaticlabs_ethereumapis",
|
||||
commit = "fca4d6f69bedb8615c2fc916d1a68f2692285caa",
|
||||
commit = "25f267e475788bf8e5e01cb9d73cfd0c87020822",
|
||||
importpath = "github.com/prysmaticlabs/ethereumapis",
|
||||
patch_args = ["-p1"],
|
||||
patches = [
|
||||
@@ -1375,13 +1373,6 @@ go_repository(
|
||||
version = "v0.10.5",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "in_gopkg_urfave_cli_v1",
|
||||
importpath = "gopkg.in/urfave/cli.v1",
|
||||
sum = "h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=",
|
||||
version = "v1.20.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_naoina_go_stringutil",
|
||||
importpath = "github.com/naoina/go-stringutil",
|
||||
@@ -1598,7 +1589,48 @@ go_repository(
|
||||
|
||||
go_repository(
|
||||
name = "com_github_ferranbt_fastssz",
|
||||
commit = "06015a5d84f9e4eefe2c21377ca678fa8f1a1b09",
|
||||
importpath = "github.com/ferranbt/fastssz",
|
||||
sum = "h1:oUQredbOIzWIMmeGR9dTLzSi4DqRVwxrPzSDiLJBp4Q=",
|
||||
version = "v0.0.0-20200310214500-3283b9706406",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_burntsushi_toml",
|
||||
importpath = "github.com/BurntSushi/toml",
|
||||
sum = "h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=",
|
||||
version = "v0.3.1",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_cpuguy83_go_md2man_v2",
|
||||
importpath = "github.com/cpuguy83/go-md2man/v2",
|
||||
sum = "h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=",
|
||||
version = "v2.0.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_russross_blackfriday_v2",
|
||||
importpath = "github.com/russross/blackfriday/v2",
|
||||
sum = "h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=",
|
||||
version = "v2.0.1",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_shurcool_sanitized_anchor_name",
|
||||
importpath = "github.com/shurcooL/sanitized_anchor_name",
|
||||
sum = "h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=",
|
||||
version = "v1.0.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "in_gopkg_urfave_cli_v2",
|
||||
importpath = "gopkg.in/urfave/cli.v2",
|
||||
sum = "h1:OvXt/p4cdwNl+mwcWMq/AxaKFkhdxcjx+tx+qf4EOvY=",
|
||||
version = "v2.0.0-20190806201727-b62605953717",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "in_gopkg_urfave_cli_v1",
|
||||
importpath = "gopkg.in/urfave/cli.v1",
|
||||
sum = "h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=",
|
||||
version = "v1.20.0",
|
||||
)
|
||||
|
||||
@@ -23,9 +23,10 @@ go_library(
|
||||
"@com_github_ipfs_go_log//:go_default_library",
|
||||
"@com_github_joonix_log//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_whyrusleeping_go_logging//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//altsrc:go_default_library",
|
||||
"@org_uber_go_automaxprocs//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -55,9 +56,10 @@ go_image(
|
||||
"@com_github_ipfs_go_log//:go_default_library",
|
||||
"@com_github_joonix_log//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_whyrusleeping_go_logging//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//altsrc:go_default_library",
|
||||
"@org_uber_go_automaxprocs//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -111,7 +113,10 @@ go_test(
|
||||
size = "small",
|
||||
srcs = ["usage_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["@com_github_urfave_cli//:go_default_library"],
|
||||
deps = [
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
[go_binary(
|
||||
|
||||
@@ -135,10 +135,18 @@ func (s *Service) Start() {
|
||||
if err != nil {
|
||||
log.Fatalf("Could not fetch finalized cp: %v", err)
|
||||
}
|
||||
|
||||
if beaconState == nil {
|
||||
beaconState, err = s.beaconDB.State(ctx, bytesutil.ToBytes32(cp.Root))
|
||||
if err != nil {
|
||||
log.Fatalf("Could not fetch beacon state: %v", err)
|
||||
if featureconfig.Get().NewStateMgmt {
|
||||
beaconState, err = s.stateGen.StateByRoot(ctx, bytesutil.ToBytes32(cp.Root))
|
||||
if err != nil {
|
||||
log.Fatalf("Could not fetch beacon state: %v", err)
|
||||
}
|
||||
} else {
|
||||
beaconState, err = s.beaconDB.State(ctx, bytesutil.ToBytes32(cp.Root))
|
||||
if err != nil {
|
||||
log.Fatalf("Could not fetch beacon state: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +443,6 @@ func (s *Service) initializeChainInfo(ctx context.Context) error {
|
||||
if finalizedState == nil || finalizedBlock == nil {
|
||||
return errors.New("finalized state and block can't be nil")
|
||||
}
|
||||
|
||||
s.setHead(finalizedRoot, finalizedBlock, finalizedState)
|
||||
|
||||
return nil
|
||||
|
||||
2
beacon-chain/cache/committee.go
vendored
2
beacon-chain/cache/committee.go
vendored
@@ -96,7 +96,7 @@ func (c *CommitteeCache) Committee(slot uint64, seed [32]byte, index uint64) ([]
|
||||
indexOffSet := index + (slot%params.BeaconConfig().SlotsPerEpoch)*committeeCountPerSlot
|
||||
start, end := startEndIndices(item, indexOffSet)
|
||||
|
||||
if int(end) > len(item.ShuffledIndices) {
|
||||
if int(end) > len(item.ShuffledIndices) || end < start {
|
||||
return nil, errors.New("requested index out of bound")
|
||||
}
|
||||
|
||||
|
||||
17
beacon-chain/cache/committee_test.go
vendored
17
beacon-chain/cache/committee_test.go
vendored
@@ -1,6 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -172,3 +173,19 @@ func TestCommitteeCache_CanRotate(t *testing.T) {
|
||||
t.Error("incorrect key received for slot 199")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitteeCacheOutOfRange(t *testing.T) {
|
||||
cache := NewCommitteesCache()
|
||||
seed := bytesutil.ToBytes32([]byte("foo"))
|
||||
cache.CommitteeCache.Add(&Committees{
|
||||
CommitteeCount: 1,
|
||||
Seed: seed,
|
||||
ShuffledIndices: []uint64{0},
|
||||
SortedIndices: []uint64{},
|
||||
ProposerIndices: []uint64{},
|
||||
})
|
||||
_, err := cache.Committee(0, seed, math.MaxUint64) // Overflow!
|
||||
if err == nil {
|
||||
t.Fatal("Did not fail as expected")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ go_test(
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -68,8 +68,8 @@ go_test(
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,6 +13,6 @@ go_library(
|
||||
deps = [
|
||||
"//shared/cmd:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// ArchiveEnableFlag defines whether or not the beacon chain should archive
|
||||
// historical blocks, attestations, and validator set changes.
|
||||
ArchiveEnableFlag = cli.BoolFlag{
|
||||
ArchiveEnableFlag = &cli.BoolFlag{
|
||||
Name: "archive",
|
||||
Usage: "Whether or not beacon chain should archive historical data including blocks, attestations, and validator set changes",
|
||||
}
|
||||
// ArchiveValidatorSetChangesFlag defines whether or not the beacon chain should archive
|
||||
// historical validator set changes in persistent storage.
|
||||
ArchiveValidatorSetChangesFlag = cli.BoolFlag{
|
||||
ArchiveValidatorSetChangesFlag = &cli.BoolFlag{
|
||||
Name: "archive-validator-set-changes",
|
||||
Usage: "Whether or not beacon chain should archive historical validator set changes",
|
||||
}
|
||||
// ArchiveBlocksFlag defines whether or not the beacon chain should archive
|
||||
// historical block data in persistent storage.
|
||||
ArchiveBlocksFlag = cli.BoolFlag{
|
||||
ArchiveBlocksFlag = &cli.BoolFlag{
|
||||
Name: "archive-blocks",
|
||||
Usage: "Whether or not beacon chain should archive historical blocks",
|
||||
}
|
||||
// ArchiveAttestationsFlag defines whether or not the beacon chain should archive
|
||||
// historical attestation data in persistent storage.
|
||||
ArchiveAttestationsFlag = cli.BoolFlag{
|
||||
ArchiveAttestationsFlag = &cli.BoolFlag{
|
||||
Name: "archive-attestations",
|
||||
Usage: "Whether or not beacon chain should archive historical blocks",
|
||||
}
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// HTTPWeb3ProviderFlag provides an HTTP access endpoint to an ETH 1.0 RPC.
|
||||
HTTPWeb3ProviderFlag = cli.StringFlag{
|
||||
HTTPWeb3ProviderFlag = &cli.StringFlag{
|
||||
Name: "http-web3provider",
|
||||
Usage: "A mainchain web3 provider string http endpoint",
|
||||
Value: "https://goerli.prylabs.net",
|
||||
}
|
||||
// Web3ProviderFlag defines a flag for a mainchain RPC endpoint.
|
||||
Web3ProviderFlag = cli.StringFlag{
|
||||
Web3ProviderFlag = &cli.StringFlag{
|
||||
Name: "web3provider",
|
||||
Usage: "A mainchain web3 provider string endpoint. Can either be an IPC file string or a WebSocket endpoint. Cannot be an HTTP endpoint.",
|
||||
Value: "wss://goerli.prylabs.net/websocket",
|
||||
}
|
||||
// DepositContractFlag defines a flag for the deposit contract address.
|
||||
DepositContractFlag = cli.StringFlag{
|
||||
DepositContractFlag = &cli.StringFlag{
|
||||
Name: "deposit-contract",
|
||||
Usage: "Deposit contract address. Beacon chain node will listen logs coming from the deposit contract to determine when validator is eligible to participate.",
|
||||
Value: "0x4689a3C63CE249355C8a573B5974db21D2d1b8Ef",
|
||||
}
|
||||
// RPCHost defines the host on which the RPC server should listen.
|
||||
RPCHost = cli.StringFlag{
|
||||
RPCHost = &cli.StringFlag{
|
||||
Name: "rpc-host",
|
||||
Usage: "Host on which the RPC server should listen",
|
||||
Value: "0.0.0.0",
|
||||
}
|
||||
// RPCPort defines a beacon node RPC port to open.
|
||||
RPCPort = cli.IntFlag{
|
||||
RPCPort = &cli.IntFlag{
|
||||
Name: "rpc-port",
|
||||
Usage: "RPC port exposed by a beacon node",
|
||||
Value: 4000,
|
||||
}
|
||||
// RPCMaxPageSize defines the maximum numbers per page returned in RPC responses from this
|
||||
// beacon node (default: 500).
|
||||
RPCMaxPageSize = cli.IntFlag{
|
||||
RPCMaxPageSize = &cli.IntFlag{
|
||||
Name: "rpc-max-page-size",
|
||||
Usage: "Max number of items returned per page in RPC responses for paginated endpoints (default: 500)",
|
||||
Usage: "Max number of items returned per page in RPC responses for paginated endpoints.",
|
||||
Value: 500,
|
||||
}
|
||||
// CertFlag defines a flag for the node's TLS certificate.
|
||||
CertFlag = cli.StringFlag{
|
||||
CertFlag = &cli.StringFlag{
|
||||
Name: "tls-cert",
|
||||
Usage: "Certificate for secure gRPC. Pass this and the tls-key flag in order to use gRPC securely.",
|
||||
}
|
||||
// KeyFlag defines a flag for the node's TLS key.
|
||||
KeyFlag = cli.StringFlag{
|
||||
KeyFlag = &cli.StringFlag{
|
||||
Name: "tls-key",
|
||||
Usage: "Key for secure gRPC. Pass this and the tls-cert flag in order to use gRPC securely.",
|
||||
}
|
||||
// GRPCGatewayPort enables a gRPC gateway to be exposed for Prysm.
|
||||
GRPCGatewayPort = cli.IntFlag{
|
||||
GRPCGatewayPort = &cli.IntFlag{
|
||||
Name: "grpc-gateway-port",
|
||||
Usage: "Enable gRPC gateway for JSON requests",
|
||||
}
|
||||
// MinSyncPeers specifies the required number of successful peer handshakes in order
|
||||
// to start syncing with external peers.
|
||||
MinSyncPeers = cli.IntFlag{
|
||||
MinSyncPeers = &cli.IntFlag{
|
||||
Name: "min-sync-peers",
|
||||
Usage: "The required number of valid peers to connect with before syncing.",
|
||||
Value: 3,
|
||||
}
|
||||
// ContractDeploymentBlock is the block in which the eth1 deposit contract was deployed.
|
||||
ContractDeploymentBlock = cli.IntFlag{
|
||||
ContractDeploymentBlock = &cli.IntFlag{
|
||||
Name: "contract-deployment-block",
|
||||
Usage: "The eth1 block in which the deposit contract was deployed.",
|
||||
Value: 1960177,
|
||||
}
|
||||
// SetGCPercent is the percentage of current live allocations at which the garbage collector is to run.
|
||||
SetGCPercent = cli.IntFlag{
|
||||
SetGCPercent = &cli.IntFlag{
|
||||
Name: "gc-percent",
|
||||
Usage: "The percentage of freshly allocated data to live data on which the gc will be run again.",
|
||||
Value: 100,
|
||||
}
|
||||
// UnsafeSync starts the beacon node from the previously saved head state and syncs from there.
|
||||
UnsafeSync = cli.BoolFlag{
|
||||
UnsafeSync = &cli.BoolFlag{
|
||||
Name: "unsafe-sync",
|
||||
Usage: "Starts the beacon node with the previously saved head state instead of finalized state.",
|
||||
}
|
||||
// SlasherCertFlag defines a flag for the slasher TLS certificate.
|
||||
SlasherCertFlag = cli.StringFlag{
|
||||
SlasherCertFlag = &cli.StringFlag{
|
||||
Name: "slasher-tls-cert",
|
||||
Usage: "Certificate for secure slasher gRPC connection. Pass this in order to use slasher gRPC securely.",
|
||||
}
|
||||
// SlasherProviderFlag defines a flag for a slasher RPC provider.
|
||||
SlasherProviderFlag = cli.StringFlag{
|
||||
SlasherProviderFlag = &cli.StringFlag{
|
||||
Name: "slasher-provider",
|
||||
Usage: "A slasher provider string endpoint. Can either be an grpc server endpoint.",
|
||||
Value: "127.0.0.1:5000",
|
||||
}
|
||||
// SlotsPerArchivedPoint specifies the number of slots between the archived points, to save beacon state in the cold
|
||||
// section of DB.
|
||||
SlotsPerArchivedPoint = cli.IntFlag{
|
||||
SlotsPerArchivedPoint = &cli.IntFlag{
|
||||
Name: "slots-per-archive-point",
|
||||
Usage: "The slot durations of when an archived state gets saved in the DB.",
|
||||
Value: 128,
|
||||
|
||||
@@ -3,7 +3,7 @@ package flags
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// GlobalFlags specifies all the global flags for the
|
||||
@@ -38,31 +38,31 @@ func Init(c *GlobalFlags) {
|
||||
// based on the provided cli context.
|
||||
func ConfigureGlobalFlags(ctx *cli.Context) {
|
||||
cfg := &GlobalFlags{}
|
||||
if ctx.GlobalBool(ArchiveEnableFlag.Name) {
|
||||
if ctx.Bool(ArchiveEnableFlag.Name) {
|
||||
cfg.EnableArchive = true
|
||||
}
|
||||
if ctx.GlobalBool(ArchiveValidatorSetChangesFlag.Name) {
|
||||
if ctx.Bool(ArchiveValidatorSetChangesFlag.Name) {
|
||||
cfg.EnableArchivedValidatorSetChanges = true
|
||||
}
|
||||
if ctx.GlobalBool(ArchiveBlocksFlag.Name) {
|
||||
if ctx.Bool(ArchiveBlocksFlag.Name) {
|
||||
cfg.EnableArchivedBlocks = true
|
||||
}
|
||||
if ctx.GlobalBool(ArchiveAttestationsFlag.Name) {
|
||||
if ctx.Bool(ArchiveAttestationsFlag.Name) {
|
||||
cfg.EnableArchivedAttestations = true
|
||||
}
|
||||
if ctx.GlobalBool(UnsafeSync.Name) {
|
||||
if ctx.Bool(UnsafeSync.Name) {
|
||||
cfg.UnsafeSync = true
|
||||
}
|
||||
cfg.MaxPageSize = ctx.GlobalInt(RPCMaxPageSize.Name)
|
||||
cfg.DeploymentBlock = ctx.GlobalInt(ContractDeploymentBlock.Name)
|
||||
cfg.MaxPageSize = ctx.Int(RPCMaxPageSize.Name)
|
||||
cfg.DeploymentBlock = ctx.Int(ContractDeploymentBlock.Name)
|
||||
configureMinimumPeers(ctx, cfg)
|
||||
|
||||
Init(cfg)
|
||||
}
|
||||
|
||||
func configureMinimumPeers(ctx *cli.Context, cfg *GlobalFlags) {
|
||||
cfg.MinimumSyncPeers = ctx.GlobalInt(MinSyncPeers.Name)
|
||||
maxPeers := int(ctx.GlobalInt64(cmd.P2PMaxPeers.Name))
|
||||
cfg.MinimumSyncPeers = ctx.Int(MinSyncPeers.Name)
|
||||
maxPeers := int(ctx.Int64(cmd.P2PMaxPeers.Name))
|
||||
if cfg.MinimumSyncPeers > maxPeers {
|
||||
log.Warnf("Changing Minimum Sync Peers to %d", maxPeers)
|
||||
cfg.MinimumSyncPeers = maxPeers
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// InteropGenesisStateFlag defines a flag for the beacon node to load genesis state via file.
|
||||
InteropGenesisStateFlag = cli.StringFlag{
|
||||
InteropGenesisStateFlag = &cli.StringFlag{
|
||||
Name: "interop-genesis-state",
|
||||
Usage: "The genesis state file (.SSZ) to load from",
|
||||
}
|
||||
// InteropMockEth1DataVotesFlag enables mocking the eth1 proof-of-work chain data put into blocks by proposers.
|
||||
InteropMockEth1DataVotesFlag = cli.BoolFlag{
|
||||
InteropMockEth1DataVotesFlag = &cli.BoolFlag{
|
||||
Name: "interop-eth1data-votes",
|
||||
Usage: "Enable mocking of eth1 data votes for proposers to package into blocks",
|
||||
}
|
||||
|
||||
// InteropGenesisTimeFlag specifies genesis time for state generation.
|
||||
InteropGenesisTimeFlag = cli.Uint64Flag{
|
||||
InteropGenesisTimeFlag = &cli.Uint64Flag{
|
||||
Name: "interop-genesis-time",
|
||||
Usage: "Specify the genesis time for interop genesis state generation. Must be used with " +
|
||||
"--interop-num-validators",
|
||||
}
|
||||
// InteropNumValidatorsFlag specifies number of genesis validators for state generation.
|
||||
InteropNumValidatorsFlag = cli.Uint64Flag{
|
||||
InteropNumValidatorsFlag = &cli.Uint64Flag{
|
||||
Name: "interop-num-validators",
|
||||
Usage: "Specify number of genesis validators to generate for interop. Must be used with --interop-genesis-time",
|
||||
}
|
||||
|
||||
@@ -17,10 +17,11 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/logutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
gologging "github.com/whyrusleeping/go-logging"
|
||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||||
_ "go.uber.org/automaxprocs"
|
||||
"gopkg.in/urfave/cli.v2/altsrc"
|
||||
)
|
||||
|
||||
var appFlags = []cli.Flag{
|
||||
@@ -79,15 +80,16 @@ var appFlags = []cli.Flag{
|
||||
debug.TraceFlag,
|
||||
cmd.LogFileName,
|
||||
cmd.EnableUPnPFlag,
|
||||
cmd.ConfigFileFlag,
|
||||
}
|
||||
|
||||
func init() {
|
||||
appFlags = append(appFlags, featureconfig.BeaconChainFlags...)
|
||||
appFlags = cmd.WrapFlags(append(appFlags, featureconfig.BeaconChainFlags...))
|
||||
}
|
||||
|
||||
func main() {
|
||||
log := logrus.WithField("prefix", "main")
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
app.Name = "beacon-chain"
|
||||
app.Usage = "this is a beacon chain implementation for Ethereum 2.0"
|
||||
app.Action = startNode
|
||||
@@ -96,7 +98,14 @@ func main() {
|
||||
app.Flags = appFlags
|
||||
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
format := ctx.GlobalString(cmd.LogFormat.Name)
|
||||
// Load any flags from file, if specified.
|
||||
if ctx.IsSet(cmd.ConfigFileFlag.Name) {
|
||||
if err := altsrc.InitInputSourceWithContext(appFlags, altsrc.NewYamlSourceFromFlagFunc(cmd.ConfigFileFlag.Name))(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
format := ctx.String(cmd.LogFormat.Name)
|
||||
switch format {
|
||||
case "text":
|
||||
formatter := new(prefixed.TextFormatter)
|
||||
@@ -104,7 +113,7 @@ func main() {
|
||||
formatter.FullTimestamp = true
|
||||
// If persistent log files are written - we disable the log messages coloring because
|
||||
// the colors are ANSI codes and seen as gibberish in the log files.
|
||||
formatter.DisableColors = ctx.GlobalString(cmd.LogFileName.Name) != ""
|
||||
formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != ""
|
||||
logrus.SetFormatter(formatter)
|
||||
break
|
||||
case "fluentd":
|
||||
@@ -121,7 +130,7 @@ func main() {
|
||||
return fmt.Errorf("unknown log format %s", format)
|
||||
}
|
||||
|
||||
logFileName := ctx.GlobalString(cmd.LogFileName.Name)
|
||||
logFileName := ctx.String(cmd.LogFileName.Name)
|
||||
if logFileName != "" {
|
||||
if err := logutil.ConfigurePersistentLogging(logFileName); err != nil {
|
||||
log.WithError(err).Error("Failed to configuring logging to disk.")
|
||||
@@ -129,7 +138,7 @@ func main() {
|
||||
}
|
||||
|
||||
if ctx.IsSet(flags.SetGCPercent.Name) {
|
||||
runtimeDebug.SetGCPercent(ctx.GlobalInt(flags.SetGCPercent.Name))
|
||||
runtimeDebug.SetGCPercent(ctx.Int(flags.SetGCPercent.Name))
|
||||
}
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
return debug.Setup(ctx)
|
||||
@@ -149,7 +158,7 @@ func main() {
|
||||
}
|
||||
|
||||
func startNode(ctx *cli.Context) error {
|
||||
verbosity := ctx.GlobalString(cmd.VerbosityFlag.Name)
|
||||
verbosity := ctx.String(cmd.VerbosityFlag.Name)
|
||||
level, err := logrus.ParseLevel(verbosity)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -38,7 +38,7 @@ go_library(
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -51,6 +51,6 @@ go_test(
|
||||
"//beacon-chain/core/feed/state:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -46,7 +46,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/tracing"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "node")
|
||||
@@ -79,10 +79,10 @@ type BeaconNode struct {
|
||||
func NewBeaconNode(ctx *cli.Context) (*BeaconNode, error) {
|
||||
if err := tracing.Setup(
|
||||
"beacon-chain", // service name
|
||||
ctx.GlobalString(cmd.TracingProcessNameFlag.Name),
|
||||
ctx.GlobalString(cmd.TracingEndpointFlag.Name),
|
||||
ctx.GlobalFloat64(cmd.TraceSampleFractionFlag.Name),
|
||||
ctx.GlobalBool(cmd.EnableTracingFlag.Name),
|
||||
ctx.String(cmd.TracingProcessNameFlag.Name),
|
||||
ctx.String(cmd.TracingEndpointFlag.Name),
|
||||
ctx.Float64(cmd.TraceSampleFractionFlag.Name),
|
||||
ctx.Bool(cmd.EnableTracingFlag.Name),
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func NewBeaconNode(ctx *cli.Context) (*BeaconNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !ctx.GlobalBool(cmd.DisableMonitoringFlag.Name) {
|
||||
if !ctx.Bool(cmd.DisableMonitoringFlag.Name) {
|
||||
if err := beacon.registerPrometheusService(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -228,10 +228,10 @@ func (b *BeaconNode) startForkChoice() {
|
||||
}
|
||||
|
||||
func (b *BeaconNode) startDB(ctx *cli.Context) error {
|
||||
baseDir := ctx.GlobalString(cmd.DataDirFlag.Name)
|
||||
baseDir := ctx.String(cmd.DataDirFlag.Name)
|
||||
dbPath := path.Join(baseDir, beaconChainDBName)
|
||||
clearDB := ctx.GlobalBool(cmd.ClearDB.Name)
|
||||
forceClearDB := ctx.GlobalBool(cmd.ForceClearDB.Name)
|
||||
clearDB := ctx.Bool(cmd.ClearDB.Name)
|
||||
forceClearDB := ctx.Bool(cmd.ForceClearDB.Name)
|
||||
|
||||
d, err := db.NewDB(dbPath)
|
||||
if err != nil {
|
||||
@@ -269,7 +269,7 @@ func (b *BeaconNode) startStateGen() {
|
||||
|
||||
func (b *BeaconNode) registerP2P(ctx *cli.Context) error {
|
||||
// Bootnode ENR may be a filepath to an ENR file.
|
||||
bootnodeAddrs := strings.Split(ctx.GlobalString(cmd.BootstrapNode.Name), ",")
|
||||
bootnodeAddrs := strings.Split(ctx.String(cmd.BootstrapNode.Name), ",")
|
||||
for i, addr := range bootnodeAddrs {
|
||||
if filepath.Ext(addr) == ".enr" {
|
||||
b, err := ioutil.ReadFile(addr)
|
||||
@@ -280,22 +280,27 @@ func (b *BeaconNode) registerP2P(ctx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
datadir := ctx.String(cmd.DataDirFlag.Name)
|
||||
if datadir == "" {
|
||||
datadir = cmd.DefaultDataDir()
|
||||
}
|
||||
|
||||
svc, err := p2p.NewService(&p2p.Config{
|
||||
NoDiscovery: ctx.GlobalBool(cmd.NoDiscovery.Name),
|
||||
StaticPeers: sliceutil.SplitCommaSeparated(ctx.GlobalStringSlice(cmd.StaticPeers.Name)),
|
||||
NoDiscovery: ctx.Bool(cmd.NoDiscovery.Name),
|
||||
StaticPeers: sliceutil.SplitCommaSeparated(ctx.StringSlice(cmd.StaticPeers.Name)),
|
||||
BootstrapNodeAddr: bootnodeAddrs,
|
||||
RelayNodeAddr: ctx.GlobalString(cmd.RelayNode.Name),
|
||||
DataDir: ctx.GlobalString(cmd.DataDirFlag.Name),
|
||||
LocalIP: ctx.GlobalString(cmd.P2PIP.Name),
|
||||
HostAddress: ctx.GlobalString(cmd.P2PHost.Name),
|
||||
HostDNS: ctx.GlobalString(cmd.P2PHostDNS.Name),
|
||||
PrivateKey: ctx.GlobalString(cmd.P2PPrivKey.Name),
|
||||
TCPPort: ctx.GlobalUint(cmd.P2PTCPPort.Name),
|
||||
UDPPort: ctx.GlobalUint(cmd.P2PUDPPort.Name),
|
||||
MaxPeers: ctx.GlobalUint(cmd.P2PMaxPeers.Name),
|
||||
WhitelistCIDR: ctx.GlobalString(cmd.P2PWhitelist.Name),
|
||||
EnableUPnP: ctx.GlobalBool(cmd.EnableUPnPFlag.Name),
|
||||
Encoding: ctx.GlobalString(cmd.P2PEncoding.Name),
|
||||
RelayNodeAddr: ctx.String(cmd.RelayNode.Name),
|
||||
DataDir: datadir,
|
||||
LocalIP: ctx.String(cmd.P2PIP.Name),
|
||||
HostAddress: ctx.String(cmd.P2PHost.Name),
|
||||
HostDNS: ctx.String(cmd.P2PHostDNS.Name),
|
||||
PrivateKey: ctx.String(cmd.P2PPrivKey.Name),
|
||||
TCPPort: ctx.Uint(cmd.P2PTCPPort.Name),
|
||||
UDPPort: ctx.Uint(cmd.P2PUDPPort.Name),
|
||||
MaxPeers: ctx.Uint(cmd.P2PMaxPeers.Name),
|
||||
WhitelistCIDR: ctx.String(cmd.P2PWhitelist.Name),
|
||||
EnableUPnP: ctx.Bool(cmd.EnableUPnPFlag.Name),
|
||||
Encoding: ctx.String(cmd.P2PEncoding.Name),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -332,7 +337,7 @@ func (b *BeaconNode) registerBlockchainService(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
maxRoutines := ctx.GlobalInt64(cmd.MaxGoroutines.Name)
|
||||
maxRoutines := ctx.Int64(cmd.MaxGoroutines.Name)
|
||||
blockchainService, err := blockchain.NewService(context.Background(), &blockchain.Config{
|
||||
BeaconDB: b.db,
|
||||
DepositCache: b.depositCache,
|
||||
@@ -354,10 +359,10 @@ func (b *BeaconNode) registerBlockchainService(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
func (b *BeaconNode) registerPOWChainService(cliCtx *cli.Context) error {
|
||||
if cliCtx.GlobalBool(testSkipPowFlag) {
|
||||
if cliCtx.Bool(testSkipPowFlag) {
|
||||
return b.services.RegisterService(&powchain.Service{})
|
||||
}
|
||||
depAddress := cliCtx.GlobalString(flags.DepositContractFlag.Name)
|
||||
depAddress := cliCtx.String(flags.DepositContractFlag.Name)
|
||||
if depAddress == "" {
|
||||
log.Fatal(fmt.Sprintf("%s is required", flags.DepositContractFlag.Name))
|
||||
}
|
||||
@@ -368,8 +373,8 @@ func (b *BeaconNode) registerPOWChainService(cliCtx *cli.Context) error {
|
||||
|
||||
ctx := context.Background()
|
||||
cfg := &powchain.Web3ServiceConfig{
|
||||
ETH1Endpoint: cliCtx.GlobalString(flags.Web3ProviderFlag.Name),
|
||||
HTTPEndPoint: cliCtx.GlobalString(flags.HTTPWeb3ProviderFlag.Name),
|
||||
ETH1Endpoint: cliCtx.String(flags.Web3ProviderFlag.Name),
|
||||
HTTPEndPoint: cliCtx.String(flags.HTTPWeb3ProviderFlag.Name),
|
||||
DepositContract: common.HexToAddress(depAddress),
|
||||
BeaconDB: b.db,
|
||||
DepositCache: b.depositCache,
|
||||
@@ -489,8 +494,8 @@ func (b *BeaconNode) registerRPCService(ctx *cli.Context) error {
|
||||
syncService = initSyncTmp
|
||||
}
|
||||
|
||||
genesisValidators := ctx.GlobalUint64(flags.InteropNumValidatorsFlag.Name)
|
||||
genesisStatePath := ctx.GlobalString(flags.InteropGenesisStateFlag.Name)
|
||||
genesisValidators := ctx.Uint64(flags.InteropNumValidatorsFlag.Name)
|
||||
genesisStatePath := ctx.String(flags.InteropGenesisStateFlag.Name)
|
||||
var depositFetcher depositcache.DepositFetcher
|
||||
var chainStartFetcher powchain.ChainStartFetcher
|
||||
if genesisValidators > 0 || genesisStatePath != "" {
|
||||
@@ -505,14 +510,14 @@ func (b *BeaconNode) registerRPCService(ctx *cli.Context) error {
|
||||
chainStartFetcher = web3Service
|
||||
}
|
||||
|
||||
host := ctx.GlobalString(flags.RPCHost.Name)
|
||||
port := ctx.GlobalString(flags.RPCPort.Name)
|
||||
cert := ctx.GlobalString(flags.CertFlag.Name)
|
||||
key := ctx.GlobalString(flags.KeyFlag.Name)
|
||||
slasherCert := ctx.GlobalString(flags.SlasherCertFlag.Name)
|
||||
slasherProvider := ctx.GlobalString(flags.SlasherProviderFlag.Name)
|
||||
host := ctx.String(flags.RPCHost.Name)
|
||||
port := ctx.String(flags.RPCPort.Name)
|
||||
cert := ctx.String(flags.CertFlag.Name)
|
||||
key := ctx.String(flags.KeyFlag.Name)
|
||||
slasherCert := ctx.String(flags.SlasherCertFlag.Name)
|
||||
slasherProvider := ctx.String(flags.SlasherProviderFlag.Name)
|
||||
|
||||
mockEth1DataVotes := ctx.GlobalBool(flags.InteropMockEth1DataVotesFlag.Name)
|
||||
mockEth1DataVotes := ctx.Bool(flags.InteropMockEth1DataVotesFlag.Name)
|
||||
rpcService := rpc.NewService(context.Background(), &rpc.Config{
|
||||
Host: host,
|
||||
Port: port,
|
||||
@@ -568,7 +573,7 @@ func (b *BeaconNode) registerPrometheusService(ctx *cli.Context) error {
|
||||
additionalHandlers = append(additionalHandlers, prometheus.Handler{Path: "/tree", Handler: c.TreeHandler})
|
||||
|
||||
service := prometheus.NewPrometheusService(
|
||||
fmt.Sprintf(":%d", ctx.GlobalInt64(cmd.MonitoringPortFlag.Name)),
|
||||
fmt.Sprintf(":%d", ctx.Int64(cmd.MonitoringPortFlag.Name)),
|
||||
b.services,
|
||||
additionalHandlers...,
|
||||
)
|
||||
@@ -578,9 +583,9 @@ func (b *BeaconNode) registerPrometheusService(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
func (b *BeaconNode) registerGRPCGateway(ctx *cli.Context) error {
|
||||
gatewayPort := ctx.GlobalInt(flags.GRPCGatewayPort.Name)
|
||||
gatewayPort := ctx.Int(flags.GRPCGatewayPort.Name)
|
||||
if gatewayPort > 0 {
|
||||
selfAddress := fmt.Sprintf("127.0.0.1:%d", ctx.GlobalInt(flags.RPCPort.Name))
|
||||
selfAddress := fmt.Sprintf("127.0.0.1:%d", ctx.Int(flags.RPCPort.Name))
|
||||
gatewayAddress := fmt.Sprintf("0.0.0.0:%d", gatewayPort)
|
||||
return b.services.RegisterService(gateway.New(context.Background(), selfAddress, gatewayAddress, nil /*optional mux*/))
|
||||
}
|
||||
@@ -588,9 +593,9 @@ func (b *BeaconNode) registerGRPCGateway(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
func (b *BeaconNode) registerInteropServices(ctx *cli.Context) error {
|
||||
genesisTime := ctx.GlobalUint64(flags.InteropGenesisTimeFlag.Name)
|
||||
genesisValidators := ctx.GlobalUint64(flags.InteropNumValidatorsFlag.Name)
|
||||
genesisStatePath := ctx.GlobalString(flags.InteropGenesisStateFlag.Name)
|
||||
genesisTime := ctx.Uint64(flags.InteropGenesisTimeFlag.Name)
|
||||
genesisValidators := ctx.Uint64(flags.InteropNumValidatorsFlag.Name)
|
||||
genesisStatePath := ctx.String(flags.InteropGenesisStateFlag.Name)
|
||||
|
||||
if genesisValidators > 0 || genesisStatePath != "" {
|
||||
svc := interopcoldstart.NewColdStartService(context.Background(), &interopcoldstart.Config{
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// Ensure BeaconNode implements interfaces.
|
||||
@@ -22,7 +22,7 @@ func TestNodeClose_OK(t *testing.T) {
|
||||
tmp := fmt.Sprintf("%s/datadirtest2", testutil.TempDir())
|
||||
os.RemoveAll(tmp)
|
||||
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("web3provider", "ws//127.0.0.1:8546", "web3 provider ws or IPC endpoint")
|
||||
set.Bool("test-skip-pow", true, "skip pow dial")
|
||||
@@ -31,7 +31,7 @@ func TestNodeClose_OK(t *testing.T) {
|
||||
set.Bool("demo-config", true, "demo configuration")
|
||||
set.String("deposit-contract", "0x0000000000000000000000000000000000000000", "deposit contract address")
|
||||
|
||||
context := cli.NewContext(app, set, nil)
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
|
||||
node, err := NewBeaconNode(context)
|
||||
if err != nil {
|
||||
|
||||
@@ -89,6 +89,7 @@ go_test(
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/attestationutil:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
)
|
||||
@@ -937,7 +938,7 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
|
||||
for j := 0; j < numValidators; j++ {
|
||||
attExample := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: []byte("root"),
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("root"), 32),
|
||||
Slot: i,
|
||||
Target: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
|
||||
@@ -81,13 +81,10 @@ func (bs *Server) ListValidatorBalances(
|
||||
if len(pubKey) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
index, ok, err := bs.BeaconDB.ValidatorIndex(ctx, pubKey)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not retrieve validator index: %v", err)
|
||||
}
|
||||
pubkeyBytes := bytesutil.ToBytes48(pubKey)
|
||||
index, ok := headState.ValidatorIndexByPubkey(pubkeyBytes)
|
||||
if !ok {
|
||||
return nil, status.Errorf(codes.NotFound, "Could not find validator index for public key %#x", pubKey)
|
||||
return nil, status.Errorf(codes.NotFound, "Could not find validator index for public key %#x", pubkeyBytes)
|
||||
}
|
||||
|
||||
filtered[index] = true
|
||||
@@ -124,6 +121,10 @@ func (bs *Server) ListValidatorBalances(
|
||||
}
|
||||
balancesCount = len(res)
|
||||
}
|
||||
// Depending on the indices and public keys given, results might not be sorted.
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i].Index < res[j].Index
|
||||
})
|
||||
|
||||
// If there are no balances, we simply return a response specifying this.
|
||||
// Otherwise, attempting to paginate 0 balances below would result in an error.
|
||||
@@ -199,16 +200,55 @@ func (bs *Server) ListValidators(
|
||||
}
|
||||
|
||||
validatorList := make([]*ethpb.Validators_ValidatorContainer, 0)
|
||||
for i := 0; i < headState.NumValidators(); i++ {
|
||||
val, err := headState.ValidatorAtIndex(uint64(i))
|
||||
|
||||
for _, index := range req.Indices {
|
||||
val, err := headState.ValidatorAtIndex(index)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "Could not get validator")
|
||||
}
|
||||
validatorList = append(validatorList, ðpb.Validators_ValidatorContainer{
|
||||
Index: uint64(i),
|
||||
Index: index,
|
||||
Validator: val,
|
||||
})
|
||||
}
|
||||
|
||||
for _, pubKey := range req.PublicKeys {
|
||||
// Skip empty public key.
|
||||
if len(pubKey) == 0 {
|
||||
continue
|
||||
}
|
||||
pubkeyBytes := bytesutil.ToBytes48(pubKey)
|
||||
index, ok := headState.ValidatorIndexByPubkey(pubkeyBytes)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
val, err := headState.ValidatorAtIndex(index)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "Could not get validator")
|
||||
}
|
||||
validatorList = append(validatorList, ðpb.Validators_ValidatorContainer{
|
||||
Index: index,
|
||||
Validator: val,
|
||||
})
|
||||
}
|
||||
// Depending on the indices and public keys given, results might not be sorted.
|
||||
sort.Slice(validatorList, func(i, j int) bool {
|
||||
return validatorList[i].Index < validatorList[j].Index
|
||||
})
|
||||
|
||||
if len(req.PublicKeys) == 0 && len(req.Indices) == 0 {
|
||||
for i := 0; i < headState.NumValidators(); i++ {
|
||||
val, err := headState.ValidatorAtIndex(uint64(i))
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "Could not get validator")
|
||||
}
|
||||
validatorList = append(validatorList, ðpb.Validators_ValidatorContainer{
|
||||
Index: uint64(i),
|
||||
Validator: val,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if requestedEpoch < currentEpoch {
|
||||
stopIdx := len(validatorList)
|
||||
for idx, item := range validatorList {
|
||||
@@ -611,13 +651,15 @@ func (bs *Server) GetValidatorPerformance(
|
||||
correctlyVotedHead := make([]bool, 0, reqPubKeysCount)
|
||||
missingValidators := make([][]byte, 0, reqPubKeysCount)
|
||||
|
||||
headState, err := bs.HeadFetcher.HeadState(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, "Could not get head state")
|
||||
}
|
||||
// Convert the list of validator public keys to list of validator indices.
|
||||
// Also track missing validators using public keys.
|
||||
for _, key := range req.PublicKeys {
|
||||
idx, ok, err := bs.BeaconDB.ValidatorIndex(ctx, key)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not fetch validator idx for public key %#x: %v", key, err)
|
||||
}
|
||||
pubkeyBytes := bytesutil.ToBytes48(key)
|
||||
idx, ok := headState.ValidatorIndexByPubkey(pubkeyBytes)
|
||||
if !ok {
|
||||
missingValidators = append(missingValidators, key)
|
||||
continue
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -694,6 +695,59 @@ func TestServer_ListValidators_NoPagination(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_IndicesPubKeys(t *testing.T) {
|
||||
db := dbTest.SetupDB(t)
|
||||
defer dbTest.TeardownDB(t, db)
|
||||
|
||||
validators, _ := setupValidators(t, db, 100)
|
||||
indicesWanted := []uint64{2, 7, 11, 17}
|
||||
pubkeyIndicesWanted := []uint64{3, 5, 9, 15}
|
||||
allIndicesWanted := append(indicesWanted, pubkeyIndicesWanted...)
|
||||
want := make([]*ethpb.Validators_ValidatorContainer, len(allIndicesWanted))
|
||||
for i, idx := range allIndicesWanted {
|
||||
want[i] = ðpb.Validators_ValidatorContainer{
|
||||
Index: idx,
|
||||
Validator: validators[idx],
|
||||
}
|
||||
}
|
||||
sort.Slice(want, func(i int, j int) bool {
|
||||
return want[i].Index < want[j].Index
|
||||
})
|
||||
|
||||
headState, err := db.HeadState(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bs := &Server{
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
FinalizationFetcher: &mock.ChainService{
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
pubKeysWanted := make([][]byte, len(pubkeyIndicesWanted))
|
||||
for i, indice := range pubkeyIndicesWanted {
|
||||
pubKeysWanted[i] = pubKey(indice)
|
||||
}
|
||||
req := ðpb.ListValidatorsRequest{
|
||||
Indices: indicesWanted,
|
||||
PublicKeys: pubKeysWanted,
|
||||
}
|
||||
received, err := bs.ListValidators(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(want, received.ValidatorList) {
|
||||
t.Fatal("Incorrect respond of validators")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_Pagination(t *testing.T) {
|
||||
db := dbTest.SetupDB(t)
|
||||
defer dbTest.TeardownDB(t, db)
|
||||
|
||||
@@ -78,7 +78,10 @@ func (s *State) MigrateToCold(ctx context.Context, finalizedState *state.BeaconS
|
||||
}).Info("Saved archived point during state migration")
|
||||
}
|
||||
|
||||
if s.beaconDB.HasState(ctx, r) {
|
||||
// Do not delete the current finalized state in case user wants to
|
||||
// switch back to old state service, deleting the recent finalized state
|
||||
// could cause issue switching back.
|
||||
if s.beaconDB.HasState(ctx, r) && r != finalizedRoot {
|
||||
if err := s.beaconDB.DeleteState(ctx, r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func newBlocksFetcher(ctx context.Context, cfg *blocksFetcherConfig) *blocksFetc
|
||||
rateLimiter := leakybucket.NewCollector(
|
||||
allowedBlocksPerSecond, /* rate */
|
||||
allowedBlocksPerSecond, /* capacity */
|
||||
false /* deleteEmptyBuckets */)
|
||||
false /* deleteEmptyBuckets */)
|
||||
|
||||
return &blocksFetcher{
|
||||
ctx: ctx,
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
||||
@@ -61,7 +62,8 @@ func (s *Service) processPendingAtts(ctx context.Context) error {
|
||||
attestations := s.blkRootToPendingAtts[bRoot]
|
||||
s.pendingAttsLock.RUnlock()
|
||||
// Has the pending attestation's missing block arrived and the node processed block yet?
|
||||
if s.db.HasBlock(ctx, bRoot) && s.db.HasState(ctx, bRoot) {
|
||||
hasStateSummary := featureconfig.Get().NewStateMgmt && s.db.HasStateSummary(ctx, bRoot)
|
||||
if s.db.HasBlock(ctx, bRoot) && (s.db.HasState(ctx, bRoot) || hasStateSummary) {
|
||||
numberOfBlocksRecoveredFromAtt.Inc()
|
||||
for _, att := range attestations {
|
||||
// The pending attestations can arrive in both aggregated and unaggregated forms,
|
||||
|
||||
@@ -45,7 +45,7 @@ func (r *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handle block when the parent is unknown
|
||||
// Handle block when the parent is unknown.
|
||||
if !r.db.HasBlock(ctx, bytesutil.ToBytes32(block.ParentRoot)) {
|
||||
r.pendingQueueLock.Lock()
|
||||
r.slotToPendingBlocks[block.Slot] = signed
|
||||
|
||||
@@ -128,7 +128,8 @@ func (r *Service) validateAggregatedAtt(ctx context.Context, a *ethpb.AggregateA
|
||||
|
||||
func (r *Service) validateBlockInAttestation(ctx context.Context, a *ethpb.AggregateAttestationAndProof) bool {
|
||||
// Verify the block being voted and the processed state is in DB. The block should have passed validation if it's in the DB.
|
||||
hasState := r.db.HasState(ctx, bytesutil.ToBytes32(a.Aggregate.Data.BeaconBlockRoot))
|
||||
hasStateSummary := featureconfig.Get().NewStateMgmt && r.db.HasStateSummary(ctx, bytesutil.ToBytes32(a.Aggregate.Data.BeaconBlockRoot))
|
||||
hasState := r.db.HasState(ctx, bytesutil.ToBytes32(a.Aggregate.Data.BeaconBlockRoot)) || hasStateSummary
|
||||
hasBlock := r.db.HasBlock(ctx, bytesutil.ToBytes32(a.Aggregate.Data.BeaconBlockRoot))
|
||||
if !(hasState && hasBlock) {
|
||||
// A node doesn't have the block, it'll request from peer while saving the pending attestation to a queue.
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestValidateBeaconBlockPubSub_InvalidSignature(t *testing.T) {
|
||||
Slot: 1,
|
||||
ParentRoot: testutil.Random32Bytes(t),
|
||||
},
|
||||
Signature: []byte("fake"),
|
||||
Signature: bytesutil.PadTo([]byte("fake"), 96),
|
||||
}
|
||||
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
@@ -74,7 +74,8 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
|
||||
}
|
||||
|
||||
// Verify the block being voted and the processed state is in DB and. The block should have passed validation if it's in the DB.
|
||||
hasState := s.db.HasState(ctx, bytesutil.ToBytes32(att.Data.BeaconBlockRoot))
|
||||
hasStateSummary := featureconfig.Get().NewStateMgmt && s.db.HasStateSummary(ctx, bytesutil.ToBytes32(att.Data.BeaconBlockRoot))
|
||||
hasState := s.db.HasState(ctx, bytesutil.ToBytes32(att.Data.BeaconBlockRoot)) || hasStateSummary
|
||||
hasBlock := s.db.HasBlock(ctx, bytesutil.ToBytes32(att.Data.BeaconBlockRoot))
|
||||
if !(hasState && hasBlock) {
|
||||
// A node doesn't have the block, it'll request from peer while saving the pending attestation to a queue.
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
@@ -108,7 +109,7 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) {
|
||||
msg: ðpb.Attestation{
|
||||
AggregationBits: bitfield.Bitlist{0b1010},
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: []byte("missing"),
|
||||
BeaconBlockRoot: bytesutil.PadTo([]byte("missing"), 32),
|
||||
CommitteeIndex: 1,
|
||||
Slot: 63,
|
||||
},
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/prysmaticlabs/prysm/shared/debug"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var appHelpTemplate = `NAME:
|
||||
@@ -60,6 +60,7 @@ var appHelpFlagGroups = []flagGroup{
|
||||
cmd.MaxGoroutines,
|
||||
cmd.ForceClearDB,
|
||||
cmd.ClearDB,
|
||||
cmd.ConfigFileFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -117,7 +118,7 @@ var appHelpFlagGroups = []flagGroup{
|
||||
},
|
||||
{
|
||||
Name: "features",
|
||||
Flags: featureconfig.BeaconChainFlags,
|
||||
Flags: featureconfig.ActiveFlags(featureconfig.BeaconChainFlags),
|
||||
},
|
||||
{
|
||||
Name: "interop",
|
||||
|
||||
@@ -3,7 +3,8 @@ package main
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestAllFlagsExistInHelp(t *testing.T) {
|
||||
@@ -15,24 +16,26 @@ func TestAllFlagsExistInHelp(t *testing.T) {
|
||||
for _, group := range appHelpFlagGroups {
|
||||
helpFlags = append(helpFlags, group.Flags...)
|
||||
}
|
||||
helpFlags = featureconfig.ActiveFlags(helpFlags)
|
||||
appFlags = featureconfig.ActiveFlags(appFlags)
|
||||
|
||||
for _, flag := range appFlags {
|
||||
if !doesFlagExist(flag, helpFlags) {
|
||||
t.Errorf("Flag %s does not exist in help/usage flags.", flag.GetName())
|
||||
t.Errorf("Flag %s does not exist in help/usage flags.", flag.Names()[0])
|
||||
}
|
||||
}
|
||||
|
||||
for _, flag := range helpFlags {
|
||||
if !doesFlagExist(flag, appFlags) {
|
||||
t.Errorf("Flag %s does not exist in main.go, "+
|
||||
"but exists in help flags", flag.GetName())
|
||||
"but exists in help flags", flag.Names()[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func doesFlagExist(flag cli.Flag, flags []cli.Flag) bool {
|
||||
for _, f := range flags {
|
||||
if f == flag {
|
||||
if f.String() == flag.String() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ go_test(
|
||||
srcs = [
|
||||
"demo_e2e_test.go",
|
||||
"endtoend_test.go",
|
||||
"minimal_antiflake_e2e_test.go",
|
||||
"minimal_e2e_test.go",
|
||||
"minimal_slashing_e2e_test.go",
|
||||
],
|
||||
@@ -17,7 +18,7 @@ go_test(
|
||||
"@com_github_ethereum_go_ethereum//cmd/geth",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
shard_count = 2,
|
||||
shard_count = 3,
|
||||
tags = [
|
||||
"block-network",
|
||||
"e2e",
|
||||
|
||||
@@ -17,8 +17,11 @@ Evaluators have 3 parts, the name for it's test name, a `policy` which declares
|
||||
## Instructions
|
||||
If you wish to run all the E2E tests, you can run them through bazel with:
|
||||
|
||||
```bazel test //endtoend:go_default_test --test_output=streamed```
|
||||
```
|
||||
bazel test //endtoend:go_default_test --test_output=streamed --test_arg=-test.v --nocache_test_results
|
||||
```
|
||||
|
||||
To test only for a specific config, run:
|
||||
|
||||
```bazel test //endtoend:go_default_test --test_output=streamed --test_filter=TestEndToEnd_DemoConfig```
|
||||
To run the anti-flake E2E tests, run:
|
||||
```
|
||||
bazel test //endtoend:go_default_test --test_output=streamed --test_filter=TestEndToEnd_AntiFlake_MinimalConfig --test_arg=-test.v --nocache_test_results
|
||||
```
|
||||
@@ -21,6 +21,7 @@ type end2EndConfig struct {
|
||||
numValidators uint64
|
||||
numBeaconNodes uint64
|
||||
testSync bool
|
||||
testSlasher bool
|
||||
contractAddr common.Address
|
||||
evaluators []ev.Evaluator
|
||||
}
|
||||
@@ -31,7 +32,7 @@ var beaconNodeLogFileName = "beacon-%d.log"
|
||||
func startBeaconNodes(t *testing.T, config *end2EndConfig) []*ev.BeaconNodeInfo {
|
||||
numNodes := config.numBeaconNodes
|
||||
|
||||
nodeInfo := []*ev.BeaconNodeInfo{}
|
||||
var nodeInfo []*ev.BeaconNodeInfo
|
||||
for i := uint64(0); i < numNodes; i++ {
|
||||
newNode := startNewBeaconNode(t, config, nodeInfo)
|
||||
nodeInfo = append(nodeInfo, newNode)
|
||||
|
||||
@@ -33,9 +33,14 @@ func runEndToEndTest(t *testing.T, config *end2EndConfig) {
|
||||
for _, bb := range beaconNodes {
|
||||
processIDs = append(processIDs, bb.ProcessID)
|
||||
}
|
||||
defer logOutput(t, tmpPath, config)
|
||||
defer logOutput(t, config)
|
||||
defer killProcesses(t, processIDs)
|
||||
|
||||
if config.testSlasher {
|
||||
slasherPIDs := startSlashers(t, config)
|
||||
defer killProcesses(t, slasherPIDs)
|
||||
}
|
||||
|
||||
beaconLogFile, err := os.Open(path.Join(tmpPath, fmt.Sprintf(beaconNodeLogFileName, 0)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -49,9 +54,6 @@ func runEndToEndTest(t *testing.T, config *end2EndConfig) {
|
||||
return
|
||||
}
|
||||
|
||||
slasherPIDs := startSlashers(t, config)
|
||||
defer killProcesses(t, slasherPIDs)
|
||||
|
||||
conns := make([]*grpc.ClientConn, len(beaconNodes))
|
||||
for i := 0; i < len(conns); i++ {
|
||||
conn, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", beaconNodes[i].RPCPort), grpc.WithInsecure())
|
||||
@@ -59,6 +61,7 @@ func runEndToEndTest(t *testing.T, config *end2EndConfig) {
|
||||
t.Fatalf("Failed to dial: %v", err)
|
||||
}
|
||||
conns[i] = conn
|
||||
defer conn.Close()
|
||||
}
|
||||
nodeClient := eth.NewNodeClient(conns[0])
|
||||
genesis, err := nodeClient.GetGenesis(context.Background(), &ptypes.Empty{})
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// ValidatorsAreActive ensures the expected amount of validators are active.
|
||||
var ValidatorsAreActive = Evaluator{
|
||||
Name: "validators_active_epoch_%d",
|
||||
Policy: afterNthEpoch(1),
|
||||
Policy: allEpochs,
|
||||
Evaluation: validatorsAreActive,
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ func afterNthEpoch(afterEpoch uint64) func(uint64) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// All epochs.
|
||||
func allEpochs(currentEpoch uint64) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func validatorsAreActive(conns ...*grpc.ClientConn) error {
|
||||
conn := conns[0]
|
||||
client := eth.NewBeaconChainClient(conn)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
const (
|
||||
maxPollingWaitTime = 60 * time.Second
|
||||
filePollingInterval = 1 * time.Second
|
||||
filePollingInterval = 500 * time.Millisecond
|
||||
)
|
||||
|
||||
func killProcesses(t *testing.T, pIDs []int) {
|
||||
@@ -82,26 +82,28 @@ func waitForTextInFile(file *os.File, text string) error {
|
||||
}
|
||||
}
|
||||
|
||||
func logOutput(t *testing.T, tmpPath string, config *end2EndConfig) {
|
||||
func logOutput(t *testing.T, config *end2EndConfig) {
|
||||
// Log out errors from beacon chain nodes.
|
||||
for i := uint64(0); i < config.numBeaconNodes; i++ {
|
||||
beaconLogFile, err := os.Open(path.Join(tmpPath, fmt.Sprintf(beaconNodeLogFileName, i)))
|
||||
beaconLogFile, err := os.Open(path.Join(config.tmpPath, fmt.Sprintf(beaconNodeLogFileName, i)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logErrorOutput(t, beaconLogFile, "beacon chain node", i)
|
||||
|
||||
validatorLogFile, err := os.Open(path.Join(tmpPath, fmt.Sprintf(validatorLogFileName, i)))
|
||||
validatorLogFile, err := os.Open(path.Join(config.tmpPath, fmt.Sprintf(validatorLogFileName, i)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logErrorOutput(t, validatorLogFile, "validator client", i)
|
||||
|
||||
slasherLogFile, err := os.Open(path.Join(tmpPath, fmt.Sprintf(slasherLogFileName, i)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
if config.testSlasher {
|
||||
slasherLogFile, err := os.Open(path.Join(config.tmpPath, fmt.Sprintf(slasherLogFileName, i)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logErrorOutput(t, slasherLogFile, "slasher client", i)
|
||||
}
|
||||
logErrorOutput(t, slasherLogFile, "slasher client", i)
|
||||
}
|
||||
t.Logf("Ending time: %s\n", time.Now().String())
|
||||
}
|
||||
|
||||
32
endtoend/minimal_antiflake_e2e_test.go
Normal file
32
endtoend/minimal_antiflake_e2e_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package endtoend
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ev "github.com/prysmaticlabs/prysm/endtoend/evaluators"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
)
|
||||
|
||||
func TestEndToEnd_AntiFlake_MinimalConfig(t *testing.T) {
|
||||
testutil.ResetCache()
|
||||
params.UseMinimalConfig()
|
||||
|
||||
minimalConfig := &end2EndConfig{
|
||||
beaconFlags: append(featureconfig.E2EBeaconChainFlags, "--minimal-config", "--custom-genesis-delay=10"),
|
||||
validatorFlags: append(featureconfig.E2EValidatorFlags, "--minimal-config"),
|
||||
epochsToRun: 2,
|
||||
numBeaconNodes: 4,
|
||||
numValidators: params.BeaconConfig().MinGenesisActiveValidatorCount,
|
||||
testSync: false,
|
||||
testSlasher: false,
|
||||
evaluators: []ev.Evaluator{
|
||||
ev.PeersConnect,
|
||||
ev.ValidatorsAreActive,
|
||||
},
|
||||
}
|
||||
// Running this test twice to test the quickest conditions (3 epochs) twice.
|
||||
runEndToEndTest(t, minimalConfig)
|
||||
runEndToEndTest(t, minimalConfig)
|
||||
}
|
||||
@@ -20,6 +20,7 @@ func TestEndToEnd_MinimalConfig(t *testing.T) {
|
||||
numBeaconNodes: 4,
|
||||
numValidators: params.BeaconConfig().MinGenesisActiveValidatorCount,
|
||||
testSync: true,
|
||||
testSlasher: true,
|
||||
evaluators: []ev.Evaluator{
|
||||
ev.PeersConnect,
|
||||
ev.ValidatorsAreActive,
|
||||
|
||||
@@ -20,6 +20,7 @@ func TestEndToEnd_Slashing_MinimalConfig(t *testing.T) {
|
||||
numBeaconNodes: 2,
|
||||
numValidators: params.BeaconConfig().MinGenesisActiveValidatorCount,
|
||||
testSync: false,
|
||||
testSlasher: true,
|
||||
evaluators: []ev.Evaluator{
|
||||
ev.PeersConnect,
|
||||
ev.ValidatorsSlashed,
|
||||
|
||||
@@ -4,6 +4,7 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
|
||||
load("//proto:ssz_proto_library.bzl", "ssz_proto_files")
|
||||
load("//tools:ssz.bzl", "SSZ_DEPS", "ssz_gen_marshal")
|
||||
|
||||
go_proto_library(
|
||||
name = "v1_go_proto",
|
||||
@@ -17,11 +18,27 @@ go_proto_library(
|
||||
],
|
||||
)
|
||||
|
||||
ssz_gen_marshal(
|
||||
name = "ssz_generated_files",
|
||||
go_proto = ":v1_go_proto",
|
||||
includes = [
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
],
|
||||
objs = [
|
||||
"BeaconBlocksByRangeRequest",
|
||||
"Fork",
|
||||
"HistoricalBatch",
|
||||
"Status",
|
||||
"BeaconState",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [":ssz_generated_files"],
|
||||
embed = [":v1_go_proto"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = SSZ_DEPS,
|
||||
)
|
||||
|
||||
ssz_proto_files(
|
||||
|
||||
@@ -232,3 +232,12 @@ func ReverseBytes32Slice(arr [][32]byte) [][32]byte {
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// PadTo pads a byte slice to the given size. If the byte slice is larger than the given size, the
|
||||
// original slice is returned.
|
||||
func PadTo(b []byte, size int) []byte {
|
||||
if len(b) > size {
|
||||
return b
|
||||
}
|
||||
return append(b, make([]byte, size-len(b))...)
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ go_library(
|
||||
"defaults.go",
|
||||
"flags.go",
|
||||
"helpers.go",
|
||||
"wrap_flags.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/cmd",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//altsrc:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -1,94 +1,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DirectoryString -- Custom type which is registered in the flags library
|
||||
// which cli uses for argument parsing. This allows us to expand Value to
|
||||
// an absolute path when the argument is parsed.
|
||||
type DirectoryString struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func (d *DirectoryString) String() string {
|
||||
return d.Value
|
||||
}
|
||||
|
||||
// Set directory string value
|
||||
func (d *DirectoryString) Set(value string) error {
|
||||
d.Value = expandPath(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func prefixFor(name string) (prefix string) {
|
||||
if len(name) == 1 {
|
||||
prefix = "-"
|
||||
} else {
|
||||
prefix = "--"
|
||||
}
|
||||
return prefix
|
||||
}
|
||||
|
||||
func prefixedNames(fullName string) (prefixed string) {
|
||||
parts := strings.Split(fullName, ",")
|
||||
for i, name := range parts {
|
||||
name = strings.Trim(name, " ")
|
||||
prefixed += prefixFor(name) + name
|
||||
if i < len(parts)-1 {
|
||||
prefixed += ", "
|
||||
}
|
||||
}
|
||||
return prefixed
|
||||
}
|
||||
|
||||
// DirectoryFlag expands the received string to an absolute path.
|
||||
// e.g. ~/.ethereum -> /home/username/.ethereum
|
||||
type DirectoryFlag struct {
|
||||
Name string
|
||||
Value DirectoryString
|
||||
Usage string
|
||||
}
|
||||
|
||||
func (d DirectoryFlag) String() string {
|
||||
fmtString := "%s %v\t%v"
|
||||
if len(d.Value.Value) > 0 {
|
||||
fmtString = "%s \"%v\"\t%v"
|
||||
}
|
||||
return fmt.Sprintf(fmtString, prefixedNames(d.Name), d.Value.Value, d.Usage)
|
||||
}
|
||||
|
||||
func eachName(longName string, fn func(string)) {
|
||||
parts := strings.Split(longName, ",")
|
||||
for _, name := range parts {
|
||||
name = strings.Trim(name, " ")
|
||||
fn(name)
|
||||
}
|
||||
}
|
||||
|
||||
// Apply is called by cli library, grabs variable from environment (if in env)
|
||||
// and adds variable to flag set for parsing.
|
||||
func (d DirectoryFlag) Apply(set *flag.FlagSet) {
|
||||
eachName(d.Name, func(name string) {
|
||||
set.Var(&d.Value, d.Name, d.Usage)
|
||||
})
|
||||
}
|
||||
|
||||
// GetName of directory.
|
||||
func (d DirectoryFlag) GetName() string {
|
||||
return d.Name
|
||||
}
|
||||
|
||||
// Set flag value.
|
||||
func (d *DirectoryFlag) Set(value string) {
|
||||
d.Value.Value = value
|
||||
}
|
||||
|
||||
// Expands a file path
|
||||
// 1. replace tilde with users home dir
|
||||
// 2. expands embedded environment variables
|
||||
|
||||
@@ -2,165 +2,170 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// VerbosityFlag defines the logrus configuration.
|
||||
VerbosityFlag = cli.StringFlag{
|
||||
VerbosityFlag = &cli.StringFlag{
|
||||
Name: "verbosity",
|
||||
Usage: "Logging verbosity (trace, debug, info=default, warn, error, fatal, panic)",
|
||||
Value: "info",
|
||||
}
|
||||
// DataDirFlag defines a path on disk.
|
||||
DataDirFlag = DirectoryFlag{
|
||||
DataDirFlag = &cli.StringFlag{
|
||||
Name: "datadir",
|
||||
Usage: "Data directory for the databases and keystore",
|
||||
Value: DirectoryString{DefaultDataDir()},
|
||||
Value: DefaultDataDir(),
|
||||
}
|
||||
// EnableTracingFlag defines a flag to enable p2p message tracing.
|
||||
EnableTracingFlag = cli.BoolFlag{
|
||||
EnableTracingFlag = &cli.BoolFlag{
|
||||
Name: "enable-tracing",
|
||||
Usage: "Enable request tracing.",
|
||||
}
|
||||
// TracingProcessNameFlag defines a flag to specify a process name.
|
||||
TracingProcessNameFlag = cli.StringFlag{
|
||||
TracingProcessNameFlag = &cli.StringFlag{
|
||||
Name: "tracing-process-name",
|
||||
Usage: "The name to apply to tracing tag \"process_name\"",
|
||||
}
|
||||
// TracingEndpointFlag flag defines the http endpoint for serving traces to Jaeger.
|
||||
TracingEndpointFlag = cli.StringFlag{
|
||||
TracingEndpointFlag = &cli.StringFlag{
|
||||
Name: "tracing-endpoint",
|
||||
Usage: "Tracing endpoint defines where beacon chain traces are exposed to Jaeger.",
|
||||
Value: "http://127.0.0.1:14268/api/traces",
|
||||
}
|
||||
// TraceSampleFractionFlag defines a flag to indicate what fraction of p2p
|
||||
// messages are sampled for tracing.
|
||||
TraceSampleFractionFlag = cli.Float64Flag{
|
||||
TraceSampleFractionFlag = &cli.Float64Flag{
|
||||
Name: "trace-sample-fraction",
|
||||
Usage: "Indicate what fraction of p2p messages are sampled for tracing.",
|
||||
Value: 0.20,
|
||||
}
|
||||
// DisableMonitoringFlag defines a flag to disable the metrics collection.
|
||||
DisableMonitoringFlag = cli.BoolFlag{
|
||||
DisableMonitoringFlag = &cli.BoolFlag{
|
||||
Name: "disable-monitoring",
|
||||
Usage: "Disable monitoring service.",
|
||||
}
|
||||
// MonitoringPortFlag defines the http port used to serve prometheus metrics.
|
||||
MonitoringPortFlag = cli.Int64Flag{
|
||||
MonitoringPortFlag = &cli.Int64Flag{
|
||||
Name: "monitoring-port",
|
||||
Usage: "Port used to listening and respond metrics for prometheus.",
|
||||
Value: 8080,
|
||||
}
|
||||
// NoDiscovery specifies whether we are running a local network and have no need for connecting
|
||||
// to the bootstrap nodes in the cloud
|
||||
NoDiscovery = cli.BoolFlag{
|
||||
NoDiscovery = &cli.BoolFlag{
|
||||
Name: "no-discovery",
|
||||
Usage: "Enable only local network p2p and do not connect to cloud bootstrap nodes.",
|
||||
}
|
||||
// StaticPeers specifies a set of peers to connect to explicitly.
|
||||
StaticPeers = cli.StringSliceFlag{
|
||||
StaticPeers = &cli.StringSliceFlag{
|
||||
Name: "peer",
|
||||
Usage: "Connect with this peer. This flag may be used multiple times.",
|
||||
}
|
||||
// BootstrapNode tells the beacon node which bootstrap node to connect to
|
||||
BootstrapNode = cli.StringFlag{
|
||||
BootstrapNode = &cli.StringFlag{
|
||||
Name: "bootstrap-node",
|
||||
Usage: "The address of bootstrap node. Beacon node will connect for peer discovery via DHT. Multiple nodes can be separated with a comma",
|
||||
Value: "/dns4/prylabs.net/tcp/30001/p2p/16Uiu2HAm7Qwe19vz9WzD2Mxn7fXd1vgHHp4iccuyq7TxwRXoAGfc",
|
||||
}
|
||||
// RelayNode tells the beacon node which relay node to connect to.
|
||||
RelayNode = cli.StringFlag{
|
||||
RelayNode = &cli.StringFlag{
|
||||
Name: "relay-node",
|
||||
Usage: "The address of relay node. The beacon node will connect to the " +
|
||||
"relay node and advertise their address via the relay node to other peers",
|
||||
Value: "",
|
||||
}
|
||||
// P2PUDPPort defines the port to be used by discv5.
|
||||
P2PUDPPort = cli.IntFlag{
|
||||
P2PUDPPort = &cli.IntFlag{
|
||||
Name: "p2p-udp-port",
|
||||
Usage: "The port used by discv5.",
|
||||
Value: 12000,
|
||||
}
|
||||
// P2PTCPPort defines the port to be used by libp2p.
|
||||
P2PTCPPort = cli.IntFlag{
|
||||
P2PTCPPort = &cli.IntFlag{
|
||||
Name: "p2p-tcp-port",
|
||||
Usage: "The port used by libp2p.",
|
||||
Value: 13000,
|
||||
}
|
||||
// P2PIP defines the local IP to be used by libp2p.
|
||||
P2PIP = cli.StringFlag{
|
||||
P2PIP = &cli.StringFlag{
|
||||
Name: "p2p-local-ip",
|
||||
Usage: "The local ip address to listen for incoming data.",
|
||||
Value: "",
|
||||
}
|
||||
// P2PHost defines the host IP to be used by libp2p.
|
||||
P2PHost = cli.StringFlag{
|
||||
P2PHost = &cli.StringFlag{
|
||||
Name: "p2p-host-ip",
|
||||
Usage: "The IP address advertised by libp2p. This may be used to advertise an external IP.",
|
||||
Value: "",
|
||||
}
|
||||
// P2PHostDNS defines the host DNS to be used by libp2p.
|
||||
P2PHostDNS = cli.StringFlag{
|
||||
P2PHostDNS = &cli.StringFlag{
|
||||
Name: "p2p-host-dns",
|
||||
Usage: "The DNS address advertised by libp2p. This may be used to advertise an external DNS.",
|
||||
Value: "",
|
||||
}
|
||||
// P2PPrivKey defines a flag to specify the location of the private key file for libp2p.
|
||||
P2PPrivKey = cli.StringFlag{
|
||||
P2PPrivKey = &cli.StringFlag{
|
||||
Name: "p2p-priv-key",
|
||||
Usage: "The file containing the private key to use in communications with other peers.",
|
||||
Value: "",
|
||||
}
|
||||
// P2PMaxPeers defines a flag to specify the max number of peers in libp2p.
|
||||
P2PMaxPeers = cli.Int64Flag{
|
||||
P2PMaxPeers = &cli.Int64Flag{
|
||||
Name: "p2p-max-peers",
|
||||
Usage: "The max number of p2p peers to maintain.",
|
||||
Value: 30,
|
||||
}
|
||||
// P2PWhitelist defines a CIDR subnet to exclusively allow connections.
|
||||
P2PWhitelist = cli.StringFlag{
|
||||
P2PWhitelist = &cli.StringFlag{
|
||||
Name: "p2p-whitelist",
|
||||
Usage: "The CIDR subnet for whitelisting peer connections. Example: 192.168.0.0/16 " +
|
||||
"would whitelist connections to peers on your local network only. The default " +
|
||||
"is to accept all connections.",
|
||||
}
|
||||
// P2PEncoding defines the encoding format for p2p messages.
|
||||
P2PEncoding = cli.StringFlag{
|
||||
P2PEncoding = &cli.StringFlag{
|
||||
Name: "p2p-encoding",
|
||||
Usage: "The encoding format of messages sent over the wire. The default is 0, which represents ssz",
|
||||
Value: "ssz",
|
||||
}
|
||||
// ForceClearDB removes any previously stored data at the data directory.
|
||||
ForceClearDB = cli.BoolFlag{
|
||||
ForceClearDB = &cli.BoolFlag{
|
||||
Name: "force-clear-db",
|
||||
Usage: "Clear any previously stored data at the data directory",
|
||||
}
|
||||
// ClearDB prompts user to see if they want to remove any previously stored data at the data directory.
|
||||
ClearDB = cli.BoolFlag{
|
||||
ClearDB = &cli.BoolFlag{
|
||||
Name: "clear-db",
|
||||
Usage: "Prompt for clearing any previously stored data at the data directory",
|
||||
}
|
||||
// LogFormat specifies the log output format.
|
||||
LogFormat = cli.StringFlag{
|
||||
LogFormat = &cli.StringFlag{
|
||||
Name: "log-format",
|
||||
Usage: "Specify log formatting. Supports: text, json, fluentd.",
|
||||
Value: "text",
|
||||
}
|
||||
// MaxGoroutines specifies the maximum amount of goroutines tolerated, before a status check fails.
|
||||
MaxGoroutines = cli.Int64Flag{
|
||||
MaxGoroutines = &cli.Int64Flag{
|
||||
Name: "max-goroutines",
|
||||
Usage: "Specifies the upper limit of goroutines running before a status check fails",
|
||||
Value: 5000,
|
||||
}
|
||||
// LogFileName specifies the log output file name.
|
||||
LogFileName = cli.StringFlag{
|
||||
LogFileName = &cli.StringFlag{
|
||||
Name: "log-file",
|
||||
Usage: "Specify log file name, relative or absolute",
|
||||
}
|
||||
// EnableUPnPFlag specifies if UPnP should be enabled or not. The default value is false.
|
||||
EnableUPnPFlag = cli.BoolFlag{
|
||||
EnableUPnPFlag = &cli.BoolFlag{
|
||||
Name: "enable-upnp",
|
||||
Usage: "Enable the service (Beacon chain or Validator) to use UPnP when possible.",
|
||||
}
|
||||
// ConfigFileFlag specifies the filepath to load flag values.
|
||||
ConfigFileFlag = &cli.StringFlag{
|
||||
Name: "config-file",
|
||||
Usage: "The filepath to a yaml file with flag values",
|
||||
}
|
||||
)
|
||||
|
||||
41
shared/cmd/wrap_flags.go
Normal file
41
shared/cmd/wrap_flags.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"gopkg.in/urfave/cli.v2/altsrc"
|
||||
)
|
||||
|
||||
// WrapFlags so that they can be loaded from alternative sources.
|
||||
func WrapFlags(flags []cli.Flag) []cli.Flag {
|
||||
wrapped := make([]cli.Flag, 0, len(flags))
|
||||
for _, f := range flags {
|
||||
switch f.(type) {
|
||||
case *cli.BoolFlag:
|
||||
f = altsrc.NewBoolFlag(f.(*cli.BoolFlag))
|
||||
case *cli.DurationFlag:
|
||||
f = altsrc.NewDurationFlag(f.(*cli.DurationFlag))
|
||||
case *cli.GenericFlag:
|
||||
f = altsrc.NewGenericFlag(f.(*cli.GenericFlag))
|
||||
case *cli.Float64Flag:
|
||||
f = altsrc.NewFloat64Flag(f.(*cli.Float64Flag))
|
||||
case *cli.IntFlag:
|
||||
f = altsrc.NewIntFlag(f.(*cli.IntFlag))
|
||||
case *cli.Int64Flag:
|
||||
f = altsrc.NewInt64Flag(f.(*cli.Int64Flag))
|
||||
case *cli.StringFlag:
|
||||
f = altsrc.NewStringFlag(f.(*cli.StringFlag))
|
||||
case *cli.StringSliceFlag:
|
||||
f = altsrc.NewStringSliceFlag(f.(*cli.StringSliceFlag))
|
||||
case *cli.Uint64Flag:
|
||||
f = altsrc.NewUint64Flag(f.(*cli.Uint64Flag))
|
||||
case *cli.UintFlag:
|
||||
f = altsrc.NewUintFlag(f.(*cli.UintFlag))
|
||||
default:
|
||||
panic(fmt.Sprintf("cannot convert type %T", f))
|
||||
}
|
||||
wrapped = append(wrapped, f)
|
||||
}
|
||||
return wrapped
|
||||
}
|
||||
@@ -13,6 +13,6 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
|
||||
"github.com/fjl/memsize/memsizeui"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// Handler is the global debugging handler.
|
||||
@@ -46,35 +46,35 @@ var Handler = new(HandlerT)
|
||||
var Memsize memsizeui.Handler
|
||||
var (
|
||||
// PProfFlag to enable pprof HTTP server.
|
||||
PProfFlag = cli.BoolFlag{
|
||||
PProfFlag = &cli.BoolFlag{
|
||||
Name: "pprof",
|
||||
Usage: "Enable the pprof HTTP server",
|
||||
}
|
||||
// PProfPortFlag to specify HTTP server listening port.
|
||||
PProfPortFlag = cli.IntFlag{
|
||||
PProfPortFlag = &cli.IntFlag{
|
||||
Name: "pprofport",
|
||||
Usage: "pprof HTTP server listening port",
|
||||
Value: 6060,
|
||||
}
|
||||
// PProfAddrFlag to specify HTTP server address.
|
||||
PProfAddrFlag = cli.StringFlag{
|
||||
PProfAddrFlag = &cli.StringFlag{
|
||||
Name: "pprofaddr",
|
||||
Usage: "pprof HTTP server listening interface",
|
||||
Value: "127.0.0.1",
|
||||
}
|
||||
// MemProfileRateFlag to specify the mem profiling rate.
|
||||
MemProfileRateFlag = cli.IntFlag{
|
||||
MemProfileRateFlag = &cli.IntFlag{
|
||||
Name: "memprofilerate",
|
||||
Usage: "Turn on memory profiling with the given rate",
|
||||
Value: runtime.MemProfileRate,
|
||||
}
|
||||
// CPUProfileFlag to specify where to write the CPU profile.
|
||||
CPUProfileFlag = cli.StringFlag{
|
||||
CPUProfileFlag = &cli.StringFlag{
|
||||
Name: "cpuprofile",
|
||||
Usage: "Write CPU profile to the given file",
|
||||
}
|
||||
// TraceFlag to specify where to write the trace execution profile.
|
||||
TraceFlag = cli.StringFlag{
|
||||
TraceFlag = &cli.StringFlag{
|
||||
Name: "trace",
|
||||
Usage: "Write execution trace to the given file",
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func MigrateFlags(action func(ctx *cli.Context) error) func(*cli.Context) error
|
||||
return func(ctx *cli.Context) error {
|
||||
for _, name := range ctx.FlagNames() {
|
||||
if ctx.IsSet(name) {
|
||||
if err := ctx.GlobalSet(name, ctx.String(name)); err != nil {
|
||||
if err := ctx.Set(name, ctx.String(name)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -333,21 +333,21 @@ func MigrateFlags(action func(ctx *cli.Context) error) func(*cli.Context) error
|
||||
// It should be called as early as possible in the program.
|
||||
func Setup(ctx *cli.Context) error {
|
||||
// profiling, tracing
|
||||
runtime.MemProfileRate = ctx.GlobalInt(MemProfileRateFlag.Name)
|
||||
if traceFile := ctx.GlobalString(TraceFlag.Name); traceFile != "" {
|
||||
runtime.MemProfileRate = ctx.Int(MemProfileRateFlag.Name)
|
||||
if traceFile := ctx.String(TraceFlag.Name); traceFile != "" {
|
||||
if err := Handler.StartGoTrace(TraceFlag.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if cpuFile := ctx.GlobalString(CPUProfileFlag.Name); cpuFile != "" {
|
||||
if cpuFile := ctx.String(CPUProfileFlag.Name); cpuFile != "" {
|
||||
if err := Handler.StartCPUProfile(cpuFile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// pprof server
|
||||
if ctx.GlobalBool(PProfFlag.Name) {
|
||||
address := fmt.Sprintf("%s:%d", ctx.GlobalString(PProfAddrFlag.Name), ctx.GlobalInt(PProfPortFlag.Name))
|
||||
if ctx.Bool(PProfFlag.Name) {
|
||||
address := fmt.Sprintf("%s:%d", ctx.String(PProfAddrFlag.Name), ctx.Int(PProfPortFlag.Name))
|
||||
startPProf(address)
|
||||
}
|
||||
return nil
|
||||
@@ -366,12 +366,12 @@ func startPProf(address string) {
|
||||
// Exit stops all running profiles, flushing their output to the
|
||||
// respective file.
|
||||
func Exit(ctx *cli.Context) {
|
||||
if traceFile := ctx.GlobalString(TraceFlag.Name); traceFile != "" {
|
||||
if traceFile := ctx.String(TraceFlag.Name); traceFile != "" {
|
||||
if err := Handler.StopGoTrace(); err != nil {
|
||||
log.Errorf("Failed to stop go tracing: %v", err)
|
||||
}
|
||||
}
|
||||
if cpuFile := ctx.GlobalString(CPUProfileFlag.Name); cpuFile != "" {
|
||||
if cpuFile := ctx.String(CPUProfileFlag.Name); cpuFile != "" {
|
||||
if err := Handler.StopCPUProfile(); err != nil {
|
||||
log.Errorf("Failed to stop CPU profiling: %v", err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"config.go",
|
||||
"filter_flags.go",
|
||||
"flags.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/featureconfig",
|
||||
@@ -11,7 +12,7 @@ go_library(
|
||||
deps = [
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -23,5 +24,5 @@ go_test(
|
||||
"flags_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["@com_github_urfave_cli//:go_default_library"],
|
||||
deps = ["@in_gopkg_urfave_cli_v2//:go_default_library"],
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ package featureconfig
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "flags")
|
||||
@@ -90,98 +90,98 @@ func ConfigureBeaconChain(ctx *cli.Context) {
|
||||
cfg := &Flags{}
|
||||
cfg = configureConfig(ctx, cfg)
|
||||
delay := params.BeaconConfig().MinGenesisDelay
|
||||
if ctx.GlobalIsSet(customGenesisDelayFlag.Name) {
|
||||
delay = ctx.GlobalUint64(customGenesisDelayFlag.Name)
|
||||
if ctx.IsSet(customGenesisDelayFlag.Name) {
|
||||
delay = ctx.Uint64(customGenesisDelayFlag.Name)
|
||||
log.Warnf("Starting ETH2 with genesis delay of %d seconds", delay)
|
||||
}
|
||||
cfg.CustomGenesisDelay = delay
|
||||
if ctx.GlobalBool(writeSSZStateTransitionsFlag.Name) {
|
||||
if ctx.Bool(writeSSZStateTransitionsFlag.Name) {
|
||||
log.Warn("Writing SSZ states and blocks after state transitions")
|
||||
cfg.WriteSSZStateTransitions = true
|
||||
}
|
||||
if ctx.GlobalBool(disableForkChoiceUnsafeFlag.Name) {
|
||||
if ctx.Bool(disableForkChoiceUnsafeFlag.Name) {
|
||||
log.Warn("UNSAFE: Disabled fork choice for updating chain head")
|
||||
cfg.DisableForkChoice = true
|
||||
}
|
||||
if ctx.GlobalBool(enableDynamicCommitteeSubnets.Name) {
|
||||
if ctx.Bool(enableDynamicCommitteeSubnets.Name) {
|
||||
log.Warn("Enabled dynamic attestation committee subnets")
|
||||
cfg.EnableDynamicCommitteeSubnets = true
|
||||
}
|
||||
if ctx.GlobalBool(enableSSZCache.Name) {
|
||||
if ctx.Bool(enableSSZCache.Name) {
|
||||
log.Warn("Enabled unsafe ssz cache")
|
||||
cfg.EnableSSZCache = true
|
||||
}
|
||||
if ctx.GlobalBool(enableEth1DataVoteCacheFlag.Name) {
|
||||
if ctx.Bool(enableEth1DataVoteCacheFlag.Name) {
|
||||
log.Warn("Enabled unsafe eth1 data vote cache")
|
||||
cfg.EnableEth1DataVoteCache = true
|
||||
}
|
||||
if ctx.GlobalBool(initSyncVerifyEverythingFlag.Name) {
|
||||
if ctx.Bool(initSyncVerifyEverythingFlag.Name) {
|
||||
log.Warn("Initial syncing with verifying all block's content signatures.")
|
||||
cfg.InitSyncNoVerify = false
|
||||
} else {
|
||||
cfg.InitSyncNoVerify = true
|
||||
}
|
||||
if ctx.GlobalBool(skipBLSVerifyFlag.Name) {
|
||||
if ctx.Bool(skipBLSVerifyFlag.Name) {
|
||||
log.Warn("UNSAFE: Skipping BLS verification at runtime")
|
||||
cfg.SkipBLSVerify = true
|
||||
}
|
||||
if ctx.GlobalBool(enableBackupWebhookFlag.Name) {
|
||||
if ctx.Bool(enableBackupWebhookFlag.Name) {
|
||||
log.Warn("Allowing database backups to be triggered from HTTP webhook.")
|
||||
cfg.EnableBackupWebhook = true
|
||||
}
|
||||
if ctx.GlobalBool(enableSkipSlotsCacheFlag.Name) {
|
||||
if ctx.Bool(enableSkipSlotsCacheFlag.Name) {
|
||||
log.Warn("Enabled skip slots cache.")
|
||||
cfg.EnableSkipSlotsCache = true
|
||||
}
|
||||
if ctx.GlobalString(kafkaBootstrapServersFlag.Name) != "" {
|
||||
if ctx.String(kafkaBootstrapServersFlag.Name) != "" {
|
||||
log.Warn("Enabling experimental kafka streaming.")
|
||||
cfg.KafkaBootstrapServers = ctx.GlobalString(kafkaBootstrapServersFlag.Name)
|
||||
cfg.KafkaBootstrapServers = ctx.String(kafkaBootstrapServersFlag.Name)
|
||||
}
|
||||
if ctx.GlobalBool(enableSlasherFlag.Name) {
|
||||
if ctx.Bool(enableSlasherFlag.Name) {
|
||||
log.Warn("Enable slasher connection.")
|
||||
cfg.EnableSlasherConnection = true
|
||||
}
|
||||
if ctx.GlobalBool(cacheFilteredBlockTreeFlag.Name) {
|
||||
if ctx.Bool(cacheFilteredBlockTreeFlag.Name) {
|
||||
log.Warn("Enabled filtered block tree cache for fork choice.")
|
||||
cfg.EnableBlockTreeCache = true
|
||||
}
|
||||
if ctx.GlobalBool(disableStrictAttestationPubsubVerificationFlag.Name) {
|
||||
if ctx.Bool(disableStrictAttestationPubsubVerificationFlag.Name) {
|
||||
log.Warn("Disabled strict attestation signature verification in pubsub")
|
||||
cfg.DisableStrictAttestationPubsubVerification = true
|
||||
}
|
||||
if ctx.GlobalBool(disableUpdateHeadPerAttestation.Name) {
|
||||
if ctx.Bool(disableUpdateHeadPerAttestation.Name) {
|
||||
log.Warn("Disabled update head on per attestation basis")
|
||||
cfg.DisableUpdateHeadPerAttestation = true
|
||||
}
|
||||
if ctx.GlobalBool(enableByteMempool.Name) {
|
||||
if ctx.Bool(enableByteMempool.Name) {
|
||||
log.Warn("Enabling experimental memory management for beacon state")
|
||||
cfg.EnableByteMempool = true
|
||||
}
|
||||
if ctx.GlobalBool(enableStateGenSigVerify.Name) {
|
||||
if ctx.Bool(enableStateGenSigVerify.Name) {
|
||||
log.Warn("Enabling sig verify for state gen")
|
||||
cfg.EnableStateGenSigVerify = true
|
||||
}
|
||||
if ctx.GlobalBool(checkHeadState.Name) {
|
||||
if ctx.Bool(checkHeadState.Name) {
|
||||
log.Warn("Enabling check head state for chainservice")
|
||||
cfg.CheckHeadState = true
|
||||
}
|
||||
if ctx.GlobalBool(enableNoiseHandshake.Name) {
|
||||
if ctx.Bool(enableNoiseHandshake.Name) {
|
||||
log.Warn("Enabling noise handshake for peer")
|
||||
cfg.EnableNoise = true
|
||||
}
|
||||
if ctx.GlobalBool(dontPruneStateStartUp.Name) {
|
||||
if ctx.Bool(dontPruneStateStartUp.Name) {
|
||||
log.Warn("Not enabling state pruning upon start up")
|
||||
cfg.DontPruneStateStartUp = true
|
||||
}
|
||||
if ctx.GlobalBool(newStateMgmt.Name) {
|
||||
if ctx.Bool(newStateMgmt.Name) {
|
||||
log.Warn("Enabling experimental state management service")
|
||||
cfg.NewStateMgmt = true
|
||||
}
|
||||
if ctx.GlobalBool(enableInitSyncQueue.Name) {
|
||||
if ctx.Bool(enableInitSyncQueue.Name) {
|
||||
log.Warn("Enabling initial sync queue")
|
||||
cfg.EnableInitSyncQueue = true
|
||||
}
|
||||
if ctx.GlobalBool(enableFieldTrie.Name) {
|
||||
if ctx.Bool(enableFieldTrie.Name) {
|
||||
log.Warn("Enabling state field trie")
|
||||
cfg.EnableFieldTrie = true
|
||||
}
|
||||
@@ -194,15 +194,15 @@ func ConfigureValidator(ctx *cli.Context) {
|
||||
complainOnDeprecatedFlags(ctx)
|
||||
cfg := &Flags{}
|
||||
cfg = configureConfig(ctx, cfg)
|
||||
if ctx.GlobalBool(protectProposerFlag.Name) {
|
||||
if ctx.Bool(protectProposerFlag.Name) {
|
||||
log.Warn("Enabled validator proposal slashing protection.")
|
||||
cfg.ProtectProposer = true
|
||||
}
|
||||
if ctx.GlobalBool(protectAttesterFlag.Name) {
|
||||
if ctx.Bool(protectAttesterFlag.Name) {
|
||||
log.Warn("Enabled validator attestation slashing protection.")
|
||||
cfg.ProtectAttester = true
|
||||
}
|
||||
if ctx.GlobalBool(enableDomainDataCacheFlag.Name) {
|
||||
if ctx.Bool(enableDomainDataCacheFlag.Name) {
|
||||
log.Warn("Enabled domain data cache.")
|
||||
cfg.EnableDomainDataCache = true
|
||||
}
|
||||
@@ -211,18 +211,18 @@ func ConfigureValidator(ctx *cli.Context) {
|
||||
|
||||
func complainOnDeprecatedFlags(ctx *cli.Context) {
|
||||
for _, f := range deprecatedFlags {
|
||||
if ctx.IsSet(f.GetName()) {
|
||||
log.Errorf("%s is deprecated and has no effect. Do not use this flag, it will be deleted soon.", f.GetName())
|
||||
if ctx.IsSet(f.Names()[0]) {
|
||||
log.Errorf("%s is deprecated and has no effect. Do not use this flag, it will be deleted soon.", f.Names()[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func configureConfig(ctx *cli.Context, cfg *Flags) *Flags {
|
||||
if ctx.GlobalBool(noCustomConfigFlag.Name) {
|
||||
if ctx.Bool(noCustomConfigFlag.Name) {
|
||||
log.Warn("Using default mainnet config")
|
||||
cfg.NoCustomConfig = true
|
||||
}
|
||||
if ctx.GlobalBool(minimalConfigFlag.Name) {
|
||||
if ctx.Bool(minimalConfigFlag.Name) {
|
||||
log.Warn("Using minimal config")
|
||||
cfg.MinimalConfig = true
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"flag"
|
||||
"testing"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestInitFeatureConfig(t *testing.T) {
|
||||
@@ -18,10 +18,10 @@ func TestInitFeatureConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigureBeaconConfig(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Bool(minimalConfigFlag.Name, true, "test")
|
||||
context := cli.NewContext(app, set, nil)
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
ConfigureBeaconChain(context)
|
||||
if c := Get(); !c.MinimalConfig {
|
||||
t.Errorf("MinimalConfig in FeatureFlags incorrect. Wanted true, got false")
|
||||
|
||||
28
shared/featureconfig/filter_flags.go
Normal file
28
shared/featureconfig/filter_flags.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package featureconfig
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
|
||||
// ActiveFlags returns all of the flags that are not Hidden.
|
||||
func ActiveFlags(flags []cli.Flag) []cli.Flag {
|
||||
visible := make([]cli.Flag, 0, len(flags))
|
||||
for _, flag := range flags {
|
||||
field := flagValue(flag).FieldByName("Hidden")
|
||||
if !field.IsValid() || !field.Bool() {
|
||||
visible = append(visible, flag)
|
||||
}
|
||||
}
|
||||
return visible
|
||||
}
|
||||
|
||||
func flagValue(f cli.Flag) reflect.Value {
|
||||
fv := reflect.ValueOf(f)
|
||||
for fv.Kind() == reflect.Ptr {
|
||||
fv = reflect.Indirect(fv)
|
||||
}
|
||||
return fv
|
||||
}
|
||||
@@ -1,139 +1,139 @@
|
||||
package featureconfig
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
broadcastSlashingFlag = cli.BoolFlag{
|
||||
broadcastSlashingFlag = &cli.BoolFlag{
|
||||
Name: "broadcast-slashing",
|
||||
Usage: "Broadcast slashings from slashing pool.",
|
||||
}
|
||||
noCustomConfigFlag = cli.BoolFlag{
|
||||
noCustomConfigFlag = &cli.BoolFlag{
|
||||
Name: "no-custom-config",
|
||||
Usage: "Run the beacon chain with the real parameters from phase 0.",
|
||||
}
|
||||
minimalConfigFlag = cli.BoolFlag{
|
||||
minimalConfigFlag = &cli.BoolFlag{
|
||||
Name: "minimal-config",
|
||||
Usage: "Use minimal config with parameters as defined in the spec.",
|
||||
}
|
||||
writeSSZStateTransitionsFlag = cli.BoolFlag{
|
||||
writeSSZStateTransitionsFlag = &cli.BoolFlag{
|
||||
Name: "interop-write-ssz-state-transitions",
|
||||
Usage: "Write ssz states to disk after attempted state transition",
|
||||
}
|
||||
enableDynamicCommitteeSubnets = cli.BoolFlag{
|
||||
enableDynamicCommitteeSubnets = &cli.BoolFlag{
|
||||
Name: "enable-dynamic-committee-subnets",
|
||||
Usage: "Enable dynamic committee attestation subnets.",
|
||||
}
|
||||
// disableForkChoiceUnsafeFlag disables using the LMD-GHOST fork choice to update
|
||||
// the head of the chain based on attestations and instead accepts any valid received block
|
||||
// as the chain head. UNSAFE, use with caution.
|
||||
disableForkChoiceUnsafeFlag = cli.BoolFlag{
|
||||
disableForkChoiceUnsafeFlag = &cli.BoolFlag{
|
||||
Name: "disable-fork-choice-unsafe",
|
||||
Usage: "UNSAFE: disable fork choice for determining head of the beacon chain.",
|
||||
}
|
||||
// enableAttestationCacheFlag see https://github.com/prysmaticlabs/prysm/issues/3106.
|
||||
// enableSSZCache see https://github.com/prysmaticlabs/prysm/pull/4558.
|
||||
enableSSZCache = cli.BoolFlag{
|
||||
enableSSZCache = &cli.BoolFlag{
|
||||
Name: "enable-ssz-cache",
|
||||
Usage: "Enable ssz state root cache mechanism.",
|
||||
}
|
||||
// enableEth1DataVoteCacheFlag see https://github.com/prysmaticlabs/prysm/issues/3106.
|
||||
enableEth1DataVoteCacheFlag = cli.BoolFlag{
|
||||
enableEth1DataVoteCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-eth1-data-vote-cache",
|
||||
Usage: "Enable unsafe cache mechanism. See https://github.com/prysmaticlabs/prysm/issues/3106",
|
||||
}
|
||||
skipBLSVerifyFlag = cli.BoolFlag{
|
||||
skipBLSVerifyFlag = &cli.BoolFlag{
|
||||
Name: "skip-bls-verify",
|
||||
Usage: "Whether or not to skip BLS verification of signature at runtime, this is unsafe and should only be used for development",
|
||||
}
|
||||
enableBackupWebhookFlag = cli.BoolFlag{
|
||||
enableBackupWebhookFlag = &cli.BoolFlag{
|
||||
Name: "enable-db-backup-webhook",
|
||||
Usage: "Serve HTTP handler to initiate database backups. The handler is served on the monitoring port at path /db/backup.",
|
||||
}
|
||||
enableSkipSlotsCacheFlag = cli.BoolFlag{
|
||||
enableSkipSlotsCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-skip-slots-cache",
|
||||
Usage: "Enables the skip slot cache to be used in the event of skipped slots.",
|
||||
}
|
||||
kafkaBootstrapServersFlag = cli.StringFlag{
|
||||
kafkaBootstrapServersFlag = &cli.StringFlag{
|
||||
Name: "kafka-url",
|
||||
Usage: "Stream attestations and blocks to specified kafka servers. This field is used for bootstrap.servers kafka config field.",
|
||||
}
|
||||
initSyncVerifyEverythingFlag = cli.BoolFlag{
|
||||
initSyncVerifyEverythingFlag = &cli.BoolFlag{
|
||||
Name: "initial-sync-verify-all-signatures",
|
||||
Usage: "Initial sync to finalized checkpoint with verifying block's signature, RANDAO " +
|
||||
"and attestation's aggregated signatures. Without this flag, only the proposer " +
|
||||
"signature is verified until the node reaches the end of the finalized chain.",
|
||||
}
|
||||
enableSlasherFlag = cli.BoolFlag{
|
||||
enableSlasherFlag = &cli.BoolFlag{
|
||||
Name: "enable-slasher",
|
||||
Usage: "Enables connection to a slasher service in order to retrieve slashable events. Slasher is connected to the beacon node using gRPC and " +
|
||||
"the slasher-provider flag can be used to pass its address.",
|
||||
}
|
||||
customGenesisDelayFlag = cli.Uint64Flag{
|
||||
customGenesisDelayFlag = &cli.Uint64Flag{
|
||||
Name: "custom-genesis-delay",
|
||||
Usage: "Start the genesis event with the configured genesis delay in seconds. " +
|
||||
"This flag should be used for local development and testing only.",
|
||||
}
|
||||
cacheFilteredBlockTreeFlag = cli.BoolFlag{
|
||||
cacheFilteredBlockTreeFlag = &cli.BoolFlag{
|
||||
Name: "cache-filtered-block-tree",
|
||||
Usage: "Cache filtered block tree by maintaining it rather than continually recalculating on the fly, " +
|
||||
"this is used for fork choice.",
|
||||
}
|
||||
protectProposerFlag = cli.BoolFlag{
|
||||
protectProposerFlag = &cli.BoolFlag{
|
||||
Name: "protect-proposer",
|
||||
Usage: "Prevent the validator client from signing and broadcasting 2 different block " +
|
||||
"proposals in the same epoch. Protects from slashing.",
|
||||
}
|
||||
protectAttesterFlag = cli.BoolFlag{
|
||||
protectAttesterFlag = &cli.BoolFlag{
|
||||
Name: "protect-attester",
|
||||
Usage: "Prevent the validator client from signing and broadcasting 2 any slashable attestations. " +
|
||||
"Protects from slashing.",
|
||||
}
|
||||
disableStrictAttestationPubsubVerificationFlag = cli.BoolFlag{
|
||||
disableStrictAttestationPubsubVerificationFlag = &cli.BoolFlag{
|
||||
Name: "disable-strict-attestation-pubsub-verification",
|
||||
Usage: "Disable strict signature verification of attestations in pubsub. See PR 4782 for details.",
|
||||
}
|
||||
disableUpdateHeadPerAttestation = cli.BoolFlag{
|
||||
disableUpdateHeadPerAttestation = &cli.BoolFlag{
|
||||
Name: "disable-update-head-attestation",
|
||||
Usage: "Disable update fork choice head on per attestation. See PR 4802 for details.",
|
||||
}
|
||||
enableByteMempool = cli.BoolFlag{
|
||||
enableByteMempool = &cli.BoolFlag{
|
||||
Name: "enable-byte-mempool",
|
||||
Usage: "Enable use of sync.Pool for certain byte arrays in the beacon state",
|
||||
}
|
||||
enableDomainDataCacheFlag = cli.BoolFlag{
|
||||
enableDomainDataCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-domain-data-cache",
|
||||
Usage: "Enable caching of domain data requests per epoch. This feature reduces the total " +
|
||||
"calls to the beacon node for each assignment.",
|
||||
}
|
||||
enableStateGenSigVerify = cli.BoolFlag{
|
||||
enableStateGenSigVerify = &cli.BoolFlag{
|
||||
Name: "enable-state-gen-sig-verify",
|
||||
Usage: "Enable signature verification for state gen. This feature increases the cost to generate a historical state," +
|
||||
"the resulting state is signature verified.",
|
||||
}
|
||||
checkHeadState = cli.BoolFlag{
|
||||
checkHeadState = &cli.BoolFlag{
|
||||
Name: "check-head-state",
|
||||
Usage: "Enables the checking of head state in chainservice first before retrieving the desired state from the db.",
|
||||
}
|
||||
enableNoiseHandshake = cli.BoolFlag{
|
||||
enableNoiseHandshake = &cli.BoolFlag{
|
||||
Name: "enable-noise",
|
||||
Usage: "This enables the beacon node to use NOISE instead of SECIO for performing handshakes between peers and " +
|
||||
"securing transports between peers",
|
||||
}
|
||||
dontPruneStateStartUp = cli.BoolFlag{
|
||||
dontPruneStateStartUp = &cli.BoolFlag{
|
||||
Name: "dont-prune-state-start-up",
|
||||
Usage: "Don't prune historical states upon start up",
|
||||
}
|
||||
newStateMgmt = cli.BoolFlag{
|
||||
newStateMgmt = &cli.BoolFlag{
|
||||
Name: "new-state-mgmt",
|
||||
Usage: "This enables the usage of experimental state mgmt service across Prysm",
|
||||
}
|
||||
enableInitSyncQueue = cli.BoolFlag{
|
||||
enableInitSyncQueue = &cli.BoolFlag{
|
||||
Name: "enable-initial-sync-queue",
|
||||
Usage: "Enables concurrent fetching and processing of blocks on initial sync.",
|
||||
}
|
||||
enableFieldTrie = cli.BoolFlag{
|
||||
enableFieldTrie = &cli.BoolFlag{
|
||||
Name: "enable-state-field-trie",
|
||||
Usage: "Enables the usage of state field tries to compute the state root",
|
||||
}
|
||||
@@ -143,108 +143,108 @@ var (
|
||||
const deprecatedUsage = "DEPRECATED. DO NOT USE."
|
||||
|
||||
var (
|
||||
deprecatedEnableFinalizedBlockRootIndexFlag = cli.BoolFlag{
|
||||
deprecatedEnableFinalizedBlockRootIndexFlag = &cli.BoolFlag{
|
||||
Name: "enable-finalized-block-root-index",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedOptimizeProcessEpochFlag = cli.BoolFlag{
|
||||
deprecatedOptimizeProcessEpochFlag = &cli.BoolFlag{
|
||||
Name: "optimize-process-epoch",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedPruneFinalizedStatesFlag = cli.BoolFlag{
|
||||
deprecatedPruneFinalizedStatesFlag = &cli.BoolFlag{
|
||||
Name: "prune-finalized-states",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedScatterFlag = cli.BoolFlag{
|
||||
deprecatedScatterFlag = &cli.BoolFlag{
|
||||
Name: "scatter",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableSnappyDBCompressionFlag = cli.BoolFlag{
|
||||
deprecatedEnableSnappyDBCompressionFlag = &cli.BoolFlag{
|
||||
Name: "snappy",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnablePruneBoundaryStateFlag = cli.BoolFlag{
|
||||
deprecatedEnablePruneBoundaryStateFlag = &cli.BoolFlag{
|
||||
Name: "prune-states",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableActiveIndicesCacheFlag = cli.BoolFlag{
|
||||
deprecatedEnableActiveIndicesCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-active-indices-cache",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableActiveCountCacheFlag = cli.BoolFlag{
|
||||
deprecatedEnableActiveCountCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-active-count-cache",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
deprecatedEnableCustomStateSSZFlag = cli.BoolFlag{
|
||||
deprecatedEnableCustomStateSSZFlag = &cli.BoolFlag{
|
||||
Name: "enable-custom-state-ssz",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableCommitteeCacheFlag = cli.BoolFlag{
|
||||
deprecatedEnableCommitteeCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-committee-cache",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableBLSPubkeyCacheFlag = cli.BoolFlag{
|
||||
deprecatedEnableBLSPubkeyCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-bls-pubkey-cache",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedFastCommitteeAssignmentsFlag = cli.BoolFlag{
|
||||
deprecatedFastCommitteeAssignmentsFlag = &cli.BoolFlag{
|
||||
Name: "fast-assignments",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedGenesisDelayFlag = cli.BoolFlag{
|
||||
deprecatedGenesisDelayFlag = &cli.BoolFlag{
|
||||
Name: "genesis-delay",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedNewCacheFlag = cli.BoolFlag{
|
||||
deprecatedNewCacheFlag = &cli.BoolFlag{
|
||||
Name: "new-cache",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableShuffledIndexCacheFlag = cli.BoolFlag{
|
||||
deprecatedEnableShuffledIndexCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-shuffled-index-cache",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedSaveDepositDataFlag = cli.BoolFlag{
|
||||
deprecatedSaveDepositDataFlag = &cli.BoolFlag{
|
||||
Name: "save-deposit-data",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedCacheProposerIndicesFlag = cli.BoolFlag{
|
||||
deprecatedCacheProposerIndicesFlag = &cli.BoolFlag{
|
||||
Name: "cache-proposer-indices",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedprotoArrayForkChoice = cli.BoolFlag{
|
||||
deprecatedprotoArrayForkChoice = &cli.BoolFlag{
|
||||
Name: "proto-array-forkchoice",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedForkchoiceAggregateAttestations = cli.BoolFlag{
|
||||
deprecatedForkchoiceAggregateAttestations = &cli.BoolFlag{
|
||||
Name: "forkchoice-aggregate-attestations",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableAttestationCacheFlag = cli.BoolFlag{
|
||||
deprecatedEnableAttestationCacheFlag = &cli.BoolFlag{
|
||||
Name: "enable-attestation-cache",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedInitSyncCacheStateFlag = cli.BoolFlag{
|
||||
deprecatedInitSyncCacheStateFlag = &cli.BoolFlag{
|
||||
Name: "initial-sync-cache-state",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
@@ -330,5 +330,6 @@ var E2EBeaconChainFlags = []string{
|
||||
"--enable-state-gen-sig-verify",
|
||||
"--check-head-state",
|
||||
"--enable-initial-sync-queue",
|
||||
"--enable-dynamic-committee-subnets",
|
||||
// TODO(5123): This flag currently fails E2E. Commenting until it's resolved.
|
||||
//"--enable-dynamic-committee-subnets",
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import (
|
||||
func TestDeprecatedFlags(t *testing.T) {
|
||||
for _, f := range deprecatedFlags {
|
||||
fv := reflect.ValueOf(f)
|
||||
if !fv.FieldByName("Hidden").Bool() {
|
||||
t.Errorf("%s must be hidden when deprecated.", f.GetName())
|
||||
field := reflect.Indirect(fv).FieldByName("Hidden")
|
||||
if !field.IsValid() || !field.Bool() {
|
||||
t.Errorf("%s must be hidden when deprecated.", f.Names()[0])
|
||||
}
|
||||
if !strings.Contains(fv.FieldByName("Usage").String(), "DEPRECATED. DO NOT USE.") {
|
||||
t.Errorf("Usage for %s must contain \"DEPRECATED. DO NOT USE.\"", f.GetName())
|
||||
if !strings.Contains(reflect.Indirect(fv).FieldByName("Usage").String(), "DEPRECATED. DO NOT USE.") {
|
||||
t.Errorf("Usage for %s must contain \"DEPRECATED. DO NOT USE.\"", f.Names()[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
@@ -163,7 +164,7 @@ func GenerateProposerSlashingForValidator(
|
||||
header1 := ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
Slot: bState.Slot(),
|
||||
BodyRoot: []byte{0, 1, 0},
|
||||
BodyRoot: bytesutil.PadTo([]byte{0, 1, 0}, 32),
|
||||
},
|
||||
}
|
||||
root, err := ssz.HashTreeRoot(header1.Header)
|
||||
@@ -180,7 +181,7 @@ func GenerateProposerSlashingForValidator(
|
||||
header2 := ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
Slot: bState.Slot(),
|
||||
BodyRoot: []byte{0, 2, 0},
|
||||
BodyRoot: bytesutil.PadTo([]byte{0, 2, 0}, 32),
|
||||
},
|
||||
}
|
||||
root, err = ssz.HashTreeRoot(header2.Header)
|
||||
|
||||
@@ -20,8 +20,8 @@ go_library(
|
||||
"//slasher/node:go_default_library",
|
||||
"@com_github_joonix_log//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -30,7 +30,7 @@ go_test(
|
||||
size = "small",
|
||||
srcs = ["usage_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["@com_github_urfave_cli//:go_default_library"],
|
||||
deps = ["@in_gopkg_urfave_cli_v2//:go_default_library"],
|
||||
)
|
||||
|
||||
go_image(
|
||||
@@ -56,8 +56,8 @@ go_image(
|
||||
"//slasher/node:go_default_library",
|
||||
"@com_github_joonix_log//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ type WriteAccessDatabase interface {
|
||||
SetLatestEpochDetected(ctx context.Context, epoch uint64) error
|
||||
|
||||
// BlockHeader related methods.
|
||||
SaveBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
|
||||
DeleteBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
|
||||
SaveBlockHeader(ctx context.Context, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
|
||||
DeleteBlockHeader(ctx context.Context, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
|
||||
PruneBlockHistory(ctx context.Context, currentEpoch uint64, pruningEpochAge uint64) error
|
||||
|
||||
// IndexedAttestations related methods.
|
||||
|
||||
@@ -16,6 +16,7 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/slasher/db/kv",
|
||||
visibility = ["//slasher:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
@@ -47,6 +48,8 @@ go_test(
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//slasher/db/iface:go_default_library",
|
||||
"//slasher/db/types:go_default_library",
|
||||
@@ -54,6 +57,6 @@ go_test(
|
||||
"//slasher/flags:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/slasher/db/types"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestStore_AttesterSlashingNilBucket(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -38,9 +38,9 @@ func TestStore_AttesterSlashingNilBucket(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_SaveAttesterSlashing(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -81,9 +81,9 @@ func TestStore_SaveAttesterSlashing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_SaveAttesterSlashings(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -109,9 +109,9 @@ func TestStore_SaveAttesterSlashings(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_UpdateAttesterSlashingStatus(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -167,9 +167,9 @@ func TestStore_UpdateAttesterSlashingStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_LatestEpochDetected(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"go.opencensus.io/trace"
|
||||
@@ -66,9 +67,10 @@ func (db *Store) HasBlockHeader(ctx context.Context, epoch uint64, validatorID u
|
||||
}
|
||||
|
||||
// SaveBlockHeader accepts a block header and writes it to disk.
|
||||
func (db *Store) SaveBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error {
|
||||
func (db *Store) SaveBlockHeader(ctx context.Context, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error {
|
||||
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveBlockHeader")
|
||||
defer span.End()
|
||||
epoch := helpers.SlotToEpoch(blockHeader.Header.Slot)
|
||||
key := encodeEpochValidatorIDSig(epoch, validatorID, blockHeader.Signature)
|
||||
enc, err := proto.Marshal(blockHeader)
|
||||
if err != nil {
|
||||
@@ -95,9 +97,10 @@ func (db *Store) SaveBlockHeader(ctx context.Context, epoch uint64, validatorID
|
||||
}
|
||||
|
||||
// DeleteBlockHeader deletes a block header using the epoch and validator id.
|
||||
func (db *Store) DeleteBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error {
|
||||
func (db *Store) DeleteBlockHeader(ctx context.Context, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error {
|
||||
ctx, span := trace.StartSpan(ctx, "slasherDB.DeleteBlockHeader")
|
||||
defer span.End()
|
||||
epoch := helpers.SlotToEpoch(blockHeader.Header.Slot)
|
||||
key := encodeEpochValidatorIDSig(epoch, validatorID, blockHeader.Signature)
|
||||
return db.update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(historicBlockHeadersBucket)
|
||||
|
||||
@@ -7,13 +7,15 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestNilDBHistoryBlkHdr(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -35,40 +37,36 @@ func TestNilDBHistoryBlkHdr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSaveHistoryBlkHdr(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
ctx := context.Background()
|
||||
|
||||
tests := []struct {
|
||||
epoch uint64
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
}{
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd")},
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(1),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd"), Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch + 1}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
err := db.SaveBlockHeader(ctx, tt.epoch, tt.vID, tt.bh)
|
||||
err := db.SaveBlockHeader(ctx, tt.vID, tt.bh)
|
||||
if err != nil {
|
||||
t.Fatalf("save block failed: %v", err)
|
||||
}
|
||||
|
||||
bha, err := db.BlockHeaders(ctx, tt.epoch, tt.vID)
|
||||
bha, err := db.BlockHeaders(ctx, helpers.SlotToEpoch(tt.bh.Header.Slot), tt.vID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get block: %v", err)
|
||||
}
|
||||
@@ -81,43 +79,39 @@ func TestSaveHistoryBlkHdr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteHistoryBlkHdr(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
tests := []struct {
|
||||
epoch uint64
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
}{
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd")},
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(1),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd"), Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch + 1}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
err := db.SaveBlockHeader(ctx, tt.epoch, tt.vID, tt.bh)
|
||||
err := db.SaveBlockHeader(ctx, tt.vID, tt.bh)
|
||||
if err != nil {
|
||||
t.Fatalf("save block failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
bha, err := db.BlockHeaders(ctx, tt.epoch, tt.vID)
|
||||
bha, err := db.BlockHeaders(ctx, helpers.SlotToEpoch(tt.bh.Header.Slot), tt.vID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get block: %v", err)
|
||||
}
|
||||
@@ -125,11 +119,11 @@ func TestDeleteHistoryBlkHdr(t *testing.T) {
|
||||
if bha == nil || !reflect.DeepEqual(bha[0], tt.bh) {
|
||||
t.Fatalf("get should return bh: %v", bha)
|
||||
}
|
||||
err = db.DeleteBlockHeader(ctx, tt.epoch, tt.vID, tt.bh)
|
||||
err = db.DeleteBlockHeader(ctx, tt.vID, tt.bh)
|
||||
if err != nil {
|
||||
t.Fatalf("save block failed: %v", err)
|
||||
}
|
||||
bh, err := db.BlockHeaders(ctx, tt.epoch, tt.vID)
|
||||
bh, err := db.BlockHeaders(ctx, helpers.SlotToEpoch(tt.bh.Header.Slot), tt.vID)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -143,51 +137,47 @@ func TestDeleteHistoryBlkHdr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHasHistoryBlkHdr(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
tests := []struct {
|
||||
epoch uint64
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
}{
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd")},
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(1),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd"), Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch + 1}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
found := db.HasBlockHeader(ctx, tt.epoch, tt.vID)
|
||||
found := db.HasBlockHeader(ctx, helpers.SlotToEpoch(tt.bh.Header.Slot), tt.vID)
|
||||
if found {
|
||||
t.Fatal("has block header should return false for block headers that are not in db")
|
||||
}
|
||||
err := db.SaveBlockHeader(ctx, tt.epoch, tt.vID, tt.bh)
|
||||
err := db.SaveBlockHeader(ctx, tt.vID, tt.bh)
|
||||
if err != nil {
|
||||
t.Fatalf("save block failed: %v", err)
|
||||
}
|
||||
}
|
||||
for _, tt := range tests {
|
||||
err := db.SaveBlockHeader(ctx, tt.epoch, tt.vID, tt.bh)
|
||||
err := db.SaveBlockHeader(ctx, tt.vID, tt.bh)
|
||||
if err != nil {
|
||||
t.Fatalf("save block failed: %v", err)
|
||||
}
|
||||
|
||||
found := db.HasBlockHeader(ctx, tt.epoch, tt.vID)
|
||||
found := db.HasBlockHeader(ctx, helpers.SlotToEpoch(tt.bh.Header.Slot), tt.vID)
|
||||
|
||||
if !found {
|
||||
t.Fatal("has block header should return true")
|
||||
@@ -196,51 +186,45 @@ func TestHasHistoryBlkHdr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPruneHistoryBlkHdr(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
tests := []struct {
|
||||
epoch uint64
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
vID uint64
|
||||
bh *ethpb.SignedBeaconBlockHeader
|
||||
}{
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(0),
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd")},
|
||||
vID: uint64(1),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 2nd"), Header: ðpb.BeaconBlockHeader{Slot: 0}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(1),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 3rd"), Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch + 1}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(2),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 4th")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 4th"), Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch*2 + 1}},
|
||||
},
|
||||
{
|
||||
epoch: uint64(3),
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 5th")},
|
||||
vID: uint64(0),
|
||||
bh: ðpb.SignedBeaconBlockHeader{Signature: []byte("let me in 5th"), Header: ðpb.BeaconBlockHeader{Slot: params.BeaconConfig().SlotsPerEpoch*3 + 1}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
err := db.SaveBlockHeader(ctx, tt.epoch, tt.vID, tt.bh)
|
||||
err := db.SaveBlockHeader(ctx, tt.vID, tt.bh)
|
||||
if err != nil {
|
||||
t.Fatalf("save block header failed: %v", err)
|
||||
}
|
||||
|
||||
bha, err := db.BlockHeaders(ctx, tt.epoch, tt.vID)
|
||||
bha, err := db.BlockHeaders(ctx, helpers.SlotToEpoch(tt.bh.Header.Slot), tt.vID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get block header: %v", err)
|
||||
}
|
||||
@@ -257,11 +241,11 @@ func TestPruneHistoryBlkHdr(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
bha, err := db.BlockHeaders(ctx, tt.epoch, tt.vID)
|
||||
bha, err := db.BlockHeaders(ctx, helpers.SlotToEpoch(tt.bh.Header.Slot), tt.vID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get block header: %v", err)
|
||||
}
|
||||
if tt.epoch > currentEpoch-historyToKeep {
|
||||
if helpers.SlotToEpoch(tt.bh.Header.Slot) > currentEpoch-historyToKeep {
|
||||
if bha == nil || !reflect.DeepEqual(bha[0], tt.bh) {
|
||||
t.Fatalf("get should return bh: %v", bha)
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestChainHead(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := &cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
type testStruct struct {
|
||||
@@ -62,9 +62,9 @@ func init() {
|
||||
}
|
||||
|
||||
func TestHasIndexedAttestation_NilDB(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestHasIndexedAttestation_NilDB(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSaveIndexedAttestation(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := &cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
@@ -324,9 +324,9 @@ func TestIndexedAttestationsWithPrefix(t *testing.T) {
|
||||
}
|
||||
for _, tt := range prefixTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -494,9 +494,9 @@ func TestIndexedAttestationsForTarget(t *testing.T) {
|
||||
}
|
||||
for _, tt := range prefixTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -688,7 +688,7 @@ func TestDeleteIndexedAttestation(t *testing.T) {
|
||||
}
|
||||
for _, tt := range deleteTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := &cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
@@ -728,9 +728,9 @@ func TestDeleteIndexedAttestation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHasIndexedAttestation(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -760,9 +760,9 @@ func TestHasIndexedAttestation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPruneHistoryIndexedAttestation(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/slasher/db/iface"
|
||||
"github.com/prysmaticlabs/prysm/slasher/flags"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func setupDB(t testing.TB, ctx *cli.Context) *Store {
|
||||
@@ -23,7 +23,7 @@ func setupDB(t testing.TB, ctx *cli.Context) *Store {
|
||||
if err := os.RemoveAll(p); err != nil {
|
||||
t.Fatalf("Failed to remove directory: %v", err)
|
||||
}
|
||||
cfg := &Config{SpanCacheEnabled: ctx.GlobalBool(flags.UseSpanCacheFlag.Name)}
|
||||
cfg := &Config{SpanCacheEnabled: ctx.Bool(flags.UseSpanCacheFlag.Name)}
|
||||
db, err := NewKVStore(p, cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to instantiate DB: %v", err)
|
||||
|
||||
@@ -9,13 +9,13 @@ import (
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/slasher/db/types"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestStore_ProposerSlashingNilBucket(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -38,9 +38,9 @@ func TestStore_ProposerSlashingNilBucket(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_SaveProposerSlashing(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -81,9 +81,9 @@ func TestStore_SaveProposerSlashing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_UpdateProposerSlashingStatus(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -141,9 +141,9 @@ func TestStore_UpdateProposerSlashingStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_SaveProposerSlashings(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
|
||||
"github.com/prysmaticlabs/prysm/slasher/flags"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
type spanMapTestStruct struct {
|
||||
@@ -49,9 +49,9 @@ func init() {
|
||||
}
|
||||
|
||||
func TestValidatorSpanMap_NilDB(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -66,9 +66,9 @@ func TestValidatorSpanMap_NilDB(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_SaveSpans(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -96,10 +96,10 @@ func TestStore_SaveSpans(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_SaveCachedSpans(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -129,9 +129,9 @@ func TestStore_SaveCachedSpans(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_DeleteEpochSpans(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -165,10 +165,10 @@ func TestStore_DeleteEpochSpans(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorSpanMap_DeletesOnCacheSavesToDB(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -240,10 +240,10 @@ func TestValidatorSpanMap_SaveOnEvict(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorSpanMap_SaveCachedSpansMaps(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.Bool(flags.UseSpanCacheFlag.Name, true, "enable span map cache")
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"flag"
|
||||
"testing"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
type publicKeyTestStruct struct {
|
||||
@@ -34,9 +34,9 @@ func init() {
|
||||
}
|
||||
|
||||
func TestNilDBValidatorPublicKey(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -53,9 +53,9 @@ func TestNilDBValidatorPublicKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSavePubKey(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -78,9 +78,9 @@ func TestSavePubKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeletePublicKey(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
db := setupDB(t, cli.NewContext(app, set, nil))
|
||||
db := setupDB(t, cli.NewContext(&app, set, nil))
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ go_library(
|
||||
"//slasher/detection/attestations:go_default_library",
|
||||
"//slasher/detection/attestations/iface:go_default_library",
|
||||
"//slasher/detection/attestations/types:go_default_library",
|
||||
"//slasher/detection/proposals:go_default_library",
|
||||
"//slasher/detection/proposals/iface:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
|
||||
@@ -152,6 +152,10 @@ func (ds *Service) detectSurroundVotes(
|
||||
return nil, errors.New("unexpected false positive in surround vote detection")
|
||||
}
|
||||
|
||||
func (ds *Service) detectDoubleProposels(ctx context.Context, incommingBlk *ethpb.SignedBeaconBlockHeader) (*ethpb.ProposerSlashing, error) {
|
||||
return ds.proposalsDetector.DetectDoublePropose(ctx, incommingBlk)
|
||||
}
|
||||
|
||||
func isDoubleVote(incomingAtt *ethpb.IndexedAttestation, prevAtt *ethpb.IndexedAttestation) bool {
|
||||
return !proto.Equal(incomingAtt.Data, prevAtt.Data) && incomingAtt.Data.Target.Epoch == prevAtt.Data.Target.Epoch
|
||||
}
|
||||
|
||||
27
slasher/detection/proposals/BUILD.bazel
Normal file
27
slasher/detection/proposals/BUILD.bazel
Normal file
@@ -0,0 +1,27 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["detector.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/slasher/detection/proposals",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//slasher/db:go_default_library",
|
||||
"//slasher/db/types:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["detector_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//shared/params:go_default_library",
|
||||
"//slasher/db/testing:go_default_library",
|
||||
"//slasher/detection/proposals/iface:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
],
|
||||
)
|
||||
54
slasher/detection/proposals/detector.go
Normal file
54
slasher/detection/proposals/detector.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package proposals
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/slasher/db"
|
||||
status "github.com/prysmaticlabs/prysm/slasher/db/types"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// ProposeDetector defines a struct which can detect slashable
|
||||
// block proposals.
|
||||
type ProposeDetector struct {
|
||||
slasherDB db.Database
|
||||
}
|
||||
|
||||
// NewProposeDetector creates a new instance of a struct.
|
||||
func NewProposeDetector(db db.Database) *ProposeDetector {
|
||||
return &ProposeDetector{
|
||||
slasherDB: db,
|
||||
}
|
||||
}
|
||||
|
||||
// DetectDoublePropose detects double proposals given a block by looking in the db.
|
||||
func (dd *ProposeDetector) DetectDoublePropose(
|
||||
ctx context.Context,
|
||||
incomingBlk *ethpb.SignedBeaconBlockHeader,
|
||||
) (*ethpb.ProposerSlashing, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "detector.DetectDoublePropose")
|
||||
defer span.End()
|
||||
epoch := helpers.SlotToEpoch(incomingBlk.Header.Slot)
|
||||
//TODO(#5119) remove constand and use input from block header.
|
||||
//validatorIdx:=blk.Header.ProposerIndex
|
||||
proposerIdx := uint64(0)
|
||||
bha, err := dd.slasherDB.BlockHeaders(ctx, epoch, proposerIdx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, bh := range bha {
|
||||
if bytes.Equal(bh.Signature, incomingBlk.Signature) {
|
||||
continue
|
||||
}
|
||||
ps := ðpb.ProposerSlashing{ProposerIndex: proposerIdx, Header_1: incomingBlk, Header_2: bh}
|
||||
err := dd.slasherDB.SaveProposerSlashing(ctx, status.Active, ps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ps, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
114
slasher/detection/proposals/detector_test.go
Normal file
114
slasher/detection/proposals/detector_test.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package proposals
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
testDB "github.com/prysmaticlabs/prysm/slasher/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/slasher/detection/proposals/iface"
|
||||
)
|
||||
|
||||
var _ = iface.ProposalsDetector(&ProposeDetector{})
|
||||
|
||||
func TestProposalsDetector_DetectSlashingsForBlockHeaders(t *testing.T) {
|
||||
type testStruct struct {
|
||||
name string
|
||||
blk *ethpb.SignedBeaconBlockHeader
|
||||
incomingBlk *ethpb.SignedBeaconBlockHeader
|
||||
slashing *ethpb.ProposerSlashing
|
||||
}
|
||||
blk1epoch0, err := signedBlockHeader(startSlot(0), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk2epoch0, err := signedBlockHeader(startSlot(0)+1, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk1epoch1, err := signedBlockHeader(startSlot(1), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
//blk1epoch3, err := signedBlockHeader(startSlot(3), 0)
|
||||
//if err != nil {
|
||||
// t.Fatal(err)
|
||||
//}
|
||||
tests := []testStruct{
|
||||
{
|
||||
name: "same block sig dont slash",
|
||||
blk: blk1epoch0,
|
||||
incomingBlk: blk1epoch0,
|
||||
slashing: nil,
|
||||
},
|
||||
{
|
||||
name: "block from different epoch dont slash",
|
||||
blk: blk1epoch0,
|
||||
incomingBlk: blk1epoch1,
|
||||
slashing: nil,
|
||||
},
|
||||
{
|
||||
name: "different sig from same epoch slash",
|
||||
blk: blk1epoch0,
|
||||
incomingBlk: blk2epoch0,
|
||||
slashing: ðpb.ProposerSlashing{ProposerIndex: 0, Header_1: blk2epoch0, Header_2: blk1epoch0},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db := testDB.SetupSlasherDB(t, false)
|
||||
defer testDB.TeardownSlasherDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
sd := &ProposeDetector{
|
||||
slasherDB: db,
|
||||
}
|
||||
|
||||
if err := sd.slasherDB.SaveBlockHeader(ctx, 0, tt.blk); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
res, err := sd.DetectDoublePropose(ctx, tt.incomingBlk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(res, tt.slashing) {
|
||||
t.Errorf("Wanted: %v, received %v", tt.slashing, res)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func signedBlockHeader(slot uint64, proposerIdx uint64) (*ethpb.SignedBeaconBlockHeader, error) {
|
||||
sig, err := genRandomSig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
root := [32]byte{1, 2, 3}
|
||||
return ðpb.SignedBeaconBlockHeader{
|
||||
Header: ðpb.BeaconBlockHeader{
|
||||
//ProposerIndex proposerIndex,
|
||||
Slot: slot,
|
||||
ParentRoot: root[:],
|
||||
StateRoot: root[:],
|
||||
BodyRoot: root[:],
|
||||
},
|
||||
Signature: sig,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func genRandomSig() (blk []byte, err error) {
|
||||
blk = make([]byte, 96)
|
||||
_, err = rand.Read(blk)
|
||||
return
|
||||
}
|
||||
|
||||
func startSlot(epoch uint64) uint64 {
|
||||
return epoch * params.BeaconConfig().SlotsPerEpoch
|
||||
}
|
||||
9
slasher/detection/proposals/iface/BUILD.bazel
Normal file
9
slasher/detection/proposals/iface/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["iface.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/slasher/detection/proposals/iface",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library"],
|
||||
)
|
||||
12
slasher/detection/proposals/iface/iface.go
Normal file
12
slasher/detection/proposals/iface/iface.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package iface
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
)
|
||||
|
||||
// ProposalsDetector defines an interface for different implementations.
|
||||
type ProposalsDetector interface {
|
||||
DetectDoublePropose(ctx context.Context, incomingBlk *ethpb.SignedBeaconBlockHeader) (*ethpb.ProposerSlashing, error)
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/slasher/db"
|
||||
"github.com/prysmaticlabs/prysm/slasher/detection/attestations"
|
||||
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/iface"
|
||||
"github.com/prysmaticlabs/prysm/slasher/detection/proposals"
|
||||
proposerIface "github.com/prysmaticlabs/prysm/slasher/detection/proposals/iface"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@@ -29,6 +31,7 @@ type Service struct {
|
||||
attesterSlashingsFeed *event.Feed
|
||||
proposerSlashingsFeed *event.Feed
|
||||
minMaxSpanDetector iface.SpanDetector
|
||||
proposalsDetector proposerIface.ProposalsDetector
|
||||
}
|
||||
|
||||
// Config options for the detection service.
|
||||
@@ -56,6 +59,7 @@ func NewDetectionService(ctx context.Context, cfg *Config) *Service {
|
||||
attesterSlashingsFeed: cfg.AttesterSlashingsFeed,
|
||||
proposerSlashingsFeed: cfg.ProposerSlashingsFeed,
|
||||
minMaxSpanDetector: attestations.NewSpanDetector(cfg.SlasherDB),
|
||||
proposalsDetector: proposals.NewProposeDetector(cfg.SlasherDB),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@ go_library(
|
||||
srcs = ["flags.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/slasher/flags",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_urfave_cli//:go_default_library"],
|
||||
deps = ["@in_gopkg_urfave_cli_v2//:go_default_library"],
|
||||
)
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// CertFlag defines a flag for the node's TLS certificate.
|
||||
CertFlag = cli.StringFlag{
|
||||
CertFlag = &cli.StringFlag{
|
||||
Name: "tls-cert",
|
||||
Usage: "Certificate for secure gRPC. Pass this and the tls-key flag in order to use gRPC securely.",
|
||||
}
|
||||
// RPCPort defines a slasher node RPC port to open.
|
||||
RPCPort = cli.IntFlag{
|
||||
RPCPort = &cli.IntFlag{
|
||||
Name: "rpc-port",
|
||||
Usage: "RPC port exposed by a beacon node",
|
||||
Value: 5000,
|
||||
}
|
||||
// KeyFlag defines a flag for the node's TLS key.
|
||||
KeyFlag = cli.StringFlag{
|
||||
KeyFlag = &cli.StringFlag{
|
||||
Name: "tls-key",
|
||||
Usage: "Key for secure gRPC. Pass this and the tls-cert flag in order to use gRPC securely.",
|
||||
}
|
||||
// BeaconCertFlag defines a flag for the beacon api certificate.
|
||||
BeaconCertFlag = cli.StringFlag{
|
||||
BeaconCertFlag = &cli.StringFlag{
|
||||
Name: "beacon-tls-cert",
|
||||
Usage: "Certificate for secure beacon gRPC connection. Pass this in order to use beacon gRPC securely.",
|
||||
}
|
||||
// BeaconRPCProviderFlag defines a flag for the beacon host ip or address.
|
||||
BeaconRPCProviderFlag = cli.StringFlag{
|
||||
BeaconRPCProviderFlag = &cli.StringFlag{
|
||||
Name: "beacon-rpc-provider",
|
||||
Usage: "Beacon node RPC provider endpoint",
|
||||
Value: "localhost:4000",
|
||||
}
|
||||
// UseSpanCacheFlag enables the slasher to use span cache.
|
||||
UseSpanCacheFlag = cli.BoolFlag{
|
||||
UseSpanCacheFlag = &cli.BoolFlag{
|
||||
Name: "span-map-cache",
|
||||
Usage: "Enable span map cache",
|
||||
}
|
||||
// RebuildSpanMapsFlag iterate through all indexed attestations in db and update all validators span maps from scratch.
|
||||
RebuildSpanMapsFlag = cli.BoolFlag{
|
||||
RebuildSpanMapsFlag = &cli.BoolFlag{
|
||||
Name: "rebuild-span-maps",
|
||||
Usage: "Rebuild span maps from indexed attestations in db",
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/slasher/flags"
|
||||
"github.com/prysmaticlabs/prysm/slasher/node"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "main")
|
||||
|
||||
func startSlasher(ctx *cli.Context) error {
|
||||
verbosity := ctx.GlobalString(cmd.VerbosityFlag.Name)
|
||||
verbosity := ctx.String(cmd.VerbosityFlag.Name)
|
||||
level, err := logrus.ParseLevel(verbosity)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -62,14 +62,14 @@ var appFlags = []cli.Flag{
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
app.Name = "hash slinging slasher"
|
||||
app.Usage = `launches an Ethereum Serenity slasher server that interacts with a beacon chain.`
|
||||
app.Version = version.GetVersion()
|
||||
app.Flags = appFlags
|
||||
app.Action = startSlasher
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
format := ctx.GlobalString(cmd.LogFormat.Name)
|
||||
format := ctx.String(cmd.LogFormat.Name)
|
||||
switch format {
|
||||
case "text":
|
||||
formatter := new(prefixed.TextFormatter)
|
||||
@@ -77,7 +77,7 @@ func main() {
|
||||
formatter.FullTimestamp = true
|
||||
// If persistent log files are written - we disable the log messages coloring because
|
||||
// the colors are ANSI codes and seen as Gibberish in the log files.
|
||||
formatter.DisableColors = ctx.GlobalString(cmd.LogFileName.Name) != ""
|
||||
formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != ""
|
||||
logrus.SetFormatter(formatter)
|
||||
break
|
||||
case "fluentd":
|
||||
@@ -90,7 +90,7 @@ func main() {
|
||||
return fmt.Errorf("unknown log format %s", format)
|
||||
}
|
||||
|
||||
logFileName := ctx.GlobalString(cmd.LogFileName.Name)
|
||||
logFileName := ctx.String(cmd.LogFileName.Name)
|
||||
if logFileName != "" {
|
||||
if err := logutil.ConfigurePersistentLogging(logFileName); err != nil {
|
||||
log.WithError(err).Error("Failed to configuring logging to disk.")
|
||||
|
||||
@@ -18,7 +18,7 @@ go_library(
|
||||
"//slasher/detection:go_default_library",
|
||||
"//slasher/flags:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -29,6 +29,6 @@ go_test(
|
||||
deps = [
|
||||
"//shared/testutil:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/slasher/detection"
|
||||
"github.com/prysmaticlabs/prysm/slasher/flags"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "node")
|
||||
@@ -46,10 +46,10 @@ type SlasherNode struct {
|
||||
func NewSlasherNode(ctx *cli.Context) (*SlasherNode, error) {
|
||||
if err := tracing.Setup(
|
||||
"slasher", // Service name.
|
||||
ctx.GlobalString(cmd.TracingProcessNameFlag.Name),
|
||||
ctx.GlobalString(cmd.TracingEndpointFlag.Name),
|
||||
ctx.GlobalFloat64(cmd.TraceSampleFractionFlag.Name),
|
||||
ctx.GlobalBool(cmd.EnableTracingFlag.Name),
|
||||
ctx.String(cmd.TracingProcessNameFlag.Name),
|
||||
ctx.String(cmd.TracingEndpointFlag.Name),
|
||||
ctx.Float64(cmd.TraceSampleFractionFlag.Name),
|
||||
ctx.Bool(cmd.EnableTracingFlag.Name),
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (s *SlasherNode) Close() {
|
||||
|
||||
func (s *SlasherNode) registerPrometheusService(ctx *cli.Context) error {
|
||||
service := prometheus.NewPrometheusService(
|
||||
fmt.Sprintf(":%d", ctx.GlobalInt64(cmd.MonitoringPortFlag.Name)),
|
||||
fmt.Sprintf(":%d", ctx.Int64(cmd.MonitoringPortFlag.Name)),
|
||||
s.services,
|
||||
)
|
||||
logrus.AddHook(prometheus.NewLogrusCollector())
|
||||
@@ -132,11 +132,11 @@ func (s *SlasherNode) registerPrometheusService(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
func (s *SlasherNode) startDB(ctx *cli.Context) error {
|
||||
baseDir := ctx.GlobalString(cmd.DataDirFlag.Name)
|
||||
clearDB := ctx.GlobalBool(cmd.ClearDB.Name)
|
||||
forceClearDB := ctx.GlobalBool(cmd.ForceClearDB.Name)
|
||||
baseDir := ctx.String(cmd.DataDirFlag.Name)
|
||||
clearDB := ctx.Bool(cmd.ClearDB.Name)
|
||||
forceClearDB := ctx.Bool(cmd.ForceClearDB.Name)
|
||||
dbPath := path.Join(baseDir, slasherDBName)
|
||||
cfg := &kv.Config{SpanCacheEnabled: ctx.GlobalBool(flags.UseSpanCacheFlag.Name)}
|
||||
cfg := &kv.Config{SpanCacheEnabled: ctx.Bool(flags.UseSpanCacheFlag.Name)}
|
||||
d, err := db.NewDB(dbPath, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -167,8 +167,8 @@ func (s *SlasherNode) startDB(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
func (s *SlasherNode) registerBeaconClientService(ctx *cli.Context) error {
|
||||
beaconCert := ctx.GlobalString(flags.BeaconCertFlag.Name)
|
||||
beaconProvider := ctx.GlobalString(flags.BeaconRPCProviderFlag.Name)
|
||||
beaconCert := ctx.String(flags.BeaconCertFlag.Name)
|
||||
beaconProvider := ctx.String(flags.BeaconRPCProviderFlag.Name)
|
||||
if beaconProvider == "" {
|
||||
beaconProvider = flags.BeaconRPCProviderFlag.Value
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// Test that slasher node can close.
|
||||
@@ -20,12 +20,12 @@ func TestNodeClose_OK(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("beacon-rpc-provider", "localhost:4232", "beacon node RPC server")
|
||||
set.String("datadir", tmp, "node data directory")
|
||||
|
||||
context := cli.NewContext(app, set, nil)
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
|
||||
node, err := NewSlasherNode(context)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/prysmaticlabs/prysm/shared/debug"
|
||||
"github.com/prysmaticlabs/prysm/slasher/flags"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var appHelpTemplate = `NAME:
|
||||
|
||||
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestAllFlagsExistInHelp(t *testing.T) {
|
||||
@@ -18,14 +18,14 @@ func TestAllFlagsExistInHelp(t *testing.T) {
|
||||
|
||||
for _, flag := range appFlags {
|
||||
if !doesFlagExist(flag, helpFlags) {
|
||||
t.Errorf("Flag %s does not exist in help/usage flags.", flag.GetName())
|
||||
t.Errorf("Flag %s does not exist in help/usage flags.", flag.Names()[0])
|
||||
}
|
||||
}
|
||||
|
||||
for _, flag := range helpFlags {
|
||||
if !doesFlagExist(flag, appFlags) {
|
||||
t.Errorf("Flag %s does not exist in main.go, "+
|
||||
"but exists in help flags", flag.GetName())
|
||||
"but exists in help flags", flag.Names()[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
diff --git a/eth/v1alpha1/BUILD.bazel b/eth/v1alpha1/BUILD.bazel
|
||||
index c0fbe31..ae4ff87 100644
|
||||
index c0fbe31..1211829 100644
|
||||
--- a/eth/v1alpha1/BUILD.bazel
|
||||
+++ b/eth/v1alpha1/BUILD.bazel
|
||||
@@ -25,7 +25,6 @@ proto_library(
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||
load("@rules_java//java:defs.bzl", "java_proto_library")
|
||||
+load("@prysm//tools:ssz.bzl", "SSZ_DEPS", "ssz_gen_marshal")
|
||||
|
||||
##############################################################################
|
||||
# Go
|
||||
@@ -25,7 +26,6 @@ proto_library(
|
||||
"beacon_chain.proto",
|
||||
"node.proto",
|
||||
"validator.proto",
|
||||
@@ -10,7 +18,7 @@ index c0fbe31..ae4ff87 100644
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
@@ -33,6 +32,7 @@ proto_library(
|
||||
@@ -33,6 +33,7 @@ proto_library(
|
||||
"@com_google_protobuf//:any_proto",
|
||||
"@com_google_protobuf//:timestamp_proto",
|
||||
"@go_googleapis//google/api:annotations_proto",
|
||||
@@ -18,7 +26,7 @@ index c0fbe31..ae4ff87 100644
|
||||
"@grpc_ecosystem_grpc_gateway//protoc-gen-swagger/options:options_proto",
|
||||
],
|
||||
)
|
||||
@@ -48,11 +48,30 @@ java_proto_library(
|
||||
@@ -48,11 +49,46 @@ java_proto_library(
|
||||
|
||||
go_proto_library(
|
||||
name = "go_proto",
|
||||
@@ -33,6 +41,22 @@ index c0fbe31..ae4ff87 100644
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+ssz_gen_marshal(
|
||||
+ name = "ssz_generated_files",
|
||||
+ go_proto = ":go_proto",
|
||||
+ objs = [
|
||||
+ "Attestation",
|
||||
+ "BeaconBlock",
|
||||
+ "SignedBeaconBlock",
|
||||
+ "Validator",
|
||||
+ "BeaconBlockHeader",
|
||||
+ "AttesterSlashing",
|
||||
+ "VoluntaryExit",
|
||||
+ "Deposit",
|
||||
+ "ProposerSlashing",
|
||||
+ ],
|
||||
+)
|
||||
+
|
||||
+go_proto_library(
|
||||
+ name = "go_grpc_gateway_library",
|
||||
+ compilers = [
|
||||
@@ -50,6 +74,18 @@ index c0fbe31..ae4ff87 100644
|
||||
"@go_googleapis//google/api:annotations_go_proto",
|
||||
"@grpc_ecosystem_grpc_gateway//protoc-gen-swagger/options:options_go_proto",
|
||||
],
|
||||
@@ -60,9 +96,11 @@ go_proto_library(
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
+ srcs = [":ssz_generated_files"],
|
||||
embed = [":go_proto"],
|
||||
importpath = "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1",
|
||||
visibility = ["//visibility:public"],
|
||||
+ deps = SSZ_DEPS,
|
||||
)
|
||||
|
||||
protoc_gen_swagger(
|
||||
diff --git a/eth/v1alpha1/attestation.proto b/eth/v1alpha1/attestation.proto
|
||||
index b177b76..28b4b46 100644
|
||||
--- a/eth/v1alpha1/attestation.proto
|
||||
@@ -262,7 +298,7 @@ index 2ce5c34..4cbb276 100644
|
||||
+ bytes signature = 3 [(gogoproto.moretags) = "ssz-size:\"96\""];
|
||||
}
|
||||
diff --git a/eth/v1alpha1/beacon_chain.proto b/eth/v1alpha1/beacon_chain.proto
|
||||
index 0099328..8b8c6eb 100644
|
||||
index 32d0b16..1679371 100644
|
||||
--- a/eth/v1alpha1/beacon_chain.proto
|
||||
+++ b/eth/v1alpha1/beacon_chain.proto
|
||||
@@ -15,6 +15,7 @@ syntax = "proto3";
|
||||
@@ -327,7 +363,7 @@ index 0099328..8b8c6eb 100644
|
||||
|
||||
// Validator's index in the validator set.
|
||||
uint64 index = 2;
|
||||
@@ -552,7 +553,7 @@ message GetValidatorRequest {
|
||||
@@ -560,7 +561,7 @@ message GetValidatorRequest {
|
||||
uint64 index = 1;
|
||||
|
||||
// 48 byte validator public key.
|
||||
@@ -336,7 +372,7 @@ index 0099328..8b8c6eb 100644
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,26 +595,25 @@ message ActiveSetChanges {
|
||||
@@ -602,26 +603,25 @@ message ActiveSetChanges {
|
||||
uint64 epoch = 1;
|
||||
|
||||
// 48 byte validator public keys that have been activated in the given epoch.
|
||||
@@ -369,7 +405,7 @@ index 0099328..8b8c6eb 100644
|
||||
|
||||
// Indices of validators ejected in the given epoch.
|
||||
repeated uint64 ejected_indices = 9;
|
||||
@@ -663,11 +663,11 @@ message ValidatorQueue {
|
||||
@@ -671,11 +671,11 @@ message ValidatorQueue {
|
||||
|
||||
// Ordered list of 48 byte public keys awaiting activation. 0th index is the
|
||||
// next key to be processed.
|
||||
@@ -383,7 +419,7 @@ index 0099328..8b8c6eb 100644
|
||||
}
|
||||
|
||||
message ListValidatorAssignmentsRequest {
|
||||
@@ -679,7 +679,7 @@ message ListValidatorAssignmentsRequest {
|
||||
@@ -687,7 +687,7 @@ message ListValidatorAssignmentsRequest {
|
||||
bool genesis = 2;
|
||||
}
|
||||
// 48 byte validator public keys to filter assignments for the given epoch.
|
||||
@@ -392,7 +428,7 @@ index 0099328..8b8c6eb 100644
|
||||
|
||||
// Validator indicies to filter assignments for the given epoch.
|
||||
repeated uint64 indices = 4;
|
||||
@@ -714,7 +714,7 @@ message ValidatorAssignments {
|
||||
@@ -722,7 +722,7 @@ message ValidatorAssignments {
|
||||
uint64 proposer_slot = 4;
|
||||
|
||||
// 48 byte BLS public key.
|
||||
|
||||
46
third_party/com_github_prysmaticlabs_go_ssz.patch
vendored
Normal file
46
third_party/com_github_prysmaticlabs_go_ssz.patch
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
diff --git a/BUILD.bazel b/BUILD.bazel
|
||||
index e502174..1c29b7a 100644
|
||||
--- a/BUILD.bazel
|
||||
+++ b/BUILD.bazel
|
||||
@@ -61,6 +61,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//types:go_default_library",
|
||||
+ "@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
diff --git a/ssz.go b/ssz.go
|
||||
index 61fb9ef..24755fc 100644
|
||||
--- a/ssz.go
|
||||
+++ b/ssz.go
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
+ fssz "github.com/ferranbt/fastssz"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz/types"
|
||||
@@ -48,6 +49,11 @@ func Marshal(val interface{}) ([]byte, error) {
|
||||
if val == nil {
|
||||
return nil, errors.New("untyped-value nil cannot be marshaled")
|
||||
}
|
||||
+
|
||||
+ if v, ok := val.(fssz.Marshaler); ok {
|
||||
+ return v.MarshalSSZ()
|
||||
+ }
|
||||
+
|
||||
rval := reflect.ValueOf(val)
|
||||
|
||||
// We pre-allocate a buffer-size depending on the value's calculated total byte size.
|
||||
@@ -87,6 +93,9 @@ func Unmarshal(input []byte, val interface{}) error {
|
||||
if val == nil {
|
||||
return errors.New("cannot unmarshal into untyped, nil value")
|
||||
}
|
||||
+ if v, ok := val.(fssz.Unmarshaler); ok {
|
||||
+ return v.UnmarshalSSZ(input)
|
||||
+ }
|
||||
if len(input) == 0 {
|
||||
return errors.New("no data to unmarshal from, input is an empty byte slice []byte{}")
|
||||
}
|
||||
@@ -15,8 +15,8 @@ go_library(
|
||||
"@com_github_ethereum_go_ethereum//ethclient:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
|
||||
"@io_k8s_client_go//kubernetes:go_default_library",
|
||||
"@io_k8s_client_go//rest:go_default_library",
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
k8s "k8s.io/client-go/kubernetes"
|
||||
@@ -40,44 +40,44 @@ func main() {
|
||||
logrus.SetFormatter(customFormatter)
|
||||
log := logrus.WithField("prefix", "main")
|
||||
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
app.Name = "deployDepositContract"
|
||||
app.Usage = "this is a util to deploy deposit contract"
|
||||
app.Version = version.GetVersion()
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "keystoreUTCPath",
|
||||
Usage: "Location of keystore",
|
||||
Destination: &keystoreUTCPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "ipcPath",
|
||||
Usage: "Filename for IPC socket/pipe within the datadir",
|
||||
Destination: &ipcPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "httpPath",
|
||||
Value: "http://localhost:8545/",
|
||||
Usage: "HTTP-RPC server listening interface",
|
||||
Destination: &httpPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "passwordFile",
|
||||
Value: "./password.txt",
|
||||
Usage: "Password file for unlock account",
|
||||
Destination: &passwordFile,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "privKey",
|
||||
Usage: "Private key to unlock account",
|
||||
Destination: &privKeyString,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "k8sConfig",
|
||||
Usage: "Name of kubernetes config map to update with the contract address",
|
||||
Destination: &k8sConfigMapName,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "drainAddress",
|
||||
Value: "",
|
||||
Usage: "The drain address to specify in the contract. The default will be msg.sender",
|
||||
@@ -85,7 +85,7 @@ func main() {
|
||||
},
|
||||
}
|
||||
|
||||
app.Action = func(c *cli.Context) {
|
||||
app.Action = func(c *cli.Context) error {
|
||||
// Set up RPC client
|
||||
var rpcClient *rpc.Client
|
||||
var err error
|
||||
@@ -98,7 +98,7 @@ func main() {
|
||||
rpcClient, err = rpc.Dial(ipcPath)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
client := ethclient.NewClient(rpcClient)
|
||||
@@ -117,7 +117,7 @@ func main() {
|
||||
// #nosec - Inclusion of file via variable is OK for this tool.
|
||||
file, err := os.Open(passwordFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
@@ -128,11 +128,11 @@ func main() {
|
||||
// #nosec - Inclusion of file via variable is OK for this tool.
|
||||
keyJSON, err := ioutil.ReadFile(keystoreUTCPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
privKey, err := keystore.DecryptKey(keyJSON, password)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
txOps = bind.NewKeyedTransactor(privKey.PrivateKey)
|
||||
@@ -155,13 +155,13 @@ func main() {
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Wait for contract to mine
|
||||
for pending := true; pending; _, pending, err = client.TransactionByHash(context.Background(), tx.Hash()) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
@@ -177,6 +177,7 @@ func main() {
|
||||
log.Printf("Updated config map %s", k8sConfigMapName)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
|
||||
@@ -17,8 +17,8 @@ go_library(
|
||||
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||||
)
|
||||
|
||||
@@ -36,36 +36,36 @@ func main() {
|
||||
customFormatter.FullTimestamp = true
|
||||
logrus.SetFormatter(customFormatter)
|
||||
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
app.Name = "drainContracts"
|
||||
app.Usage = "this is a util to drain all (testing) deposit contracts of their ETH."
|
||||
app.Version = version.GetVersion()
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "keystoreUTCPath",
|
||||
Usage: "Location of keystore",
|
||||
Destination: &keystoreUTCPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "httpPath",
|
||||
Value: "https://goerli.infura.io/v3/be3fb7ed377c418087602876a40affa1",
|
||||
Usage: "HTTP-RPC server listening interface",
|
||||
Destination: &httpPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "passwordFile",
|
||||
Value: "./password.txt",
|
||||
Usage: "Password file for unlock account",
|
||||
Destination: &passwordFile,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "privKey",
|
||||
Usage: "Private key to send ETH transaction",
|
||||
Destination: &privKeyString,
|
||||
},
|
||||
}
|
||||
|
||||
app.Action = func(c *cli.Context) {
|
||||
app.Action = func(c *cli.Context) error {
|
||||
// Set up RPC client
|
||||
var rpcClient *rpc.Client
|
||||
var err error
|
||||
@@ -74,7 +74,7 @@ func main() {
|
||||
// Uses HTTP-RPC if IPC is not set
|
||||
rpcClient, err = rpc.Dial(httpPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
client := ethclient.NewClient(rpcClient)
|
||||
@@ -83,14 +83,14 @@ func main() {
|
||||
if privKeyString != "" {
|
||||
privKey, err := crypto.HexToECDSA(privKeyString)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
txOps = bind.NewKeyedTransactor(privKey)
|
||||
txOps.Value = big.NewInt(0)
|
||||
txOps.GasLimit = 4000000
|
||||
nonce, err := client.NonceAt(context.Background(), crypto.PubkeyToAddress(privKey.PublicKey), nil)
|
||||
if err != nil {
|
||||
log.Fatalf("could not get account nonce: %v", err)
|
||||
return errors.Wrap(err, "could not get account nonce")
|
||||
}
|
||||
txOps.Nonce = big.NewInt(int64(nonce))
|
||||
fmt.Printf("current address is %s\n", crypto.PubkeyToAddress(privKey.PublicKey).String())
|
||||
@@ -102,11 +102,11 @@ func main() {
|
||||
// #nosec - Inclusion of file via variable is OK for this tool.
|
||||
keyJSON, err := ioutil.ReadFile(keystoreUTCPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
privKey, err := keystore.DecryptKey(keyJSON, password)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
txOps = bind.NewKeyedTransactor(privKey.PrivateKey)
|
||||
@@ -114,7 +114,7 @@ func main() {
|
||||
txOps.GasLimit = 4000000
|
||||
nonce, err := client.NonceAt(context.Background(), privKey.Address, nil)
|
||||
if err != nil {
|
||||
log.Fatalf("could not get account nonce: %v", err)
|
||||
return err
|
||||
}
|
||||
txOps.Nonce = big.NewInt(int64(nonce))
|
||||
fmt.Printf("current address is %s\n", privKey.Address.String())
|
||||
@@ -123,7 +123,7 @@ func main() {
|
||||
|
||||
addresses, err := allDepositContractAddresses(client)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not get all deposit contract address: %v", err)
|
||||
return errors.Wrap(err, "Could not get all deposit contract address")
|
||||
}
|
||||
|
||||
fmt.Printf("%d contracts ready to drain found\n", len(addresses))
|
||||
@@ -131,7 +131,7 @@ func main() {
|
||||
for _, address := range addresses {
|
||||
bal, err := client.BalanceAt(context.Background(), address, nil /*blockNum*/)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
if bal.Cmp(big.NewInt(0)) < 1 {
|
||||
continue
|
||||
@@ -150,6 +150,7 @@ func main() {
|
||||
fmt.Printf("Contract address %s drained in TX hash: %s\n", address.String(), tx.Hash().String())
|
||||
time.Sleep(time.Duration(1) * time.Second)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
|
||||
@@ -16,9 +16,10 @@ go_library(
|
||||
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//ethclient:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//rpc:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -15,12 +15,13 @@ import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/pkg/errors"
|
||||
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
||||
prysmKeyStore "github.com/prysmaticlabs/prysm/shared/keystore"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||||
)
|
||||
|
||||
@@ -46,74 +47,74 @@ func main() {
|
||||
customFormatter.FullTimestamp = true
|
||||
logrus.SetFormatter(customFormatter)
|
||||
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
app.Name = "sendDepositTx"
|
||||
app.Usage = "this is a util to send deposit transactions"
|
||||
app.Version = version.GetVersion()
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "keystoreUTCPath",
|
||||
Usage: "Location of keystore",
|
||||
Destination: &keystoreUTCPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "prysm-keystore",
|
||||
Usage: "The path to the existing prysm keystore. This flag is ignored if used with --random-key",
|
||||
Destination: &prysmKeystorePath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "ipcPath",
|
||||
Usage: "Filename for IPC socket/pipe within the datadir",
|
||||
Destination: &ipcPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "httpPath",
|
||||
Value: "http://localhost:8545/",
|
||||
Usage: "HTTP-RPC server listening interface",
|
||||
Destination: &httpPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "passwordFile",
|
||||
Value: "./password.txt",
|
||||
Usage: "Password file for unlock account",
|
||||
Destination: &passwordFile,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "privKey",
|
||||
Usage: "Private key to send ETH transaction",
|
||||
Destination: &privKeyString,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "depositContract",
|
||||
Usage: "Address of the deposit contract",
|
||||
Destination: &depositContractAddr,
|
||||
},
|
||||
cli.Int64Flag{
|
||||
&cli.Int64Flag{
|
||||
Name: "numberOfDeposits",
|
||||
Value: 1,
|
||||
Usage: "number of deposits to send to the contract",
|
||||
Destination: &numberOfDeposits,
|
||||
},
|
||||
cli.Int64Flag{
|
||||
&cli.Int64Flag{
|
||||
Name: "depositAmount",
|
||||
Value: 3200,
|
||||
Usage: "Maximum deposit value allowed in contract(in gwei)",
|
||||
Destination: &depositAmount,
|
||||
},
|
||||
cli.Int64Flag{
|
||||
&cli.Int64Flag{
|
||||
Name: "depositDelay",
|
||||
Value: 5,
|
||||
Usage: "The time delay between sending the deposits to the contract(in seconds)",
|
||||
Destination: &depositDelay,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "random-key",
|
||||
Usage: "Use a randomly generated keystore key",
|
||||
Destination: &randomKey,
|
||||
},
|
||||
}
|
||||
|
||||
app.Action = func(c *cli.Context) {
|
||||
app.Action = func(c *cli.Context) error {
|
||||
// Set up RPC client
|
||||
var rpcClient *rpc.Client
|
||||
var err error
|
||||
@@ -126,7 +127,7 @@ func main() {
|
||||
rpcClient, err = rpc.Dial(ipcPath)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
client := ethclient.NewClient(rpcClient)
|
||||
@@ -136,7 +137,7 @@ func main() {
|
||||
// User inputs private key, sign tx with private key
|
||||
privKey, err := crypto.HexToECDSA(privKeyString)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
txOps = bind.NewKeyedTransactor(privKey)
|
||||
txOps.Value = new(big.Int).Mul(big.NewInt(depositAmount), big.NewInt(1e9))
|
||||
@@ -147,11 +148,11 @@ func main() {
|
||||
// #nosec - Inclusion of file via variable is OK for this tool.
|
||||
keyJSON, err := ioutil.ReadFile(keystoreUTCPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
privKey, err := keystore.DecryptKey(keyJSON, password)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
txOps = bind.NewKeyedTransactor(privKey.PrivateKey)
|
||||
@@ -161,7 +162,7 @@ func main() {
|
||||
|
||||
depositContract, err := contracts.NewDepositContract(common.HexToAddress(depositContractAddr), client)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
validatorKeys := make(map[string]*prysmKeyStore.Key)
|
||||
@@ -169,7 +170,7 @@ func main() {
|
||||
validatorKey, err := prysmKeyStore.NewKey()
|
||||
validatorKeys[hex.EncodeToString(validatorKey.PublicKey.Marshal())] = validatorKey
|
||||
if err != nil {
|
||||
log.Errorf("Could not generate random key: %v", err)
|
||||
return errors.Wrap(err, "Could not generate random key")
|
||||
}
|
||||
} else {
|
||||
// Load from keystore
|
||||
@@ -204,6 +205,8 @@ func main() {
|
||||
}
|
||||
keyCounter++
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
|
||||
@@ -1,26 +1,40 @@
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"GoLibrary",
|
||||
"GoSource",
|
||||
)
|
||||
|
||||
def _ssz_go_proto_library_impl(ctx):
|
||||
go_proto = ctx.attr.go_proto
|
||||
if ctx.attr.go_proto != None:
|
||||
go_proto = ctx.attr.go_proto
|
||||
input_files = go_proto[OutputGroupInfo].go_generated_srcs.to_list()
|
||||
package_path = input_files[0].dirname
|
||||
elif hasattr(ctx.attr, "srcs") and len(ctx.attr.srcs) > 0:
|
||||
package_path = ctx.attr.srcs[0].files.to_list()[0].dirname
|
||||
input_files = ctx.attr.srcs[0].files.to_list()
|
||||
else:
|
||||
fail("Must have go_proto or srcs")
|
||||
|
||||
generated_pb_go_files = go_proto[OutputGroupInfo].go_generated_srcs
|
||||
|
||||
# Run the tool on the generated files
|
||||
package_path = generated_pb_go_files.to_list()[0].dirname
|
||||
# Run the tool.
|
||||
output = ctx.outputs.out
|
||||
args = [
|
||||
"--output=%s" % output.path,
|
||||
"--path=%s" % package_path,
|
||||
]
|
||||
if hasattr(ctx.attr, "includes") and len(ctx.attr.includes) > 0:
|
||||
incs = []
|
||||
for include in ctx.attr.includes:
|
||||
incs.append(include[GoSource].srcs[0].dirname)
|
||||
input_files += include[GoSource].srcs
|
||||
args.append("--include=%s" % ",".join(incs))
|
||||
|
||||
if len(ctx.attr.objs) > 0:
|
||||
args += ["--objs=%s" % ",".join(ctx.attr.objs)]
|
||||
|
||||
ctx.actions.run(
|
||||
executable = ctx.executable.sszgen,
|
||||
progress_message = "Generating ssz marshal and unmarshal functions",
|
||||
inputs = generated_pb_go_files,
|
||||
inputs = input_files,
|
||||
arguments = args,
|
||||
outputs = [output],
|
||||
)
|
||||
@@ -56,6 +70,7 @@ go_library(
|
||||
ssz_gen_marshal = rule(
|
||||
implementation = _ssz_go_proto_library_impl,
|
||||
attrs = {
|
||||
"srcs": attr.label_list(allow_files = True),
|
||||
"go_proto": attr.label(providers = [GoLibrary]),
|
||||
"sszgen": attr.label(
|
||||
default = Label("@com_github_ferranbt_fastssz//sszgen:sszgen"),
|
||||
@@ -63,6 +78,7 @@ ssz_gen_marshal = rule(
|
||||
cfg = "host",
|
||||
),
|
||||
"objs": attr.string_list(),
|
||||
"includes": attr.label_list(providers = [GoLibrary]),
|
||||
},
|
||||
outputs = {"out": "generated.ssz.go"},
|
||||
)
|
||||
|
||||
@@ -24,8 +24,9 @@ go_library(
|
||||
"//validator/node:go_default_library",
|
||||
"@com_github_joonix_log//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//altsrc:go_default_library",
|
||||
"@org_uber_go_automaxprocs//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -56,8 +57,9 @@ go_image(
|
||||
"//validator/node:go_default_library",
|
||||
"@com_github_joonix_log//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//altsrc:go_default_library",
|
||||
"@org_uber_go_automaxprocs//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -123,5 +125,8 @@ go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["usage_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["@com_github_urfave_cli//:go_default_library"],
|
||||
deps = [
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -135,7 +135,6 @@ func (v *validator) WaitForActivation(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not receive validator activation from stream")
|
||||
}
|
||||
log.Info("Waiting for validator to be activated in the beacon chain")
|
||||
activatedKeys := v.checkAndLogValidatorStatus(res.Statuses)
|
||||
|
||||
if len(activatedKeys) > 0 {
|
||||
@@ -206,6 +205,10 @@ func (v *validator) checkAndLogValidatorStatus(validatorStatuses []*ethpb.Valida
|
||||
"Deposit for validator received but not processed into state")
|
||||
continue
|
||||
}
|
||||
if status.Status.DepositInclusionSlot == 0 && status.Status.PositionInActivationQueue == 0 {
|
||||
log.Info("Waiting for deposit to be seen")
|
||||
continue
|
||||
}
|
||||
if uint64(status.Status.ActivationEpoch) == params.BeaconConfig().FarFutureEpoch {
|
||||
log.WithFields(logrus.Fields{
|
||||
"depositInclusionSlot": status.Status.DepositInclusionSlot,
|
||||
@@ -268,6 +271,8 @@ func (v *validator) UpdateDuties(ctx context.Context, slot uint64) error {
|
||||
PublicKeys: bytesutil.FromBytes48Array(validatingKeys),
|
||||
}
|
||||
|
||||
// If duties is nil it means we have had no prior duties and just started up.
|
||||
firstDutiesReceived := v.duties == nil
|
||||
resp, err := v.validatorClient.GetDuties(ctx, req)
|
||||
if err != nil {
|
||||
v.duties = nil // Clear assignments so we know to retry the request.
|
||||
@@ -277,7 +282,8 @@ func (v *validator) UpdateDuties(ctx context.Context, slot uint64) error {
|
||||
|
||||
v.duties = resp
|
||||
// Only log the full assignments output on epoch start to be less verbose.
|
||||
if slot%params.BeaconConfig().SlotsPerEpoch == 0 {
|
||||
// Also log out on first launch so the user doesn't have to wait a whole epoch to see their assignments.
|
||||
if slot%params.BeaconConfig().SlotsPerEpoch == 0 || firstDutiesReceived {
|
||||
for _, duty := range v.duties.Duties {
|
||||
lFields := logrus.Fields{
|
||||
"pubKey": fmt.Sprintf("%#x", bytesutil.Trunc(duty.PublicKey)),
|
||||
|
||||
@@ -8,8 +8,5 @@ go_library(
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/validator/flags",
|
||||
visibility = ["//validator:__subpackages__"],
|
||||
deps = [
|
||||
"//shared/cmd:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
],
|
||||
deps = ["@in_gopkg_urfave_cli_v2//:go_default_library"],
|
||||
)
|
||||
|
||||
@@ -1,80 +1,78 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// NoCustomConfigFlag determines whether to launch a beacon chain using real parameters or demo parameters.
|
||||
NoCustomConfigFlag = cli.BoolFlag{
|
||||
NoCustomConfigFlag = &cli.BoolFlag{
|
||||
Name: "no-custom-config",
|
||||
Usage: "Run the beacon chain with the real parameters from phase 0.",
|
||||
}
|
||||
// BeaconRPCProviderFlag defines a beacon node RPC endpoint.
|
||||
BeaconRPCProviderFlag = cli.StringFlag{
|
||||
BeaconRPCProviderFlag = &cli.StringFlag{
|
||||
Name: "beacon-rpc-provider",
|
||||
Usage: "Beacon node RPC provider endpoint",
|
||||
Value: "localhost:4000",
|
||||
}
|
||||
// CertFlag defines a flag for the node's TLS certificate.
|
||||
CertFlag = cli.StringFlag{
|
||||
CertFlag = &cli.StringFlag{
|
||||
Name: "tls-cert",
|
||||
Usage: "Certificate for secure gRPC. Pass this and the tls-key flag in order to use gRPC securely.",
|
||||
}
|
||||
// KeystorePathFlag defines the location of the keystore directory for a validator's account.
|
||||
KeystorePathFlag = cmd.DirectoryFlag{
|
||||
KeystorePathFlag = &cli.StringFlag{
|
||||
Name: "keystore-path",
|
||||
Usage: "Path to the desired keystore directory",
|
||||
Value: cmd.DirectoryString{Value: ""},
|
||||
}
|
||||
// UnencryptedKeysFlag specifies a file path of a JSON file of unencrypted validator keys as an
|
||||
// alternative from launching the validator client from decrypting a keystore directory.
|
||||
UnencryptedKeysFlag = cli.StringFlag{
|
||||
UnencryptedKeysFlag = &cli.StringFlag{
|
||||
Name: "unencrypted-keys",
|
||||
Usage: "Filepath to a JSON file of unencrypted validator keys for easier launching of the validator client",
|
||||
Value: "",
|
||||
}
|
||||
// KeyManager specifies the key manager to use.
|
||||
KeyManager = cli.StringFlag{
|
||||
KeyManager = &cli.StringFlag{
|
||||
Name: "keymanager",
|
||||
Usage: "The keymanger to use (unencrypted, interop, keystore, wallet)",
|
||||
Value: "",
|
||||
}
|
||||
// KeyManagerOpts specifies the key manager options.
|
||||
KeyManagerOpts = cli.StringFlag{
|
||||
KeyManagerOpts = &cli.StringFlag{
|
||||
Name: "keymanageropts",
|
||||
Usage: "The options for the keymanger, either a JSON string or path to same",
|
||||
Value: "",
|
||||
}
|
||||
// PasswordFlag defines the password value for storing and retrieving validator private keys from the keystore.
|
||||
PasswordFlag = cli.StringFlag{
|
||||
PasswordFlag = &cli.StringFlag{
|
||||
Name: "password",
|
||||
Usage: "String value of the password for your validator private keys",
|
||||
}
|
||||
// DisablePenaltyRewardLogFlag defines the ability to not log reward/penalty information during deployment
|
||||
DisablePenaltyRewardLogFlag = cli.BoolFlag{
|
||||
DisablePenaltyRewardLogFlag = &cli.BoolFlag{
|
||||
Name: "disable-rewards-penalties-logging",
|
||||
Usage: "Disable reward/penalty logging during cluster deployment",
|
||||
}
|
||||
// GraffitiFlag defines the graffiti value included in proposed blocks
|
||||
GraffitiFlag = cli.StringFlag{
|
||||
GraffitiFlag = &cli.StringFlag{
|
||||
Name: "graffiti",
|
||||
Usage: "String to include in proposed blocks",
|
||||
}
|
||||
// GrpcMaxCallRecvMsgSizeFlag defines the max call message size for GRPC
|
||||
GrpcMaxCallRecvMsgSizeFlag = cli.IntFlag{
|
||||
GrpcMaxCallRecvMsgSizeFlag = &cli.IntFlag{
|
||||
Name: "grpc-max-msg-size",
|
||||
Usage: "Integer to define max recieve message call size (default: 52428800 (for 50Mb)).",
|
||||
}
|
||||
// GrpcRetriesFlag defines the number of times to retry a failed gRPC request.
|
||||
GrpcRetriesFlag = cli.UintFlag{
|
||||
GrpcRetriesFlag = &cli.UintFlag{
|
||||
Name: "grpc-retries",
|
||||
Usage: "Number of attempts to retry gRPC requests",
|
||||
Value: 5,
|
||||
}
|
||||
// AccountMetricsFlag defines the graffiti value included in proposed blocks, default false.
|
||||
AccountMetricsFlag = cli.BoolFlag{
|
||||
AccountMetricsFlag = &cli.BoolFlag{
|
||||
Name: "enable-account-metrics",
|
||||
Usage: "Enable prometheus metrics for validator accounts",
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// Flags defined for interoperability testing.
|
||||
var (
|
||||
InteropStartIndex = cli.Uint64Flag{
|
||||
InteropStartIndex = &cli.Uint64Flag{
|
||||
Name: "interop-start-index",
|
||||
Usage: "The start index to deterministically generate validator keys when used in combination with " +
|
||||
"--interop-num-validators. Example: --interop-start-index=5 --interop-num-validators=3 would generate " +
|
||||
"keys from index 5 to 7.",
|
||||
}
|
||||
InteropNumValidators = cli.Uint64Flag{
|
||||
InteropNumValidators = &cli.Uint64Flag{
|
||||
Name: "interop-num-validators",
|
||||
Usage: "The number of validators to deterministically generate when used in combination with " +
|
||||
"--interop-num-validators. Example: --interop-start-index=5 --interop-num-validators=3 would generate " +
|
||||
|
||||
@@ -17,9 +17,10 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
"github.com/prysmaticlabs/prysm/validator/node"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||||
_ "go.uber.org/automaxprocs"
|
||||
"gopkg.in/urfave/cli.v2/altsrc"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "main")
|
||||
@@ -57,7 +58,6 @@ var appFlags = []cli.Flag{
|
||||
cmd.TracingProcessNameFlag,
|
||||
cmd.TracingEndpointFlag,
|
||||
cmd.TraceSampleFractionFlag,
|
||||
cmd.BootstrapNode,
|
||||
cmd.MonitoringPortFlag,
|
||||
cmd.LogFormat,
|
||||
debug.PProfFlag,
|
||||
@@ -67,27 +67,27 @@ var appFlags = []cli.Flag{
|
||||
debug.CPUProfileFlag,
|
||||
debug.TraceFlag,
|
||||
cmd.LogFileName,
|
||||
cmd.EnableUPnPFlag,
|
||||
cmd.ConfigFileFlag,
|
||||
}
|
||||
|
||||
func init() {
|
||||
appFlags = append(appFlags, featureconfig.ValidatorFlags...)
|
||||
appFlags = cmd.WrapFlags(append(appFlags, featureconfig.ValidatorFlags...))
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
app.Name = "validator"
|
||||
app.Usage = `launches an Ethereum Serenity validator client that interacts with a beacon chain,
|
||||
starts proposer services, shardp2p connections, and more`
|
||||
app.Version = version.GetVersion()
|
||||
app.Action = startNode
|
||||
app.Commands = []cli.Command{
|
||||
app.Commands = []*cli.Command{
|
||||
{
|
||||
Name: "accounts",
|
||||
Category: "accounts",
|
||||
Usage: "defines useful functions for interacting with the validator client's account",
|
||||
Subcommands: cli.Commands{
|
||||
cli.Command{
|
||||
Subcommands: []*cli.Command{
|
||||
{
|
||||
Name: "create",
|
||||
Description: `creates a new validator account keystore containing private keys for Ethereum Serenity -
|
||||
this command outputs a deposit data string which can be used to deposit Ether into the ETH1.0 deposit
|
||||
@@ -96,10 +96,10 @@ contract in order to activate the validator client`,
|
||||
flags.KeystorePathFlag,
|
||||
flags.PasswordFlag,
|
||||
},
|
||||
Action: func(ctx *cli.Context) {
|
||||
Action: func(ctx *cli.Context) error {
|
||||
featureconfig.ConfigureValidator(ctx)
|
||||
// Use custom config values if the --no-custom-config flag is set.
|
||||
if !ctx.GlobalBool(flags.NoCustomConfigFlag.Name) {
|
||||
if !ctx.Bool(flags.NoCustomConfigFlag.Name) {
|
||||
log.Info("Using custom parameter configuration")
|
||||
if featureconfig.Get().MinimalConfig {
|
||||
log.Warn("Using Minimal Config")
|
||||
@@ -113,16 +113,17 @@ contract in order to activate the validator client`,
|
||||
if keystoreDir, _, err := accounts.CreateValidatorAccount(ctx.String(flags.KeystorePathFlag.Name), ctx.String(flags.PasswordFlag.Name)); err != nil {
|
||||
log.WithError(err).Fatalf("Could not create validator at path: %s", keystoreDir)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
cli.Command{
|
||||
{
|
||||
Name: "keys",
|
||||
Description: `lists the private keys for 'keystore' keymanager keys`,
|
||||
Flags: []cli.Flag{
|
||||
flags.KeystorePathFlag,
|
||||
flags.PasswordFlag,
|
||||
},
|
||||
Action: func(ctx *cli.Context) {
|
||||
Action: func(ctx *cli.Context) error {
|
||||
if ctx.String(flags.KeystorePathFlag.Name) == "" {
|
||||
log.Fatalf("%s is required", flags.KeystorePathFlag.Name)
|
||||
}
|
||||
@@ -136,6 +137,7 @@ contract in order to activate the validator client`,
|
||||
for _, v := range keystores {
|
||||
fmt.Printf("Public key: %#x private key: %#x\n", v.PublicKey.Marshal(), v.SecretKey.Marshal())
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -144,7 +146,13 @@ contract in order to activate the validator client`,
|
||||
app.Flags = appFlags
|
||||
|
||||
app.Before = func(ctx *cli.Context) error {
|
||||
format := ctx.GlobalString(cmd.LogFormat.Name)
|
||||
if ctx.IsSet(cmd.ConfigFileFlag.Name) {
|
||||
if err := altsrc.InitInputSourceWithContext(appFlags, altsrc.NewYamlSourceFromFlagFunc(cmd.ConfigFileFlag.Name))(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
format := ctx.String(cmd.LogFormat.Name)
|
||||
switch format {
|
||||
case "text":
|
||||
formatter := new(prefixed.TextFormatter)
|
||||
@@ -152,7 +160,7 @@ contract in order to activate the validator client`,
|
||||
formatter.FullTimestamp = true
|
||||
// If persistent log files are written - we disable the log messages coloring because
|
||||
// the colors are ANSI codes and seen as Gibberish in the log files.
|
||||
formatter.DisableColors = ctx.GlobalString(cmd.LogFileName.Name) != ""
|
||||
formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != ""
|
||||
logrus.SetFormatter(formatter)
|
||||
break
|
||||
case "fluentd":
|
||||
@@ -169,7 +177,7 @@ contract in order to activate the validator client`,
|
||||
return fmt.Errorf("unknown log format %s", format)
|
||||
}
|
||||
|
||||
logFileName := ctx.GlobalString(cmd.LogFileName.Name)
|
||||
logFileName := ctx.String(cmd.LogFileName.Name)
|
||||
if logFileName != "" {
|
||||
if err := logutil.ConfigurePersistentLogging(logFileName); err != nil {
|
||||
log.WithError(err).Error("Failed to configuring logging to disk.")
|
||||
|
||||
@@ -8,7 +8,7 @@ go_test(
|
||||
deps = [
|
||||
"//shared/testutil:go_default_library",
|
||||
"//validator/accounts:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -31,6 +31,6 @@ go_library(
|
||||
"//validator/keymanager:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli//:go_default_library",
|
||||
"@in_gopkg_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "node")
|
||||
@@ -44,15 +44,15 @@ type ValidatorClient struct {
|
||||
func NewValidatorClient(ctx *cli.Context) (*ValidatorClient, error) {
|
||||
if err := tracing.Setup(
|
||||
"validator", // service name
|
||||
ctx.GlobalString(cmd.TracingProcessNameFlag.Name),
|
||||
ctx.GlobalString(cmd.TracingEndpointFlag.Name),
|
||||
ctx.GlobalFloat64(cmd.TraceSampleFractionFlag.Name),
|
||||
ctx.GlobalBool(cmd.EnableTracingFlag.Name),
|
||||
ctx.String(cmd.TracingProcessNameFlag.Name),
|
||||
ctx.String(cmd.TracingEndpointFlag.Name),
|
||||
ctx.Float64(cmd.TraceSampleFractionFlag.Name),
|
||||
ctx.Bool(cmd.EnableTracingFlag.Name),
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
verbosity := ctx.GlobalString(cmd.VerbosityFlag.Name)
|
||||
verbosity := ctx.String(cmd.VerbosityFlag.Name)
|
||||
level, err := logrus.ParseLevel(verbosity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -87,14 +87,17 @@ func NewValidatorClient(ctx *cli.Context) (*ValidatorClient, error) {
|
||||
}
|
||||
}
|
||||
|
||||
clearFlag := ctx.GlobalBool(cmd.ClearDB.Name)
|
||||
forceClearFlag := ctx.GlobalBool(cmd.ForceClearDB.Name)
|
||||
clearFlag := ctx.Bool(cmd.ClearDB.Name)
|
||||
forceClearFlag := ctx.Bool(cmd.ForceClearDB.Name)
|
||||
if clearFlag || forceClearFlag {
|
||||
pubkeys, err := keyManager.FetchValidatingKeys()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dataDir := ctx.GlobalString(cmd.DataDirFlag.Name)
|
||||
dataDir := ctx.String(cmd.DataDirFlag.Name)
|
||||
if dataDir == "" {
|
||||
dataDir = cmd.DefaultDataDir()
|
||||
}
|
||||
if err := clearDB(dataDir, pubkeys, forceClearFlag); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -158,7 +161,7 @@ func (s *ValidatorClient) Close() {
|
||||
|
||||
func (s *ValidatorClient) registerPrometheusService(ctx *cli.Context) error {
|
||||
service := prometheus.NewPrometheusService(
|
||||
fmt.Sprintf(":%d", ctx.GlobalInt64(cmd.MonitoringPortFlag.Name)),
|
||||
fmt.Sprintf(":%d", ctx.Int64(cmd.MonitoringPortFlag.Name)),
|
||||
s.services,
|
||||
)
|
||||
logrus.AddHook(prometheus.NewLogrusCollector())
|
||||
@@ -166,14 +169,14 @@ func (s *ValidatorClient) registerPrometheusService(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
func (s *ValidatorClient) registerClientService(ctx *cli.Context, keyManager keymanager.KeyManager) error {
|
||||
endpoint := ctx.GlobalString(flags.BeaconRPCProviderFlag.Name)
|
||||
dataDir := ctx.GlobalString(cmd.DataDirFlag.Name)
|
||||
logValidatorBalances := !ctx.GlobalBool(flags.DisablePenaltyRewardLogFlag.Name)
|
||||
emitAccountMetrics := ctx.GlobalBool(flags.AccountMetricsFlag.Name)
|
||||
cert := ctx.GlobalString(flags.CertFlag.Name)
|
||||
graffiti := ctx.GlobalString(flags.GraffitiFlag.Name)
|
||||
maxCallRecvMsgSize := ctx.GlobalInt(flags.GrpcMaxCallRecvMsgSizeFlag.Name)
|
||||
grpcRetries := ctx.GlobalUint(flags.GrpcRetriesFlag.Name)
|
||||
endpoint := ctx.String(flags.BeaconRPCProviderFlag.Name)
|
||||
dataDir := ctx.String(cmd.DataDirFlag.Name)
|
||||
logValidatorBalances := !ctx.Bool(flags.DisablePenaltyRewardLogFlag.Name)
|
||||
emitAccountMetrics := ctx.Bool(flags.AccountMetricsFlag.Name)
|
||||
cert := ctx.String(flags.CertFlag.Name)
|
||||
graffiti := ctx.String(flags.GraffitiFlag.Name)
|
||||
maxCallRecvMsgSize := ctx.Int(flags.GrpcMaxCallRecvMsgSizeFlag.Name)
|
||||
grpcRetries := ctx.Uint(flags.GrpcRetriesFlag.Name)
|
||||
v, err := client.NewValidatorService(context.Background(), &client.Config{
|
||||
Endpoint: endpoint,
|
||||
DataDir: dataDir,
|
||||
@@ -211,9 +214,9 @@ func selectKeyManager(ctx *cli.Context) (keymanager.KeyManager, error) {
|
||||
manager = "unencrypted"
|
||||
opts = fmt.Sprintf(`{"path":%q}`, unencryptedKeys)
|
||||
log.Warn(fmt.Sprintf("--unencrypted-keys flag is deprecated. Please use --keymanager=unencrypted --keymanageropts='%s'", opts))
|
||||
} else if numValidatorKeys := ctx.GlobalUint64(flags.InteropNumValidators.Name); numValidatorKeys > 0 {
|
||||
} else if numValidatorKeys := ctx.Uint64(flags.InteropNumValidators.Name); numValidatorKeys > 0 {
|
||||
manager = "interop"
|
||||
opts = fmt.Sprintf(`{"keys":%d,"offset":%d}`, numValidatorKeys, ctx.GlobalUint64(flags.InteropStartIndex.Name))
|
||||
opts = fmt.Sprintf(`{"keys":%d,"offset":%d}`, numValidatorKeys, ctx.Uint64(flags.InteropStartIndex.Name))
|
||||
log.Warn(fmt.Sprintf("--interop-num-validators and --interop-start-index flags are deprecated. Please use --keymanager=interop --keymanageropts='%s'", opts))
|
||||
} else if keystorePath := ctx.String(flags.KeystorePathFlag.Name); keystorePath != "" {
|
||||
manager = "keystore"
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// Test that the sharding node can build with default flag values.
|
||||
func TestNode_Builds(t *testing.T) {
|
||||
app := cli.NewApp()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("datadir", testutil.TempDir()+"/datadir", "the node data directory")
|
||||
dir := testutil.TempDir() + "/keystore1"
|
||||
@@ -21,7 +21,7 @@ func TestNode_Builds(t *testing.T) {
|
||||
set.String("keystore-path", dir, "path to keystore")
|
||||
set.String("password", "1234", "validator account password")
|
||||
set.String("verbosity", "debug", "log verbosity")
|
||||
context := cli.NewContext(app, set, nil)
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
|
||||
if err := accounts.NewValidatorAccount(dir, "1234"); err != nil {
|
||||
t.Fatalf("Could not create validator account: %v", err)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/debug"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/validator/flags"
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
var appHelpTemplate = `NAME:
|
||||
@@ -52,11 +52,10 @@ var appHelpFlagGroups = []flagGroup{
|
||||
cmd.TracingProcessNameFlag,
|
||||
cmd.TracingEndpointFlag,
|
||||
cmd.TraceSampleFractionFlag,
|
||||
cmd.BootstrapNode,
|
||||
cmd.MonitoringPortFlag,
|
||||
cmd.LogFormat,
|
||||
cmd.LogFileName,
|
||||
cmd.EnableUPnPFlag,
|
||||
cmd.ConfigFileFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -90,7 +89,7 @@ var appHelpFlagGroups = []flagGroup{
|
||||
},
|
||||
{
|
||||
Name: "features",
|
||||
Flags: featureconfig.ValidatorFlags,
|
||||
Flags: featureconfig.ActiveFlags(featureconfig.ValidatorFlags),
|
||||
},
|
||||
{
|
||||
Name: "interop",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user