Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add L1 validator fees API #3647

Merged
merged 9 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,15 @@ This version is backwards compatible to [v1.12.0](https://github.com/ava-labs/av

The plugin version is unchanged at `38` and is compatible with versions `v1.12.0-v1.12.1`.

### APIs

- Removed:
- `info.GetTxFee`
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this affected by the rollback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - that is unrelated to this PR

- Added:
- `avm.GetTxFee`
- `platform.getValidatorFeeConfig`
- `platform.getValidatorFeeState`

### Configs

- Removed static fee config flags
@@ -16,11 +25,6 @@ The plugin version is unchanged at `38` and is compatible with versions `v1.12.0
- `--add-primary-network-delegator-fee`
- `--add-subnet-validator-fee`
- `--add-subnet-delegator-fee`

### APIs

- Removed `info.GetTxFee`
- Added `avm.GetTxFee`

### What's Changed

42 changes: 40 additions & 2 deletions vms/platformvm/client.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanchego/vms/components/gas"
"github.com/ava-labs/avalanchego/vms/platformvm/fx"
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/validators/fee"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

platformapi "github.com/ava-labs/avalanchego/vms/platformvm/api"
@@ -136,7 +137,22 @@ type Client interface {
// GetFeeConfig returns the dynamic fee config of the chain.
GetFeeConfig(ctx context.Context, options ...rpc.Option) (*gas.Config, error)
// GetFeeState returns the current fee state of the chain.
GetFeeState(ctx context.Context, options ...rpc.Option) (gas.State, gas.Price, time.Time, error)
GetFeeState(ctx context.Context, options ...rpc.Option) (
gas.State,
gas.Price,
time.Time,
error,
)
// GetValidatorFeeConfig returns the validator fee config of the chain.
GetValidatorFeeConfig(ctx context.Context, options ...rpc.Option) (*fee.Config, error)
// GetValidatorFeeState returns the current validator fee state of the
// chain.
GetValidatorFeeState(ctx context.Context, options ...rpc.Option) (
gas.Gas,
gas.Price,
time.Time,
error,
)
}

// Client implementation for interacting with the P Chain endpoint
@@ -615,12 +631,34 @@ func (c *client) GetFeeConfig(ctx context.Context, options ...rpc.Option) (*gas.
return res, err
}

func (c *client) GetFeeState(ctx context.Context, options ...rpc.Option) (gas.State, gas.Price, time.Time, error) {
func (c *client) GetFeeState(ctx context.Context, options ...rpc.Option) (
gas.State,
gas.Price,
time.Time,
error,
) {
res := &GetFeeStateReply{}
err := c.requester.SendRequest(ctx, "platform.getFeeState", struct{}{}, res, options...)
return res.State, res.Price, res.Time, err
}

func (c *client) GetValidatorFeeConfig(ctx context.Context, options ...rpc.Option) (*fee.Config, error) {
res := &fee.Config{}
err := c.requester.SendRequest(ctx, "platform.getValidatorFeeConfig", struct{}{}, res, options...)
return res, err
}

func (c *client) GetValidatorFeeState(ctx context.Context, options ...rpc.Option) (
gas.Gas,
gas.Price,
time.Time,
error,
) {
res := &GetValidatorFeeStateReply{}
err := c.requester.SendRequest(ctx, "platform.getValidatorFeeState", struct{}{}, res, options...)
return res.Excess, res.Price, res.Time, err
}

func AwaitTxAccepted(
c Client,
ctx context.Context,
44 changes: 38 additions & 6 deletions vms/platformvm/service.go
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/state"
"github.com/ava-labs/avalanchego/vms/platformvm/status"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/validators/fee"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/vms/types"
@@ -1972,12 +1973,6 @@ func (s *Service) GetFeeConfig(_ *http.Request, _ *struct{}, reply *gas.Config)
zap.String("method", "getFeeConfig"),
)

// TODO: Remove after Etna is activated.
now := time.Now()
if !s.vm.Internal.UpgradeConfig.IsEtnaActivated(now) {
return nil
}

*reply = s.vm.DynamicFeeConfig
return nil
}
@@ -2008,6 +2003,43 @@ func (s *Service) GetFeeState(_ *http.Request, _ *struct{}, reply *GetFeeStateRe
return nil
}

// GetValidatorFeeConfig returns the validator fee config of the chain.
func (s *Service) GetValidatorFeeConfig(_ *http.Request, _ *struct{}, reply *fee.Config) error {
s.vm.ctx.Log.Debug("API called",
zap.String("service", "platform"),
zap.String("method", "getValidatorFeeConfig"),
)

*reply = s.vm.ValidatorFeeConfig
return nil
}

type GetValidatorFeeStateReply struct {
Excess gas.Gas `json:"excess"`
Price gas.Price `json:"price"`
Time time.Time `json:"timestamp"`
}

// GetValidatorFeeState returns the current validator fee state of the chain.
func (s *Service) GetValidatorFeeState(_ *http.Request, _ *struct{}, reply *GetValidatorFeeStateReply) error {
s.vm.ctx.Log.Debug("API called",
zap.String("service", "platform"),
zap.String("method", "getValidatorFeeState"),
)

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

reply.Excess = s.vm.state.GetL1ValidatorExcess()
reply.Price = gas.CalculatePrice(
s.vm.ValidatorFeeConfig.MinPrice,
reply.Excess,
s.vm.ValidatorFeeConfig.ExcessConversionConstant,
)
reply.Time = s.vm.state.GetTimestamp()
return nil
}

func (s *Service) getAPIOwner(owner *secp256k1fx.OutputOwners) (*platformapi.Owner, error) {
apiOwner := &platformapi.Owner{
Locktime: avajson.Uint64(owner.Locktime),
Loading