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

GetTXFee API Refactor #3598

Closed
wants to merge 13 commits into from
7 changes: 0 additions & 7 deletions api/info/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type Client interface {
GetBlockchainID(context.Context, string, ...rpc.Option) (ids.ID, error)
Peers(context.Context, []ids.NodeID, ...rpc.Option) ([]Peer, error)
IsBootstrapped(context.Context, string, ...rpc.Option) (bool, error)
GetTxFee(context.Context, ...rpc.Option) (*GetTxFeeResponse, error)
Upgrades(context.Context, ...rpc.Option) (*upgrade.Config, error)
Uptime(context.Context, ...rpc.Option) (*UptimeResponse, error)
GetVMs(context.Context, ...rpc.Option) (map[ids.ID][]string, error)
Expand Down Expand Up @@ -99,12 +98,6 @@ func (c *client) IsBootstrapped(ctx context.Context, chainID string, options ...
return res.IsBootstrapped, err
}

func (c *client) GetTxFee(ctx context.Context, options ...rpc.Option) (*GetTxFeeResponse, error) {
res := &GetTxFeeResponse{}
err := c.requester.SendRequest(ctx, "info.getTxFee", struct{}{}, res, options...)
return res, err
}

func (c *client) Upgrades(ctx context.Context, options ...rpc.Option) (*upgrade.Config, error) {
res := &upgrade.Config{}
err := c.requester.SendRequest(ctx, "info.upgrades", struct{}{}, res, options...)
Expand Down
45 changes: 6 additions & 39 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/chains"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network"
"github.com/ava-labs/avalanchego/network/peer"
Expand Down Expand Up @@ -48,13 +47,12 @@ type Info struct {
}

type Parameters struct {
Version *version.Application
NodeID ids.NodeID
NodePOP *signer.ProofOfPossession
NetworkID uint32
TxFeeConfig genesis.TxFeeConfig
VMManager vms.Manager
Upgrades upgrade.Config
Version *version.Application
NodeID ids.NodeID
NodePOP *signer.ProofOfPossession
NetworkID uint32
VMManager vms.Manager
Upgrades upgrade.Config
}

func NewService(
Expand Down Expand Up @@ -386,37 +384,6 @@ func (i *Info) Acps(_ *http.Request, _ *struct{}, reply *ACPsReply) error {
return nil
}

type GetTxFeeResponse struct {
TxFee json.Uint64 `json:"txFee"`
CreateAssetTxFee json.Uint64 `json:"createAssetTxFee"`
CreateSubnetTxFee json.Uint64 `json:"createSubnetTxFee"`
TransformSubnetTxFee json.Uint64 `json:"transformSubnetTxFee"`
CreateBlockchainTxFee json.Uint64 `json:"createBlockchainTxFee"`
AddPrimaryNetworkValidatorFee json.Uint64 `json:"addPrimaryNetworkValidatorFee"`
AddPrimaryNetworkDelegatorFee json.Uint64 `json:"addPrimaryNetworkDelegatorFee"`
AddSubnetValidatorFee json.Uint64 `json:"addSubnetValidatorFee"`
AddSubnetDelegatorFee json.Uint64 `json:"addSubnetDelegatorFee"`
}

// GetTxFee returns the transaction fee in nAVAX.
func (i *Info) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeResponse) error {
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getTxFee"),
)

reply.TxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.TxFee)
reply.CreateAssetTxFee = json.Uint64(i.TxFeeConfig.CreateAssetTxFee)
reply.CreateSubnetTxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.CreateSubnetTxFee)
reply.TransformSubnetTxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.TransformSubnetTxFee)
reply.CreateBlockchainTxFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.CreateBlockchainTxFee)
reply.AddPrimaryNetworkValidatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddPrimaryNetworkValidatorFee)
reply.AddPrimaryNetworkDelegatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddPrimaryNetworkDelegatorFee)
reply.AddSubnetValidatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee)
reply.AddSubnetDelegatorFee = json.Uint64(i.TxFeeConfig.StaticFeeConfig.AddSubnetDelegatorFee)
return nil
}

