Skip to content

Commit a1f85e1

Browse files
committed
Move opcodeBudget field and update state outside renderer
1 parent c41baad commit a1f85e1

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

cmd/tealdbg/cdtSession.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (s *cdtSession) websocketHandler(w http.ResponseWriter, r *http.Request) {
169169
state.Update(cdtStateUpdate{
170170
dbgState.Stack, dbgState.Scratch,
171171
0, 0, "",
172-
s.debugger.GetStates(nil),
172+
0, s.debugger.GetStates(nil),
173173
})
174174

175175
hash := sha256.Sum256([]byte(state.disassembly)) // some random hash
@@ -247,7 +247,7 @@ func (s *cdtSession) websocketHandler(w http.ResponseWriter, r *http.Request) {
247247
state.Update(cdtStateUpdate{
248248
dbgState.Stack, dbgState.Scratch,
249249
dbgState.PC, dbgState.Line, dbgState.Error,
250-
appState,
250+
dbgState.OpcodeBudget, appState,
251251
})
252252
dbgStateMu.Unlock()
253253

cmd/tealdbg/cdtState.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ type cdtState struct {
4242
globals []basics.TealValue
4343

4444
// mutable program state
45-
mu deadlock.Mutex
46-
stack []basics.TealValue
47-
scratch []basics.TealValue
48-
pc atomicInt
49-
line atomicInt
50-
err atomicString
45+
mu deadlock.Mutex
46+
stack []basics.TealValue
47+
scratch []basics.TealValue
48+
pc atomicInt
49+
line atomicInt
50+
err atomicString
51+
opcodeBudget int
5152
AppState
5253

5354
// debugger states
@@ -58,11 +59,12 @@ type cdtState struct {
5859
}
5960

6061
type cdtStateUpdate struct {
61-
stack []basics.TealValue
62-
scratch []basics.TealValue
63-
pc int
64-
line int
65-
err string
62+
stack []basics.TealValue
63+
scratch []basics.TealValue
64+
pc int
65+
line int
66+
err string
67+
opcodeBudget int
6668

6769
AppState
6870
}
@@ -74,6 +76,8 @@ const (
7476
addressHint
7577
)
7678

79+
const opcodeBudgetFieldIdx = 12
80+
7781
var txnFileTypeHints = map[logic.TxnField]typeHint{
7882
logic.Sender: addressHint,
7983
logic.Receiver: addressHint,
@@ -107,6 +111,8 @@ func (s *cdtState) Update(state cdtStateUpdate) {
107111
s.stack = state.stack
108112
s.scratch = state.scratch
109113
s.AppState = state.AppState
114+
// We need to dynamically override opcodeBudget with the proper value each step.
115+
s.globals[opcodeBudgetFieldIdx].Uint = uint64(state.opcodeBudget)
110116
}
111117

112118
const localScopeObjID = "localScopeObjId"
@@ -839,10 +845,6 @@ func makeGlobals(s *cdtState, preview bool) (desc []cdt.RuntimePropertyDescripto
839845
fields := prepareGlobals(s.globals)
840846
desc = make([]cdt.RuntimePropertyDescriptor, len(fields))
841847
for i, field := range fields {
842-
// We need to dynamically override this field with the proper value each step.
843-
if field.Name == "OpcodeBudget" {
844-
field.Value = strconv.Itoa(s.opcodeBudget)
845-
}
846848
desc[i] = makePrimitive(field)
847849
}
848850
return

cmd/tealdbg/debugger.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,6 @@ func (s *session) GetStates(st *logic.DebugState) AppState {
369369
newStates.innerTxns = changes.InnerTxns
370370
}
371371

372-
newStates.opcodeBudget = st.OpcodeBudget
373-
374372
return newStates
375373
}
376374

cmd/tealdbg/local.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,12 @@ type evalResult struct {
158158

159159
// AppState encapsulates information about execution of stateful teal program
160160
type AppState struct {
161-
appIdx basics.AppIndex
162-
schemas basics.StateSchemas
163-
global map[basics.AppIndex]basics.TealKeyValue
164-
locals map[basics.Address]map[basics.AppIndex]basics.TealKeyValue
165-
logs []string
166-
innerTxns []transactions.SignedTxnWithAD
167-
opcodeBudget int
161+
appIdx basics.AppIndex
162+
schemas basics.StateSchemas
163+
global map[basics.AppIndex]basics.TealKeyValue
164+
locals map[basics.Address]map[basics.AppIndex]basics.TealKeyValue
165+
logs []string
166+
innerTxns []transactions.SignedTxnWithAD
168167
}
169168

170169
func cloneInners(a []transactions.SignedTxnWithAD) (b []transactions.SignedTxnWithAD) {
@@ -194,7 +193,6 @@ func (a *AppState) clone() (b AppState) {
194193
b.logs = make([]string, len(a.logs))
195194
copy(b.logs, a.logs)
196195
b.innerTxns = cloneInners(a.innerTxns)
197-
b.opcodeBudget = a.opcodeBudget
198196
return
199197
}
200198

@@ -203,8 +201,7 @@ func (a *AppState) empty() bool {
203201
len(a.global) == 0 &&
204202
len(a.locals) == 0 &&
205203
len(a.logs) == 0 &&
206-
len(a.innerTxns) == 0 &&
207-
a.opcodeBudget == 0
204+
len(a.innerTxns) == 0
208205
}
209206

210207
type modeType int

0 commit comments

Comments
 (0)