Skip to content

Commit

Permalink
[vms/platformvm] Remove platform.getMaxStakeAmount (#2795)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Mar 4, 2024
1 parent f546ca4 commit 11372a4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 83 deletions.
24 changes: 0 additions & 24 deletions vms/platformvm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,6 @@ type Client interface {
GetMinStake(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (uint64, uint64, error)
// GetTotalStake returns the total amount (in nAVAX) staked on the network
GetTotalStake(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (uint64, error)
// GetMaxStakeAmount returns the maximum amount of nAVAX staking to the named
// node during the time period.
//
// Deprecated: The MaxStakeAmount should be calculated using
// GetCurrentValidators, and GetPendingValidators.
GetMaxStakeAmount(
ctx context.Context,
subnetID ids.ID,
nodeID ids.NodeID,
startTime uint64,
endTime uint64,
options ...rpc.Option,
) (uint64, error)
// GetRewardUTXOs returns the reward UTXOs for a transaction
//
// Deprecated: GetRewardUTXOs should be fetched from a dedicated indexer.
Expand Down Expand Up @@ -516,17 +503,6 @@ func (c *client) GetTotalStake(ctx context.Context, subnetID ids.ID, options ...
return uint64(amount), err
}

func (c *client) GetMaxStakeAmount(ctx context.Context, subnetID ids.ID, nodeID ids.NodeID, startTime, endTime uint64, options ...rpc.Option) (uint64, error) {
res := &GetMaxStakeAmountReply{}
err := c.requester.SendRequest(ctx, "platform.getMaxStakeAmount", &GetMaxStakeAmountArgs{
SubnetID: subnetID,
NodeID: nodeID,
StartTime: json.Uint64(startTime),
EndTime: json.Uint64(endTime),
}, res, options...)
return uint64(res.Amount), err
}

func (c *client) GetRewardUTXOs(ctx context.Context, args *api.GetTxArgs, options ...rpc.Option) ([][]byte, error) {
res := &GetRewardUTXOsReply{}
err := c.requester.SendRequest(ctx, "platform.getRewardUTXOs", args, res, options...)
Expand Down
59 changes: 0 additions & 59 deletions vms/platformvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/builder"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

avajson "github.com/ava-labs/avalanchego/utils/json"
Expand All @@ -62,8 +61,6 @@ var (
errPrimaryNetworkIsNotASubnet = errors.New("the primary network isn't a subnet")
errNoAddresses = errors.New("no addresses provided")
errMissingBlockchainID = errors.New("argument 'blockchainID' not given")
errStartAfterEndTime = errors.New("start time must be before end time")
errStartTimeInThePast = errors.New("start time in the past")
)

// Service defines the API calls that can be made to the platform chain
Expand Down Expand Up @@ -1712,62 +1709,6 @@ func (s *Service) GetTotalStake(_ *http.Request, args *GetTotalStakeArgs, reply
return nil
}

// GetMaxStakeAmountArgs is the request for calling GetMaxStakeAmount.
type GetMaxStakeAmountArgs struct {
SubnetID ids.ID `json:"subnetID"`
NodeID ids.NodeID `json:"nodeID"`
StartTime avajson.Uint64 `json:"startTime"`
EndTime avajson.Uint64 `json:"endTime"`
}

// GetMaxStakeAmountReply is the response from calling GetMaxStakeAmount.
type GetMaxStakeAmountReply struct {
Amount avajson.Uint64 `json:"amount"`
}

// GetMaxStakeAmount returns the maximum amount of nAVAX staking to the named
// node during the time period.
func (s *Service) GetMaxStakeAmount(_ *http.Request, args *GetMaxStakeAmountArgs, reply *GetMaxStakeAmountReply) error {
s.vm.ctx.Log.Debug("deprecated API called",
zap.String("service", "platform"),
zap.String("method", "getMaxStakeAmount"),
)

startTime := time.Unix(int64(args.StartTime), 0)
endTime := time.Unix(int64(args.EndTime), 0)

if startTime.After(endTime) {
return errStartAfterEndTime
}

s.vm.ctx.Lock.Lock()
defer s.vm.ctx.Lock.Unlock()

now := s.vm.state.GetTimestamp()
if startTime.Before(now) {
return errStartTimeInThePast
}

staker, err := executor.GetValidator(s.vm.state, args.SubnetID, args.NodeID)
if err == database.ErrNotFound {
return nil
}
if err != nil {
return err
}

if startTime.After(staker.EndTime) {
return nil
}
if endTime.Before(staker.StartTime) {
return nil
}

maxStakeAmount, err := executor.GetMaxWeight(s.vm.state, staker, startTime, endTime)
reply.Amount = avajson.Uint64(maxStakeAmount)
return err
}

// GetRewardUTXOsReply defines the GetRewardUTXOs replies returned from the API
type GetRewardUTXOsReply struct {
// Number of UTXOs returned
Expand Down

0 comments on commit 11372a4

Please sign in to comment.