Skip to content

Commit

Permalink
add flags for partial sync to local and remote
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Nov 12, 2024
1 parent 2885ec5 commit 44b6dab
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/ava-labs/avalanche-cli/pkg/contract"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
Expand Down Expand Up @@ -82,6 +81,7 @@ var (
avagoBinaryPath string
numBootstrapValidators int
numLocalNodes int
partialSync bool
changeOwnerAddress string
subnetOnly bool
icmSpec subnet.ICMSpec
Expand Down Expand Up @@ -152,6 +152,7 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().IntVar(&numBootstrapValidators, "num-bootstrap-validators", 0, "(only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)")
cmd.Flags().IntVar(&numLocalNodes, "num-local-nodes", 5, "number of nodes to be created on local machine")
cmd.Flags().StringVar(&changeOwnerAddress, "change-owner-address", "", "address that will receive change if node is no longer L1 validator")
cmd.Flags().BoolVar(&partialSync, "partial-sync", true, "set primary network partial sync for new validators")
return cmd
}

Expand Down Expand Up @@ -542,14 +543,14 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
}
nodeConfig[config.PartialSyncPrimaryNetworkKey] = true
// anrSettings, avagoVersionSettings, globalNetworkFlags are empty
if err = node.StartLocalNode(
app,
clusterName,
useEtnaDevnet,
avagoBinaryPath,
uint32(numLocalNodes),
partialSync,
nodeConfig,
anrSettings,
avagoVersionSettings,
Expand Down
9 changes: 8 additions & 1 deletion cmd/nodecmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ will apply to all nodes in the cluster`,
cmd.Flags().StringArrayVar(&bootstrapIPs, "bootstrap-ips", []string{}, "IP:port pairs of bootstrap nodes")
cmd.Flags().StringVar(&genesisPath, "genesis", "", "path to genesis file")
cmd.Flags().StringVar(&upgradePath, "upgrade", "", "path to upgrade file")
cmd.Flags().BoolVar(&partialSync, "partial-sync", true, "primary network partial sync")
return cmd
}

Expand Down Expand Up @@ -231,6 +232,10 @@ func preCreateChecks(clusterName string) error {
return fmt.Errorf("invalid ip:port pair %s", ipPortPair)
}
}
if globalNetworkFlags.UseDevnet {
partialSync = false
ux.Logger.PrintToUser("disabling partial sync default for devnet")
}

return nil
}
Expand Down Expand Up @@ -790,10 +795,12 @@ func createNodes(cmd *cobra.Command, args []string) error {
avalancheGoVersion,
bootstrapIDs,
bootstrapIPs,
partialSync,
genesisPath,
upgradePath,
addMonitoring,
publicAccessToHTTPPort); err != nil {
publicAccessToHTTPPort,
); err != nil {
nodeResults.AddResult(host.NodeID, nil, err)
ux.SpinFailWithError(spinner, "", err)
return
Expand Down
5 changes: 3 additions & 2 deletions cmd/nodecmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/node"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/spf13/cobra"
)
Expand All @@ -27,6 +26,7 @@ var (
stakingSignerKeyPath string
numNodes uint32
nodeConfigPath string
partialSync bool
)

// const snapshotName = "local_snapshot"
Expand Down Expand Up @@ -85,6 +85,7 @@ status by running avalanche node status local
cmd.Flags().StringVar(&stakingSignerKeyPath, "staking-signer-key-path", "", "path to provided staking signer key for node")
cmd.Flags().Uint32Var(&numNodes, "num-nodes", 1, "number of nodes to start")
cmd.Flags().StringVar(&nodeConfigPath, "node-config", "", "path to common avalanchego config settings for all nodes")
cmd.Flags().BoolVar(&partialSync, "partial-sync", true, "primary network partial sync")
return cmd
}

Expand Down Expand Up @@ -162,14 +163,14 @@ func localStartNode(_ *cobra.Command, args []string) error {
return err
}
}
nodeConfig[config.PartialSyncPrimaryNetworkKey] = true

return node.StartLocalNode(
app,
clusterName,
globalNetworkFlags.UseEtnaDevnet,
avalanchegoBinaryPath,
numNodes,
partialSync,
nodeConfig,
anrSettings,
avaGoVersionSetting,
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type AvalancheGoConfigOptions struct {
BootstrapIPs []string
BootstrapIDs []string
PartialSync bool
GenesisPath string
UpgradePath string
AllowPublicAccess bool
Expand All @@ -31,6 +32,7 @@ func prepareAvalanchegoConfig(
if avalancheGoConfig.AllowPublicAccess || utils.IsE2E() {
avagoConf.HTTPHost = "0.0.0.0"
}
avagoConf.PartialSync = avalancheGoConfig.PartialSync
avagoConf.BootstrapIPs = strings.Join(avalancheGoConfig.BootstrapIPs, ",")
avagoConf.BootstrapIDs = strings.Join(avalancheGoConfig.BootstrapIDs, ",")
if avalancheGoConfig.GenesisPath != "" {
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func ComposeSSHSetupNode(
avalancheGoVersion string,
avalanchegoBootstrapIDs []string,
avalanchegoBootstrapIPs []string,
partialSync bool,
avalanchegoGenesisFilePath string,
avalanchegoUpgradeFilePath string,
withMonitoring bool,
Expand All @@ -57,6 +58,7 @@ func ComposeSSHSetupNode(
AvalancheGoConfigOptions{
BootstrapIDs: avalanchegoBootstrapIDs,
BootstrapIPs: avalanchegoBootstrapIPs,
PartialSync: partialSync,
GenesisPath: avalanchegoGenesisFilePath,
UpgradePath: avalanchegoUpgradeFilePath,
AllowPublicAccess: publicAccessToHTTPPort,
Expand Down
6 changes: 6 additions & 0 deletions pkg/node/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ava-labs/avalanche-network-runner/client"
anrutils "github.com/ava-labs/avalanche-network-runner/utils"
"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"
avagoconstants "github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -155,6 +156,7 @@ func StartLocalNode(
useEtnaDevnet bool,
avalanchegoBinaryPath string,
numNodes uint32,
partialSync bool,
nodeConfig map[string]interface{},
anrSettings ANRSettings,
avaGoVersionSetting AvalancheGoVersionSettings,
Expand Down Expand Up @@ -237,6 +239,10 @@ func StartLocalNode(
return nil
}

if partialSync {
nodeConfig[config.PartialSyncPrimaryNetworkKey] = true
}

nodeConfigBytes, err := json.Marshal(nodeConfig)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/remoteconfig/avalanche.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type AvalancheConfigInputs struct {
TrackSubnets string
BootstrapIDs string
BootstrapIPs string
PartialSync bool
GenesisPath string
UpgradePath string
ProposerVMUseCurrentHeight bool
Expand Down
1 change: 1 addition & 0 deletions pkg/remoteconfig/templates/avalanche-node.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"index-enabled": {{.IndexEnabled}},
"proposervm-use-current-height-bool": {{.ProposerVMUseCurrentHeight}},
"network-id": "{{if .NetworkID}}{{.NetworkID}}{{else}}fuji{{end}}",
"partial-sync-primary-network": "{{ .PartialSync }}",
{{- if .BootstrapIDs }}
"bootstrap-ids": "{{ .BootstrapIDs }}",
{{- end }}
Expand Down
8 changes: 8 additions & 0 deletions pkg/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/remoteconfig"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/pkg/ux"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"

"github.com/ava-labs/avalanche-cli/pkg/constants"
Expand Down Expand Up @@ -587,6 +588,13 @@ func RunSSHRenderAvalancheNodeConfig(
bootstrapIPs, _ := utils.StringValue(remoteAvagoConf, "bootstrap-ips")
avagoConf.BootstrapIDs = bootstrapIDs
avagoConf.BootstrapIPs = bootstrapIPs
partialSyncI, ok := remoteAvagoConf[config.PartialSyncPrimaryNetworkKey]
if ok {
partialSync, ok := partialSyncI.(bool)
if ok {
avagoConf.PartialSync = partialSync
}
}
}
// ready to render node config
nodeConf, err := remoteconfig.RenderAvalancheNodeConfig(avagoConf)
Expand Down

0 comments on commit 44b6dab

Please sign in to comment.