// GetVMsReply contains the response metadata for GetVMs
type GetVMsReply struct {
VMs map[ids.ID][]string `json:"vms"`
Expand Down
63 changes: 0 additions & 63 deletions api/info/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,69 +382,6 @@ curl -X POST --data '{
}
```

### `info.getTxFee`

Get the fees of the network.

**Signature**:

```
info.getTxFee() ->
{
txFee: uint64,
createAssetTxFee: uint64,
createSubnetTxFee: uint64,
transformSubnetTxFee: uint64,
createBlockchainTxFee: uint64,
addPrimaryNetworkValidatorFee: uint64,
addPrimaryNetworkDelegatorFee: uint64,
addSubnetValidatorFee: uint64,
addSubnetDelegatorFee: uint64
}
```

- `txFee` is the default fee for making transactions.
- `createAssetTxFee` is the fee for creating a new asset.
- `createSubnetTxFee` is the fee for creating a new Avalanche L1.
- `transformSubnetTxFee` is the fee for converting a PoA Avalanche L1 into a PoS Avalanche L1.
- `createBlockchainTxFee` is the fee for creating a new blockchain.
- `addPrimaryNetworkValidatorFee` is the fee for adding a new primary network validator.
- `addPrimaryNetworkDelegatorFee` is the fee for adding a new primary network delegator.
- `addSubnetValidatorFee` is the fee for adding a new Avalanche L1 validator.
- `addSubnetDelegatorFee` is the fee for adding a new Avalanche L1 delegator.

All fees are denominated in nAVAX.

**Example Call**:

```sh
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"info.getTxFee"
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info
```

**Example Response**:

```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"txFee": "1000000",
"createAssetTxFee": "10000000",
"createSubnetTxFee": "1000000000",
"transformSubnetTxFee": "10000000000",
"createBlockchainTxFee": "1000000000",
"addPrimaryNetworkValidatorFee": "0",
"addPrimaryNetworkDelegatorFee": "0",
"addSubnetValidatorFee": "1000000",
"addSubnetDelegatorFee": "1000000"
}
}
```

### `info.getVMs`

Get the virtual machines installed on this node.
Expand Down
13 changes: 6 additions & 7 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,13 +1403,12 @@ func (n *Node) initInfoAPI() error {

service, err := info.NewService(
info.Parameters{
Version: version.CurrentApp,
NodeID: n.ID,
NodePOP: signer.NewProofOfPossession(n.Config.StakingSigningKey),
NetworkID: n.Config.NetworkID,
TxFeeConfig: n.Config.TxFeeConfig,
VMManager: n.VMManager,
Upgrades: n.Config.UpgradeConfig,
Version: version.CurrentApp,
NodeID: n.ID,
NodePOP: signer.NewProofOfPossession(n.Config.StakingSigningKey),
NetworkID: n.Config.NetworkID,
VMManager: n.VMManager,
Upgrades: n.Config.UpgradeConfig,
},
n.Log,
n.vdrs,
Expand Down
10 changes: 10 additions & 0 deletions vms/avm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ type Client interface {
//
// Deprecated: GetUTXOs should be used instead.
GetAllBalances(ctx context.Context, addr ids.ShortID, includePartial bool, options ...rpc.Option) ([]Balance, error)

// GetTxFee returns the cost to issue certain transactions
GetTxFee(context.Context, ...rpc.Option) (*GetTxFeeReply, error)

// CreateAsset creates a new asset and returns its assetID
//
// Deprecated: Transactions should be issued using the
Expand Down Expand Up @@ -385,6 +389,12 @@ func (c *client) GetAllBalances(
return res.Balances, err
}

func (c *client) GetTxFee(ctx context.Context, options ...rpc.Option) (*GetTxFeeReply, error) {
res := &GetTxFeeReply{}
err := c.requester.SendRequest(ctx, "avm.getTxFee", struct{}{}, res, options...)
return res, err
}

// ClientHolder describes how much an address owns of an asset
type ClientHolder struct {
Amount uint64
Expand Down
16 changes: 16 additions & 0 deletions vms/avm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,22 @@ func (s *Service) GetAllBalances(_ *http.Request, args *GetAllBalancesArgs, repl
return nil
}

type GetTxFeeReply struct {
TxFee avajson.Uint64 `json:"txFee"`
CreateAssetTxFee avajson.Uint64 `json:"createAssetTxFee"`
}

func (s *Service) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeReply) error {
s.vm.ctx.Log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getTxFee"),
)

reply.TxFee = avajson.Uint64(s.vm.TxFee)
reply.CreateAssetTxFee = avajson.Uint64(s.vm.CreateAssetTxFee)
return nil
}

// Holder describes how much an address owns of an asset
type Holder struct {
Amount avajson.Uint64 `json:"amount"`
Expand Down
41 changes: 41 additions & 0 deletions vms/avm/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,47 @@ curl -X POST --data '{
}
```

