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
33 changes: 0 additions & 33 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 @@ -52,7 +51,6 @@ type Parameters struct {
NodeID ids.NodeID
NodePOP *signer.ProofOfPossession
NetworkID uint32
TxFeeConfig genesis.TxFeeConfig
VMManager vms.Manager
Upgrades upgrade.Config
}
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
99 changes: 18 additions & 81 deletions api/info/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ info.getNodeID() -> {

- `nodeID` Node ID is the unique identifier of the node that you set to act as a validator on the Primary Network.
- `nodePOP` is this node's BLS key and proof of possession. Nodes must register a BLS key to act as a validator on the Primary Network. Your node's POP is logged on startup and is accessible over this endpoint.
- `publicKey` is the 48 byte hex representation of the BLS key.
- `proofOfPossession` is the 96 byte hex representation of the BLS signature.
- `publicKey` is the 48 byte hex representation of the BLS key.
- `proofOfPossession` is the 96 byte hex representation of the BLS signature.

**Example Call**:

Expand Down 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 Expand Up @@ -607,7 +544,7 @@ info.uptime() ->

- `rewardingStakePercentage` is the percent of stake which thinks this node is above the uptime requirement.
- `weightedAveragePercentage` is the stake-weighted average of all observed uptimes for this node.

**Example Call**:

```sh
Expand Down Expand Up @@ -677,21 +614,21 @@ curl -X POST --data '{
{
"jsonrpc": "2.0",
"result": {
"apricotPhase1Time": "2020-12-05T05:00:00Z",
"apricotPhase2Time": "2020-12-05T05:00:00Z",
"apricotPhase3Time": "2020-12-05T05:00:00Z",
"apricotPhase4Time": "2020-12-05T05:00:00Z",
"apricotPhase4MinPChainHeight": 0,
"apricotPhase5Time": "2020-12-05T05:00:00Z",
"apricotPhasePre6Time": "2020-12-05T05:00:00Z",
"apricotPhase6Time": "2020-12-05T05:00:00Z",
"apricotPhasePost6Time": "2020-12-05T05:00:00Z",
"banffTime": "2020-12-05T05:00:00Z",
"cortinaTime": "2020-12-05T05:00:00Z",
"cortinaXChainStopVertexID": "11111111111111111111111111111111LpoYY",
"durangoTime": "2020-12-05T05:00:00Z",
"etnaTime": "2024-10-09T20:00:00Z"
},
"apricotPhase1Time": "2020-12-05T05:00:00Z",
"apricotPhase2Time": "2020-12-05T05:00:00Z",
"apricotPhase3Time": "2020-12-05T05:00:00Z",
"apricotPhase4Time": "2020-12-05T05:00:00Z",
"apricotPhase4MinPChainHeight": 0,
"apricotPhase5Time": "2020-12-05T05:00:00Z",
"apricotPhasePre6Time": "2020-12-05T05:00:00Z",
"apricotPhase6Time": "2020-12-05T05:00:00Z",
"apricotPhasePost6Time": "2020-12-05T05:00:00Z",
"banffTime": "2020-12-05T05:00:00Z",
"cortinaTime": "2020-12-05T05:00:00Z",
"cortinaXChainStopVertexID": "11111111111111111111111111111111LpoYY",
"durangoTime": "2020-12-05T05:00:00Z",
"etnaTime": "2024-10-09T20:00:00Z"
},
"id": 1
}
```
1 change: 0 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,6 @@ func (n *Node) initInfoAPI() error {
NodeID: n.ID,
NodePOP: signer.NewProofOfPossession(n.Config.StakingSigningKey),
NetworkID: n.Config.NetworkID,
TxFeeConfig: n.Config.TxFeeConfig,
VMManager: n.VMManager,
Upgrades: n.Config.UpgradeConfig,
},
Expand Down
15 changes: 15 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,17 @@ func (c *client) GetAllBalances(
return res.Balances, err
}

type GetTxFeeReply struct {
TxFee uint64 `json:"txFee"`
CreateAssetTxFee uint64 `json:"createAssetTxFee"`
}
samliok marked this conversation as resolved.
Show resolved Hide resolved

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
11 changes: 11 additions & 0 deletions vms/avm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,17 @@ func (s *Service) GetAllBalances(_ *http.Request, args *GetAllBalancesArgs, repl
return nil
}

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 = s.vm.TxFee
reply.CreateAssetTxFee = 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(testTxFee, reply.TxFee)
require.Equal(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
}
6 changes: 3 additions & 3 deletions 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 All @@ -46,7 +46,7 @@ func NewContextFromClients(
NetworkID: networkID,
BlockchainID: chainID,
AVAXAssetID: asset.AssetID,
BaseTxFee: uint64(txFees.TxFee),
CreateAssetTxFee: uint64(txFees.CreateAssetTxFee),
BaseTxFee: txFees.TxFee,
CreateAssetTxFee: txFees.CreateAssetTxFee,
}, nil
}
Loading