-
Notifications
You must be signed in to change notification settings - Fork 672
/
config.go
142 lines (106 loc) · 4.16 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package config
import (
"time"
"github.com/ava-labs/avalanchego/chains"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/uptime"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
// Struct collecting all foundational parameters of PlatformVM
type Config struct {
// The node's chain manager
Chains chains.Manager
// Node's validator set maps subnetID -> validators of the subnet
Validators validators.Manager
// Provides access to subnet tracking
SubnetTracker common.SubnetTracker
// Provides access to the uptime manager as a thread safe data structure
UptimeLockedCalculator uptime.LockedCalculator
// True if the node is being run with staking enabled
StakingEnabled bool
// Set of subnets that this node is validating
WhitelistedSubnets ids.Set
// Fee that is burned by every non-state creating transaction
TxFee uint64
// Fee that must be burned by every state creating transaction before AP3
CreateAssetTxFee uint64
// Fee that must be burned by every subnet creating transaction after AP3
CreateSubnetTxFee uint64
// Fee that must be burned by every transform subnet transaction
TransformSubnetTxFee uint64
// Fee that must be burned by every blockchain creating transaction after AP3
CreateBlockchainTxFee uint64
// Transaction fee for adding a primary network validator
AddPrimaryNetworkValidatorFee uint64
// Transaction fee for adding a primary network delegator
AddPrimaryNetworkDelegatorFee uint64
// Transaction fee for adding a subnet validator
AddSubnetValidatorFee uint64
// Transaction fee for adding a subnet delegator
AddSubnetDelegatorFee uint64
// The minimum amount of tokens one must bond to be a validator
MinValidatorStake uint64
// The maximum amount of tokens that can be bonded on a validator
MaxValidatorStake uint64
// Minimum stake, in nAVAX, that can be delegated on the primary network
MinDelegatorStake uint64
// Minimum fee that can be charged for delegation
MinDelegationFee uint32
// UptimePercentage is the minimum uptime required to be rewarded for staking
UptimePercentage float64
// Minimum amount of time to allow a staker to stake
MinStakeDuration time.Duration
// Maximum amount of time to allow a staker to stake
MaxStakeDuration time.Duration
// Config for the minting function
RewardConfig reward.Config
// Time of the AP3 network upgrade
ApricotPhase3Time time.Time
// Time of the AP5 network upgrade
ApricotPhase5Time time.Time
// Time of the Blueberry network upgrade
BlueberryTime time.Time
}
func (c *Config) IsApricotPhase3Activated(timestamp time.Time) bool {
return !timestamp.Before(c.ApricotPhase3Time)
}
func (c *Config) IsApricotPhase5Activated(timestamp time.Time) bool {
return !timestamp.Before(c.ApricotPhase5Time)
}
func (c *Config) IsBlueberryActivated(timestamp time.Time) bool {
return !timestamp.Before(c.BlueberryTime)
}
func (c *Config) GetCreateBlockchainTxFee(timestamp time.Time) uint64 {
if c.IsApricotPhase3Activated(timestamp) {
return c.CreateBlockchainTxFee
}
return c.CreateAssetTxFee
}
func (c *Config) GetCreateSubnetTxFee(timestamp time.Time) uint64 {
if c.IsApricotPhase3Activated(timestamp) {
return c.CreateSubnetTxFee
}
return c.CreateAssetTxFee
}
// 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
constants.PrimaryNetworkID != tx.SubnetID && // All nodes must validate the primary network
!c.WhitelistedSubnets.Contains(tx.SubnetID) { // This node doesn't validate this blockchain
return
}
c.Chains.CreateChain(chains.ChainParameters{
ID: chainID,
SubnetID: tx.SubnetID,
GenesisData: tx.GenesisData,
VMID: tx.VMID,
FxIDs: tx.FxIDs,
})
}