Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit f625faa

Browse files
authored
Merge pull request #5519 from trufflesuite/log-when
Add step information to txlog
2 parents 444d064 + 17ed93c commit f625faa

File tree

5 files changed

+130
-17
lines changed

5 files changed

+130
-17
lines changed

packages/debugger/lib/txlog/actions/index.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export const INTERNAL_CALL = "TXLOG_INTERNAL_CALL";
2-
export function internalCall(pointer, newPointer) {
2+
export function internalCall(pointer, newPointer, step) {
33
return {
44
type: INTERNAL_CALL,
55
pointer,
6-
newPointer
6+
newPointer,
7+
step
78
};
89
}
910

@@ -16,11 +17,12 @@ export function absorbedCall(pointer) {
1617
}
1718

1819
export const INTERNAL_RETURN = "TXLOG_INTERNAL_RETURN";
19-
export function internalReturn(pointer, newPointer, variables) {
20+
export function internalReturn(pointer, newPointer, step, variables) {
2021
return {
2122
type: INTERNAL_RETURN,
2223
pointer,
2324
newPointer,
25+
step,
2426
variables
2527
};
2628
}
@@ -29,6 +31,7 @@ export const EXTERNAL_CALL = "TXLOG_EXTERNAL_CALL";
2931
export function externalCall(
3032
pointer,
3133
newPointer,
34+
step,
3235
address,
3336
context,
3437
value,
@@ -42,6 +45,7 @@ export function externalCall(
4245
type: EXTERNAL_CALL,
4346
pointer,
4447
newPointer,
48+
step,
4549
address,
4650
context,
4751
value,
@@ -57,6 +61,7 @@ export const INSTANT_EXTERNAL_CALL = "TXLOG_INSTANT_EXTERNAL_CALL";
5761
export function instantExternalCall(
5862
pointer,
5963
newPointer, //does not actually affect the current pointer!
64+
step,
6065
address,
6166
context,
6267
value,
@@ -71,6 +76,7 @@ export function instantExternalCall(
7176
type: INSTANT_EXTERNAL_CALL,
7277
pointer,
7378
newPointer,
79+
step,
7480
address,
7581
context,
7682
value,
@@ -87,6 +93,7 @@ export const CREATE = "TXLOG_CREATE";
8793
export function create(
8894
pointer,
8995
newPointer,
96+
step,
9097
address,
9198
context,
9299
value,
@@ -98,6 +105,7 @@ export function create(
98105
type: CREATE,
99106
pointer,
100107
newPointer,
108+
step,
101109
address,
102110
context,
103111
value,
@@ -111,6 +119,7 @@ export const INSTANT_CREATE = "TXLOG_INSTANT_CREATE";
111119
export function instantCreate(
112120
pointer,
113121
newPointer, //does not actually affect the current pointer!
122+
step,
114123
address,
115124
context,
116125
value,
@@ -123,6 +132,7 @@ export function instantCreate(
123132
type: INSTANT_CREATE,
124133
pointer,
125134
newPointer,
135+
step,
126136
address,
127137
context,
128138
value,
@@ -134,32 +144,41 @@ export function instantCreate(
134144
}
135145

136146
export const EXTERNAL_RETURN = "TXLOG_EXTERNAL_RETURN";
137-
export function externalReturn(pointer, newPointer, decodings, returnData) {
147+
export function externalReturn(
148+
pointer,
149+
newPointer,
150+
step,
151+
decodings,
152+
returnData
153+
) {
138154
return {
139155
type: EXTERNAL_RETURN,
140156
pointer,
141157
newPointer,
158+
step,
142159
decodings,
143160
returnData
144161
};
145162
}
146163

147164
export const SELFDESTRUCT = "TXLOG_SELFDESTRUCT";
148-
export function selfdestruct(pointer, newPointer, beneficiary) {
165+
export function selfdestruct(pointer, newPointer, step, beneficiary) {
149166
return {
150167
type: SELFDESTRUCT,
151168
pointer,
152169
newPointer,
170+
step,
153171
beneficiary
154172
};
155173
}
156174

157175
export const REVERT = "TXLOG_REVERT";
158-
export function revert(pointer, newPointer, error) {
176+
export function revert(pointer, newPointer, step, error) {
159177
return {
160178
type: REVERT,
161179
pointer,
162180
newPointer,
181+
step,
163182
error
164183
};
165184
}
@@ -181,11 +200,12 @@ export function identifyFunctionCall(
181200
}
182201

183202
export const LOG_EVENT = "TXLOG_LOG_EVENT";
184-
export function logEvent(pointer, newPointer, decoding, rawEventInfo) {
203+
export function logEvent(pointer, newPointer, step, decoding, rawEventInfo) {
185204
return {
186205
type: LOG_EVENT,
187206
pointer,
188207
newPointer, //does not actually affect current pointer!
208+
step,
189209
decoding,
190210
rawEventInfo
191211
};

packages/debugger/lib/txlog/reducers.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const DEFAULT_TX_LOG = {
2222
};
2323

2424
function transactionLog(state = DEFAULT_TX_LOG, action) {
25-
const { pointer, newPointer } = action;
25+
const { pointer, newPointer, step } = action;
2626
const node = state.byPointer[pointer];
2727
switch (action.type) {
2828
case actions.RECORD_ORIGIN:
@@ -52,7 +52,8 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
5252
[newPointer]: {
5353
type: "event",
5454
decoding: action.decoding,
55-
raw: action.rawEventInfo
55+
raw: action.rawEventInfo,
56+
step
5657
}
5758
}
5859
};
@@ -68,6 +69,7 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
6869
[newPointer]: {
6970
type: "callinternal",
7071
actions: [],
72+
beginStep: step,
7173
waitingForFunctionDefinition: true
7274
}
7375
}
@@ -99,6 +101,7 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
99101
} else {
100102
debug("returninternal once tx done!");
101103
}
104+
modifiedNode.endStep = step;
102105
return {
103106
byPointer: {
104107
...state.byPointer,
@@ -161,7 +164,8 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
161164
functionName,
162165
contractName,
163166
arguments: variables,
164-
actions: []
167+
actions: [],
168+
beginStep: step
165169
};
166170
if (kind === "message" || kind === "library") {
167171
call.data = calldata;
@@ -173,6 +177,7 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
173177
}
174178
if (instant) {
175179
call.returnKind = status ? "return" : "revert";
180+
call.endStep = step;
176181
} else {
177182
//If kind === "message", set waiting to false.
178183
//Why? Well, because fallback functions and receive functions
@@ -228,6 +233,7 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
228233
modifiedNode.beneficiary = action.beneficiary;
229234
break;
230235
}
236+
modifiedNode.endStep = step;
231237
let newState = {
232238
byPointer: {
233239
...state.byPointer,
@@ -250,6 +256,7 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
250256
//one already to note that they failed to return due to a call they made
251257
//reverting
252258
currentNode.returnKind = "unwind";
259+
currentNode.endStep = step;
253260
}
254261
delete currentNode.waitingForFunctionDefinition;
255262
debug("set currentNode!");
@@ -302,6 +309,8 @@ function transactionLog(state = DEFAULT_TX_LOG, action) {
302309
finalNode.returnImmutables = decoding.immutables;
303310
}
304311
}
312+
//and of course set the end step
313+
finalNode.endStep = step;
305314
//finally, delete internal info
306315
delete finalNode.waitingForFunctionDefinition;
307316
delete finalNode.absorbNextInternalCall;

packages/debugger/lib/txlog/sagas/index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function* tickSaga() {
1919

2020
function* updateTransactionLogSaga() {
2121
const pointer = yield select(txlog.current.pointer); //log pointer, not AST pointer
22+
const step = yield select(txlog.current.step);
2223
if (yield select(txlog.current.isHalting)) {
2324
//note that we process this case first so that it overrides the others!
2425
const newPointer = yield select(txlog.current.externalReturnPointer);
@@ -28,19 +29,19 @@ function* updateTransactionLogSaga() {
2829
const beneficiary = yield select(txlog.current.beneficiary);
2930
//note: this selector returns null for a value-destroying selfdestruct
3031
debug("sd: %o %o", pointer, newPointer);
31-
yield put(actions.selfdestruct(pointer, newPointer, beneficiary));
32+
yield put(actions.selfdestruct(pointer, newPointer, step, beneficiary));
3233
} else {
3334
const decodings = yield* data.decodeReturnValue();
3435
const rawData = yield select(txlog.current.returnData);
3536
debug("external return: %o %o", pointer, newPointer);
3637
yield put(
37-
actions.externalReturn(pointer, newPointer, decodings, rawData)
38+
actions.externalReturn(pointer, newPointer, step, decodings, rawData)
3839
);
3940
}
4041
} else {
4142
const error = (yield* data.decodeReturnValue())[0];
4243
debug("revert: %o %o", pointer, newPointer);
43-
yield put(actions.revert(pointer, newPointer, error));
44+
yield put(actions.revert(pointer, newPointer, step, error));
4445
}
4546
} else if (yield select(txlog.current.isJump)) {
4647
const jumpDirection = yield select(txlog.current.jumpDirection);
@@ -52,7 +53,7 @@ function* updateTransactionLogSaga() {
5253
if (!(yield select(txlog.current.waitingForInternalCallToAbsorb))) {
5354
const newPointer = yield select(txlog.current.nextActionPointer);
5455
debug("internal call: %o %o", pointer, newPointer);
55-
yield put(actions.internalCall(pointer, newPointer));
56+
yield put(actions.internalCall(pointer, newPointer, step));
5657
} else {
5758
debug("absorbed call: %o", pointer);
5859
yield put(actions.absorbedCall(pointer));
@@ -84,10 +85,14 @@ function* updateTransactionLogSaga() {
8485
variables.push({ name, value: decodedValue });
8586
}
8687
debug("internal return: %o %o", pointer, newPointer);
87-
yield put(actions.internalReturn(pointer, newPointer, variables));
88+
yield put(
89+
actions.internalReturn(pointer, newPointer, step, variables)
90+
);
8891
} else {
8992
debug("internal return: %o %o", pointer, newPointer);
90-
yield put(actions.internalReturn(pointer, newPointer, undefined)); //I guess?
93+
yield put(
94+
actions.internalReturn(pointer, newPointer, step, undefined)
95+
); //I guess?
9196
}
9297
}
9398
}
@@ -113,6 +118,7 @@ function* updateTransactionLogSaga() {
113118
actions.instantExternalCall(
114119
pointer,
115120
newPointer, //note: doesn't actually change the current pointer
121+
step,
116122
address,
117123
context,
118124
value,
@@ -130,6 +136,7 @@ function* updateTransactionLogSaga() {
130136
actions.externalCall(
131137
pointer,
132138
newPointer,
139+
step,
133140
address,
134141
context,
135142
value,
@@ -157,6 +164,7 @@ function* updateTransactionLogSaga() {
157164
actions.instantCreate(
158165
pointer,
159166
newPointer, //note: doesn't actually change the current pointer
167+
step,
160168
address,
161169
context,
162170
value,
@@ -172,6 +180,7 @@ function* updateTransactionLogSaga() {
172180
actions.create(
173181
pointer,
174182
newPointer,
183+
step,
175184
address,
176185
context,
177186
value,
@@ -186,7 +195,7 @@ function* updateTransactionLogSaga() {
186195
//(note: because we know the event ID, there should typically only be one decoding)
187196
const rawInfo = yield select(txlog.current.rawEventInfo);
188197
const newPointer = yield select(txlog.current.nextActionPointer);
189-
yield put(actions.logEvent(pointer, newPointer, decoding, rawInfo));
198+
yield put(actions.logEvent(pointer, newPointer, step, decoding, rawInfo));
190199
} else if (yield select(txlog.current.onFunctionDefinition)) {
191200
if (yield select(txlog.current.waitingForFunctionDefinition)) {
192201
debug("identifying");
@@ -280,6 +289,7 @@ export function* begin() {
280289
actions.externalCall(
281290
pointer,
282291
newPointer,
292+
-1, //initial call considered to happen at "step -1"
283293
address,
284294
context,
285295
value,
@@ -296,6 +306,7 @@ export function* begin() {
296306
actions.create(
297307
pointer,
298308
newPointer,
309+
-1, //initial call considered to happen at "step -1"
299310
storageAddress,
300311
context,
301312
value,

packages/debugger/lib/txlog/selectors/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ let txlog = createSelectorTree({
119119
(pointer, log) => log[pointer]
120120
),
121121

122+
/**
123+
* txlog.current.step
124+
*/
125+
step: createLeaf(
126+
[trace.index, trace.steps],
127+
(index, steps) =>
128+
steps.length === 0
129+
? -1 //special case: we use step -1 to mean before the steps start;
130+
: //so if there are no steps, that's what we want to report. trace.index
131+
//won't do that, though, so we special-case it in here.
132+
index //normal case
133+
),
134+
122135
/**
123136
* txlog.current.waitingForFunctionDefinition
124137
* This selector indicates whether there's a call (internal or external)
@@ -481,6 +494,7 @@ let txlog = createSelectorTree({
481494
{
482495
decoding: node.decoding,
483496
raw: node.raw,
497+
step: node.step,
484498
address,
485499
codeAddress,
486500
status

0 commit comments

Comments
 (0)