Skip to content

Commit f181a25

Browse files
Minimal primary sync (#1784)
1 parent 7499e6c commit f181a25

File tree

15 files changed

+97
-65
lines changed

15 files changed

+97
-65
lines changed

chains/manager.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ var (
8787
// Bootstrapping prefixes for ChainVMs
8888
bootstrappingDB = []byte("bs")
8989

90-
errUnknownVMType = errors.New("the vm should have type avalanche.DAGVM or snowman.ChainVM")
91-
errCreatePlatformVM = errors.New("attempted to create a chain running the PlatformVM")
92-
errNotBootstrapped = errors.New("subnets not bootstrapped")
93-
errNoPrimaryNetworkConfig = errors.New("no subnet config for primary network found")
90+
errUnknownVMType = errors.New("the vm should have type avalanche.DAGVM or snowman.ChainVM")
91+
errCreatePlatformVM = errors.New("attempted to create a chain running the PlatformVM")
92+
errNotBootstrapped = errors.New("subnets not bootstrapped")
93+
errNoPrimaryNetworkConfig = errors.New("no subnet config for primary network found")
94+
errNoLiteSyncForValidators = errors.New("lite sync cannot be configured for a validator")
9495

9596
_ Manager = (*manager)(nil)
9697
)
@@ -183,7 +184,7 @@ type ManagerConfig struct {
183184
Router router.Router // Routes incoming messages to the appropriate chain
184185
Net network.Network // Sends consensus messages to other validators
185186
Validators validators.Manager // Validators validating on this chain
186-
ReducedMode bool
187+
LiteSyncPrimaryNetwork bool
187188
NodeID ids.NodeID // The ID of this node
188189
NetworkID uint32 // ID of the network this node is connected to
189190
Server server.Server // Handles HTTP API calls
@@ -870,7 +871,6 @@ func (m *manager) createAvalancheChain(
870871
Validators: vdrs,
871872
Params: consensusParams,
872873
Consensus: snowmanConsensus,
873-
ReducedMode: m.ReducedMode && snowmanCommonCfg.Ctx.ChainID == constants.PlatformChainID,
874874
}
875875
snowmanEngine, err := smeng.New(snowmanEngineConfig)
876876
if err != nil {
@@ -1214,6 +1214,7 @@ func (m *manager) createSnowmanChain(
12141214
Validators: vdrs,
12151215
Params: consensusParams,
12161216
Consensus: consensus,
1217+
LiteSync: m.LiteSyncPrimaryNetwork && commonCfg.Ctx.ChainID == constants.PlatformChainID,
12171218
}
12181219
engine, err := smeng.New(engineConfig)
12191220
if err != nil {
@@ -1323,6 +1324,33 @@ func (m *manager) registerBootstrappedHealthChecks() error {
13231324
if err := m.Health.RegisterHealthCheck("bootstrapped", bootstrappedCheck, health.ApplicationTag); err != nil {
13241325
return fmt.Errorf("couldn't register bootstrapped health check: %w", err)
13251326
}
1327+
1328+
// If the node is not lite syncing the Primary Network, there is no reason
1329+
// to shutdown if it is a validator.
1330+
if !m.LiteSyncPrimaryNetwork {
1331+
return nil
1332+
}
1333+
1334+
liteSyncCheck := health.CheckerFunc(func(ctx context.Context) (interface{}, error) {
1335+
// Note: The health check is skipped during bootstrapping to allow a
1336+
// node to sync the network even if it was previously a validator.
1337+
if !m.IsBootstrapped(constants.PlatformChainID) {
1338+
return "node is currently bootstrapping", nil
1339+
}
1340+
if !validators.Contains(m.Validators, constants.PrimaryNetworkID, m.NodeID) {
1341+
return "node is not a primary network validator", nil
1342+
}
1343+
1344+
m.Log.Fatal("node is a primary network validator. Shutting down...",
1345+
zap.Error(errNoLiteSyncForValidators),
1346+
)
1347+
go m.ShutdownNodeFunc(1)
1348+
return "node is a primary network validator", errNoLiteSyncForValidators
1349+
})
1350+
1351+
if err := m.Health.RegisterHealthCheck("validation", liteSyncCheck, health.ApplicationTag); err != nil {
1352+
return fmt.Errorf("couldn't register validation health check: %w", err)
1353+
}
13261354
return nil
13271355
}
13281356

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err
777777
config := node.StakingConfig{
778778
SybilProtectionEnabled: v.GetBool(SybilProtectionEnabledKey),
779779
SybilProtectionDisabledWeight: v.GetUint64(SybilProtectionDisabledWeightKey),
780-
ReducedMode: v.GetBool(ReducedModeKey),
780+
LiteSyncPrimaryNetwork: v.GetBool(LiteSyncPrimaryNetworkKey),
781781
StakingKeyPath: GetExpandedArg(v, StakingTLSKeyPathKey),
782782
StakingCertPath: GetExpandedArg(v, StakingCertPathKey),
783783
StakingSignerPath: GetExpandedArg(v, StakingSignerKeyPathKey),

config/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func addNodeFlags(fs *pflag.FlagSet) {
259259
fs.String(StakingSignerKeyContentKey, "", "Specifies base64 encoded signer private key for staking")
260260
fs.Bool(SybilProtectionEnabledKey, true, "Enables sybil protection. If enabled, Network TLS is required")
261261
fs.Uint64(SybilProtectionDisabledWeightKey, 100, "Weight to provide to each peer when sybil protection is disabled")
262-
fs.Bool(ReducedModeKey, false, "Disable C-chain and X-chain validation. Only allowed for non-validators. Node would shutdown otherwise")
262+
fs.Bool(LiteSyncPrimaryNetworkKey, false, "Only sync the P-chain on the Primary Network. If the node is a Primary Network validator, it will shutdown")
263263
// Uptime Requirement
264264
fs.Float64(UptimeRequirementKey, genesis.LocalParams.UptimeRequirement, "Fraction of time a validator must be online to receive rewards")
265265
// Minimum Stake required to validate the Primary Network

config/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const (
7474
StakingSignerKeyContentKey = "staking-signer-key-file-content"
7575
SybilProtectionEnabledKey = "sybil-protection-enabled"
7676
SybilProtectionDisabledWeightKey = "sybil-protection-disabled-weight"
77-
ReducedModeKey = "reduced-mode"
7877
NetworkInitialTimeoutKey = "network-initial-timeout"
7978
NetworkMinimumTimeoutKey = "network-minimum-timeout"
8079
NetworkMaximumTimeoutKey = "network-maximum-timeout"
@@ -130,6 +129,7 @@ const (
130129
SnowOptimalProcessingKey = "snow-optimal-processing"
131130
SnowMaxProcessingKey = "snow-max-processing"
132131
SnowMaxTimeProcessingKey = "snow-max-time-processing"
132+
LiteSyncPrimaryNetworkKey = "lite-sync-primary-network"
133133
TrackSubnetsKey = "track-subnets"
134134
AdminAPIEnabledKey = "api-admin-enabled"
135135
InfoAPIEnabledKey = "api-info-enabled"

node/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type IPConfig struct {
9292
type StakingConfig struct {
9393
genesis.StakingConfig
9494
SybilProtectionEnabled bool `json:"sybilProtectionEnabled"`
95-
ReducedMode bool `json:"reducedModeEnabled"`
95+
LiteSyncPrimaryNetwork bool `json:"liteSyncPrimaryNetwork"`
9696
StakingTLSCert tls.Certificate `json:"-"`
9797
StakingSigningKey *bls.SecretKey `json:"-"`
9898
SybilProtectionDisabledWeight uint64 `json:"sybilProtectionDisabledWeight"`

node/node.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ var (
9191
genesisHashKey = []byte("genesisID")
9292
indexerDBPrefix = []byte{0x00}
9393

94-
errInvalidTLSKey = errors.New("invalid TLS key")
95-
errShuttingDown = errors.New("server shutting down")
96-
errNoReducedModeForValidators = errors.New("reduced mode cannot be configured for validators")
94+
errInvalidTLSKey = errors.New("invalid TLS key")
95+
errShuttingDown = errors.New("server shutting down")
9796
)
9897

9998
// Node is an instance of an Avalanche node.
@@ -818,7 +817,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error {
818817
Router: n.Config.ConsensusRouter,
819818
Net: n.Net,
820819
Validators: n.vdrs,
821-
ReducedMode: n.Config.ReducedMode,
820+
LiteSyncPrimaryNetwork: n.Config.LiteSyncPrimaryNetwork,
822821
NodeID: n.ID,
823822
NetworkID: n.Config.NetworkID,
824823
Server: n.APIServer,
@@ -887,7 +886,7 @@ func (n *Node) initVMs() error {
887886
Validators: vdrs,
888887
UptimeLockedCalculator: n.uptimeCalculator,
889888
SybilProtectionEnabled: n.Config.SybilProtectionEnabled,
890-
ReducedMode: n.Config.ReducedMode,
889+
LiteSyncPrimaryNetwork: n.Config.LiteSyncPrimaryNetwork,
891890
TrackedSubnets: n.Config.TrackedSubnets,
892891
TxFee: n.Config.TxFee,
893892
CreateAssetTxFee: n.Config.CreateAssetTxFee,
@@ -1171,20 +1170,6 @@ func (n *Node) initHealthAPI() error {
11711170
return fmt.Errorf("couldn't register resource health check: %w", err)
11721171
}
11731172

1174-
reducedModeCheck := health.CheckerFunc(func(ctx context.Context) (interface{}, error) {
1175-
primaryValidators, _ := n.vdrs.Get(constants.PrimaryNetworkID)
1176-
if n.Config.ReducedMode && primaryValidators.GetWeight(n.ID) != 0 {
1177-
n.Log.Fatal(fmt.Sprintf("%s. Shutting down...", errNoReducedModeForValidators.Error()))
1178-
go n.Shutdown(1)
1179-
return nil, errNoReducedModeForValidators
1180-
}
1181-
return nil, nil
1182-
})
1183-
err = n.health.RegisterHealthCheck("reducedmode", reducedModeCheck, health.ApplicationTag)
1184-
if err != nil {
1185-
return fmt.Errorf("couldn't register reduced mode health check: %w", err)
1186-
}
1187-
11881173
handler, err := health.NewGetAndPostHandler(n.Log, healthChecker)
11891174
if err != nil {
11901175
return err
@@ -1445,7 +1430,6 @@ func (n *Node) Initialize(
14451430

14461431
// Start the Health API
14471432
// Has to be initialized before chain manager
1448-
// Has to be initialized after Validators Set
14491433
// [n.Net] must already be set
14501434
if err := n.initHealthAPI(); err != nil {
14511435
return fmt.Errorf("couldn't initialize health API: %w", err)

snow/engine/snowman/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
type Config struct {
1717
common.AllGetsServer
1818

19-
Ctx *snow.ConsensusContext
20-
VM block.ChainVM
21-
Sender common.Sender
22-
Validators validators.Set
23-
Params snowball.Parameters
24-
Consensus snowman.Consensus
25-
ReducedMode bool
19+
Ctx *snow.ConsensusContext
20+
VM block.ChainVM
21+
Sender common.Sender
22+
Validators validators.Set
23+
Params snowball.Parameters
24+
Consensus snowman.Consensus
25+
LiteSync bool
2626
}

snow/engine/snowman/transitive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func (t *Transitive) GetBlock(ctx context.Context, blkID ids.ID) (snowman.Block,
455455

456456
func (t *Transitive) sendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32) {
457457
lastAccepted := t.Consensus.LastAccepted()
458-
if t.Ctx.StateSyncing.Get() || t.Config.ReducedMode {
458+
if t.Ctx.StateSyncing.Get() || t.Config.LiteSync {
459459
t.Sender.SendChits(ctx, nodeID, requestID, lastAccepted, lastAccepted)
460460
} else {
461461
t.Sender.SendChits(ctx, nodeID, requestID, t.Consensus.Preference(), lastAccepted)

vms/platformvm/blocks/builder/builder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ func (b *builder) AddUnverifiedTx(tx *txs.Tx) error {
147147
return err
148148
}
149149

150-
if err := b.Mempool.Add(tx); err != nil {
151-
return err
150+
// If we are lite syncing the Primary Network, we should not be maintaining
151+
// the transaction mempool locally.
152+
if !b.txExecutorBackend.Config.LiteSyncPrimaryNetwork {
153+
if err := b.Mempool.Add(tx); err != nil {
154+
return err
155+
}
152156
}
153157
return b.GossipTx(tx)
154158
}

vms/platformvm/blocks/executor/manager.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ func NewManager(
5353
validators: validatorManager,
5454
bootstrapped: txExecutorBackend.Bootstrapped,
5555
},
56-
rejector: &rejector{backend: backend},
56+
rejector: &rejector{
57+
backend: backend,
58+
addTxsToMempool: !txExecutorBackend.Config.LiteSyncPrimaryNetwork,
59+
},
5760
}
5861
}
5962

0 commit comments

Comments
 (0)