### `info.getTxFee`
samliok marked this conversation as resolved.
Show resolved Hide resolved
samliok marked this conversation as resolved.
Show resolved Hide resolved

Get the fees of the network.

**Signature**:

```
info.getTxFee() ->
samliok marked this conversation as resolved.
Show resolved Hide resolved
{
txFee: uint64,
createAssetTxFee: uint64,
}
```

- `txFee` is the default fee for making transactions.
- `createAssetTxFee` is the fee for creating a new asset.

All fees are denominated in nAVAX.

**Example Call**:

```sh
curl -X POST --data '{
"jsonrpc":"2.0",
"id" : 1,
"method" :"avm.getTxFee",
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X
```

**Example Response**:

```json
{
"jsonrpc": "2.0",
"result": {
"txFee": "1000000",
"createAssetTxFee": "10000000"
samliok marked this conversation as resolved.
Show resolved Hide resolved
}
}
```

### `avm.getAssetDescription`

Get information about an asset.
Expand Down
16 changes: 16 additions & 0 deletions vms/avm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,22 @@ func TestServiceGetAllBalances(t *testing.T) {
require.Empty(reply.Balances)
}

func TestServiceGetTxFee(t *testing.T) {
require := require.New(t)

env := setup(t, &envConfig{
fork: upgradetest.Latest,
})
service := &Service{vm: env.vm}
env.vm.ctx.Lock.Unlock()

reply := GetTxFeeReply{}
require.NoError(service.GetTxFee(nil, nil, &reply))

require.Equal(avajson.Uint64(testTxFee), reply.TxFee)
require.Equal(avajson.Uint64(testTxFee), reply.CreateAssetTxFee)
}

func TestServiceGetTx(t *testing.T) {
require := require.New(t)

Expand Down
34 changes: 5 additions & 29 deletions wallet/chain/p/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/wallet/chain/p/builder"
)

Expand Down Expand Up @@ -45,38 +44,15 @@ func NewContextFromClients(
return nil, err
}

// TODO: After Etna is activated, assume the gas price is always non-zero.
if dynamicFeeConfig.MinPrice != 0 {
_, gasPrice, _, err := chainClient.GetFeeState(ctx)
if err != nil {
return nil, err
}

return &builder.Context{
NetworkID: networkID,
AVAXAssetID: avaxAssetID,
ComplexityWeights: dynamicFeeConfig.Weights,
GasPrice: gasPriceMultiplier * gasPrice,
}, nil
}

staticFeeConfig, err := infoClient.GetTxFee(ctx)
_, gasPrice, _, err := chainClient.GetFeeState(ctx)
if err != nil {
return nil, err
}

return &builder.Context{
NetworkID: networkID,
AVAXAssetID: avaxAssetID,
StaticFeeConfig: fee.StaticConfig{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove StaticFeeConfig entirely? Perhaps we should add a TODO to the context to remove that field (as I don't think we need it anymore).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created this, will tackle in another pr
#3601

TxFee: uint64(staticFeeConfig.TxFee),
CreateSubnetTxFee: uint64(staticFeeConfig.CreateSubnetTxFee),
TransformSubnetTxFee: uint64(staticFeeConfig.TransformSubnetTxFee),
CreateBlockchainTxFee: uint64(staticFeeConfig.CreateBlockchainTxFee),
AddPrimaryNetworkValidatorFee: uint64(staticFeeConfig.AddPrimaryNetworkValidatorFee),
AddPrimaryNetworkDelegatorFee: uint64(staticFeeConfig.AddPrimaryNetworkDelegatorFee),
AddSubnetValidatorFee: uint64(staticFeeConfig.AddSubnetValidatorFee),
AddSubnetDelegatorFee: uint64(staticFeeConfig.AddSubnetDelegatorFee),
},
NetworkID: networkID,
AVAXAssetID: avaxAssetID,
ComplexityWeights: dynamicFeeConfig.Weights,
GasPrice: gasPriceMultiplier * gasPrice,
}, nil
}
2 changes: 1 addition & 1 deletion wallet/chain/x/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewContextFromClients(
return nil, err
}

txFees, err := infoClient.GetTxFee(ctx)
txFees, err := xChainClient.GetTxFee(ctx)
if err != nil {
return nil, err
}
Expand Down
Loading