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