Skip to content

Commit 7b9efbe

Browse files
authored
Merge pull request #2180 from onflow/cf/compute-limit-change
Change gas limit to compute limit
2 parents be55887 + 1469e85 commit 7b9efbe

4 files changed

Lines changed: 55 additions & 28 deletions

File tree

internal/super/flix.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ type flixFlags struct {
5050
Authorizers []string `default:"" flag:"authorizer" info:"Name of a single or multiple comma-separated accounts used as authorizers from configuration"`
5151
Include []string `default:"" flag:"include" info:"Fields to include in the output"`
5252
Exclude []string `default:"" flag:"exclude" info:"Fields to exclude from the output (events)"`
53-
GasLimit uint64 `default:"1000" flag:"gas-limit" info:"transaction gas limit"`
53+
ComputeLimit uint64 `default:"1000" flag:"compute-limit" info:"transaction compute limit"`
54+
GasLimit uint64 `default:"" flag:"gas-limit" info:"(deprecated: use compute-limit) transaction gas limit"`
5455
PreFill string `default:"" flag:"pre-fill" info:"template path to pre fill the FLIX"`
5556
Lang string `default:"js" flag:"lang" info:"language to generate the template for"`
5657
ExcludeNetworks []string `default:"" flag:"exclude-networks" info:"Specify which networks to exclude when generating a FLIX template"`
@@ -149,18 +150,28 @@ func executeFlixCmd(
149150
return scripts.SendScript([]byte(cadenceWithImportsReplaced.Cadence), args[1:], "", flow, scriptsFlags)
150151
}
151152

153+
// Use GasLimit if set (for backwards compatibility), otherwise use ComputeLimit
154+
computeLimit := flags.ComputeLimit
155+
gasLimit := uint64(0)
156+
if flags.GasLimit > 0 {
157+
logger.Info("⚠️ Warning: --gas-limit flag is deprecated, please use --compute-limit instead")
158+
computeLimit = flags.GasLimit
159+
gasLimit = flags.GasLimit
160+
}
161+
152162
transactionFlags := transactions.Flags{
153-
ArgsJSON: flags.ArgsJSON,
154-
Signer: flags.Signer,
155-
Proposer: flags.Proposer,
156-
Payer: flags.Payer,
157-
Authorizers: flags.Authorizers,
158-
Include: flags.Include,
159-
Exclude: flags.Exclude,
160-
GasLimit: flags.GasLimit,
163+
ArgsJSON: flags.ArgsJSON,
164+
Signer: flags.Signer,
165+
Proposer: flags.Proposer,
166+
Payer: flags.Payer,
167+
Authorizers: flags.Authorizers,
168+
Include: flags.Include,
169+
Exclude: flags.Exclude,
170+
ComputeLimit: computeLimit,
171+
GasLimit: gasLimit,
161172
}
162173
// some reason sendTransaction clips the first argument
163-
return transactions.SendTransaction([]byte(cadenceWithImportsReplaced.Cadence), args, "", flow, state, transactionFlags)
174+
return transactions.SendTransaction([]byte(cadenceWithImportsReplaced.Cadence), args, "", flow, state, transactionFlags, logger)
164175
}
165176

