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

Algod: Simulation run with extra budget per transaction group #5354

Merged
merged 20 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
requestFilename string
requestOutFilename string

simulateAllowEmptySignatures bool
simulateAllowMoreLogging bool
simulateAllowExtraOpcodeBudget bool
simulateExtraOpcodeBudget uint64
simulateAllowEmptySignatures bool
simulateAllowMoreLogging bool
simulateAllowExtraBudget bool
simulateExtraBudget uint64
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
)

func init() {
Expand Down Expand Up @@ -159,8 +159,8 @@
simulateCmd.Flags().StringVarP(&outFilename, "result-out", "o", "", "Filename for writing simulation result")
simulateCmd.Flags().BoolVar(&simulateAllowEmptySignatures, "allow-empty-signatures", false, "Allow transactions without signatures to be simulated as if they had correct signatures")
simulateCmd.Flags().BoolVar(&simulateAllowMoreLogging, "allow-more-logging", false, "Lift the limits on log opcode during simulation")
simulateCmd.Flags().BoolVar(&simulateAllowExtraOpcodeBudget, "allow-extra-opcode-budget", false, "Apply max extra budget for apps during simulation")
simulateCmd.Flags().Uint64Var(&simulateExtraOpcodeBudget, "extra-opcode-budget", 0, "Apply extra budget during simulation")
simulateCmd.Flags().BoolVar(&simulateAllowExtraBudget, "allow-extra-opcode-budget", false, "Apply max extra budget for apps during simulation")
simulateCmd.Flags().Uint64Var(&simulateExtraBudget, "extra-opcode-budget", 0, "Apply extra budget during simulation")
}

var clerkCmd = &cobra.Command{
Expand Down Expand Up @@ -1246,13 +1246,13 @@
reportErrorf("exactly one of --txfile or --request must be provided")
}

allowExtraBudgetProvided := cmd.Flags().Changed("allow-extra-opcode-budget")
extraBudgetProvided := cmd.Flags().Changed("extra-opcode-budget")
if allowExtraBudgetProvided && extraBudgetProvided {
reportErrorf("--allow-extra-opcode-budget and --extra-opcode-budget are mutually exclusive")

Check warning on line 1252 in cmd/goal/clerk.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/clerk.go#L1249-L1252

Added lines #L1249 - L1252 were not covered by tests
}
if allowExtraBudgetProvided {
simulateExtraOpcodeBudget = simulation.MaxExtraOpcodeBudget
simulateExtraBudget = simulation.MaxExtraOpcodeBudget

Check warning on line 1255 in cmd/goal/clerk.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/clerk.go#L1254-L1255

Added lines #L1254 - L1255 were not covered by tests
}

requestOutProvided := cmd.Flags().Changed("request-only-out")
Expand All @@ -1276,7 +1276,7 @@
},
AllowEmptySignatures: simulateAllowEmptySignatures,
AllowMoreLogging: simulateAllowMoreLogging,
ExtraOpcodeBudget: simulateExtraOpcodeBudget,
ExtraOpcodeBudget: simulateExtraBudget,

Check warning on line 1279 in cmd/goal/clerk.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/clerk.go#L1279

Added line #L1279 was not covered by tests
}
err := writeFile(requestOutFilename, protocol.EncodeJSON(simulateRequest), 0600)
if err != nil {
Expand All @@ -1299,7 +1299,7 @@
},
AllowEmptySignatures: simulateAllowEmptySignatures,
AllowMoreLogging: simulateAllowMoreLogging,
ExtraOpcodeBudget: simulateExtraOpcodeBudget,
ExtraOpcodeBudget: simulateExtraBudget,

Check warning on line 1302 in cmd/goal/clerk.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/clerk.go#L1302

