prysm-pulse/shared/featureconfig/config.go

242 lines
9.1 KiB
Go
Raw Normal View History

/*
Package featureconfig defines which features are enabled for runtime
in order to selectively enable certain features to maintain a stable runtime.
The process for implementing new features using this package is as follows:
1. Add a new CMD flag in flags.go, and place it in the proper list(s) var for its client.
2. Add a condition for the flag in the proper Configure function(s) below.
3. Place any "new" behavior in the `if flagEnabled` statement.
4. Place any "previous" behavior in the `else` statement.
5. Ensure any tests using the new feature fail if the flag isn't enabled.
5a. Use the following to enable your flag for tests:
cfg := &featureconfig.Flags{
VerifyAttestationSigs: true,
}
resetCfg := featureconfig.InitWithReset(cfg)
defer resetCfg()
6. Add the string for the flags that should be running within E2E to E2EValidatorFlags
and E2EBeaconChainFlags.
*/
package featureconfig
import (
"sync"
2020-06-24 14:03:16 +00:00
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/sirupsen/logrus"
Refactor dependencies, make Prysm "go gettable" (#6053) * Fix a few deps to work with go.mod, check in generated files * Update Gossipsub to 1.1 (#5998) * update libs * add new validators * add new deps * new set of deps * tls * further fix gossip update * get everything to build * clean up * gaz * fix build * fix all tests * add deps to images * imports Co-authored-by: rauljordan <raul@prysmaticlabs.com> * Beacon chain builds with go build * fix bazel * fix dep * lint * Add github action for testing go * on PR for any branch * fix libp2p test failure * Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test * Revert "Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test" This reverts commit 43676894ab01f03fe90a9b8ee3ecfbc2ec1ec4e4. * Compute and set proposer index instead of hard code * Add back go mod/sum, fix deps * go build ./... * Temporarily skip two tests * Fix kafka confluent patch * Fix kafka confluent patch * fix kafka build * fix kafka * Add info in DEPENDENCIES. Added a stub link for Why Bazel? until https://github.com/prysmaticlabs/documentation/issues/138 * Update fuzz ssz files as well * Update fuzz ssz files as well * getting closer * rollback rules_go and gazelle * fix gogo protobuf * install librdkafka-dev as part of github actions * Update kafka to a recent version where librkafkfa is not required for go modules * clarify comment * fix kafka build * disable go tests * comment * Fix geth dependencies for end to end * rename word * lint * fix docker Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2020-05-31 06:44:34 +00:00
"github.com/urfave/cli/v2"
)
var log = logrus.WithField("prefix", "flags")
// Flags is a struct to represent which features the client will perform on runtime.
type Flags struct {
2020-06-24 14:03:16 +00:00
// Testnet Flags.
2020-09-30 18:19:05 +00:00
AltonaTestnet bool // AltonaTestnet defines the flag through which we can enable the node to run on the Altona testnet.
OnyxTestnet bool // OnyxTestnet defines the flag through which we can enable the node to run on the Onyx testnet.
MedallaTestnet bool // MedallaTestnet defines the flag through which we can enable the node to run on the Medalla testnet.
2020-09-30 18:19:05 +00:00
SpadinaTestnet bool // SpadinaTestnet defines the flag through which we can enable the node to run on the Spadina testnet.
ZinkenTestnet bool // ZinkenTestnet defines the flag through which we can enable the node to run on the Zinken testnet.
2020-09-15 04:21:46 +00:00
// Feature related flags.
WriteSSZStateTransitions bool // WriteSSZStateTransitions to tmp directory.
SkipBLSVerify bool // Skips BLS verification across the runtime.
EnableBlst bool // Enables new BLS library from supranational.
PruneEpochBoundaryStates bool // PruneEpochBoundaryStates prunes the epoch boundary state before last finalized check point.
EnableSnappyDBCompression bool // EnableSnappyDBCompression in the database.
SlasherProtection bool // SlasherProtection protects validator fron sending over a slashable offense over the network using external slasher.
EnableNoise bool // EnableNoise enables the beacon node to use NOISE instead of SECIO when performing a handshake with another peer.
WaitForSynced bool // WaitForSynced uses WaitForSynced in validator startup to ensure it can communicate with the beacon node as soon as possible.
EnableEth1DataMajorityVote bool // EnableEth1DataMajorityVote uses the Voting With The Majority algorithm to vote for eth1data.
EnablePeerScorer bool // EnablePeerScorer enables experimental peer scoring in p2p.
EnablePruningDepositProofs bool // EnablePruningDepositProofs enables pruning deposit proofs which significantly reduces the size of a deposit
Finalized deposits cache (#6391) * Renamed beforeBlk to untilBlk * finalized deposits cache logic * Merge branch 'master' into deposit-trie-cache # Conflicts: # beacon-chain/blockchain/process_block.go * simplified returning of finalized deposits * added comment to FinalizedDeposits struct * fixes after code review * Merge branch 'master' into deposit-trie-cache * fixed variable declaration * renamed deposit cache test file * fixed type casting * compilation error fix * deposit cache tests * proposer test * Merge branch 'master' into deposit-trie-cache * added missing methods to interop beacon-chain service * gofmt * Merge branch 'master' into deposit-trie-cache * gazelle * cache deposit with eth1DepositIndex * Merge branch 'master' into deposit-trie-cache * fixed MerkleTrieIndex name * Merge branch 'master' into deposit-trie-cache * Merge branch 'master' into deposit-trie-cache * Merge branch 'master' into deposit-trie-cache * code review adjustments * feature flag * Merge branch 'master' into deposit-trie-cache # Conflicts: # beacon-chain/cache/depositcache/pending_deposits.go # shared/featureconfig/config.go # shared/featureconfig/flags.go * merge fix * gazelle * Merge branch 'master' into deposit-trie-cache * return a copy of deposits trie from the cache * move more logic under feature flag * Merge branch 'master' into deposit-trie-cache * added missing beacon chain flag * Merge branch 'master' into deposit-trie-cache * use helper function for trie copying * Merge branch 'master' into deposit-trie-cache * Merge branch 'master' into deposit-trie-cache * Merge branch 'master' into deposit-trie-cache * Merge branch 'master' into deposit-trie-cache * Merge branch 'master' into deposit-trie-cache
2020-07-09 20:24:40 +00:00
// Logging related toggles.
DisableGRPCConnectionLogs bool // Disables logging when a new grpc client has connected.
// Slasher toggles.
EnableHistoricalDetection bool // EnableHistoricalDetection disables historical attestation detection and performs detection on the chain head immediately.
DisableLookback bool // DisableLookback updates slasher to not use the lookback and update validator histories until epoch 0.
// Cache toggles.
EnableSSZCache bool // EnableSSZCache see https://github.com/prysmaticlabs/prysm/pull/4558.
EnableEth1DataVoteCache bool // EnableEth1DataVoteCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
EnableSlasherConnection bool // EnableSlasher enable retrieval of slashing events from a slasher instance.
UseCheckPointInfoCache bool // UseCheckPointInfoCache uses check point info cache to efficiently verify attestation signatures.
KafkaBootstrapServers string // KafkaBootstrapServers to find kafka servers to stream blocks, attestations, etc.
AttestationAggregationStrategy string // AttestationAggregationStrategy defines aggregation strategy to be used when aggregating.
}
var featureConfig *Flags
var featureConfigLock sync.RWMutex
2019-10-07 05:11:49 +00:00
// Get retrieves feature config.
func Get() *Flags {
featureConfigLock.RLock()
defer featureConfigLock.RUnlock()
if featureConfig == nil {
return &Flags{}
}
return featureConfig
}
2019-10-07 05:11:49 +00:00
// Init sets the global config equal to the config that is passed in.
func Init(c *Flags) {
featureConfigLock.Lock()
defer featureConfigLock.Unlock()
featureConfig = c
}
// InitWithReset sets the global config and returns function that is used to reset configuration.
func InitWithReset(c *Flags) func() {
var prevConfig Flags
if featureConfig != nil {
prevConfig = *featureConfig
} else {
prevConfig = Flags{}
}
resetFunc := func() {
Init(&prevConfig)
}
Init(c)
return resetFunc
}
// configureTestnet sets the config according to specified testnet flag
func configureTestnet(ctx *cli.Context, cfg *Flags) {
if ctx.Bool(AltonaTestnet.Name) {
log.Warn("Running on Altona Testnet")
2020-06-24 14:03:16 +00:00
params.UseAltonaConfig()
params.UseAltonaNetworkConfig()
cfg.AltonaTestnet = true
} else if ctx.Bool(OnyxTestnet.Name) {
log.Warn("Running on Onyx Testnet")
params.UseOnyxConfig()
params.UseOnyxNetworkConfig()
cfg.OnyxTestnet = true
} else if ctx.Bool(MedallaTestnet.Name) {
log.Warn("Running on Medalla Testnet")
params.UseMedallaConfig()
params.UseMedallaNetworkConfig()
cfg.MedallaTestnet = true
} else if ctx.Bool(SpadinaTestnet.Name) {
log.Warn("Running on Spadina Testnet")
2020-09-15 04:21:46 +00:00
params.UseSpadinaConfig()
params.UseSpadinaNetworkConfig()
cfg.SpadinaTestnet = true
} else if ctx.Bool(ZinkenTestnet.Name) {
log.Warn("Running on Zinken Testnet")
2020-09-30 18:19:05 +00:00
params.UseZinkenConfig()
params.UseZinkenNetworkConfig()
cfg.ZinkenTestnet = true
} else {
log.Warn("--<testnet> flag is not specified (default: Medalla), this will become required from next release! ")
params.UseMedallaConfig()
params.UseMedallaNetworkConfig()
cfg.MedallaTestnet = true
2020-09-30 18:19:05 +00:00
}
}
// ConfigureBeaconChain sets the global config based
// on what flags are enabled for the beacon-chain client.
func ConfigureBeaconChain(ctx *cli.Context) {
complainOnDeprecatedFlags(ctx)
cfg := &Flags{}
if ctx.Bool(devModeFlag.Name) {
enableDevModeFlags(ctx)
}
configureTestnet(ctx, cfg)
if ctx.Bool(writeSSZStateTransitionsFlag.Name) {
log.Warn("Writing SSZ states and blocks after state transitions")
cfg.WriteSSZStateTransitions = true
}
cfg.EnableSSZCache = true
if ctx.String(kafkaBootstrapServersFlag.Name) != "" {
log.Warn("Enabling experimental kafka streaming.")
cfg.KafkaBootstrapServers = ctx.String(kafkaBootstrapServersFlag.Name)
}
if ctx.IsSet(disableGRPCConnectionLogging.Name) {
cfg.DisableGRPCConnectionLogs = true
}
cfg.AttestationAggregationStrategy = ctx.String(attestationAggregationStrategy.Name)
log.Infof("Using %q strategy on attestation aggregation", cfg.AttestationAggregationStrategy)
cfg.EnableEth1DataMajorityVote = true
if ctx.Bool(disableEth1DataMajorityVote.Name) {
log.Warn("Disabling eth1data majority vote")
cfg.EnableEth1DataMajorityVote = false
}
Peer scoring: init sync (#6709) * refactors redundant part of varname * introduces score_block_providers * Merge branch 'master' into init-sync-peer-scoring-slow-peers * gazelle * adds comment * Merge branch 'master' into init-sync-peer-scoring-slow-peers * removes redundant checks * add block provider decay test * Merge branch 'master' into init-sync-peer-scoring-slow-peers * adds case * penalize inactive peers * adds scorebadresponses test * inroduces no-activity penalty * gazelle * gofmt * Merge branch 'master' into init-sync-peer-scoring-slow-peers * expanded tests * implement SortBlockProviders * change -> update * updates block fetcher peer filter * fixes test * allows to keep track of peer id * updates scoring coefficients * fixes test * block fetcher update * Merge branch 'master' into init-sync-peer-scoring-slow-peers * disables empty batch penalty * Merge branch 'master' into init-sync-peer-scoring-slow-peers * Merge branch 'master' into init-sync-peer-scoring-slow-peers * removes outdated code * update filterPeers * gazelle * updates var * revert changes to var name * updates blocks_fetcher * minor fix to import name * Merge branch 'master' into init-sync-peer-scoring-slow-peers * add max processed blocks cap * impoves scoring of stale peers * Merge branch 'master' into init-sync-peer-scoring-slow-peers * fixes test * adds weight sorting to scored peers * return pid when fetching batches * updates round robin * gazelle * Merge branch 'master' into init-sync-peer-scoring-slow-peers * updates block provider decay count * go tidy * cherry pick * fixes test * go tidy * Merge branch 'peer-scorer-weighted-sorter' into init-sync-peer-scoring-slow-peers * Merge branch 'master' into init-sync-peer-scoring-slow-peers * Merge branch 'master' into init-sync-peer-scoring-slow-peers * refactors blocks fetcher: repackage methods * Merge branch 'refactor-blocks-fetcher' into init-sync-peer-scoring-slow-peers * minor fixes * Merge branch 'master' into init-sync-peer-scoring-slow-peers * Merge branch 'master' into init-sync-peer-scoring-slow-peers * allow scores in range (0;1) in weighted filter * filterScoredPeers improve test suite * puts feature behind the flag * Merge branch 'master' into init-sync-peer-scoring-slow-peers * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * fixes tests * Merge branch 'init-sync-peer-scoring-slow-peers' of github.com:prysmaticlabs/prysm into init-sync-peer-scoring-slow-peers * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * Merge branch 'master' into init-sync-peer-scoring-slow-peers * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * Update beacon-chain/sync/initial-sync/blocks_fetcher_test.go Co-authored-by: Shay Zluf <thezluf@gmail.com> * Nishant's suggestion on peer limit variable * better explanation of non-blocking peer scoring * Shay's sugession on peer naming * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * Update beacon-chain/sync/initial-sync/blocks_fetcher.go Co-authored-by: Nishant Das <nishdas93@gmail.com> * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * gofmt * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * Merge refs/heads/master into init-sync-peer-scoring-slow-peers * Merge refs/heads/master into init-sync-peer-scoring-slow-peers
2020-08-13 17:33:57 +00:00
if ctx.Bool(enablePeerScorer.Name) {
log.Warn("Enabling peer scoring in P2P")
cfg.EnablePeerScorer = true
}
if ctx.Bool(checkPtInfoCache.Name) {
log.Warn("Advance check point info cache is no longer supported and will soon be deleted")
}
Add blst for BLS (#6539) * Add blst third party dep * initial build * add init * blst passing tests * add feature flag * blst and herumi for spec tests * maybe this works for mac * Actually set feature flag * Add stub for VerifyMultipleSignatures for blst * verifyCompressed * use correct cores sizes * aggregate public keys * add multi-sig verification * encode not hash * revert back * go mod tidy * update blst to latest commit * add batch decompress * fix * add test * gofmt * update blst * go mod tidy * remove kubesec, fix * mod tidy * disable some remote cache * disable some remote cache * disable some remote cache * disable some remote cache * Switch to -D__ADX__ * update * tidy * fix build * Make blst for only linux,amd64 * gofmt * lint * lint * gazelle * fix build tag * more stub methods * shift adx instructions to x86 * fix arm64 * Revert "fix arm64" This reverts commit 4d34ac21b7509a1b385374e3039efecfcab614c1. * add one more in * Revert "Revert "fix arm64"" This reverts commit 1c8ae24ad16ff9811590f1058b9d98c90b63251a. * try darwin now * Revert "try darwin now" This reverts commit 6f884714b8e14a7a803b72157672b6e942047f37. * Add sha256 * remove TODO * checkpoint * finally builds * fix up * add tag * try again * explicit disabling * remove * select properly * fix * better * make CI happy too * Update .bazelrc * Update .bazelrc * fix tests * revert back * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update shared/bls/blst/public_key.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * clean up tests * more clean up * clean up * add * Update shared/bls/blst/signature.go * Update shared/bls/blst/signature.go * Update .buildkite-bazelrc Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * try again * remove go tag * revert change * gaz * gazelle ignore Co-authored-by: nisdas <nishdas93@gmail.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-09-16 13:28:28 +00:00
if ctx.Bool(enableBlst.Name) {
log.Warn("Enabling new BLS library blst")
cfg.EnableBlst = true
}
cfg.EnablePruningDepositProofs = true
if ctx.Bool(disablePruningDepositProofs.Name) {
log.Warn("Disabling pruning deposit proofs")
cfg.EnablePruningDepositProofs = false
}
Init(cfg)
}
// ConfigureSlasher sets the global config based
// on what flags are enabled for the slasher client.
func ConfigureSlasher(ctx *cli.Context) {
complainOnDeprecatedFlags(ctx)
cfg := &Flags{}
configureTestnet(ctx, cfg)
if ctx.Bool(disableLookbackFlag.Name) {
log.Warn("Disabling slasher lookback")
cfg.DisableLookback = true
}
Init(cfg)
}
2019-10-07 05:11:49 +00:00
// ConfigureValidator sets the global config based
// on what flags are enabled for the validator client.
2019-10-07 05:11:49 +00:00
func ConfigureValidator(ctx *cli.Context) {
complainOnDeprecatedFlags(ctx)
cfg := &Flags{}
configureTestnet(ctx, cfg)
if ctx.Bool(enableExternalSlasherProtectionFlag.Name) {
log.Warn("Enabled validator attestation and block slashing protection using an external slasher.")
cfg.SlasherProtection = true
}
2019-10-07 05:11:49 +00:00
Init(cfg)
}
// enableDevModeFlags switches development mode features on.
func enableDevModeFlags(ctx *cli.Context) {
log.Warn("Enabling development mode flags")
for _, f := range devModeFlags {
log.WithField("flag", f.Names()[0]).Debug("Enabling development mode flag")
if !ctx.IsSet(f.Names()[0]) {
if err := ctx.Set(f.Names()[0], "true"); err != nil {
log.WithError(err).Debug("Error enabling development mode flag")
}
}
}
}
func complainOnDeprecatedFlags(ctx *cli.Context) {
for _, f := range deprecatedFlags {
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])
}
}
}