Skip to content

Commit a145557

Browse files
authored
Merge pull request OffchainLabs#2542 from OffchainLabs/debugprints
Only serialize debugprints when tracing
2 parents a89813c + 7d7c861 commit a145557

File tree

19 files changed

+160
-84
lines changed

19 files changed

+160
-84
lines changed

packages/arb-avm-cpp/avm/include/avm/machine.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ struct Assertion {
4141

4242
class MachineExecutionConfig {
4343
public:
44-
uint256_t max_gas;
45-
bool go_over_gas;
44+
uint256_t max_gas{0};
45+
bool go_over_gas{false};
4646
std::vector<MachineMessage> inbox_messages;
4747
std::deque<InboxMessage> sideloads;
48-
bool stop_on_sideload;
49-
bool stop_on_breakpoint;
48+
bool stop_on_sideload{false};
49+
bool stop_on_breakpoint{false};
5050
std::optional<uint256_t> stop_after_log_count;
51+
bool trace{false};
5152

52-
MachineExecutionConfig();
53+
MachineExecutionConfig() = default;
5354

5455
void setInboxMessagesFromBytes(
5556
const std::vector<std::vector<unsigned char>>&);

packages/arb-avm-cpp/avm/src/machine.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ void convertInboxMessagesFromBytes(
3737
}
3838
} // namespace
3939

40-
MachineExecutionConfig::MachineExecutionConfig()
41-
: max_gas(0),
42-
go_over_gas(false),
43-
inbox_messages(),
44-
sideloads(),
45-
stop_on_sideload(false),
46-
stop_on_breakpoint(false) {}
47-
4840
void MachineExecutionConfig::setInboxMessagesFromBytes(
4941
const std::vector<std::vector<unsigned char>>& bytes) {
5042
inbox_messages.clear();

packages/arb-avm-cpp/cavm/cmachine.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void machineExecutionConfigSetMaxGas(CMachineExecutionConfig* c,
178178
assert(c);
179179
auto config = static_cast<MachineExecutionConfig*>(c);
180180
config->max_gas = max_gas;
181-
config->go_over_gas = go_over_gas;
181+
config->go_over_gas = go_over_gas != 0;
182182
}
183183

184184
void machineExecutionConfigSetInboxMessages(CMachineExecutionConfig* c,
@@ -199,14 +199,20 @@ void machineExecutionConfigSetStopOnSideload(CMachineExecutionConfig* c,
199199
int stop_on_sideload) {
200200
assert(c);
201201
auto config = static_cast<MachineExecutionConfig*>(c);
202-
config->stop_on_sideload = stop_on_sideload;
202+
config->stop_on_sideload = stop_on_sideload != 0;
203203
}
204204

205205
void machineExecutionConfigSetStopOnBreakpoint(CMachineExecutionConfig* c,
206206
int stop_on_breakpoint) {
207207
assert(c);
208208
auto config = static_cast<MachineExecutionConfig*>(c);
209-
config->stop_on_breakpoint = stop_on_breakpoint;
209+
config->stop_on_breakpoint = stop_on_breakpoint != 0;
210+
}
211+
212+
void machineExecutionConfigSetTrace(CMachineExecutionConfig* c, int trace) {
213+
assert(c);
214+
auto config = static_cast<MachineExecutionConfig*>(c);
215+
config->trace = trace != 0;
210216
}
211217

212218
RawAssertionResult executeAssertion(CMachine* m,
@@ -240,8 +246,12 @@ RawAssertionResult executeAssertion(CMachine* m,
240246
}
241247

242248
std::vector<unsigned char> debugPrintData;
243-
for (const auto& debugPrint : assertion.debug_prints) {
244-
marshal_value(debugPrint.val, debugPrintData, nullptr);
249+
int debugPrintDataCount = 0;
250+
if (config->trace) {
251+
for (const auto& debugPrint : assertion.debug_prints) {
252+
debugPrintDataCount++;
253+
marshal_value(debugPrint.val, debugPrintData, nullptr);
254+
}
245255
}
246256

247257
// TODO extend usage of uint256
@@ -250,8 +260,7 @@ RawAssertionResult executeAssertion(CMachine* m,
250260
returnCharVector(sendData),
251261
static_cast<int>(assertion.sends.size()),
252262
returnCharVector(logData), static_cast<int>(assertion.logs.size()),
253-
returnCharVector(debugPrintData),
254-
static_cast<int>(assertion.debug_prints.size()),
263+
returnCharVector(debugPrintData), debugPrintDataCount,
255264
intx::narrow_cast<uint64_t>(assertion.step_count),
256265
intx::narrow_cast<uint64_t>(assertion.gas_count)},
257266
false};

packages/arb-avm-cpp/cavm/cmachine.h

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void machineExecutionConfigSetStopOnSideload(CMachineExecutionConfig* c,
9090
int stop_on_sideload);
9191
void machineExecutionConfigSetStopOnBreakpoint(CMachineExecutionConfig* c,
9292
int stop_on_breakpoint);
93+
void machineExecutionConfigSetTrace(CMachineExecutionConfig* c, int trace);
9394

9495
int dumpRetryables(CArbCore* a, CMachine* m, const char* filename);
9596

packages/arb-avm-cpp/cmachine/machine.go

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func (m *Machine) ExecuteAssertion(
167167
maxGas uint64,
168168
goOverGas bool,
169169
messages []inbox.InboxMessage,
170+
trace bool,
170171
) (*protocol.ExecutionAssertion, []value.Value, uint64, error) {
171172
defer runtime.KeepAlive(m)
172173
return m.ExecuteAssertionAdvanced(
@@ -177,6 +178,7 @@ func (m *Machine) ExecuteAssertion(
177178
nil,
178179
false,
179180
false,
181+
trace,
180182
)
181183
}
182184

@@ -188,6 +190,7 @@ func (m *Machine) ExecuteAssertionAdvanced(
188190
sideloads []inbox.InboxMessage,
189191
stopOnSideload bool,
190192
stopOnBreakpoint bool,
193+
trace bool,
191194
) (*protocol.ExecutionAssertion, []value.Value, uint64, error) {
192195
defer runtime.KeepAlive(m)
193196
conf := C.machineExecutionConfigCreate()
@@ -207,6 +210,8 @@ func (m *Machine) ExecuteAssertionAdvanced(
207210

208211
C.machineExecutionConfigSetStopOnBreakpoint(conf, boolToCInt(stopOnBreakpoint))
209212

213+
C.machineExecutionConfigSetTrace(conf, boolToCInt(trace))
214+
210215
resultChan := make(chan C.RawAssertionResult, 1)
211216
go func() {
212217
defer close(resultChan)

packages/arb-avm-cpp/data_storage/src/arbcore.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ rocksdb::Status ArbCore::advanceCoreToTarget(const MachineOutput& target_output,
915915
MachineExecutionConfig execConfig;
916916
execConfig.stop_on_sideload = cache_sideloads;
917917
execConfig.stop_on_breakpoint = false;
918+
execConfig.trace = false;
918919
execConfig.max_gas = target_output.arb_gas_used;
919920

920921
// Add messages and run machine
@@ -1944,6 +1945,7 @@ void ArbCore::operator()() {
19441945
maxGas + coreConfig.basic_machine_cache_interval);
19451946
thread_data.execConfig.stop_on_sideload = true;
19461947
thread_data.execConfig.stop_on_breakpoint = false;
1948+
thread_data.execConfig.trace = false;
19471949

19481950
if (coreConfig.database_save_interval > 0) {
19491951
thread_data.next_rocksdb_save_timepoint =

packages/arb-avm-cpp/speedtest/speed_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func runExecutableFile(b *testing.B, filePath string) {
7272
b.ResetTimer()
7373

7474
// Last parameter returned is number of steps executed
75-
_, _, _, err = mach.ExecuteAssertion(ctx, uint64(b.N)*insnMultiplier, true, nil)
75+
_, _, _, err = mach.ExecuteAssertion(ctx, uint64(b.N)*insnMultiplier, true, nil, false)
7676
if err != nil {
7777
b.Fatal(err)
7878
}

packages/arb-avm-cpp/tests/machine.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ TEST_CASE("Checkpoint State") {
8080
machine->run();
8181
REQUIRE(!machine->isAborted());
8282

83-
SECTION("default") { checkpointState(storage, *machine); }
84-
SECTION("save twice") { checkpointStateTwice(storage, *machine); }
83+
SECTION("default") {
84+
checkpointState(storage, *machine);
85+
}
86+
SECTION("save twice") {
87+
checkpointStateTwice(storage, *machine);
88+
}
8589
SECTION("assert machine hash") {
8690
auto transaction = storage.makeReadWriteTransaction();
8791
auto results = saveTestMachine(*transaction, *machine);
@@ -267,6 +271,7 @@ TEST_CASE("Stopping on sideload") {
267271
execConfig.sideloads.emplace_back(InboxMessage());
268272
execConfig.stop_on_sideload = true; // Shouldn't matter
269273
execConfig.stop_on_breakpoint = false;
274+
execConfig.trace = false;
270275
machine.machine_state.context = AssertionContext(execConfig);
271276
assertion = machine.run();
272277
REQUIRE(!machine.isAborted());
@@ -279,6 +284,7 @@ TEST_CASE("Stopping on sideload") {
279284
execConfig.sideloads.clear();
280285
execConfig.stop_on_sideload = true;
281286
execConfig.stop_on_breakpoint = false;
287+
execConfig.trace = false;
282288
machine.machine_state.context = AssertionContext(execConfig);
283289
assertion = machine.run();
284290
REQUIRE(!machine.isAborted());

packages/arb-rpc-node/arbosmachine/arbosmachine.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ func (m *Machine) ExecuteAssertion(
4545
maxGas uint64,
4646
goOverGas bool,
4747
messages []inbox.InboxMessage,
48+
trace bool,
4849
) (*protocol.ExecutionAssertion, []value.Value, uint64, error) {
49-
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages)
50+
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages, trace)
5051
if err != nil {
5152
return nil, nil, 0, err
5253
}

packages/arb-rpc-node/arbosmachine/arbostestmachine.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ func (m *TestMachine) ExecuteAssertion(
4545
maxGas uint64,
4646
goOverGas bool,
4747
messages []inbox.InboxMessage,
48+
trace bool,
4849
) (*protocol.ExecutionAssertion, []value.Value, uint64, error) {
49-
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages)
50+
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages, trace)
5051
if err != nil {
5152
return nil, nil, 0, err
5253
}

packages/arb-rpc-node/arbostest/helper_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ func runBasicAssertion(t *testing.T, inboxMessages []inbox.InboxMessage) ([]evm.
266266
var logs []value.Value
267267
var sends [][]byte
268268
var debugPrints [][]evm.EVMLogLine
269-
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil)
269+
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil, false)
270270
failIfError(t, err)
271271
logs = append(logs, assertion.Logs...)
272272
sends = append(sends, assertion.Sends...)
273273
totalExecutionGas := uint64(0)
274274
for i, msg := range inboxMessages {
275275
t.Log("Message", i)
276-
assertion, dPrints, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, []inbox.InboxMessage{msg})
276+
assertion, dPrints, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, []inbox.InboxMessage{msg}, true)
277277
failIfError(t, err)
278278
totalExecutionGas += assertion.NumGas
279279
parsedDebugPrints := processDebugPrints(t, dPrints)
@@ -316,7 +316,7 @@ func runBasicAssertion(t *testing.T, inboxMessages []inbox.InboxMessage) ([]evm.
316316
Timestamp: big.NewInt(0),
317317
},
318318
)
319-
_, _, _, err = mach.ExecuteAssertionAdvanced(ctx, 10000000000, false, []inbox.InboxMessage{msg}, nil, true, false)
319+
_, _, _, err = mach.ExecuteAssertionAdvanced(ctx, 10000000000, false, []inbox.InboxMessage{msg}, nil, true, false, false)
320320
test.FailIfError(t, err)
321321
snap, err = snapshot.NewSnapshot(ctx, mach.Clone(), lastMessage.ChainTime, seq)
322322
test.FailIfError(t, err)

packages/arb-rpc-node/arbostest/init_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestInit(t *testing.T) {
3030
cmach, err := cmachine.New(*arbosfile)
3131
failIfError(t, err)
3232
mach := arbosmachine.New(cmach)
33-
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil)
33+
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil, false)
3434
test.FailIfError(t, err)
3535
t.Log("Startup used", assertion.NumGas, "gas")
3636
}

packages/arb-rpc-node/arbostest/l2_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func TestCallTx(t *testing.T) {
151151
Payment: big.NewInt(0),
152152
Data: hexutil.MustDecode("0xf8a8fd6d"),
153153
},
154-
}, common.Address{}, math.MaxUint64)
154+
}, common.Address{}, math.MaxUint64, false)
155155
failIfError(t, err)
156156
if new(big.Int).SetBytes(callRes.ReturnData).Cmp(big.NewInt(7)) != 0 {
157157
t.Errorf("Storage was updated %X", callRes.ReturnData)
@@ -165,7 +165,7 @@ func TestCallTx(t *testing.T) {
165165
Payment: big.NewInt(0),
166166
Data: hexutil.MustDecode("0xf8a8fd6d"),
167167
},
168-
}, common.Address{}, math.MaxUint64)
168+
}, common.Address{}, math.MaxUint64, false)
169169
failIfError(t, err)
170170
if new(big.Int).SetBytes(call2Res.ReturnData).Cmp(big.NewInt(5)) != 0 {
171171
t.Errorf("Storage was updated")
@@ -179,7 +179,7 @@ func TestCallTx(t *testing.T) {
179179
Payment: big.NewInt(0),
180180
Data: hexutil.MustDecode(arbostestcontracts.SimpleBin),
181181
},
182-
}, sender, math.MaxUint64)
182+
}, sender, math.MaxUint64, false)
183183
failIfError(t, err)
184184
}
185185