Added line #L1302 was not covered by tests
}
simulateResponse, responseErr = client.SimulateTransactions(simulateRequest)
} else {
Expand Down
12 changes: 3 additions & 9 deletions ledger/simulation/simulation_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ func TestAppCallOverBudget(t *testing.T) {

simulationTest(t, func(accounts []simulationtesting.Account, txnInfo simulationtesting.TxnInfo) simulationTestCase {
sender := accounts[0]
receiver := accounts[1]

futureAppID := basics.AppIndex(1)
// App create with cost 4
Expand All @@ -805,7 +804,6 @@ int 0
Type: protocol.ApplicationCallTx,
Sender: sender.Addr,
ApplicationID: futureAppID,
Accounts: []basics.Address{receiver.Addr},
})

txntest.Group(&createTxn, &expensiveTxn)
Expand Down Expand Up @@ -861,7 +859,6 @@ func TestAppCallWithExtraBudget(t *testing.T) {

simulationTest(t, func(accounts []simulationtesting.Account, txnInfo simulationtesting.TxnInfo) simulationTestCase {
sender := accounts[0]
receiver := accounts[1]

futureAppID := basics.AppIndex(1)
// App create with cost 4
Expand All @@ -877,7 +874,6 @@ func TestAppCallWithExtraBudget(t *testing.T) {
Type: protocol.ApplicationCallTx,
Sender: sender.Addr,
ApplicationID: futureAppID,
Accounts: []basics.Address{receiver.Addr},
})

txntest.Group(&createTxn, &expensiveTxn)
Expand Down Expand Up @@ -934,7 +930,6 @@ func TestAppCallWithExtraBudgetOverBudget(t *testing.T) {

simulationTest(t, func(accounts []simulationtesting.Account, txnInfo simulationtesting.TxnInfo) simulationTestCase {
sender := accounts[0]
receiver := accounts[1]

futureAppID := basics.AppIndex(1)
// App create with cost 4
Expand All @@ -950,7 +945,6 @@ func TestAppCallWithExtraBudgetOverBudget(t *testing.T) {
Type: protocol.ApplicationCallTx,
Sender: sender.Addr,
ApplicationID: futureAppID,
Accounts: []basics.Address{receiver.Addr},
})

txntest.Group(&createTxn, &expensiveTxn)
Expand Down Expand Up @@ -1013,7 +1007,6 @@ func TestAppCallWithExtraBudgetExceedsInternalLimit(t *testing.T) {
s := simulation.MakeSimulator(l)

sender := accounts[0]
receiver := accounts[1]

futureAppID := basics.AppIndex(1)
// App create with cost 4
Expand All @@ -1029,14 +1022,14 @@ func TestAppCallWithExtraBudgetExceedsInternalLimit(t *testing.T) {
Type: protocol.ApplicationCallTx,
Sender: sender.Addr,
ApplicationID: futureAppID,
Accounts: []basics.Address{receiver.Addr},
})

txntest.Group(&createTxn, &expensiveTxn)

signedCreateTxn := createTxn.Txn().Sign(sender.Sk)
signedExpensiveTxn := expensiveTxn.Txn().Sign(sender.Sk)
// Add a small bit of extra budget, but not enough

// Add an extra budget that is exceeding simulation.MaxExtraOpcodeBudget
extraBudget := simulation.MaxExtraOpcodeBudget + 1

// should error on too high extra budgets
Expand All @@ -1045,6 +1038,7 @@ func TestAppCallWithExtraBudgetExceedsInternalLimit(t *testing.T) {
TxnGroups: [][]transactions.SignedTxn{{signedCreateTxn, signedExpensiveTxn}},
ExtraOpcodeBudget: extraBudget,
})
require.ErrorAs(t, err, &simulation.InvalidRequestError{})
require.ErrorContains(t, err, "extra budget 320001 > simulation extra budget limit 320000")
jasonpaulos marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
23 changes: 23 additions & 0 deletions test/scripts/e2e_subs/e2e-app-simulate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,26 @@ if [[ $(echo "$RES" | jq '."txn-groups"[0]."app-budget-consumed"') -ne 804 ]]; t
date '+app-simulate-test FAIL the app call to generated large TEAL should be consuming 804 budget %Y%m%d_%H%M%S'
false
fi

# SIMULATION! with --allow-extra-budget should pass direct call
RES=$(${gcmd} clerk simulate --allow-extra-opcode-budget -t "${TEMPDIR}/no-extra-opcode-budget.stx")

if [[ $(echo "$RES" | jq '."txn-groups" | any(has("failure-message"))') != $CONST_FALSE ]]; then
date '+app-simulate-test FAIL the app call to generated large TEAL with extra budget should pass %Y%m%d_%H%M%S'
false
fi

if [[ $(echo "$RES" | jq '."eval-overrides"."extra-opcode-budget"') -ne 320000 ]]; then
date '+app-simulate-test FAIL the app call to generated large TEAL should have extra-opcode-budget 320000 %Y%m%d_%H%M%S'
false
fi

if [[ $(echo "$RES" | jq '."txn-groups"[0]."app-budget-added"') -ne 320700 ]]; then
date '+app-simulate-test FAIL the app call to generated large TEAL should have app-budget-added 900 %Y%m%d_%H%M%S'
jasonpaulos marked this conversation as resolved.
Show resolved Hide resolved
false
fi

if [[ $(echo "$RES" | jq '."txn-groups"[0]."app-budget-consumed"') -ne 804 ]]; then
date '+app-simulate-test FAIL the app call to generated large TEAL should be consuming 804 budget %Y%m%d_%H%M%S'
false
fi