166177
func packageCmd(

internal/transactions/build.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ type flagsBuild struct {
4242
ProposerKeyIndex uint32 `default:"0" flag:"proposer-key-index" info:"proposer key index"`
4343
Payer string `default:"emulator-account" flag:"payer" info:"transaction payer"`
4444
Authorizer []string `default:"emulator-account" flag:"authorizer" info:"transaction authorizer"`
45-
GasLimit uint64 `default:"1000" flag:"gas-limit" info:"transaction gas limit"`
45+
ComputeLimit uint64 `default:"1000" flag:"compute-limit" info:"transaction compute limit"`
46+
GasLimit uint64 `default:"" flag:"gas-limit" info:"(deprecated: use compute-limit) transaction gas limit"`
4647
}
4748

4849
var buildFlags = flagsBuild{}
@@ -61,7 +62,7 @@ var buildCommand = &command.Command{
6162
func build(
6263
args []string,
6364
globalFlags command.GlobalFlags,
64-
_ output.Logger,
65+
logger output.Logger,
6566
flow flowkit.Services,
6667
state *flowkit.State,
6768
) (command.Result, error) {
@@ -101,6 +102,13 @@ func build(
101102
return nil, fmt.Errorf("error parsing transaction arguments: %w", err)
102103
}
103104

105+
// Use GasLimit if set (for backwards compatibility), otherwise use ComputeLimit
106+
computeLimit := buildFlags.ComputeLimit
107+
if buildFlags.GasLimit > 0 {
108+
logger.Info("⚠️ Warning: --gas-limit flag is deprecated, please use --compute-limit instead")
109+
computeLimit = buildFlags.GasLimit
110+
}
111+
104112
tx, err := flow.BuildTransaction(
105113
context.Background(),
106114
transactions.AddressesRoles{
@@ -114,7 +122,7 @@ func build(
114122
Args: transactionArgs,
115123
Location: filename,
116124
},
117-
buildFlags.GasLimit,
125+
computeLimit,
118126
)
119127
if err != nil {
120128
return nil, err

internal/transactions/send.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ import (
3535
)
3636

3737
type Flags struct {
38-
ArgsJSON string `default:"" flag:"args-json" info:"arguments in JSON-Cadence format"`
39-
Signer string `default:"" flag:"signer" info:"Account name from configuration used to sign the transaction as proposer, payer and suthorizer"`
40-
Proposer string `default:"" flag:"proposer" info:"Account name from configuration used as proposer"`
41-
Payer string `default:"" flag:"payer" info:"Account name from configuration used as payer"`
42-
Authorizers []string `default:"" flag:"authorizer" info:"Name of a single or multiple comma-separated accounts used as authorizers from configuration"`
43-
Include []string `default:"" flag:"include" info:"Fields to include in the output"`
44-
Exclude []string `default:"" flag:"exclude" info:"Fields to exclude from the output (events)"`
45-
GasLimit uint64 `default:"1000" flag:"gas-limit" info:"transaction gas limit"`
38+
ArgsJSON string `default:"" flag:"args-json" info:"arguments in JSON-Cadence format"`
39+
Signer string `default:"" flag:"signer" info:"Account name from configuration used to sign the transaction as proposer, payer and suthorizer"`
40+
Proposer string `default:"" flag:"proposer" info:"Account name from configuration used as proposer"`
41+
Payer string `default:"" flag:"payer" info:"Account name from configuration used as payer"`
42+
Authorizers []string `default:"" flag:"authorizer" info:"Name of a single or multiple comma-separated accounts used as authorizers from configuration"`
43+
Include []string `default:"" flag:"include" info:"Fields to include in the output"`
44+
Exclude []string `default:"" flag:"exclude" info:"Fields to exclude from the output (events)"`
45+
ComputeLimit uint64 `default:"1000" flag:"compute-limit" info:"transaction compute limit"`
46+
GasLimit uint64 `default:"" flag:"gas-limit" info:"(deprecated: use compute-limit) transaction gas limit"`
4647
}
4748

4849
var flags = Flags{}
@@ -61,7 +62,7 @@ var sendCommand = &command.Command{
6162
func send(
6263
args []string,
6364
_ command.GlobalFlags,
64-
_ output.Logger,
65+
logger output.Logger,
6566
flow flowkit.Services,
6667
state *flowkit.State,
6768
) (result command.Result, err error) {
@@ -72,10 +73,10 @@ func send(
7273
return nil, fmt.Errorf("error loading transaction file: %w", err)
7374
}
7475

75-
return SendTransaction(code, args, filename, flow, state, flags)
76+
return SendTransaction(code, args, filename, flow, state, flags, logger)
7677
}
7778

78-
func SendTransaction(code []byte, args []string, location string, flow flowkit.Services, state *flowkit.State, sendFlags Flags) (result command.Result, err error) {
79+
func SendTransaction(code []byte, args []string, location string, flow flowkit.Services, state *flowkit.State, sendFlags Flags, logger output.Logger) (result command.Result, err error) {
7980
proposerName := sendFlags.Proposer
8081
var proposer *accounts.Account
8182
if proposerName != "" {
@@ -138,6 +139,13 @@ func SendTransaction(code []byte, args []string, location string, flow flowkit.S
138139
return nil, fmt.Errorf("error parsing transaction arguments: %w", err)
139140
}
140141

142+
// Use GasLimit if set (for backwards compatibility), otherwise use ComputeLimit
143+
computeLimit := sendFlags.ComputeLimit
144+
if sendFlags.GasLimit > 0 {
145+
logger.Info("⚠️ Warning: --gas-limit flag is deprecated, please use --compute-limit instead")
146+
computeLimit = sendFlags.GasLimit
147+
}
148+
141149
tx, txResult, err := flow.SendTransaction(
142150
context.Background(),
143151
transactions.AccountRoles{
@@ -146,7 +154,7 @@ func SendTransaction(code []byte, args []string, location string, flow flowkit.S
146154
Payer: *payer,
147155
},
148156
flowkit.Script{Code: code, Args: transactionArgs, Location: location},
149-
sendFlags.GasLimit,
157+
computeLimit,
150158
)
151159
if err != nil {
152160
return nil, err

internal/transactions/transactions_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func Test_Send(t *testing.T) {
180180
srv, state, _ := util.TestMocks(t)
181181

182182
t.Run("Success", func(t *testing.T) {
183-
const gas = uint64(1000)
184-
flags.GasLimit = gas
183+
const compute = uint64(1000)
184+
flags.ComputeLimit = compute
185185
inArgs := []string{tests.TransactionArgString.Filename, "test"}
186186

187187
srv.SendTransaction.Run(func(args mock.Arguments) {
@@ -192,7 +192,7 @@ func Test_Send(t *testing.T) {
192192
assert.Equal(t, acc, roles.Authorizers[0].Name)
193193
script := args.Get(2).(flowkit.Script)
194194
assert.Equal(t, tests.TransactionArgString.Filename, script.Location)
195-
assert.Equal(t, args.Get(3).(uint64), gas)
195+
assert.Equal(t, args.Get(3).(uint64), compute)
196196
}).Return(nil, nil, nil)
197197

198198
result, err := send(inArgs, command.GlobalFlags{}, util.NoLogger, srv.Mock, state)

0 commit comments

Comments
 (0)