Skip to content
6 changes: 4 additions & 2 deletions conformance/src/instruction_execute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ fn executeInstruction(

if (emit_logs) {
std.debug.print("Execution Logs:\n", .{});
for (tc.log_collector.?.collect(), 1..) |msg, index| {
std.debug.print(" {}: {s}\n", .{ index, msg });
var i: usize = 0;
var msgs = tc.log_collector.?.iterator();
while (msgs.next()) |msg| : (i += 1) {
std.debug.print(" {}: {s}\n", .{ i, msg });
}
}

Expand Down
5 changes: 3 additions & 2 deletions conformance/src/txn_execute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,9 @@ fn printLogs(result: TransactionResult(ProcessedTransaction)) void {
.ok => |txn| {
switch (txn) {
.executed => |executed| {
const msgs = executed.executed_transaction.log_collector.?.messages;
for (msgs.items, 0..) |msg, i| {
var i: usize = 0;
var msgs = executed.executed_transaction.log_collector.?.iterator();
while (msgs.next()) |msg| : (i += 1) {
std.debug.print("log {}: {s}\n", .{ i, msg });
}
},
Expand Down
9 changes: 7 additions & 2 deletions conformance/src/utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ pub fn createTransactionContext(
ptr
else
try allocator.create(ProgramMap);
errdefer if (environment.program_map == null) allocator.destroy(program_map);
program_map.* = ProgramMap{};

const log_collector = try sig.runtime.LogCollector.default(allocator);
errdefer log_collector.deinit(allocator);

tc.* = TransactionContext{
.allocator = allocator,
.feature_set = feature_set,
Expand All @@ -124,7 +128,7 @@ pub fn createTransactionContext(
.compute_meter = instr_ctx.cu_avail,
.compute_budget = sig.runtime.ComputeBudget.default(instr_ctx.cu_avail),
.custom_error = null,
.log_collector = sig.runtime.LogCollector.default(),
.log_collector = log_collector,
.rent = sysvar_cache.get(sysvar.Rent) catch sysvar.Rent.DEFAULT,
.prev_blockhash = sig.core.Hash.ZEROES,
.prev_lamports_per_signature = 0,
Expand Down Expand Up @@ -495,7 +499,8 @@ pub fn createSyscallEffect(allocator: std.mem.Allocator, params: struct {
var log = std.ArrayList(u8).init(allocator);
defer log.deinit();
if (params.tc.log_collector) |log_collector| {
for (log_collector.collect()) |msg| {
var iter = log_collector.iterator();
while (iter.next()) |msg| {
try log.appendSlice(msg);
try log.append('\n');
}
Expand Down
6 changes: 4 additions & 2 deletions conformance/src/vm_syscall.zig
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ fn executeSyscall(

if (emit_logs) {
std.debug.print("Execution Logs:\n", .{});
for (tc.log_collector.?.collect(), 1..) |msg, index| {
std.debug.print(" {}: {s}\n", .{ index, msg });
var i: usize = 0;
var msgs = tc.log_collector.?.iterator();
while (msgs.next()) |msg| : (i += 1) {
std.debug.print(" {}: {s}\n", .{ i, msg });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/accountsdb/buffer_pool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ pub const FrameManager = struct {
entry.value_ptr.* = frame_ref.index;
eviction_lfu.key[frame_ref.index] = key;

std.debug.assert(!std.meta.eql(evicted_key, key)); // inserted key we just evicted
std.debug.assert(evicted_key != key); // inserted key we just evicted

const removed = frame_map.swapRemove(evicted_key);
std.debug.assert(removed); // evicted key was not in map
Expand Down
5 changes: 3 additions & 2 deletions src/accountsdb/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3875,6 +3875,7 @@ test "load sysvars" {
}

test "generate snapshot & update gossip snapshot hashes" {
const GossipDataTag = sig.gossip.data.GossipDataTag;
const SnapshotHashes = sig.gossip.data.SnapshotHashes;

const allocator = std.testing.allocator;
Expand Down Expand Up @@ -3956,7 +3957,7 @@ test "generate snapshot & update gossip snapshot hashes" {

try std.testing.expectEqual(1, queue.queue.items.len);
const queue_item_0 = queue.queue.items[0]; // should be from the full generation
try std.testing.expectEqual(.SnapshotHashes, std.meta.activeTag(queue_item_0));
try std.testing.expectEqual(.SnapshotHashes, @as(GossipDataTag, queue_item_0));

try std.testing.expectEqualDeep(
SnapshotHashes{
Expand Down Expand Up @@ -4006,7 +4007,7 @@ test "generate snapshot & update gossip snapshot hashes" {

try std.testing.expectEqual(2, queue.queue.items.len);
const queue_item_1 = queue.queue.items[1]; // should be from the incremental generation
try std.testing.expectEqual(.SnapshotHashes, std.meta.activeTag(queue_item_1));
try std.testing.expectEqual(.SnapshotHashes, @as(GossipDataTag, queue_item_1));

try std.testing.expectEqualDeep(
SnapshotHashes{
Expand Down
2 changes: 1 addition & 1 deletion src/accountsdb/download.zig
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn downloadSnapshotsFromGossip(
var function_duration = try std.time.Timer.start();
var download_attempts: u64 = 0;
while (true) {
std.time.sleep(5 * std.time.ns_per_s); // wait while gossip table updates
std.Thread.sleep(5 * std.time.ns_per_s); // wait while gossip table updates

if (download_attempts > max_number_of_download_attempts) {
logger.err().logf(
Expand Down
2 changes: 1 addition & 1 deletion src/accountsdb/fuzz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ fn readRandomAccounts(
const tracked_pubkeys = tracked_accounts.keys();
if (tracked_pubkeys.len == 0) {
// wait for some accounts to exist
std.time.sleep(std.time.ns_per_s);
std.Thread.sleep(std.time.ns_per_s);
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/accountsdb/manager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub const Manager = struct {
const elapsed = self.timer.lap();
if (elapsed < DB_MANAGER_LOOP_MIN.asNanos()) {
const delay = DB_MANAGER_LOOP_MIN.asNanos() - elapsed;
std.time.sleep(delay);
std.Thread.sleep(delay);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/accountsdb/swiss_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ test "swissmap resize" {
// this will resize the map with the key still in there
try map.ensureTotalCapacity(200);
const get_ref = map.get(sig.core.Pubkey.ZEROES) orelse return error.MissingAccount;
try std.testing.expect(std.meta.eql(get_ref, ref));
try std.testing.expectEqual(get_ref, ref);
}

test "swissmap read/write/delete" {
Expand Down
2 changes: 1 addition & 1 deletion src/adapter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub const RpcEpochContextService = struct {
result catch |e|
self.logger.err().logf("failed to refresh epoch context via rpc: {}", .{e});
}
std.time.sleep(100 * std.time.ns_per_ms);
std.Thread.sleep(100 * std.time.ns_per_ms);
i += 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/benchmarks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn exitWithUsage() noreturn {
\\
) catch @panic("failed to print usage");

inline for (std.meta.fields(Benchmark)) |field| {
inline for (@typeInfo(Benchmark).@"enum".fields) |field| {
stdout.print(
" {s}\n",
.{field.name},
Expand Down
2 changes: 1 addition & 1 deletion src/geyser/benchmark.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn runBenchmark(logger: sig.trace.Logger("geyser.benchmark")) !void {

// let it run for ~4 measurements
const NUM_MEAUSUREMENTS = 4;
std.time.sleep(MEASURE_RATE.asNanos() * NUM_MEAUSUREMENTS);
std.Thread.sleep(MEASURE_RATE.asNanos() * NUM_MEAUSUREMENTS);
exit.store(true, .release);

reader_handle.join();
Expand Down
2 changes: 1 addition & 1 deletion src/geyser/core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub const GeyserWriter = struct {
const buf = self.io_allocator.alloc(u8, total_len) catch {
// no memory available rn - unlock and wait
self.metrics.recycle_fba_empty_loop_count.inc();
std.time.sleep(std.time.ns_per_ms);
std.Thread.sleep(std.time.ns_per_ms);
if (self.exit.load(.acquire)) {
return error.MemoryBlockedWithExitSignaled;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gossip/data.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ test "LegacyContactInfo <-> ContactInfo roundtrip" {
defer ci.deinit();
const end = LegacyContactInfo.fromContactInfo(&ci);

try std.testing.expect(std.meta.eql(start, end));
try std.testing.expectEqual(start, end);
}

test "sanitize valid ContactInfo works" {
Expand Down
2 changes: 1 addition & 1 deletion src/gossip/dump_service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub const GossipDumpService = struct {

while (self.exit_condition.shouldRun()) {
try self.dumpGossip(dir, start_time);
std.time.sleep(DUMP_INTERVAL.asNanos());
std.Thread.sleep(DUMP_INTERVAL.asNanos());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gossip/fuzz_service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub fn fuzz(
std.debug.print("{d} messages sent\n", .{msg_count});
last_print_msg_count = msg_count;
}
std.time.sleep(SLEEP_TIME.asNanos());
std.Thread.sleep(SLEEP_TIME.asNanos());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/gossip/service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ pub const GossipService = struct {
// sleep
if (loop_timer.read().asNanos() < BUILD_MESSAGE_LOOP_MIN.asNanos()) {
const time_left_ms = BUILD_MESSAGE_LOOP_MIN.asMillis() -| loop_timer.read().asMillis();
std.time.sleep(time_left_ms * std.time.ns_per_ms);
std.Thread.sleep(time_left_ms * std.time.ns_per_ms);
}
}
}
Expand Down Expand Up @@ -2648,12 +2648,12 @@ test "handle old prune & pull request message" {
const MAX_N_SLEEPS = 100;
var i: u64 = 0;
while (gossip_service.metrics.pull_requests_dropped.get() != 2) {
std.time.sleep(std.time.ns_per_ms * 100);
std.Thread.sleep(std.time.ns_per_ms * 100);
if (i > MAX_N_SLEEPS) return error.LoopRangeExceeded;
i += 1;
}
while (gossip_service.metrics.prune_messages_dropped.get() != 1) {
std.time.sleep(std.time.ns_per_ms * 100);
std.Thread.sleep(std.time.ns_per_ms * 100);
if (i > MAX_N_SLEEPS) return error.LoopRangeExceeded;
i += 1;
}
Expand Down Expand Up @@ -3270,7 +3270,7 @@ test "process contact info push packet" {
const MAX_N_SLEEPS = 100;
var i: u64 = 0;
while (gossip_service.metrics.gossip_packets_processed_total.get() != valid_messages_sent) {
std.time.sleep(std.time.ns_per_ms * 100);
std.Thread.sleep(std.time.ns_per_ms * 100);
if (i > MAX_N_SLEEPS) return error.LoopRangeExceeded;
i += 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/net/socket_utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ const XevThread = struct {
if (rc.active == 1) {
// Lock the ref_count to detect if theres races (i.e. another spawn()) during shutdown.
rc = @bitCast(ref_count.swap(@bitCast(RefCount{ .shutdown = true }), .acquire));
std.debug.assert(std.meta.eql(rc, RefCount{}));
std.debug.assert(rc == .{});

defer {
rc = @bitCast(ref_count.swap(@bitCast(RefCount{}), .release));
std.debug.assert(std.meta.eql(rc, RefCount{ .shutdown = true }));
std.debug.assert(rc == .{ .shutdown = true });
}

notifyIoThread(); // wake up xev thread to see ref_count.shutdown to stop/shutdown
Expand Down Expand Up @@ -518,7 +518,7 @@ test "SocketThread: overload sendto" {
}

// Wait for all sends to have started/happened.
while (!send_channel.isEmpty()) std.time.sleep(10 * std.time.ns_per_ms);
while (!send_channel.isEmpty()) std.Thread.sleep(10 * std.time.ns_per_ms);
}

pub const BenchmarkPacketProcessing = struct {
Expand Down Expand Up @@ -586,7 +586,7 @@ pub const BenchmarkPacketProcessing = struct {
if (i % 10 == 0) {
const elapsed = timer.read();
if (elapsed < std.time.ns_per_s) {
std.time.sleep(std.time.ns_per_s);
std.Thread.sleep(std.time.ns_per_s);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/prometheus/http.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn main() !void {
var gauge = try reg.getOrCreateGauge("seconds_hand", u64);
var hist = try reg.getOrCreateHistogram("hist", &DEFAULT_BUCKETS);
while (true) {
std.time.sleep(1_000_000_000);
std.Thread.sleep(1_000_000_000);
secs_counter.inc();
gauge.set(@as(u64, @intCast(std.time.timestamp())) % @as(u64, 60));
hist.observe(1.1);
Expand Down
6 changes: 2 additions & 4 deletions src/rpc/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ pub const Client = struct {
allocator: Allocator,
id: rpc.request.Id,
comptime method: MethodAndParams.Tag,
// TODO: use this instead of `std.meta.FieldType` to avoid eval branch quota until `@FieldType`'s here.
params: @typeInfo(MethodAndParams).@"union".fields[@intFromEnum(method)].type,
params: @FieldType(MethodAndParams, @tagName(method)),
) Error!Response(@TypeOf(params).Response) {
const request: rpc.request.Request = .{
.id = id,
Expand All @@ -58,8 +57,7 @@ pub const Client = struct {
self: *Client,
id: rpc.request.Id,
comptime method: MethodAndParams.Tag,
// TODO: use this instead of `std.meta.FieldType` to avoid eval branch quota until `@FieldType`'s here.
request: @typeInfo(MethodAndParams).@"union".fields[@intFromEnum(method)].type,
request: @FieldType(MethodAndParams, @tagName(method)),
) Error!Response(@TypeOf(request).Response) {
return try self.fetchCustom(
self.fetcher.http_client.allocator,
Expand Down
3 changes: 1 addition & 2 deletions src/rpc/request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ pub const Request = struct {

const method_and_params = switch (method) {
inline else => |tag| @unionInit(MethodAndParams, @tagName(tag), blk: {
// NOTE: using `std.meta.FieldType` here hits eval branch quota, hack until `@FieldType`
const Params = @typeInfo(MethodAndParams).@"union".fields[@intFromEnum(tag)].type;
const Params = @FieldType(MethodAndParams, @tagName(tag));
if (Params == noreturn) {
std.debug.panic("TODO: implement {s}", .{@tagName(method)});
}
Expand Down
3 changes: 1 addition & 2 deletions src/rpc/test_serialize.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const Response = rpc.response.Response;
fn testRequest(
comptime method: methods.MethodAndParams.Tag,
/// passed into the client
// TODO: use this instead of `std.meta.FieldType` to avoid eval branch quota until `@FieldType`'s here.
params: @typeInfo(methods.MethodAndParams).@"union".fields[@intFromEnum(method)].type,
params: @FieldType(methods.MethodAndParams, @tagName(method)),
/// test will assert the request serializes to this json
expected_request_json: []const u8,
) !void {
Expand Down
Loading