Skip to content

Commit

Permalink
Algod: Simulation PC exposure for App approval/clear-state transaction (
Browse files Browse the repository at this point in the history
#5360)

Co-authored-by: Jason Paulos <jasonpaulos@users.noreply.github.com>
  • Loading branch information
ahangsu and jasonpaulos committed Jun 1, 2023
1 parent 6e245e7 commit bad81ee
Show file tree
Hide file tree
Showing 21 changed files with 2,770 additions and 1,165 deletions.
10 changes: 10 additions & 0 deletions cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var (
simulateAllowMoreLogging bool
simulateAllowMoreOpcodeBudget bool
simulateExtraOpcodeBudget uint64
simulateEnableRequestTrace bool
)

func init() {
Expand Down Expand Up @@ -161,6 +162,7 @@ func init() {
simulateCmd.Flags().BoolVar(&simulateAllowMoreLogging, "allow-more-logging", false, "Lift the limits on log opcode during simulation")
simulateCmd.Flags().BoolVar(&simulateAllowMoreOpcodeBudget, "allow-more-opcode-budget", false, "Apply max extra opcode budget for apps per transaction group (default 320000) during simulation")
simulateCmd.Flags().Uint64Var(&simulateExtraOpcodeBudget, "extra-opcode-budget", 0, "Apply extra opcode budget for apps per transaction group during simulation")
simulateCmd.Flags().BoolVar(&simulateEnableRequestTrace, "trace", false, "Enable simulation time execution trace of app calls")
}

var clerkCmd = &cobra.Command{
Expand Down Expand Up @@ -1276,6 +1278,7 @@ var simulateCmd = &cobra.Command{
AllowEmptySignatures: simulateAllowEmptySignatures,
AllowMoreLogging: simulateAllowMoreLogging,
ExtraOpcodeBudget: simulateExtraOpcodeBudget,
ExecTraceConfig: traceCmdOptionToSimulateTraceConfigModel(),
}
err := writeFile(requestOutFilename, protocol.EncodeJSON(simulateRequest), 0600)
if err != nil {
Expand All @@ -1299,6 +1302,7 @@ var simulateCmd = &cobra.Command{
AllowEmptySignatures: simulateAllowEmptySignatures,
AllowMoreLogging: simulateAllowMoreLogging,
ExtraOpcodeBudget: simulateExtraOpcodeBudget,
ExecTraceConfig: traceCmdOptionToSimulateTraceConfigModel(),
}
simulateResponse, responseErr = client.SimulateTransactions(simulateRequest)
} else {
Expand Down Expand Up @@ -1358,3 +1362,9 @@ func decodeTxnsFromFile(file string) []transactions.SignedTxn {
}
return txgroup
}

func traceCmdOptionToSimulateTraceConfigModel() simulation.ExecTraceConfig {
return simulation.ExecTraceConfig{
Enable: simulateEnableRequestTrace,
}
}
73 changes: 73 additions & 0 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3453,6 +3453,9 @@
"extra-opcode-budget": {
"description": "Applies extra opcode budget during simulation for each transaction group.",
"type": "integer"
},
"exec-trace-config": {
"$ref": "#/definitions/SimulateTraceConfig"
}
}
},
Expand All @@ -3475,6 +3478,16 @@
}
}
},
"SimulateTraceConfig": {
"description": "An object that configures simulation execution trace.",
"type": "object",
"properties": {
"enable": {
"description": "A boolean option for opting in execution trace features simulation endpoint.",
"type": "boolean"
}
}
},
"Box": {
"description": "Box name and its content.",
"type": "object",
Expand Down Expand Up @@ -3726,6 +3739,9 @@
"logic-sig-budget-consumed": {
"description": "Budget used during execution of a logic sig transaction.",
"type": "integer"
},
"exec-trace": {
"$ref": "#/definitions/SimulationTransactionExecTrace"
}
}
},
Expand Down Expand Up @@ -3830,6 +3846,60 @@
"type": "integer"
}
}
},
"SimulationOpcodeTraceUnit": {
"description": "The set of trace information and effect from evaluating a single opcode.",
"type": "object",
"required": [
"pc"
],
"properties": {
"pc": {
"description": "The program counter of the current opcode being evaluated.",
"type": "integer"
},
"spawned-inners": {
"description": "The indexes of the traces for inner transactions spawned by this opcode, if any.",
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"SimulationTransactionExecTrace": {
"description": "The execution trace of calling an app or a logic sig, containing the inner app call trace in a recursive way.",
"type": "object",
"properties": {
"approval-program-trace": {
"description": "Program trace that contains a trace of opcode effects in an approval program.",
"type": "array",
"items": {
"$ref": "#/definitions/SimulationOpcodeTraceUnit"
}
},
"clear-state-program-trace": {
"description": "Program trace that contains a trace of opcode effects in a clear state program.",
"type": "array",
"items": {
"$ref": "#/definitions/SimulationOpcodeTraceUnit"
}
},
"logic-sig-trace": {
"description": "Program trace that contains a trace of opcode effects in a logic sig.",
"type": "array",
"items": {
"$ref": "#/definitions/SimulationOpcodeTraceUnit"
}
},
"inner-trace": {
"description": "An array of SimulationTransactionExecTrace representing the execution trace of any inner transactions executed.",
"type": "array",
"items": {
"$ref": "#/definitions/SimulationTransactionExecTrace"
}
}
}
}
},
"parameters": {
Expand Down Expand Up @@ -4459,6 +4529,9 @@
},
"eval-overrides": {
"$ref": "#/definitions/SimulationEvalOverrides"
},
"exec-trace-config": {
"$ref": "#/definitions/SimulateTraceConfig"
}
}
}
Expand Down
79 changes: 79 additions & 0 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,9 @@
"eval-overrides": {
"$ref": "#/components/schemas/SimulationEvalOverrides"
},
"exec-trace-config": {
"$ref": "#/components/schemas/SimulateTraceConfig"
},
"last-round": {
"description": "The round immediately preceding this simulation. State changes through this round were used to run this simulation.",
"type": "integer"
Expand Down Expand Up @@ -1918,6 +1921,9 @@
"description": "Lifts limits on log opcode usage during simulation.",
"type": "boolean"
},
"exec-trace-config": {
"$ref": "#/components/schemas/SimulateTraceConfig"
},
"extra-opcode-budget": {
"description": "Applies extra opcode budget during simulation for each transaction group.",
"type": "integer"
Expand Down Expand Up @@ -1954,6 +1960,16 @@
],
"type": "object"
},
"SimulateTraceConfig": {
"description": "An object that configures simulation execution trace.",
"properties": {
"enable": {
"description": "A boolean option for opting in execution trace features simulation endpoint.",
"type": "boolean"
}
},
"type": "object"
},
"SimulateTransactionGroupResult": {
"description": "Simulation result for an atomic transaction group",
"properties": {
Expand Down Expand Up @@ -1996,6 +2012,9 @@
"description": "Budget used during execution of an app call transaction. This value includes budged used by inner app calls spawned by this transaction.",
"type": "integer"
},
"exec-trace": {
"$ref": "#/components/schemas/SimulationTransactionExecTrace"
},
"logic-sig-budget-consumed": {
"description": "Budget used during execution of a logic sig transaction.",
"type": "integer"
Expand Down Expand Up @@ -2031,6 +2050,60 @@
},
"type": "object"
},
"SimulationOpcodeTraceUnit": {
"description": "The set of trace information and effect from evaluating a single opcode.",
"properties": {
"pc": {
"description": "The program counter of the current opcode being evaluated.",
"type": "integer"
},
"spawned-inners": {
"description": "The indexes of the traces for inner transactions spawned by this opcode, if any.",
"items": {
"type": "integer"
},
"type": "array"
}
},
"required": [
"pc"
],
"type": "object"
},
"SimulationTransactionExecTrace": {
"description": "The execution trace of calling an app or a logic sig, containing the inner app call trace in a recursive way.",
"properties": {
"approval-program-trace": {
"description": "Program trace that contains a trace of opcode effects in an approval program.",
"items": {
"$ref": "#/components/schemas/SimulationOpcodeTraceUnit"
},
"type": "array"
},
"clear-state-program-trace": {
"description": "Program trace that contains a trace of opcode effects in a clear state program.",
"items": {
"$ref": "#/components/schemas/SimulationOpcodeTraceUnit"
},
"type": "array"
},
"inner-trace": {
"description": "An array of SimulationTransactionExecTrace representing the execution trace of any inner transactions executed.",
"items": {
"$ref": "#/components/schemas/SimulationTransactionExecTrace"
},
"type": "array"
},
"logic-sig-trace": {
"description": "Program trace that contains a trace of opcode effects in a logic sig.",
"items": {
"$ref": "#/components/schemas/SimulationOpcodeTraceUnit"
},
"type": "array"
}
},
"type": "object"
},
"StateDelta": {
"description": "Application state delta.",
"items": {
Expand Down Expand Up @@ -6289,6 +6362,9 @@
"eval-overrides": {
"$ref": "#/components/schemas/SimulationEvalOverrides"
},
"exec-trace-config": {
"$ref": "#/components/schemas/SimulateTraceConfig"
},
"last-round": {
"description": "The round immediately preceding this simulation. State changes through this round were used to run this simulation.",
"type": "integer"
Expand Down Expand Up @@ -6319,6 +6395,9 @@
"eval-overrides": {
"$ref": "#/components/schemas/SimulationEvalOverrides"
},
"exec-trace-config": {
"$ref": "#/components/schemas/SimulateTraceConfig"
},
"last-round": {
"description": "The round immediately preceding this simulation. State changes through this round were used to run this simulation.",
"type": "integer"
Expand Down

0 comments on commit bad81ee

Please sign in to comment.