genesis

package
v1.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: BSD-3-Clause Imports: 36 Imported by: 3

Documentation

Index

Constants

View Source
const (
	VMRQKeyStr          = "vmRQiZeXEXYMyJhEiqdC2z5JhuDbxL8ix9UVvjgMu2Er1NepE"
	VMRQKeyFormattedStr = secp256k1.PrivateKeyPrefix + VMRQKeyStr

	EWOQKeyStr          = "ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
	EWOQKeyFormattedStr = secp256k1.PrivateKeyPrefix + EWOQKeyStr
)

Variables

View Source
var (
	PChainAliases = []string{"P", "platform"}
	XChainAliases = []string{"X", "avm"}
	CChainAliases = []string{"C", "evm"}
	VMAliases     = map[ids.ID][]string{
		constants.PlatformVMID: {"platform"},
		constants.AVMID:        {"avm"},
		constants.EVMID:        {"evm"},
		secp256k1fx.ID:         {"secp256k1fx"},
		nftfx.ID:               {"nftfx"},
		propertyfx.ID:          {"propertyfx"},
	}
)
View Source
var (
	VMRQKey *secp256k1.PrivateKey
	EWOQKey *secp256k1.PrivateKey

	// LocalParams are the params used for local networks
	LocalParams = Params{
		TxFeeConfig: TxFeeConfig{
			TxFee:                         units.MilliAvax,
			CreateAssetTxFee:              units.MilliAvax,
			CreateSubnetTxFee:             100 * units.MilliAvax,
			TransformSubnetTxFee:          100 * units.MilliAvax,
			CreateBlockchainTxFee:         100 * units.MilliAvax,
			AddPrimaryNetworkValidatorFee: 0,
			AddPrimaryNetworkDelegatorFee: 0,
			AddSubnetValidatorFee:         units.MilliAvax,
			AddSubnetDelegatorFee:         units.MilliAvax,
		},
		StakingConfig: StakingConfig{
			UptimeRequirement: .8,
			MinValidatorStake: 2 * units.KiloAvax,
			MaxValidatorStake: 3 * units.MegaAvax,
			MinDelegatorStake: 25 * units.Avax,
			MinDelegationFee:  20000,
			MinStakeDuration:  24 * time.Hour,
			MaxStakeDuration:  365 * 24 * time.Hour,
			RewardConfig: reward.Config{
				MaxConsumptionRate: .12 * reward.PercentDenominator,
				MinConsumptionRate: .10 * reward.PercentDenominator,
				MintingPeriod:      365 * 24 * time.Hour,
				SupplyCap:          720 * units.MegaAvax,
			},
		},
	}
)
View Source
var (

	// MainnetParams are the params used for mainnet
	MainnetParams = Params{
		TxFeeConfig: TxFeeConfig{
			TxFee:                         units.MilliAvax,
			CreateAssetTxFee:              10 * units.MilliAvax,
			CreateSubnetTxFee:             1 * units.Avax,
			TransformSubnetTxFee:          10 * units.Avax,
			CreateBlockchainTxFee:         1 * units.Avax,
			AddPrimaryNetworkValidatorFee: 0,
			AddPrimaryNetworkDelegatorFee: 0,
			AddSubnetValidatorFee:         units.MilliAvax,
			AddSubnetDelegatorFee:         units.MilliAvax,
		},
		StakingConfig: StakingConfig{
			UptimeRequirement: .8,
			MinValidatorStake: 2 * units.KiloAvax,
			MaxValidatorStake: 3 * units.MegaAvax,
			MinDelegatorStake: 25 * units.Avax,
			MinDelegationFee:  20000,
			MinStakeDuration:  2 * 7 * 24 * time.Hour,
			MaxStakeDuration:  365 * 24 * time.Hour,
			RewardConfig: reward.Config{
				MaxConsumptionRate: .12 * reward.PercentDenominator,
				MinConsumptionRate: .10 * reward.PercentDenominator,
				MintingPeriod:      365 * 24 * time.Hour,
				SupplyCap:          666666666 * units.Avax,
			},
		},
	}
)
View Source
var (

	// TahoeParams are the params used for the tahoe testnet
	TahoeParams = Params{
		TxFeeConfig: TxFeeConfig{
			TxFee:                         units.MilliAvax,
			CreateAssetTxFee:              10 * units.MilliAvax,
			CreateSubnetTxFee:             100 * units.MilliAvax,
			TransformSubnetTxFee:          1 * units.Avax,
			CreateBlockchainTxFee:         100 * units.MilliAvax,
			AddPrimaryNetworkValidatorFee: 0,
			AddPrimaryNetworkDelegatorFee: 0,
			AddSubnetValidatorFee:         units.MilliAvax,
			AddSubnetDelegatorFee:         units.MilliAvax,
		},
		StakingConfig: StakingConfig{
			UptimeRequirement: .8,
			MinValidatorStake: 1 * units.Avax,
			MaxValidatorStake: 3 * units.MegaAvax,
			MinDelegatorStake: 1 * units.Avax,
			MinDelegationFee:  20000,
			MinStakeDuration:  24 * time.Hour,
			MaxStakeDuration:  365 * 24 * time.Hour,
			RewardConfig: reward.Config{
				MaxConsumptionRate: .12 * reward.PercentDenominator,
				MinConsumptionRate: .10 * reward.PercentDenominator,
				MintingPeriod:      365 * 24 * time.Hour,
				SupplyCap:          666666666 * units.Avax,
			},
		},
	}
)

