Skip to content

Commit

Permalink
Rename StakingEnabled to SybilProtectionEnabled (ava-labs#1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur authored May 19, 2023
1 parent 85c1d24 commit 61e7aa6
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 79 deletions.
6 changes: 2 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ func (a *app) Start() error {
}

// Track if sybil control is enforced
if !a.config.EnableStaking {
log.Warn("sybil control is not enforced",
zap.String("reason", "staking is disabled"),
)
if !a.config.SybilProtectionEnabled {
log.Warn("sybil control is not enforced")
}

// TODO move this to config
Expand Down
14 changes: 7 additions & 7 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ type ChainConfig struct {
}

type ManagerConfig struct {
StakingEnabled bool // True iff the network has staking enabled
StakingCert tls.Certificate // needed to sign snowman++ blocks
StakingBLSKey *bls.SecretKey
TracingEnabled bool
SybilProtectionEnabled bool
StakingCert tls.Certificate // needed to sign snowman++ blocks
StakingBLSKey *bls.SecretKey
TracingEnabled bool
// Must not be used unless [TracingEnabled] is true as this may be nil.
Tracer trace.Tracer
Log logging.Logger
Expand Down Expand Up @@ -522,9 +522,9 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c

var vdrs validators.Set // Validators validating this blockchain
var ok bool
if m.StakingEnabled {
if m.SybilProtectionEnabled {
vdrs, ok = m.Validators.Get(chainParams.SubnetID)
} else { // Staking is disabled. Every peer validates every subnet.
} else { // Sybil protection is disabled. Every peer validates every subnet.
vdrs, ok = m.Validators.Get(constants.PrimaryNetworkID)
}
if !ok {
Expand Down Expand Up @@ -1065,7 +1065,7 @@ func (m *manager) createSnowmanChain(
m.validatorState = validators.Trace(m.validatorState, "lockedState", m.Tracer)
}

if !m.ManagerConfig.StakingEnabled {
if !m.ManagerConfig.SybilProtectionEnabled {
m.validatorState = validators.NewNoValidatorsState(m.validatorState)
ctx.ValidatorState = validators.NewNoValidatorsState(ctx.ValidatorState)
}
Expand Down
25 changes: 11 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func getGossipConfig(v *viper.Viper) subnets.GossipConfig {

func getNetworkConfig(
v *viper.Viper,
stakingEnabled bool,
sybilProtectionEnabled bool,
halflife time.Duration,
) (network.Config, error) {
// Set the max number of recent inbound connections upgraded to be
Expand Down Expand Up @@ -380,7 +380,7 @@ func getNetworkConfig(
},

HealthConfig: network.HealthConfig{
Enabled: stakingEnabled,
Enabled: sybilProtectionEnabled,
MaxTimeSinceMsgSent: v.GetDuration(NetworkHealthMaxTimeSinceMsgSentKey),
MaxTimeSinceMsgReceived: v.GetDuration(NetworkHealthMaxTimeSinceMsgReceivedKey),
MaxPortionSendQueueBytesFull: v.GetFloat64(NetworkHealthMaxPortionSendQueueFillKey),
Expand Down Expand Up @@ -793,20 +793,17 @@ func getStakingSigner(v *viper.Viper) (*bls.SecretKey, error) {

func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, error) {
config := node.StakingConfig{
// We use SybilProtectionEnabledKey for CLI flags that is shown to the user
// and EnableStaking in the rest of the codebase. This is to avoid confusion
// with the name "staking" like in "AVAX staking".
EnableStaking: v.GetBool(getRenamedKey(v, StakingEnabledKey, SybilProtectionEnabledKey)),
DisabledStakingWeight: v.GetUint64(getRenamedKey(v, StakingDisabledWeightKey, SybilProtectionDisabledWeightKey)),
StakingKeyPath: GetExpandedArg(v, StakingTLSKeyPathKey),
StakingCertPath: GetExpandedArg(v, StakingCertPathKey),
StakingSignerPath: GetExpandedArg(v, StakingSignerKeyPathKey),
}
if !config.EnableStaking && config.DisabledStakingWeight == 0 {
SybilProtectionEnabled: v.GetBool(getRenamedKey(v, StakingEnabledKey, SybilProtectionEnabledKey)),
SybilProtectionDisabledWeight: v.GetUint64(getRenamedKey(v, StakingDisabledWeightKey, SybilProtectionDisabledWeightKey)),
StakingKeyPath: GetExpandedArg(v, StakingTLSKeyPathKey),
StakingCertPath: GetExpandedArg(v, StakingCertPathKey),
StakingSignerPath: GetExpandedArg(v, StakingSignerKeyPathKey),
}
if !config.SybilProtectionEnabled && config.SybilProtectionDisabledWeight == 0 {
return node.StakingConfig{}, errSybilProtectionDisabledStakerWeights
}

if !config.EnableStaking && (networkID == constants.MainnetID || networkID == constants.FujiID) {
if !config.SybilProtectionEnabled && (networkID == constants.MainnetID || networkID == constants.FujiID) {
return node.StakingConfig{}, errSybilProtectionDisabledOnPublicNetwork
}

Expand Down Expand Up @@ -1395,7 +1392,7 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
}

// Network Config
nodeConfig.NetworkConfig, err = getNetworkConfig(v, nodeConfig.EnableStaking, healthCheckAveragerHalflife)
nodeConfig.NetworkConfig, err = getNetworkConfig(v, nodeConfig.SybilProtectionEnabled, healthCheckAveragerHalflife)
if err != nil {
return node.Config{}, err
}
Expand Down
1 change: 0 additions & 1 deletion config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.Bool(StakingEphemeralSignerEnabledKey, false, "If true, the node uses an ephemeral staking signer key")
fs.String(StakingSignerKeyPathKey, defaultStakingSignerKeyPath, fmt.Sprintf("Path to the signer private key for staking. Ignored if %s is specified", StakingSignerKeyContentKey))
fs.String(StakingSignerKeyContentKey, "", "Specifies base64 encoded signer private key for staking")

// TODO: Remove this flag in the future
fs.Uint64(StakingDisabledWeightKey, 100, "Weight to provide to each peer when staking is disabled")
fs.Bool(SybilProtectionEnabledKey, true, "Enables sybil protection. If enabled, Network TLS is required")
Expand Down
14 changes: 7 additions & 7 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ type IPConfig struct {

type StakingConfig struct {
genesis.StakingConfig
EnableStaking bool `json:"enableStaking"`
StakingTLSCert tls.Certificate `json:"-"`
StakingSigningKey *bls.SecretKey `json:"-"`
DisabledStakingWeight uint64 `json:"disabledStakingWeight"`
StakingKeyPath string `json:"stakingKeyPath"`
StakingCertPath string `json:"stakingCertPath"`
StakingSignerPath string `json:"stakingSignerPath"`
SybilProtectionEnabled bool `json:"sybilProtectionEnabled"`
StakingTLSCert tls.Certificate `json:"-"`
StakingSigningKey *bls.SecretKey `json:"-"`
SybilProtectionDisabledWeight uint64 `json:"sybilProtectionDisabledWeight"`
StakingKeyPath string `json:"stakingKeyPath"`
StakingCertPath string `json:"stakingCertPath"`
StakingSignerPath string `json:"stakingSignerPath"`
}

type StateSyncConfig struct {
Expand Down
6 changes: 3 additions & 3 deletions node/insecure_validator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type insecureValidatorManager struct {

func (i *insecureValidatorManager) Connected(vdrID ids.NodeID, nodeVersion *version.Application, subnetID ids.ID) {
if constants.PrimaryNetworkID == subnetID {
// Staking is disabled so we don't have a txID that added the peer as a
// validator. Because each validator needs a txID associated with it, we
// hack one together by padding the nodeID with zeroes.
// Sybil protection is disabled so we don't have a txID that added the
// peer as a validator. Because each validator needs a txID associated
// with it, we hack one together by padding the nodeID with zeroes.
dummyTxID := ids.Empty
copy(dummyTxID[:], vdrID[:])

Expand Down
28 changes: 14 additions & 14 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,24 +254,24 @@ func (n *Node) initNetworking(primaryNetVdrs validators.Set) error {
// Configure benchlist
n.Config.BenchlistConfig.Validators = n.vdrs
n.Config.BenchlistConfig.Benchable = n.Config.ConsensusRouter
n.Config.BenchlistConfig.StakingEnabled = n.Config.EnableStaking
n.Config.BenchlistConfig.SybilProtectionEnabled = n.Config.SybilProtectionEnabled
n.benchlistManager = benchlist.NewManager(&n.Config.BenchlistConfig)

n.uptimeCalculator = uptime.NewLockedCalculator()

consensusRouter := n.Config.ConsensusRouter
if !n.Config.EnableStaking {
// Staking is disabled so we don't have a txID that added us as a
// validator. Because each validator needs a txID associated with it, we
// hack one together by just padding our nodeID with zeroes.
if !n.Config.SybilProtectionEnabled {
// Sybil protection is disabled so we don't have a txID that added us as
// a validator. Because each validator needs a txID associated with it,
// we hack one together by just padding our nodeID with zeroes.
dummyTxID := ids.Empty
copy(dummyTxID[:], n.ID[:])

err := primaryNetVdrs.Add(
n.ID,
bls.PublicFromSecretKey(n.Config.StakingSigningKey),
dummyTxID,
n.Config.DisabledStakingWeight,
n.Config.SybilProtectionDisabledWeight,
)
if err != nil {
return err
Expand All @@ -280,7 +280,7 @@ func (n *Node) initNetworking(primaryNetVdrs validators.Set) error {
consensusRouter = &insecureValidatorManager{
Router: consensusRouter,
vdrs: primaryNetVdrs,
weight: n.Config.DisabledStakingWeight,
weight: n.Config.SybilProtectionDisabledWeight,
}
}

Expand Down Expand Up @@ -695,7 +695,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error {
timeoutManager,
n.Config.ConsensusShutdownTimeout,
criticalChains,
n.Config.EnableStaking,
n.Config.SybilProtectionEnabled,
n.Config.TrackedSubnets,
n.Shutdown,
n.Config.RouterHealthConfig,
Expand All @@ -707,7 +707,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error {
}

n.chainManager = chains.New(&chains.ManagerConfig{
StakingEnabled: n.Config.EnableStaking,
SybilProtectionEnabled: n.Config.SybilProtectionEnabled,
StakingCert: n.Config.StakingTLSCert,
StakingBLSKey: n.Config.StakingSigningKey,
Log: n.Log,
Expand Down Expand Up @@ -764,10 +764,10 @@ func (n *Node) initVMs() error {

vdrs := n.vdrs

// If staking is disabled, ignore updates to Subnets' validator sets
// Instead of updating node's validator manager, platform chain makes changes
// to its own local validator manager (which isn't used for sampling)
if !n.Config.EnableStaking {
// If sybil protection is disabled, we provide the P-chain its own local
// validator manager that will not be used by the rest of the node. This
// allows the node's validator sets to be determined by network connections.
if !n.Config.SybilProtectionEnabled {
vdrs = validators.NewManager()
primaryVdrs := validators.NewSet()
_ = vdrs.Add(constants.PrimaryNetworkID, primaryVdrs)
Expand All @@ -788,7 +788,7 @@ func (n *Node) initVMs() error {
Chains: n.chainManager,
Validators: vdrs,
UptimeLockedCalculator: n.uptimeCalculator,
StakingEnabled: n.Config.EnableStaking,
SybilProtectionEnabled: n.Config.SybilProtectionEnabled,
TrackedSubnets: n.Config.TrackedSubnets,
TxFee: n.Config.TxFee,
CreateAssetTxFee: n.Config.CreateAssetTxFee,
Expand Down
6 changes: 3 additions & 3 deletions snow/networking/benchlist/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Manager interface {
type Config struct {
Benchable Benchable `json:"-"`
Validators validators.Manager `json:"-"`
StakingEnabled bool `json:"-"`
SybilProtectionEnabled bool `json:"-"`
Threshold int `json:"threshold"`
MinimumFailingDuration time.Duration `json:"minimumFailingDuration"`
Duration time.Duration `json:"duration"`
Expand Down Expand Up @@ -119,10 +119,10 @@ func (m *manager) RegisterChain(ctx *snow.ConsensusContext) error {
vdrs validators.Set
ok bool
)
if m.config.StakingEnabled {
if m.config.SybilProtectionEnabled {
vdrs, ok = m.config.Validators.Get(ctx.SubnetID)
} else {
// If staking is disabled, everyone validates every chain
// If sybil protection is disabled, everyone validates every chain
vdrs, ok = m.config.Validators.Get(constants.PrimaryNetworkID)
}
if !ok {
Expand Down
36 changes: 18 additions & 18 deletions snow/networking/router/chain_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ type ChainRouter struct {
peers map[ids.NodeID]*peer
// node ID --> chains that node is benched on
// invariant: if a node is benched on any chain, it is treated as disconnected on all chains
benched map[ids.NodeID]set.Set[ids.ID]
criticalChains set.Set[ids.ID]
stakingEnabled bool
onFatal func(exitCode int)
metrics *routerMetrics
benched map[ids.NodeID]set.Set[ids.ID]
criticalChains set.Set[ids.ID]
sybilProtectionEnabled bool
onFatal func(exitCode int)
metrics *routerMetrics
// Parameters for doing health checks
healthConfig HealthConfig
// aggregator of requests based on their time
Expand All @@ -98,7 +98,7 @@ func (cr *ChainRouter) Initialize(
timeoutManager timeout.Manager,
closeTimeout time.Duration,
criticalChains set.Set[ids.ID],
stakingEnabled bool,
sybilProtectionEnabled bool,
trackedSubnets set.Set[ids.ID],
onFatal func(exitCode int),
healthConfig HealthConfig,
Expand All @@ -111,7 +111,7 @@ func (cr *ChainRouter) Initialize(
cr.closeTimeout = closeTimeout
cr.benched = make(map[ids.NodeID]set.Set[ids.ID])
cr.criticalChains = criticalChains
cr.stakingEnabled = stakingEnabled
cr.sybilProtectionEnabled = sybilProtectionEnabled
cr.onFatal = onFatal
cr.timedRequests = linkedhashmap.New[ids.RequestID, requestEntry]()
cr.peers = make(map[ids.NodeID]*peer)
Expand Down Expand Up @@ -408,7 +408,7 @@ func (cr *ChainRouter) AddChain(ctx context.Context, chain handler.Handler) {

// If this peer isn't running this chain, then we shouldn't mark them as
// connected
if !peer.trackedSubnets.Contains(subnetID) && cr.stakingEnabled {
if !peer.trackedSubnets.Contains(subnetID) && cr.sybilProtectionEnabled {
continue
}

Expand Down Expand Up @@ -466,14 +466,14 @@ func (cr *ChainRouter) Connected(nodeID ids.NodeID, nodeVersion *version.Applica
// set, disconnect. we cannot put a subnet-only validator check here since
// Disconnected would not be handled properly.
//
// When staking is disabled, we only want this clause to happen once.
// Therefore, we only update the chains during the connection of the primary
// network, which is guaranteed to happen for every peer.
if cr.stakingEnabled || subnetID == constants.PrimaryNetworkID {
// When sybil protection is disabled, we only want this clause to happen
// once. Therefore, we only update the chains during the connection of the
// primary network, which is guaranteed to happen for every peer.
if cr.sybilProtectionEnabled || subnetID == constants.PrimaryNetworkID {
for _, chain := range cr.chainHandlers {
// If staking is disabled, send a Connected message to every chain
// when connecting to the primary network
if subnetID == chain.Context().SubnetID || !cr.stakingEnabled {
// If sybil protection is disabled, send a Connected message to
// every chain when connecting to the primary network.
if subnetID == chain.Context().SubnetID || !cr.sybilProtectionEnabled {
chain.Push(
context.TODO(),
handler.Message{
Expand Down Expand Up @@ -506,7 +506,7 @@ func (cr *ChainRouter) Disconnected(nodeID ids.NodeID) {
// if a validator connects then it leaves validator-set, it would not be
// disconnected properly.
for _, chain := range cr.chainHandlers {
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.stakingEnabled {
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.sybilProtectionEnabled {
chain.Push(
context.TODO(),
handler.Message{
Expand Down Expand Up @@ -536,7 +536,7 @@ func (cr *ChainRouter) Benched(chainID ids.ID, nodeID ids.NodeID) {
msg := message.InternalDisconnected(nodeID)

for _, chain := range cr.chainHandlers {
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.stakingEnabled {
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.sybilProtectionEnabled {
chain.Push(
context.TODO(),
handler.Message{
Expand Down Expand Up @@ -571,7 +571,7 @@ func (cr *ChainRouter) Unbenched(chainID ids.ID, nodeID ids.NodeID) {
msg := message.InternalConnected(nodeID, peer.version)

for _, chain := range cr.chainHandlers {
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.stakingEnabled {
if peer.trackedSubnets.Contains(chain.Context().SubnetID) || !cr.sybilProtectionEnabled {
chain.Push(
context.TODO(),
handler.Message{
Expand Down
2 changes: 1 addition & 1 deletion snow/networking/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Router interface {
timeouts timeout.Manager,
shutdownTimeout time.Duration,
criticalChains set.Set[ids.ID],
stakingEnabled bool,
sybilProtectionEnabled bool,
trackedSubnets set.Set[ids.ID],
onFatal func(exitCode int),
healthConfig HealthConfig,
Expand Down
4 changes: 2 additions & 2 deletions snow/networking/router/traced_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *tracedRouter) Initialize(
timeoutManager timeout.Manager,
closeTimeout time.Duration,
criticalChains set.Set[ids.ID],
stakingEnabled bool,
sybilProtectionEnabled bool,
trackedSubnets set.Set[ids.ID],
onFatal func(exitCode int),
healthConfig HealthConfig,
Expand All @@ -57,7 +57,7 @@ func (r *tracedRouter) Initialize(
timeoutManager,
closeTimeout,
criticalChains,
stakingEnabled,
sybilProtectionEnabled,
trackedSubnets,
onFatal,
healthConfig,
Expand Down
4 changes: 2 additions & 2 deletions vms/platformvm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Config struct {
UptimeLockedCalculator uptime.LockedCalculator

// True if the node is being run with staking enabled
StakingEnabled bool
SybilProtectionEnabled bool

// Set of subnets that this node is validating
TrackedSubnets set.Set[ids.ID]
Expand Down Expand Up @@ -149,7 +149,7 @@ func (c *Config) GetCreateSubnetTxFee(timestamp time.Time) uint64 {
// Create the blockchain described in [tx], but only if this node is a member of
// the subnet that validates the chain
func (c *Config) CreateChain(chainID ids.ID, tx *txs.CreateChainTx) {
if c.StakingEnabled && // Staking is enabled, so nodes might not validate all chains
if c.SybilProtectionEnabled && // Sybil protection is enabled, so nodes might not validate all chains
constants.PrimaryNetworkID != tx.SubnetID && // All nodes must validate the primary network
!c.TrackedSubnets.Contains(tx.SubnetID) { // This node doesn't validate this blockchain
return
Expand Down
2 changes: 1 addition & 1 deletion vms/platformvm/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (vm *VM) HealthCheck(context.Context) (interface{}, error) {
}
}

if len(errorReasons) == 0 || !vm.StakingEnabled {
if len(errorReasons) == 0 || !vm.SybilProtectionEnabled {
return details, nil
}
return details, fmt.Errorf("platform layer is unhealthy err: %w, details: %s",
Expand Down
Loading

0 comments on commit 61e7aa6

Please sign in to comment.