github.com/ava-labs/avalanchego@v1.11.11/vms/platformvm/config/config.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package config
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/ava-labs/avalanchego/chains"
    10  	"github.com/ava-labs/avalanchego/ids"
    11  	"github.com/ava-labs/avalanchego/snow/uptime"
    12  	"github.com/ava-labs/avalanchego/snow/validators"
    13  	"github.com/ava-labs/avalanchego/upgrade"
    14  	"github.com/ava-labs/avalanchego/utils/constants"
    15  	"github.com/ava-labs/avalanchego/utils/set"
    16  	"github.com/ava-labs/avalanchego/vms/components/gas"
    17  	"github.com/ava-labs/avalanchego/vms/platformvm/reward"
    18  	"github.com/ava-labs/avalanchego/vms/platformvm/txs"
    19  	"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
    20  )
    21  
    22  // Struct collecting all foundational parameters of PlatformVM
    23  type Config struct {
    24  	// The node's chain manager
    25  	Chains chains.Manager
    26  
    27  	// Node's validator set maps subnetID -> validators of the subnet
    28  	//
    29  	// Invariant: The primary network's validator set should have been added to
    30  	//            the manager before calling VM.Initialize.
    31  	// Invariant: The primary network's validator set should be empty before
    32  	//            calling VM.Initialize.
    33  	Validators validators.Manager
    34  
    35  	// Static fees are active before the E-upgrade
    36  	CreateAssetTxFee uint64 // Override for CreateSubnet and CreateChain before AP3
    37  	StaticFeeConfig  fee.StaticConfig
    38  
    39  	// Dynamic fees are active after the E-upgrade
    40  	DynamicFeeConfig gas.Config
    41  
    42  	// Provides access to the uptime manager as a thread safe data structure
    43  	UptimeLockedCalculator uptime.LockedCalculator
    44  
    45  	// True if the node is being run with staking enabled
    46  	SybilProtectionEnabled bool
    47  
    48  	// If true, only the P-chain will be instantiated on the primary network.
    49  	PartialSyncPrimaryNetwork bool
    50  
    51  	// Set of subnets that this node is validating
    52  	TrackedSubnets set.Set[ids.ID]
    53  
    54  	// The minimum amount of tokens one must bond to be a validator
    55  	MinValidatorStake uint64
    56  
    57  	// The maximum amount of tokens that can be bonded on a validator
    58  	MaxValidatorStake uint64
    59  
    60  	// Minimum stake, in nAVAX, that can be delegated on the primary network
    61  	MinDelegatorStake uint64
    62  
    63  	// Minimum fee that can be charged for delegation
    64  	MinDelegationFee uint32
    65  
    66  	// UptimePercentage is the minimum uptime required to be rewarded for staking
    67  	UptimePercentage float64
    68  
    69  	// Minimum amount of time to allow a staker to stake
    70  	MinStakeDuration time.Duration
    71  
    72  	// Maximum amount of time to allow a staker to stake
    73  	MaxStakeDuration time.Duration
    74  
    75  	// Config for the minting function
    76  	RewardConfig reward.Config
    77  
    78  	// All network upgrade timestamps
    79  	UpgradeConfig upgrade.Config
    80  
    81  	// UseCurrentHeight forces [GetMinimumHeight] to return the current height
    82  	// of the P-Chain instead of the oldest block in the [recentlyAccepted]
    83  	// window.
    84  	//
    85  	// This config is particularly useful for triggering proposervm activation
    86  	// on recently created subnets (without this, users need to wait for
    87  	// [recentlyAcceptedWindowTTL] to pass for activation to occur).
    88  	UseCurrentHeight bool
    89  }
    90  
    91  // Create the blockchain described in [tx], but only if this node is a member of
    92  // the subnet that validates the chain
    93  func (c *Config) CreateChain(chainID ids.ID, tx *txs.CreateChainTx) {
    94  	if c.SybilProtectionEnabled && // Sybil protection is enabled, so nodes might not validate all chains
    95  		constants.PrimaryNetworkID != tx.SubnetID && // All nodes must validate the primary network
    96  		!c.TrackedSubnets.Contains(tx.SubnetID) { // This node doesn't validate this blockchain
    97  		return
    98  	}
    99  
   100  	chainParams := chains.ChainParameters{
   101  		ID:          chainID,
   102  		SubnetID:    tx.SubnetID,
   103  		GenesisData: tx.GenesisData,
   104  		VMID:        tx.VMID,
   105  		FxIDs:       tx.FxIDs,
   106  	}
   107  
   108  	c.Chains.QueueChainCreation(chainParams)
   109  }