Functions

func AVAXAssetID

func AVAXAssetID(avmGenesisBytes []byte) (ids.ID, error)

func Aliases

func Aliases(genesisBytes []byte) (map[string][]string, map[ids.ID][]string, error)

Aliases returns the default aliases based on the network ID

func FromConfig

func FromConfig(config *Config) ([]byte, ids.ID, error)

FromConfig returns:

  1. The byte representation of the genesis state of the platform chain (ie the genesis state of the network)
  2. The asset ID of AVAX

func FromFile

func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

FromFile returns the genesis data of the Platform Chain.

Since an Avalanche network has exactly one Platform Chain, and the Platform Chain defines the genesis state of the network (who is staking, which chains exist, etc.), defining the genesis state of the Platform Chain is the same as defining the genesis state of the network.

FromFile accepts: 1) The ID of the new network. [networkID] 2) The location of a custom genesis config to load. filepath

If filepath is empty or the given network ID is Mainnet, Testnet, or Local, returns error. If filepath is non-empty and networkID isn't Mainnet, Testnet, or Local, loads the network genesis data from the config at filepath.

FromFile returns:

  1. The byte representation of the genesis state of the platform chain (ie the genesis state of the network)
  2. The asset ID of AVAX

func FromFlag

func FromFlag(networkID uint32, genesisContent string, stakingCfg *StakingConfig) ([]byte, ids.ID, error)

FromFlag returns the genesis data of the Platform Chain.

Since an Avalanche network has exactly one Platform Chain, and the Platform Chain defines the genesis state of the network (who is staking, which chains exist, etc.), defining the genesis state of the Platform Chain is the same as defining the genesis state of the network.

FromFlag accepts: 1) The ID of the new network. [networkID] 2) The content of a custom genesis config to load. [genesisContent]

If [genesisContent] is empty or the given network ID is Mainnet, Testnet, or Local, returns error. If [genesisContent] is non-empty and networkID isn't Mainnet, Testnet, or Local, loads the network genesis data from [genesisContent].

FromFlag returns:

  1. The byte representation of the genesis state of the platform chain (ie the genesis state of the network)
  2. The asset ID of AVAX

func VMGenesis

func VMGenesis(genesisBytes []byte, vmID ids.ID) (*pchaintxs.Tx, error)

Types

type Allocation

type Allocation struct {
	ETHAddr        ids.ShortID    `json:"ethAddr"`
	AVAXAddr       ids.ShortID    `json:"avaxAddr"`
	InitialAmount  uint64         `json:"initialAmount"`
	UnlockSchedule []LockedAmount `json:"unlockSchedule"`
}

func (Allocation) Compare added in v1.10.18

func (a Allocation) Compare(other Allocation) int

func (Allocation) Unparse

func (a Allocation) Unparse(networkID uint32) (UnparsedAllocation, error)

type Bootstrapper added in v1.10.3

type Bootstrapper struct {
	ID ids.NodeID `json:"id"`
	IP ips.IPDesc `json:"ip"`
}

Represents the relationship between the nodeID and the nodeIP. The bootstrapper is sometimes called "anchor" or "beacon" node.

func GetBootstrappers added in v1.10.18

func GetBootstrappers(networkID uint32) []Bootstrapper

GetBootstrappers returns all default bootstrappers for the provided network.

func SampleBootstrappers added in v1.10.3

func SampleBootstrappers(networkID uint32, count int) []Bootstrapper

SampleBootstrappers returns the some beacons this node should connect to

type Config

type Config struct {
	NetworkID uint32 `json:"networkID"`

	Allocations []Allocation `json:"allocations"`

	StartTime                  uint64        `json:"startTime"`
	InitialStakeDuration       uint64        `json:"initialStakeDuration"`
	InitialStakeDurationOffset uint64        `json:"initialStakeDurationOffset"`
	InitialStakedFunds         []ids.ShortID `json:"initialStakedFunds"`
	InitialStakers             []Staker      `json:"initialStakers"`

	CChainGenesis string `json:"cChainGenesis"`

	Message string `json:"message"`
}

Config contains the genesis addresses used to construct a genesis

var (
	// MainnetConfig is the config that should be used to generate the mainnet
	// genesis.
	MainnetConfig Config

	// TestnetConfig is the config that should be used to generate the testnet
	// genesis.
	TahoeConfig Config

	// LocalConfig is the config that should be used to generate a local
	// genesis.
	LocalConfig Config
)

func GetConfig

func GetConfig(networkID uint32) *Config

func GetConfigContent

func GetConfigContent(genesisContent string) (*Config, error)

GetConfigContent loads a *Config from a provided environment variable

func GetConfigFile

func GetConfigFile(fp string) (*Config, error)

