Skip to content

Commit 3809569

Browse files
usmansaleemgeorgereuben
authored andcommitted
feat: TraceFrame Builder pattern with Precompile input output fields (besu-eth#9111)
Introduce Builder for TraceFrames. Add precompile data fields in Trace Frames. Add exceptional halt and revert reason for precompile trace frame. This will be used by tracers such as CallTracers to detect and populate precompile calls to have parity with Geth. Existing tracers, such as FlatTracerGenerator doesn't need the input/output of precompiles. --------- Signed-off-by: Usman Saleem <usman@usmans.info> Signed-off-by: georgereuben <reubengeorge101@gmail.com>
1 parent 3f865e7 commit 3809569

File tree

3 files changed

+674
-222
lines changed

3 files changed

+674
-222
lines changed

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugTraceTransactionTest.java

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,25 @@ public void shouldTraceTheTransactionUsingTheTransactionTracer() {
113113
Bytes.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000002")
114114
};
115115
final TraceFrame traceFrame =
116-
new TraceFrame(
117-
12,
118-
Optional.of("NONE"),
119-
Integer.MAX_VALUE,
120-
45L,
121-
OptionalLong.of(56L),
122-
0L,
123-
2,
124-
Optional.empty(),
125-
null,
126-
Wei.ZERO,
127-
Bytes.EMPTY,
128-
Bytes.EMPTY,
129-
Optional.of(stackBytes),
130-
Optional.of(memoryBytes),
131-
Optional.empty(),
132-
null,
133-
Optional.of(Bytes.fromHexString("0x1122334455667788")),
134-
Optional.empty(),
135-
Optional.empty(),
136-
0,
137-
Optional.empty(),
138-
false,
139-
Optional.empty(),
140-
Optional.empty());
116+
TraceFrame.builder()
117+
.setPc(12)
118+
.setOpcode("NONE")
119+
.setOpcodeNumber(Integer.MAX_VALUE)
120+
.setGasRemaining(45L)
121+
.setGasCost(OptionalLong.of(56L))
122+
.setGasRefund(0L)
123+
.setDepth(2)
124+
.setRecipient(null)
125+
.setValue(Wei.ZERO)
126+
.setInputData(Bytes.EMPTY)
127+
.setOutputData(Bytes.EMPTY)
128+
.setStack(Optional.of(stackBytes))
129+
.setMemory(Optional.of(memoryBytes))
130+
.setWorldUpdater(null)
131+
.setRevertReason(Optional.of(Bytes.fromHexString("0x1122334455667788")))
132+
.setStackItemsProduced(0)
133+
.setVirtualOperation(false)
134+
.build();
141135
final List<TraceFrame> traceFrames = Collections.singletonList(traceFrame);
142136
final TransactionTrace transactionTrace =
143137
new TransactionTrace(transaction, result, traceFrames);
@@ -182,31 +176,23 @@ public void shouldNotTraceTheTransactionIfNotFound() {
182176
final TransactionProcessingResult result = mock(TransactionProcessingResult.class);
183177

184178
final TraceFrame traceFrame =
185-
new TraceFrame(
186-
12,
187-
Optional.of("NONE"),
188-
Integer.MAX_VALUE,
189-
45L,
190-
OptionalLong.of(56L),
191-
0L,
192-
2,
193-
Optional.empty(),
194-
null,
195-
Wei.ZERO,
196-
Bytes.EMPTY,
197-
Bytes.EMPTY,
198-
Optional.empty(),
199-
Optional.empty(),
200-
Optional.empty(),
201-
null,
202-
Optional.of(Bytes.fromHexString("0x1122334455667788")),
203-
Optional.empty(),
204-
Optional.empty(),
205-
0,
206-
Optional.empty(),
207-
false,
208-
Optional.empty(),
209-
Optional.empty());
179+
TraceFrame.builder()
180+
.setPc(12)
181+
.setOpcode("NONE")
182+
.setOpcodeNumber(Integer.MAX_VALUE)
183+
.setGasRemaining(45L)
184+
.setGasCost(OptionalLong.of(56L))
185+
.setGasRefund(0L)
186+
.setDepth(2)
187+
.setRecipient(null)
188+
.setValue(Wei.ZERO)
189+
.setInputData(Bytes.EMPTY)
190+
.setOutputData(Bytes.EMPTY)
191+
.setWorldUpdater(null)
192+
.setRevertReason(Optional.of(Bytes.fromHexString("0x1122334455667788")))
193+
.setStackItemsProduced(0)
194+
.setVirtualOperation(false)
195+
.build();
210196
final List<TraceFrame> traceFrames = Collections.singletonList(traceFrame);
211197
final TransactionTrace transactionTrace =
212198
new TransactionTrace(transaction, result, traceFrames);

0 commit comments

Comments
 (0)