@@ -224,7 +224,7 @@ func TestContractTx(t *testing.T) {
224224
Payment: big.NewInt(0),
225225
Data: hexutil.MustDecode("0xf8a8fd6d"),
226226
},
227-
}, common.Address{}, math.MaxUint64)
227+
}, common.Address{}, math.MaxUint64, false)
228228
failIfError(t, err)
229229
if new(big.Int).SetBytes(callRes.ReturnData).Cmp(big.NewInt(6)) != 0 {
230230
t.Errorf("Storage wasn't updated %X", callRes.ReturnData)
@@ -238,7 +238,7 @@ func TestContractTx(t *testing.T) {
238238
Payment: big.NewInt(0),
239239
Data: hexutil.MustDecode("0xf8a8fd6d"),
240240
},
241-
}, common.Address{}, math.MaxUint64)
241+
}, common.Address{}, math.MaxUint64, false)
242242
failIfError(t, err)
243243
if new(big.Int).SetBytes(callRes2.ReturnData).Cmp(big.NewInt(8)) != 0 {
244244
t.Errorf("Storage wasn't updated")

packages/arb-rpc-node/dev/transfer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func TestTransfer(t *testing.T) {
144144
test.FailIfError(t, err)
145145
snap, err := srv.PendingSnapshot(ctx)
146146
test.FailIfError(t, err)
147-
_, debugPrints, err := snap.EstimateGas(ctx, arbTx, common.Address{}, common.NewAddressFromEth(senderAuth.From), 100000000)
147+
_, debugPrints, err := snap.EstimateGas(ctx, arbTx, common.Address{}, common.NewAddressFromEth(senderAuth.From), 100000000, true)
148148
test.FailIfError(t, err)
149149
trace, err := getEVMTrace(debugPrints)
150150
test.FailIfError(t, err)
@@ -170,7 +170,7 @@ func TestTransfer(t *testing.T) {
170170
Payment: big.NewInt(0),
171171
Data: transferABI.Methods["send3"].ID,
172172
},
173-
}, common.NewAddressFromEth(senderAuth.From), math.MaxUint64)
173+
}, common.NewAddressFromEth(senderAuth.From), math.MaxUint64, true)
174174
test.FailIfError(t, err)
175175
trace, err := getEVMTrace(debugPrints)
176176
test.FailIfError(t, err)

0 commit comments

Comments
 (0)