Skip to content

Commit

Permalink
use blockchain timestamp to calculate expiry (#2391)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero authored Dec 3, 2024
1 parent 78b21fd commit 5d715b8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ func CallAddValidator(
return fmt.Errorf("failure parsing BLS info: %w", err)
}

expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix())
blockchainTimestamp, err := getBlockchainTimestamp(network)
if err != nil {
return fmt.Errorf("failed to get blockchain timestamp: %w", err)
}
expiry := uint64(blockchainTimestamp.Add(constants.DefaultValidationIDExpiryDuration).Unix())

chainSpec := contract.ChainSpec{
BlockchainName: blockchainName,
Expand Down Expand Up @@ -593,7 +597,6 @@ func getMaxValidationTime(network models.Network, nodeID ids.NodeID, startTime t
defer cancel()
platformCli := platformvm.NewClient(network.Endpoint)
vs, err := platformCli.GetCurrentValidators(ctx, avagoconstants.PrimaryNetworkID, nil)
cancel()
if err != nil {
return 0, err
}
Expand All @@ -605,6 +608,13 @@ func getMaxValidationTime(network models.Network, nodeID ids.NodeID, startTime t
return 0, errors.New("nodeID not found in validator set: " + nodeID.String())
}

func getBlockchainTimestamp(network models.Network) (time.Time, error) {
ctx, cancel := utils.GetAPIContext()
defer cancel()
platformCli := platformvm.NewClient(network.Endpoint)
return platformCli.GetTimestamp(ctx)
}

func getTimeParameters(network models.Network, nodeID ids.NodeID, isValidator bool) (time.Time, time.Duration, error) {
defaultStakingStartLeadTime := constants.StakingStartLeadTime
if network.Kind == models.Devnet {
Expand Down

0 comments on commit 5d715b8

Please sign in to comment.