GetConfigFile loads a *Config from a provided filepath.

func (*Config) InitialSupply

func (c *Config) InitialSupply() (uint64, error)

func (Config) Unparse

func (c Config) Unparse() (UnparsedConfig, error)

type LockedAmount

type LockedAmount struct {
	Amount   uint64 `json:"amount"`
	Locktime uint64 `json:"locktime"`
}

type Params

type Params struct {
	StakingConfig
	TxFeeConfig
}

type Staker

type Staker struct {
	NodeID        ids.NodeID                `json:"nodeID"`
	RewardAddress ids.ShortID               `json:"rewardAddress"`
	DelegationFee uint32                    `json:"delegationFee"`
	Signer        *signer.ProofOfPossession `json:"signer,omitempty"`
}

func (Staker) Unparse

func (s Staker) Unparse(networkID uint32) (UnparsedStaker, error)

type StakingConfig

type StakingConfig struct {
	// Staking uptime requirements
	UptimeRequirement float64 `json:"uptimeRequirement"`
	// Minimum stake, in nAVAX, required to validate the primary network
	MinValidatorStake uint64 `json:"minValidatorStake"`
	// Maximum stake, in nAVAX, allowed to be placed on a single validator in
	// the primary network
	MaxValidatorStake uint64 `json:"maxValidatorStake"`
	// Minimum stake, in nAVAX, that can be delegated on the primary network
	MinDelegatorStake uint64 `json:"minDelegatorStake"`
	// Minimum delegation fee, in the range [0, 1000000], that can be charged
	// for delegation on the primary network.
	MinDelegationFee uint32 `json:"minDelegationFee"`
	// MinStakeDuration is the minimum amount of time a validator can validate
	// for in a single period.
	MinStakeDuration time.Duration `json:"minStakeDuration"`
	// MaxStakeDuration is the maximum amount of time a validator can validate
	// for in a single period.
	MaxStakeDuration time.Duration `json:"maxStakeDuration"`
	// RewardConfig is the config for the reward function.
	RewardConfig reward.Config `json:"rewardConfig"`
}

func GetStakingConfig

func GetStakingConfig(networkID uint32) StakingConfig

type TxFeeConfig

type TxFeeConfig struct {
	// Transaction fee
	TxFee uint64 `json:"txFee"`
	// Transaction fee for create asset transactions
	CreateAssetTxFee uint64 `json:"createAssetTxFee"`
	// Transaction fee for create subnet transactions
	CreateSubnetTxFee uint64 `json:"createSubnetTxFee"`
	// Transaction fee for transform subnet transactions
	TransformSubnetTxFee uint64 `json:"transformSubnetTxFee"`
	// Transaction fee for create blockchain transactions
	CreateBlockchainTxFee uint64 `json:"createBlockchainTxFee"`
	// Transaction fee for adding a primary network validator
	AddPrimaryNetworkValidatorFee uint64 `json:"addPrimaryNetworkValidatorFee"`
	// Transaction fee for adding a primary network delegator
	AddPrimaryNetworkDelegatorFee uint64 `json:"addPrimaryNetworkDelegatorFee"`
	// Transaction fee for adding a subnet validator
	AddSubnetValidatorFee uint64 `json:"addSubnetValidatorFee"`
	// Transaction fee for adding a subnet delegator
	AddSubnetDelegatorFee uint64 `json:"addSubnetDelegatorFee"`
}

func GetTxFeeConfig

func GetTxFeeConfig(networkID uint32) TxFeeConfig

type UnparsedAllocation

type UnparsedAllocation struct {
	ETHAddr        string         `json:"ethAddr"`
	AVAXAddr       string         `json:"avaxAddr"`
	InitialAmount  uint64         `json:"initialAmount"`
	UnlockSchedule []LockedAmount `json:"unlockSchedule"`
}

func (UnparsedAllocation) Parse

func (ua UnparsedAllocation) Parse() (Allocation, error)

type UnparsedConfig

type UnparsedConfig struct {
	NetworkID uint32 `json:"networkID"`

	Allocations []UnparsedAllocation `json:"allocations"`

	StartTime                  uint64           `json:"startTime"`
	InitialStakeDuration       uint64           `json:"initialStakeDuration"`
	InitialStakeDurationOffset uint64           `json:"initialStakeDurationOffset"`
	InitialStakedFunds         []string         `json:"initialStakedFunds"`
	InitialStakers             []UnparsedStaker `json:"initialStakers"`

	CChainGenesis string `json:"cChainGenesis"`

	Message string `json:"message"`
}

UnparsedConfig contains the genesis addresses used to construct a genesis

func (UnparsedConfig) Parse

func (uc UnparsedConfig) Parse() (Config, error)

type UnparsedStaker

type UnparsedStaker struct {
	NodeID        ids.NodeID                `json:"nodeID"`
	RewardAddress string                    `json:"rewardAddress"`
	DelegationFee uint32                    `json:"delegationFee"`
	Signer        *signer.ProofOfPossession `json:"signer,omitempty"`
}

func (UnparsedStaker) Parse

func (us UnparsedStaker) Parse() (Staker, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL