Skip to content

Commit

Permalink
Merge pull request #2542 from OffchainLabs/debugprints
Browse files Browse the repository at this point in the history
Only serialize debugprints when tracing
  • Loading branch information
PlasmaPower authored Nov 30, 2022
2 parents a89813c + 7d7c861 commit a145557
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 84 deletions.
11 changes: 6 additions & 5 deletions packages/arb-avm-cpp/avm/include/avm/machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ struct Assertion {

class MachineExecutionConfig {
public:
uint256_t max_gas;
bool go_over_gas;
uint256_t max_gas{0};
bool go_over_gas{false};
std::vector<MachineMessage> inbox_messages;
std::deque<InboxMessage> sideloads;
bool stop_on_sideload;
bool stop_on_breakpoint;
bool stop_on_sideload{false};
bool stop_on_breakpoint{false};
std::optional<uint256_t> stop_after_log_count;
bool trace{false};

MachineExecutionConfig();
MachineExecutionConfig() = default;

void setInboxMessagesFromBytes(
const std::vector<std::vector<unsigned char>>&);
Expand Down
8 changes: 0 additions & 8 deletions packages/arb-avm-cpp/avm/src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ void convertInboxMessagesFromBytes(
}
} // namespace

MachineExecutionConfig::MachineExecutionConfig()
: max_gas(0),
go_over_gas(false),
inbox_messages(),
sideloads(),
stop_on_sideload(false),
stop_on_breakpoint(false) {}

void MachineExecutionConfig::setInboxMessagesFromBytes(
const std::vector<std::vector<unsigned char>>& bytes) {
inbox_messages.clear();
Expand Down
23 changes: 16 additions & 7 deletions packages/arb-avm-cpp/cavm/cmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void machineExecutionConfigSetMaxGas(CMachineExecutionConfig* c,
assert(c);
auto config = static_cast<MachineExecutionConfig*>(c);
config->max_gas = max_gas;
config->go_over_gas = go_over_gas;
config->go_over_gas = go_over_gas != 0;
}

void machineExecutionConfigSetInboxMessages(CMachineExecutionConfig* c,
Expand All @@ -199,14 +199,20 @@ void machineExecutionConfigSetStopOnSideload(CMachineExecutionConfig* c,
int stop_on_sideload) {
assert(c);
auto config = static_cast<MachineExecutionConfig*>(c);
config->stop_on_sideload = stop_on_sideload;
config->stop_on_sideload = stop_on_sideload != 0;
}

void machineExecutionConfigSetStopOnBreakpoint(CMachineExecutionConfig* c,
int stop_on_breakpoint) {
assert(c);
auto config = static_cast<MachineExecutionConfig*>(c);
config->stop_on_breakpoint = stop_on_breakpoint;
config->stop_on_breakpoint = stop_on_breakpoint != 0;
}

void machineExecutionConfigSetTrace(CMachineExecutionConfig* c, int trace) {
assert(c);
auto config = static_cast<MachineExecutionConfig*>(c);
config->trace = trace != 0;
}

RawAssertionResult executeAssertion(CMachine* m,
Expand Down Expand Up @@ -240,8 +246,12 @@ RawAssertionResult executeAssertion(CMachine* m,
}

std::vector<unsigned char> debugPrintData;
for (const auto& debugPrint : assertion.debug_prints) {
marshal_value(debugPrint.val, debugPrintData, nullptr);
int debugPrintDataCount = 0;
if (config->trace) {
for (const auto& debugPrint : assertion.debug_prints) {
debugPrintDataCount++;
marshal_value(debugPrint.val, debugPrintData, nullptr);
}
}

// TODO extend usage of uint256
Expand All @@ -250,8 +260,7 @@ RawAssertionResult executeAssertion(CMachine* m,
returnCharVector(sendData),
static_cast<int>(assertion.sends.size()),
returnCharVector(logData), static_cast<int>(assertion.logs.size()),
returnCharVector(debugPrintData),
static_cast<int>(assertion.debug_prints.size()),
returnCharVector(debugPrintData), debugPrintDataCount,
intx::narrow_cast<uint64_t>(assertion.step_count),
intx::narrow_cast<uint64_t>(assertion.gas_count)},
false};
Expand Down
1 change: 1 addition & 0 deletions packages/arb-avm-cpp/cavm/cmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void machineExecutionConfigSetStopOnSideload(CMachineExecutionConfig* c,
int stop_on_sideload);
void machineExecutionConfigSetStopOnBreakpoint(CMachineExecutionConfig* c,
int stop_on_breakpoint);
void machineExecutionConfigSetTrace(CMachineExecutionConfig* c, int trace);

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

Expand Down
5 changes: 5 additions & 0 deletions packages/arb-avm-cpp/cmachine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (m *Machine) ExecuteAssertion(
maxGas uint64,
goOverGas bool,
messages []inbox.InboxMessage,
trace bool,
) (*protocol.ExecutionAssertion, []value.Value, uint64, error) {
defer runtime.KeepAlive(m)
return m.ExecuteAssertionAdvanced(
Expand All @@ -177,6 +178,7 @@ func (m *Machine) ExecuteAssertion(
nil,
false,
false,
trace,
)
}

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

C.machineExecutionConfigSetStopOnBreakpoint(conf, boolToCInt(stopOnBreakpoint))

C.machineExecutionConfigSetTrace(conf, boolToCInt(trace))

resultChan := make(chan C.RawAssertionResult, 1)
go func() {
defer close(resultChan)
Expand Down
2 changes: 2 additions & 0 deletions packages/arb-avm-cpp/data_storage/src/arbcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ rocksdb::Status ArbCore::advanceCoreToTarget(const MachineOutput& target_output,
MachineExecutionConfig execConfig;
execConfig.stop_on_sideload = cache_sideloads;
execConfig.stop_on_breakpoint = false;
execConfig.trace = false;
execConfig.max_gas = target_output.arb_gas_used;

// Add messages and run machine
Expand Down Expand Up @@ -1944,6 +1945,7 @@ void ArbCore::operator()() {
maxGas + coreConfig.basic_machine_cache_interval);
thread_data.execConfig.stop_on_sideload = true;
thread_data.execConfig.stop_on_breakpoint = false;
thread_data.execConfig.trace = false;

if (coreConfig.database_save_interval > 0) {
thread_data.next_rocksdb_save_timepoint =
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-avm-cpp/speedtest/speed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func runExecutableFile(b *testing.B, filePath string) {
b.ResetTimer()

// Last parameter returned is number of steps executed
_, _, _, err = mach.ExecuteAssertion(ctx, uint64(b.N)*insnMultiplier, true, nil)
_, _, _, err = mach.ExecuteAssertion(ctx, uint64(b.N)*insnMultiplier, true, nil, false)
if err != nil {
b.Fatal(err)
}
Expand Down
10 changes: 8 additions & 2 deletions packages/arb-avm-cpp/tests/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ TEST_CASE("Checkpoint State") {
machine->run();
REQUIRE(!machine->isAborted());

SECTION("default") { checkpointState(storage, *machine); }
SECTION("save twice") { checkpointStateTwice(storage, *machine); }
SECTION("default") {
checkpointState(storage, *machine);
}
SECTION("save twice") {
checkpointStateTwice(storage, *machine);
}
SECTION("assert machine hash") {
auto transaction = storage.makeReadWriteTransaction();
auto results = saveTestMachine(*transaction, *machine);
Expand Down Expand Up @@ -267,6 +271,7 @@ TEST_CASE("Stopping on sideload") {
execConfig.sideloads.emplace_back(InboxMessage());
execConfig.stop_on_sideload = true; // Shouldn't matter
execConfig.stop_on_breakpoint = false;
execConfig.trace = false;
machine.machine_state.context = AssertionContext(execConfig);
assertion = machine.run();
REQUIRE(!machine.isAborted());
Expand All @@ -279,6 +284,7 @@ TEST_CASE("Stopping on sideload") {
execConfig.sideloads.clear();
execConfig.stop_on_sideload = true;
execConfig.stop_on_breakpoint = false;
execConfig.trace = false;
machine.machine_state.context = AssertionContext(execConfig);
assertion = machine.run();
REQUIRE(!machine.isAborted());
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-rpc-node/arbosmachine/arbosmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ func (m *Machine) ExecuteAssertion(
maxGas uint64,
goOverGas bool,
messages []inbox.InboxMessage,
trace bool,
) (*protocol.ExecutionAssertion, []value.Value, uint64, error) {
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages)
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages, trace)
if err != nil {
return nil, nil, 0, err
}
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-rpc-node/arbosmachine/arbostestmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ func (m *TestMachine) ExecuteAssertion(
maxGas uint64,
goOverGas bool,
messages []inbox.InboxMessage,
trace bool,
) (*protocol.ExecutionAssertion, []value.Value, uint64, error) {
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages)
assertion, debugPrints, numSteps, err := m.Machine.ExecuteAssertion(ctx, maxGas, goOverGas, messages, trace)
if err != nil {
return nil, nil, 0, err
}
Expand Down
6 changes: 3 additions & 3 deletions packages/arb-rpc-node/arbostest/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ func runBasicAssertion(t *testing.T, inboxMessages []inbox.InboxMessage) ([]evm.
var logs []value.Value
var sends [][]byte
var debugPrints [][]evm.EVMLogLine
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil)
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil, false)
failIfError(t, err)
logs = append(logs, assertion.Logs...)
sends = append(sends, assertion.Sends...)
totalExecutionGas := uint64(0)
for i, msg := range inboxMessages {
t.Log("Message", i)
assertion, dPrints, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, []inbox.InboxMessage{msg})
assertion, dPrints, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, []inbox.InboxMessage{msg}, true)
failIfError(t, err)
totalExecutionGas += assertion.NumGas
parsedDebugPrints := processDebugPrints(t, dPrints)
Expand Down Expand Up @@ -316,7 +316,7 @@ func runBasicAssertion(t *testing.T, inboxMessages []inbox.InboxMessage) ([]evm.
Timestamp: big.NewInt(0),
},
)
_, _, _, err = mach.ExecuteAssertionAdvanced(ctx, 10000000000, false, []inbox.InboxMessage{msg}, nil, true, false)
_, _, _, err = mach.ExecuteAssertionAdvanced(ctx, 10000000000, false, []inbox.InboxMessage{msg}, nil, true, false, false)
test.FailIfError(t, err)
snap, err = snapshot.NewSnapshot(ctx, mach.Clone(), lastMessage.ChainTime, seq)
test.FailIfError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-rpc-node/arbostest/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestInit(t *testing.T) {
cmach, err := cmachine.New(*arbosfile)
failIfError(t, err)
mach := arbosmachine.New(cmach)
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil)
assertion, _, _, err := mach.ExecuteAssertion(ctx, 10000000000, false, nil, false)
test.FailIfError(t, err)
t.Log("Startup used", assertion.NumGas, "gas")
}
10 changes: 5 additions & 5 deletions packages/arb-rpc-node/arbostest/l2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestCallTx(t *testing.T) {
Payment: big.NewInt(0),
Data: hexutil.MustDecode("0xf8a8fd6d"),
},
}, common.Address{}, math.MaxUint64)
}, common.Address{}, math.MaxUint64, false)
failIfError(t, err)
if new(big.Int).SetBytes(callRes.ReturnData).Cmp(big.NewInt(7)) != 0 {
t.Errorf("Storage was updated %X", callRes.ReturnData)
Expand All @@ -165,7 +165,7 @@ func TestCallTx(t *testing.T) {
Payment: big.NewInt(0),
Data: hexutil.MustDecode("0xf8a8fd6d"),
},
}, common.Address{}, math.MaxUint64)
}, common.Address{}, math.MaxUint64, false)
failIfError(t, err)
if new(big.Int).SetBytes(call2Res.ReturnData).Cmp(big.NewInt(5)) != 0 {
t.Errorf("Storage was updated")
Expand All @@ -179,7 +179,7 @@ func TestCallTx(t *testing.T) {
Payment: big.NewInt(0),
Data: hexutil.MustDecode(arbostestcontracts.SimpleBin),
},
}, sender, math.MaxUint64)
}, sender, math.MaxUint64, false)
failIfError(t, err)
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func TestContractTx(t *testing.T) {
Payment: big.NewInt(0),
Data: hexutil.MustDecode("0xf8a8fd6d"),
},
}, common.Address{}, math.MaxUint64)
}, common.Address{}, math.MaxUint64, false)
failIfError(t, err)
if new(big.Int).SetBytes(callRes.ReturnData).Cmp(big.NewInt(6)) != 0 {
t.Errorf("Storage wasn't updated %X", callRes.ReturnData)
Expand All @@ -238,7 +238,7 @@ func TestContractTx(t *testing.T) {
Payment: big.NewInt(0),
Data: hexutil.MustDecode("0xf8a8fd6d"),
},
}, common.Address{}, math.MaxUint64)
}, common.Address{}, math.MaxUint64, false)
failIfError(t, err)
if new(big.Int).SetBytes(callRes2.ReturnData).Cmp(big.NewInt(8)) != 0 {
t.Errorf("Storage wasn't updated")
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-rpc-node/dev/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestTransfer(t *testing.T) {
test.FailIfError(t, err)
snap, err := srv.PendingSnapshot(ctx)
test.FailIfError(t, err)
_, debugPrints, err := snap.EstimateGas(ctx, arbTx, common.Address{}, common.NewAddressFromEth(senderAuth.From), 100000000)
_, debugPrints, err := snap.EstimateGas(ctx, arbTx, common.Address{}, common.NewAddressFromEth(senderAuth.From), 100000000, true)
test.FailIfError(t, err)
trace, err := getEVMTrace(debugPrints)
test.FailIfError(t, err)
Expand All @@ -170,7 +170,7 @@ func TestTransfer(t *testing.T) {
Payment: big.NewInt(0),
Data: transferABI.Methods["send3"].ID,
},
}, common.NewAddressFromEth(senderAuth.From), math.MaxUint64)
}, common.NewAddressFromEth(senderAuth.From), math.MaxUint64, true)
test.FailIfError(t, err)
trace, err := getEVMTrace(debugPrints)
test.FailIfError(t, err)
Expand Down
Loading

0 comments on commit a145557

Please sign in to comment.