2019-03-21 02:57:25 +00:00
/ *
Package featureconfig defines which features are enabled for runtime
2020-01-15 23:41:40 +00:00
in order to selectively enable certain features to maintain a stable runtime .
2019-03-21 02:57:25 +00:00
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 .
5 a . Use the following to enable your flag for tests :
2019-11-20 03:03:00 +00:00
cfg := & featureconfig . Flags {
2019-03-21 02:57:25 +00:00
VerifyAttestationSigs : true ,
}
2020-04-28 01:13:33 +00:00
resetCfg := featureconfig . InitWithReset ( cfg )
defer resetCfg ( )
2020-01-27 02:42:10 +00:00
6. Add the string for the flags that should be running within E2E to E2EValidatorFlags
and E2EBeaconChainFlags .
2019-03-21 02:57:25 +00:00
* /
package featureconfig
import (
2020-10-01 20:35:44 +00:00
"sync"
2020-06-24 14:03:16 +00:00
"github.com/prysmaticlabs/prysm/shared/params"
2019-03-21 02:57:25 +00:00
"github.com/sirupsen/logrus"
2020-05-31 06:44:34 +00:00
"github.com/urfave/cli/v2"
2019-03-21 02:57:25 +00:00
)
var log = logrus . WithField ( "prefix" , "flags" )
2019-11-20 03:03:00 +00:00
// 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-11-13 01:00:05 +00:00
ToledoTestnet bool // ToledoTestnet defines the flag through which we can enable the node to run on the Toledo testnet.
PyrmontTestnet bool // PyrmontTestnet defines the flag through which we can enable the node to run on the Pyrmont testnet.
2020-09-15 04:21:46 +00:00
2020-05-26 19:04:42 +00:00
// Feature related flags.
2020-10-23 01:53:50 +00:00
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.
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
2020-11-06 15:54:20 +00:00
EnableSyncBacktracking bool // EnableSyncBacktracking enables backtracking algorithm when searching for alternative forks during initial sync.
2020-11-20 15:36:02 +00:00
EnableLargerGossipHistory bool // EnableLargerGossipHistory increases the gossip history we store in our caches.
2020-07-09 20:24:40 +00:00
2020-06-12 20:41:05 +00:00
// Logging related toggles.
DisableGRPCConnectionLogs bool // Disables logging when a new grpc client has connected.
2020-05-23 06:40:15 +00:00
// 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.
2020-03-12 20:29:23 +00:00
2019-07-30 03:38:05 +00:00
// Cache toggles.
2020-02-03 16:23:04 +00:00
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.
2020-08-24 22:11:45 +00:00
UseCheckPointInfoCache bool // UseCheckPointInfoCache uses check point info cache to efficiently verify attestation signatures.
2020-04-03 05:09:15 +00:00
2020-06-23 15:41:20 +00:00
KafkaBootstrapServers string // KafkaBootstrapServers to find kafka servers to stream blocks, attestations, etc.
2020-06-23 04:00:38 +00:00
AttestationAggregationStrategy string // AttestationAggregationStrategy defines aggregation strategy to be used when aggregating.
2019-03-21 02:57:25 +00:00
}
2019-11-20 03:03:00 +00:00
var featureConfig * Flags
2020-10-01 20:35:44 +00:00
var featureConfigLock sync . RWMutex
2019-03-21 02:57:25 +00:00
2019-10-07 05:11:49 +00:00
// Get retrieves feature config.
2019-11-20 03:03:00 +00:00
func Get ( ) * Flags {
2020-10-01 20:35:44 +00:00
featureConfigLock . RLock ( )
defer featureConfigLock . RUnlock ( )
2019-04-21 17:31:23 +00:00
if featureConfig == nil {
2019-11-20 03:03:00 +00:00
return & Flags { }
2019-04-21 17:31:23 +00:00
}
2019-03-21 02:57:25 +00:00
return featureConfig
}
2019-10-07 05:11:49 +00:00
// Init sets the global config equal to the config that is passed in.
2019-11-20 03:03:00 +00:00
func Init ( c * Flags ) {
2020-10-01 20:35:44 +00:00
featureConfigLock . Lock ( )
defer featureConfigLock . Unlock ( )
2019-03-21 02:57:25 +00:00
featureConfig = c
}
2020-04-27 19:44:35 +00:00
// InitWithReset sets the global config and returns function that is used to reset configuration.
func InitWithReset ( c * Flags ) func ( ) {
2020-10-22 05:20:56 +00:00
var prevConfig Flags
if featureConfig != nil {
prevConfig = * featureConfig
} else {
prevConfig = Flags { }
}
2020-04-27 19:44:35 +00:00
resetFunc := func ( ) {
2020-10-22 05:20:56 +00:00
Init ( & prevConfig )
2020-04-27 19:44:35 +00:00
}
Init ( c )
return resetFunc
}
2020-10-07 23:04:19 +00:00
// configureTestnet sets the config according to specified testnet flag
func configureTestnet ( ctx * cli . Context , cfg * Flags ) {
2020-11-13 06:42:33 +00:00
if ctx . Bool ( ToledoTestnet . Name ) {
2020-11-13 01:00:05 +00:00
log . Warn ( "Running on Toledo Testnet" )
params . UseToledoConfig ( )
params . UseToledoNetworkConfig ( )
cfg . ToledoTestnet = true
} else if ctx . Bool ( PyrmontTestnet . Name ) {
log . Warn ( "Running on Pyrmont Testnet" )
params . UsePyrmontConfig ( )
params . UsePyrmontNetworkConfig ( )
cfg . PyrmontTestnet = true
2020-10-07 23:04:19 +00:00
} else {
2020-11-04 17:36:31 +00:00
log . Warn ( "Running on ETH2 Mainnet" )
params . UseMainnetConfig ( )
2020-09-30 18:19:05 +00:00
}
2020-10-07 23:04:19 +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 )
2020-03-19 21:46:44 +00:00
if ctx . Bool ( writeSSZStateTransitionsFlag . Name ) {
2019-09-23 23:36:12 +00:00
log . Warn ( "Writing SSZ states and blocks after state transitions" )
cfg . WriteSSZStateTransitions = true
}
2020-10-14 03:13:59 +00:00
2020-04-12 21:33:26 +00:00
cfg . EnableSSZCache = true
2020-10-14 03:13:59 +00:00
2020-03-19 21:46:44 +00:00
if ctx . String ( kafkaBootstrapServersFlag . Name ) != "" {
2019-12-06 02:05:58 +00:00
log . Warn ( "Enabling experimental kafka streaming." )
2020-03-19 21:46:44 +00:00
cfg . KafkaBootstrapServers = ctx . String ( kafkaBootstrapServersFlag . Name )
2019-12-06 02:05:58 +00:00
}
2020-10-14 23:28:49 +00:00
2020-06-12 20:41:05 +00:00
if ctx . IsSet ( disableGRPCConnectionLogging . Name ) {
cfg . DisableGRPCConnectionLogs = true
}
2020-06-23 04:00:38 +00:00
cfg . AttestationAggregationStrategy = ctx . String ( attestationAggregationStrategy . Name )
2020-08-11 12:42:08 +00:00
log . Infof ( "Using %q strategy on attestation aggregation" , cfg . AttestationAggregationStrategy )
2020-08-10 05:10:41 +00:00
2020-10-26 17:36:47 +00:00
cfg . EnableEth1DataMajorityVote = true
if ctx . Bool ( disableEth1DataMajorityVote . Name ) {
log . Warn ( "Disabling eth1data majority vote" )
cfg . EnableEth1DataMajorityVote = false
2020-07-28 20:29:12 +00:00
}
2020-08-13 17:33:57 +00:00
if ctx . Bool ( enablePeerScorer . Name ) {
log . Warn ( "Enabling peer scoring in P2P" )
cfg . EnablePeerScorer = true
}
2020-09-24 15:03:35 +00:00
if ctx . Bool ( checkPtInfoCache . Name ) {
2020-10-26 19:09:19 +00:00
log . Warn ( "Advance check point info cache is no longer supported and will soon be deleted" )
2020-08-24 22:11:45 +00:00
}
2020-11-13 15:25:05 +00:00
cfg . EnableBlst = true
if ctx . Bool ( disableBlst . Name ) {
log . Warn ( "Disabling new BLS library blst" )
cfg . EnableBlst = false
2020-09-16 13:28:28 +00:00
}
2020-10-19 18:22:44 +00:00
cfg . EnablePruningDepositProofs = true
if ctx . Bool ( disablePruningDepositProofs . Name ) {
log . Warn ( "Disabling pruning deposit proofs" )
cfg . EnablePruningDepositProofs = false
2020-10-12 18:10:49 +00:00
}
2020-11-06 15:54:20 +00:00
if ctx . Bool ( enableSyncBacktracking . Name ) {
log . Warn ( "Enabling init-sync backtracking algorithm" )
cfg . EnableSyncBacktracking = true
}
2020-11-20 15:36:02 +00:00
if ctx . Bool ( enableLargerGossipHistory . Name ) {
log . Warn ( "Using a larger gossip history for the node" )
cfg . EnableLargerGossipHistory = true
}
2020-08-15 01:37:57 +00:00
Init ( cfg )
2019-03-21 02:57:25 +00:00
}
2019-09-12 19:02:53 +00:00
2020-04-22 15:53:09 +00:00
// ConfigureSlasher sets the global config based
// on what flags are enabled for the slasher client.
func ConfigureSlasher ( ctx * cli . Context ) {
complainOnDeprecatedFlags ( ctx )
2020-05-06 22:17:36 +00:00
cfg := & Flags { }
2020-10-07 23:04:19 +00:00
configureTestnet ( ctx , cfg )
2020-05-09 02:07:37 +00:00
if ctx . Bool ( disableLookbackFlag . Name ) {
log . Warn ( "Disabling slasher lookback" )
cfg . DisableLookback = true
}
2020-05-06 22:17:36 +00:00
Init ( cfg )
2020-04-22 15:53:09 +00:00
}
2019-10-07 05:11:49 +00:00
// ConfigureValidator sets the global config based
2019-09-12 19:02:53 +00:00
// on what flags are enabled for the validator client.
2019-10-07 05:11:49 +00:00
func ConfigureValidator ( ctx * cli . Context ) {
2019-10-29 15:30:14 +00:00
complainOnDeprecatedFlags ( ctx )
2019-11-20 03:03:00 +00:00
cfg := & Flags { }
2020-10-07 23:04:19 +00:00
configureTestnet ( ctx , cfg )
2020-05-20 15:23:22 +00:00
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 )
2019-09-12 19:02:53 +00:00
}
2019-10-29 15:30:14 +00:00
2020-04-20 17:27:24 +00:00
// enableDevModeFlags switches development mode features on.
func enableDevModeFlags ( ctx * cli . Context ) {
log . Warn ( "Enabling development mode flags" )
for _ , f := range devModeFlags {
2020-06-18 20:25:34 +00:00
log . WithField ( "flag" , f . Names ( ) [ 0 ] ) . Debug ( "Enabling development mode flag" )
2020-04-20 17:27:24 +00:00
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" )
}
}
}
}
2019-10-29 15:30:14 +00:00
func complainOnDeprecatedFlags ( ctx * cli . Context ) {
for _ , f := range deprecatedFlags {
2020-03-19 21:46:44 +00:00
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 ] )
2019-10-29 15:30:14 +00:00
}
}
}