Skip to content

Commit

Permalink
fix mainnet sa (#2454)
Browse files Browse the repository at this point in the history
* fix mainnet sa

* nit

* nit

* lint

* update version

* nit

* add a bit more of waiting time for pchain update

* validate pos L1 duration (#2455)

* validate pos L1 duration

* address comments

---------

Co-authored-by: Raymond Sukanto <rsukanto@umich.edu>
Co-authored-by: arturrez <56270896+arturrez@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 16, 2024
1 parent c091ff3 commit 769edac
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 19 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.2
1.8.3
23 changes: 11 additions & 12 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ Testnet or Mainnet.`,
return cmd
}

func preAddChecks(network models.Network, sovereign bool) error {
if sovereign && network.Kind == models.Mainnet {
return errNotSupportedOnMainnet
}
func preAddChecks() error {
if nodeEndpoint != "" && createLocalValidator {
return fmt.Errorf("cannot set both --node-endpoint and --create-local-validator")
}
Expand Down Expand Up @@ -171,7 +168,7 @@ func addValidator(_ *cobra.Command, args []string) error {
network = models.ConvertClusterToNetwork(network)
}

if err := preAddChecks(network, sc.Sovereign); err != nil {
if err := preAddChecks(); err != nil {
return err
}

Expand Down Expand Up @@ -379,7 +376,7 @@ func CallAddValidator(
}
}
if duration == 0 {
duration, err = PromptDuration(time.Now(), network)
duration, err = PromptDuration(time.Now(), network, true) // it's pos
if err != nil {
return nil
}
Expand Down Expand Up @@ -654,17 +651,19 @@ func CallAddValidatorNonSOV(
return err
}

func PromptDuration(start time.Time, network models.Network) (time.Duration, error) {
func PromptDuration(start time.Time, network models.Network, isPos bool) (time.Duration, error) {
for {
txt := "How long should this validator be validating? Enter a duration, e.g. 8760h. Valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\""
var d time.Duration
var err error
switch network.Kind {
case models.Fuji:
switch {
case network.Kind == models.Fuji:
d, err = app.Prompt.CaptureFujiDuration(txt)
case models.Mainnet:
case network.Kind == models.Mainnet && isPos:
d, err = app.Prompt.CaptureMainnetL1StakingDuration(txt)
case network.Kind == models.Mainnet && !isPos:
d, err = app.Prompt.CaptureMainnetDuration(txt)
case models.EtnaDevnet:
case network.Kind == models.EtnaDevnet:
d, err = app.Prompt.CaptureEtnaDuration(txt)
default:
d, err = app.Prompt.CaptureDuration(txt)
Expand Down Expand Up @@ -759,7 +758,7 @@ func getTimeParameters(network models.Network, nodeID ids.NodeID, isValidator bo
case defaultDurationOption:
useDefaultDuration = true
default:
duration, err = PromptDuration(start, network)
duration, err = PromptDuration(start, network, false) // notSoV
if err != nil {
return time.Time{}, 0, err
}
Expand Down
1 change: 0 additions & 1 deletion cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ var (
ErrMutuallyExlusiveKeyLedger = errors.New("key source flags --key, --ledger/--ledger-addrs are mutually exclusive")
ErrStoredKeyOnMainnet = errors.New("key --key is not available for mainnet operations")
errMutuallyExlusiveSubnetFlags = errors.New("--subnet-only and --subnet-id are mutually exclusive")
errNotSupportedOnMainnet = errors.New("deploying sovereign blockchain is currently not supported on Mainnet")
)

// avalanche blockchain deploy
Expand Down
2 changes: 1 addition & 1 deletion cmd/blockchaincmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func UpdatePChainHeight(
title string,
) error {
_, err := ux.TimedProgressBar(
30*time.Second,
40*time.Second,
title,
0,
)
Expand Down
1 change: 1 addition & 0 deletions cmd/contractcmd/init_validator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
networkoptions.Devnet,
networkoptions.EtnaDevnet,
networkoptions.Fuji,
networkoptions.Mainnet,
}
validatorManagerFlags ValidatorManagerFlags
initPOSManagerFlags POSManagerSpecFlags
Expand Down
2 changes: 1 addition & 1 deletion cmd/nodecmd/validate_primary.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func GetTimeParametersPrimaryNetwork(network models.Network, nodeIndex int, vali
}
default:
useCustomDuration = true
duration, err = blockchaincmd.PromptDuration(start, network)
duration, err = blockchaincmd.PromptDuration(start, network, false) // not L1
if err != nil {
return time.Time{}, 0, err
}
Expand Down
28 changes: 28 additions & 0 deletions internal/mocks/prompter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pkg/constants/etna.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var (
const StakingEtnaMinimumDuration = 100 * time.Second

var EtnaActivationTime = map[uint32]time.Time{
avagoconstants.FujiID: time.Date(2024, time.November, 25, 16, 0, 0, 0, time.UTC),
EtnaDevnetNetworkID: time.Date(2024, time.October, 9, 20, 0, 0, 0, time.UTC),
LocalNetworkID: upgrade.Default.EtnaTime,
avagoconstants.FujiID: time.Date(2024, time.November, 25, 16, 0, 0, 0, time.UTC),
avagoconstants.MainnetID: time.Date(2024, time.December, 16, 17, 0, 0, 0, time.UTC),
EtnaDevnetNetworkID: time.Date(2024, time.October, 9, 20, 0, 0, 0, time.UTC),
LocalNetworkID: upgrade.Default.EtnaTime,
}
15 changes: 15 additions & 0 deletions pkg/prompts/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type Prompter interface {
CaptureEtnaDuration(promptStr string) (time.Duration, error)
CaptureFujiDuration(promptStr string) (time.Duration, error)
CaptureMainnetDuration(promptStr string) (time.Duration, error)
CaptureMainnetL1StakingDuration(promptStr string) (time.Duration, error)
CaptureDate(promptStr string) (time.Time, error)
CaptureNodeID(promptStr string) (ids.NodeID, error)
CaptureID(promptStr string) (ids.ID, error)
Expand Down Expand Up @@ -263,6 +264,20 @@ func (*realPrompter) CaptureMainnetDuration(promptStr string) (time.Duration, er
return time.ParseDuration(durationStr)
}

func (*realPrompter) CaptureMainnetL1StakingDuration(promptStr string) (time.Duration, error) {
prompt := promptui.Prompt{
Label: promptStr,
Validate: validateMainnetL1StakingDuration,
}

durationStr, err := prompt.Run()
if err != nil {
return 0, err
}

return time.ParseDuration(durationStr)
}

func (*realPrompter) CaptureDate(promptStr string) (time.Time, error) {
prompt := promptui.Prompt{
Label: promptStr,
Expand Down
15 changes: 15 additions & 0 deletions pkg/prompts/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ func validateMainnetStakingDuration(input string) error {
return nil
}

func validateMainnetL1StakingDuration(input string) error {
const minL1StakingDuration = 24 * time.Hour
d, err := time.ParseDuration(input)
if err != nil {
return err
}
if d > genesis.MainnetParams.MaxStakeDuration {
return fmt.Errorf("exceeds maximum staking duration of %s", ux.FormatDuration(genesis.MainnetParams.MaxStakeDuration))
}
if d < minL1StakingDuration {
return fmt.Errorf("below the minimum staking duration of %s", ux.FormatDuration(minL1StakingDuration))
}
return nil
}

func validateFujiStakingDuration(input string) error {
d, err := time.ParseDuration(input)
if err != nil {
Expand Down

0 comments on commit 769edac

Please sign in to comment.