From 1112de96a00a14511f4362e16f9a4dd56a0e63d2 Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 16 Dec 2024 14:20:23 -0500 Subject: [PATCH 01/10] move fee from info api --- api/info/client.go | 8 +------- api/info/service.go | 33 --------------------------------- vms/avm/client.go | 17 +++++++++++++++++ vms/avm/service.go | 11 +++++++++++ wallet/chain/x/context.go | 2 +- 5 files changed, 30 insertions(+), 41 deletions(-) diff --git a/api/info/client.go b/api/info/client.go index 0e6582534660..2ace089ad553 100644 --- a/api/info/client.go +++ b/api/info/client.go @@ -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) @@ -91,6 +90,7 @@ func (c *client) Peers(ctx context.Context, nodeIDs []ids.NodeID, options ...rpc return res.Peers, err } + func (c *client) IsBootstrapped(ctx context.Context, chainID string, options ...rpc.Option) (bool, error) { res := &IsBootstrappedResponse{} err := c.requester.SendRequest(ctx, "info.isBootstrapped", &IsBootstrappedArgs{ @@ -99,12 +99,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...) diff --git a/api/info/service.go b/api/info/service.go index 383e00bef66d..a4a199d696f2 100644 --- a/api/info/service.go +++ b/api/info/service.go @@ -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" @@ -52,7 +51,6 @@ type Parameters struct { NodeID ids.NodeID NodePOP *signer.ProofOfPossession NetworkID uint32 - TxFeeConfig genesis.TxFeeConfig VMManager vms.Manager Upgrades upgrade.Config } @@ -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"` diff --git a/vms/avm/client.go b/vms/avm/client.go index e2ef96125b75..4b9d1c7235d3 100644 --- a/vms/avm/client.go +++ b/vms/avm/client.go @@ -73,6 +73,11 @@ type Client interface { // // Deprecated: GetUTXOs should be used instead. GetAllBalances(ctx context.Context, addr ids.ShortID, includePartial bool, options ...rpc.Option) ([]Balance, error) + + // Get + GetTxFee(context.Context, ...rpc.Option) (*GetTxFeeResponse, error) + + // CreateAsset creates a new asset and returns its assetID // // Deprecated: Transactions should be issued using the @@ -385,6 +390,18 @@ func (c *client) GetAllBalances( return res.Balances, err } +type GetTxFeeResponse struct { + TxFee uint64 `json:"txFee"` + CreateAssetTxFee uint64 `json:"createAssetTxFee"` +} + +func (c *client) GetTxFee(ctx context.Context, options ...rpc.Option) (*GetTxFeeResponse, error) { + res := &GetTxFeeResponse{} + 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 diff --git a/vms/avm/service.go b/vms/avm/service.go index ec36285c9e67..736766bae13e 100644 --- a/vms/avm/service.go +++ b/vms/avm/service.go @@ -672,6 +672,17 @@ func (s *Service) GetAllBalances(_ *http.Request, args *GetAllBalancesArgs, repl return nil } +func (s *Service) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeResponse) 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"` diff --git a/wallet/chain/x/context.go b/wallet/chain/x/context.go index 7bd4e280a2cf..1395f91377c1 100644 --- a/wallet/chain/x/context.go +++ b/wallet/chain/x/context.go @@ -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 } From 5f434a279fc84f750c2a0f9a9964fa11c06145c2 Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 16 Dec 2024 14:24:23 -0500 Subject: [PATCH 02/10] update markdown --- api/info/client.go | 1 - api/info/service.md | 99 +++++++++------------------------------------ vms/avm/service.md | 41 +++++++++++++++++++ 3 files changed, 59 insertions(+), 82 deletions(-) diff --git a/api/info/client.go b/api/info/client.go index 2ace089ad553..9ba829eb6e59 100644 --- a/api/info/client.go +++ b/api/info/client.go @@ -90,7 +90,6 @@ func (c *client) Peers(ctx context.Context, nodeIDs []ids.NodeID, options ...rpc return res.Peers, err } - func (c *client) IsBootstrapped(ctx context.Context, chainID string, options ...rpc.Option) (bool, error) { res := &IsBootstrappedResponse{} err := c.requester.SendRequest(ctx, "info.isBootstrapped", &IsBootstrappedArgs{ diff --git a/api/info/service.md b/api/info/service.md index 9d1119ecfef5..711ca97c515c 100644 --- a/api/info/service.md +++ b/api/info/service.md @@ -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**: @@ -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. @@ -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 @@ -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 } ``` diff --git a/vms/avm/service.md b/vms/avm/service.md index ac4558794337..3c4464fc15ad 100644 --- a/vms/avm/service.md +++ b/vms/avm/service.md @@ -783,6 +783,47 @@ curl -X POST --data '{ } ``` +### `info.getTxFee` + +Get the fees of the network. + +**Signature**: + +``` +info.getTxFee() -> +{ + 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" + } +} +``` + ### `avm.getAssetDescription` Get information about an asset. From a72dddbaed419d6223cd833a6b57d20cb0197d32 Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 16 Dec 2024 14:33:26 -0500 Subject: [PATCH 03/10] test boilerplate --- vms/avm/client.go | 4 +--- vms/avm/service_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vms/avm/client.go b/vms/avm/client.go index 4b9d1c7235d3..c95f0f052e85 100644 --- a/vms/avm/client.go +++ b/vms/avm/client.go @@ -74,10 +74,9 @@ type Client interface { // Deprecated: GetUTXOs should be used instead. GetAllBalances(ctx context.Context, addr ids.ShortID, includePartial bool, options ...rpc.Option) ([]Balance, error) - // Get + // GetTxFee returns the cost to issue certain transactions GetTxFee(context.Context, ...rpc.Option) (*GetTxFeeResponse, error) - // CreateAsset creates a new asset and returns its assetID // // Deprecated: Transactions should be issued using the @@ -401,7 +400,6 @@ func (c *client) GetTxFee(ctx context.Context, options ...rpc.Option) (*GetTxFee return res, err } - // ClientHolder describes how much an address owns of an asset type ClientHolder struct { Amount uint64 diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index c6e20c6ecb51..aac2fd55b273 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -490,6 +490,12 @@ func TestServiceGetAllBalances(t *testing.T) { require.Empty(reply.Balances) } + +func TestServiceGetTxFee(t *testing.T) { + // TODO: Implement this test +} + + func TestServiceGetTx(t *testing.T) { require := require.New(t) From ffa96fabfdd140a1b7e48a0649b87fb1822dff97 Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 16 Dec 2024 16:41:26 -0500 Subject: [PATCH 04/10] added test case --- node/node.go | 1 - vms/avm/client.go | 8 ++++---- vms/avm/service.go | 2 +- vms/avm/service_test.go | 14 +++++++++++++- wallet/chain/p/context.go | 34 +++++----------------------------- 5 files changed, 23 insertions(+), 36 deletions(-) diff --git a/node/node.go b/node/node.go index 19dfd899654d..b6f05fb343ae 100644 --- a/node/node.go +++ b/node/node.go @@ -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, }, diff --git a/vms/avm/client.go b/vms/avm/client.go index c95f0f052e85..a17ea4185afc 100644 --- a/vms/avm/client.go +++ b/vms/avm/client.go @@ -75,7 +75,7 @@ type Client interface { 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) (*GetTxFeeResponse, error) + GetTxFee(context.Context, ...rpc.Option) (*GetTxFeeReply, error) // CreateAsset creates a new asset and returns its assetID // @@ -389,13 +389,13 @@ func (c *client) GetAllBalances( return res.Balances, err } -type GetTxFeeResponse struct { +type GetTxFeeReply struct { TxFee uint64 `json:"txFee"` CreateAssetTxFee uint64 `json:"createAssetTxFee"` } -func (c *client) GetTxFee(ctx context.Context, options ...rpc.Option) (*GetTxFeeResponse, error) { - res := &GetTxFeeResponse{} +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 } diff --git a/vms/avm/service.go b/vms/avm/service.go index 736766bae13e..4a777f51f614 100644 --- a/vms/avm/service.go +++ b/vms/avm/service.go @@ -672,7 +672,7 @@ func (s *Service) GetAllBalances(_ *http.Request, args *GetAllBalancesArgs, repl return nil } -func (s *Service) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeResponse) error { +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"), diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index aac2fd55b273..83e94ee3e313 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -492,7 +492,19 @@ func TestServiceGetAllBalances(t *testing.T) { func TestServiceGetTxFee(t *testing.T) { - // TODO: Implement this test + 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(uint64(testTxFee), reply.TxFee) + require.Equal(uint64(testTxFee), reply.CreateAssetTxFee) } diff --git a/wallet/chain/p/context.go b/wallet/chain/p/context.go index 73d63c3584a2..e1fcb7826f5f 100644 --- a/wallet/chain/p/context.go +++ b/wallet/chain/p/context.go @@ -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" ) @@ -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{ - 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 } From c6dbb4ccecfd4f8c10953ce471b9bc6d5eac5afe Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 16 Dec 2024 16:58:38 -0500 Subject: [PATCH 05/10] lint --- vms/avm/client.go | 6 +++--- vms/avm/service_test.go | 6 ++---- wallet/chain/x/context.go | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/vms/avm/client.go b/vms/avm/client.go index a17ea4185afc..3990abf427ea 100644 --- a/vms/avm/client.go +++ b/vms/avm/client.go @@ -73,7 +73,7 @@ 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) @@ -390,8 +390,8 @@ func (c *client) GetAllBalances( } type GetTxFeeReply struct { - TxFee uint64 `json:"txFee"` - CreateAssetTxFee uint64 `json:"createAssetTxFee"` + TxFee uint64 `json:"txFee"` + CreateAssetTxFee uint64 `json:"createAssetTxFee"` } func (c *client) GetTxFee(ctx context.Context, options ...rpc.Option) (*GetTxFeeReply, error) { diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 83e94ee3e313..1ad500899e13 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -490,7 +490,6 @@ func TestServiceGetAllBalances(t *testing.T) { require.Empty(reply.Balances) } - func TestServiceGetTxFee(t *testing.T) { require := require.New(t) @@ -503,11 +502,10 @@ func TestServiceGetTxFee(t *testing.T) { reply := GetTxFeeReply{} require.NoError(service.GetTxFee(nil, nil, &reply)) - require.Equal(uint64(testTxFee), reply.TxFee) - require.Equal(uint64(testTxFee), reply.CreateAssetTxFee) + require.Equal(testTxFee, reply.TxFee) + require.Equal(testTxFee, reply.CreateAssetTxFee) } - func TestServiceGetTx(t *testing.T) { require := require.New(t) diff --git a/wallet/chain/x/context.go b/wallet/chain/x/context.go index 1395f91377c1..e6c15f9fc0c7 100644 --- a/wallet/chain/x/context.go +++ b/wallet/chain/x/context.go @@ -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 } From a5db622b8c4c2abb1f8db873be77a64b0cc397ad Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 16 Dec 2024 17:05:28 -0500 Subject: [PATCH 06/10] go fmt --- api/info/service.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/api/info/service.go b/api/info/service.go index a4a199d696f2..ff08d20431d2 100644 --- a/api/info/service.go +++ b/api/info/service.go @@ -47,12 +47,12 @@ type Info struct { } type Parameters struct { - Version *version.Application - NodeID ids.NodeID - NodePOP *signer.ProofOfPossession - NetworkID uint32 - 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( From c40d6548771a4117cc854ad0af207a76b8c3eacf Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 16 Dec 2024 18:14:20 -0500 Subject: [PATCH 07/10] use avajson --- vms/avm/client.go | 5 ----- vms/avm/service.go | 9 +++++++-- vms/avm/service_test.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vms/avm/client.go b/vms/avm/client.go index 3990abf427ea..da1052d6bded 100644 --- a/vms/avm/client.go +++ b/vms/avm/client.go @@ -389,11 +389,6 @@ func (c *client) GetAllBalances( return res.Balances, err } -type GetTxFeeReply struct { - TxFee uint64 `json:"txFee"` - CreateAssetTxFee uint64 `json:"createAssetTxFee"` -} - func (c *client) GetTxFee(ctx context.Context, options ...rpc.Option) (*GetTxFeeReply, error) { res := &GetTxFeeReply{} err := c.requester.SendRequest(ctx, "avm.getTxFee", struct{}{}, res, options...) diff --git a/vms/avm/service.go b/vms/avm/service.go index 4a777f51f614..28c2b848d560 100644 --- a/vms/avm/service.go +++ b/vms/avm/service.go @@ -672,14 +672,19 @@ 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 = s.vm.TxFee - reply.CreateAssetTxFee = s.vm.CreateAssetTxFee + reply.TxFee = avajson.Uint64(s.vm.TxFee) + reply.CreateAssetTxFee = avajson.Uint64(s.vm.CreateAssetTxFee) return nil } diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 1ad500899e13..c7a056dd1dd1 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -502,8 +502,8 @@ func TestServiceGetTxFee(t *testing.T) { reply := GetTxFeeReply{} require.NoError(service.GetTxFee(nil, nil, &reply)) - require.Equal(testTxFee, reply.TxFee) - require.Equal(testTxFee, reply.CreateAssetTxFee) + require.Equal(avajson.Uint64(testTxFee), reply.TxFee) + require.Equal(avajson.Uint64(testTxFee), reply.CreateAssetTxFee) } func TestServiceGetTx(t *testing.T) { From 90610f81648ff779e656aa91776c564268d9e1ca Mon Sep 17 00:00:00 2001 From: samliok Date: Tue, 17 Dec 2024 10:38:07 -0500 Subject: [PATCH 08/10] go fmt --- node/node.go | 12 ++++++------ vms/platformvm/block/executor/manager.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/node/node.go b/node/node.go index b6f05fb343ae..ba66b4e05270 100644 --- a/node/node.go +++ b/node/node.go @@ -1403,12 +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, - 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, diff --git a/vms/platformvm/block/executor/manager.go b/vms/platformvm/block/executor/manager.go index 48330dd74788..33b29354a59e 100644 --- a/vms/platformvm/block/executor/manager.go +++ b/vms/platformvm/block/executor/manager.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" + "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee" "github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool" "github.com/ava-labs/avalanchego/vms/platformvm/validators" ) @@ -168,6 +169,24 @@ func (m *manager) VerifyTx(tx *txs.Tx) error { return fmt.Errorf("failed to advance the chain time: %w", err) } + if timestamp := stateDiff.GetTimestamp(); m.txExecutorBackend.Config.UpgradeConfig.IsEtnaActivated(timestamp) { + complexity, err := fee.TxComplexity(tx.Unsigned) + if err != nil { + return fmt.Errorf("failed to calculate tx complexity: %w", err) + } + gas, err := complexity.ToGas(m.txExecutorBackend.Config.DynamicFeeConfig.Weights) + if err != nil { + return fmt.Errorf("failed to calculate tx gas: %w", err) + } + + // TODO: After the mempool is updated, convert this check to use the + // maximum mempool capacity. + feeState := stateDiff.GetFeeState() + if gas > feeState.Capacity { + return fmt.Errorf("tx exceeds current gas capacity: %d > %d", gas, feeState.Capacity) + } + } + feeCalculator := state.PickFeeCalculator(m.txExecutorBackend.Config, stateDiff) _, _, _, err = executor.StandardTx( m.txExecutorBackend, From e6bdf72220002476176f1824f42d0f3dabab1c12 Mon Sep 17 00:00:00 2001 From: samliok Date: Tue, 17 Dec 2024 10:43:05 -0500 Subject: [PATCH 09/10] forgot type converstion --- wallet/chain/x/context.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wallet/chain/x/context.go b/wallet/chain/x/context.go index e6c15f9fc0c7..1395f91377c1 100644 --- a/wallet/chain/x/context.go +++ b/wallet/chain/x/context.go @@ -46,7 +46,7 @@ func NewContextFromClients( NetworkID: networkID, BlockchainID: chainID, AVAXAssetID: asset.AssetID, - BaseTxFee: txFees.TxFee, - CreateAssetTxFee: txFees.CreateAssetTxFee, + BaseTxFee: uint64(txFees.TxFee), + CreateAssetTxFee: uint64(txFees.CreateAssetTxFee), }, nil } From f5e2dca58712379811e2f81efea43863a91bdc8f Mon Sep 17 00:00:00 2001 From: samliok Date: Tue, 17 Dec 2024 14:26:22 -0500 Subject: [PATCH 10/10] markdown fix --- vms/avm/service.md | 82 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/vms/avm/service.md b/vms/avm/service.md index 3c4464fc15ad..0c0178dc0b41 100644 --- a/vms/avm/service.md +++ b/vms/avm/service.md @@ -783,47 +783,6 @@ curl -X POST --data '{ } ``` -### `info.getTxFee` - -Get the fees of the network. - -**Signature**: - -``` -info.getTxFee() -> -{ - 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" - } -} -``` - ### `avm.getAssetDescription` Get information about an asset. @@ -1218,6 +1177,47 @@ Most outputs use the secp256k1 FX, look like this: The above output can be consumed after Unix time `locktime` by a transaction that has signatures from `threshold` of the addresses in `addresses`. +### `avm.getTxFee` + +Get the fees of the network. + +**Signature**: + +``` +avm.getTxFee() -> +{ + 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" + } +} +``` + ### `avm.getTxStatus` :::caution