diff --git a/scripts/style.py b/scripts/style.py index 4c676442d..6bde1848a 100644 --- a/scripts/style.py +++ b/scripts/style.py @@ -117,138 +117,82 @@ def unused_imports(args, files_to_check): print("Total unused imports found:", total_lines_removed) else: print("Total unused imports removed:", total_lines_removed) - + return total_lines_removed files_excluded_from_line_length_check = [ - "src/accountsdb/accounts_file.zig", - "src/accountsdb/bank.zig", - "src/accountsdb/cache.zig", - "src/accountsdb/db.zig", - "src/accountsdb/download.zig", - "src/accountsdb/fuzz_snapshot.zig", - "src/accountsdb/fuzz.zig", - "src/accountsdb/genesis_config.zig", - "src/accountsdb/index.zig", - "src/accountsdb/snapshots.zig", - "src/accountsdb/swiss_map.zig", - "src/accountsdb/sysvars.zig", - "src/benchmarks.zig", - "src/bincode/arraylist.zig", - "src/bincode/bincode.zig", - "src/bincode/bincode.zig", - "src/bincode/hashmap.zig", - "src/bincode/int.zig", - "src/bincode/list.zig", - "src/bincode/optional.zig", + "src/prometheus/metric.zig", + "src/prometheus/histogram.zig", + "src/prometheus/registry.zig", + "src/cmd/helpers.zig", + "src/geyser/core.zig", + "src/rpc/request.zig", "src/bincode/shortvec.zig", - "src/bincode/varint.zig", - "src/bloom/bit_set.zig", - "src/common/lru.zig", - "src/common/merkle_tree.zig", - "src/fuzz.zig", - "src/geyser/main.zig", - "src/gossip/service.zig", + "src/ledger/database/rocksdb.zig", + "src/ledger/database/hashmap.zig", + "src/accountsdb/bank.zig", + "src/net/echo.zig", + "src/utils/types.zig", "src/gossip/shards.zig", - "src/gossip/table.zig", + "src/bloom/bitvec.zig", + "src/bincode/int.zig", "src/ledger/benchmarks.zig", - "src/ledger/cleanup_service.zig", - "src/ledger/database/hashmap.zig", - "src/ledger/database/interface.zig", - "src/ledger/database/rocksdb.zig", - "src/ledger/meta.zig", - "src/ledger/reader.zig", - "src/ledger/reed_solomon_table.zig", - "src/ledger/reed_solomon.zig", + "src/core/leader_schedule.zig", + "src/shred_collector/repair_message.zig", + "src/gossip/pull_request.zig", + "src/bincode/arraylist.zig", + "src/utils/thread.zig", + "src/utils/allocators.zig", + "src/gossip/message.zig", + "src/bloom/bloom.zig", + "src/bloom/bit_vec.zig", "src/ledger/result_writer.zig", - "src/ledger/schema.zig", - "src/ledger/shred_inserter/merkle_root_checks.zig", - "src/ledger/shred_inserter/recovery.zig", + "src/time/time.zig", + "src/utils/tar.zig", + "src/utils/fmt.zig", + "src/gossip/fuzz_table.zig", + "src/bloom/bit_set.zig", + "src/accountsdb/sysvars.zig", "src/ledger/shred_inserter/shred_inserter.zig", - "src/ledger/shred_inserter/slot_chaining.zig", + "src/accountsdb/swiss_map.zig", "src/ledger/shred_inserter/working_state.zig", - "src/ledger/shred.zig", - "src/ledger/shredder.zig", - "src/ledger/test_shreds.zig", - "src/ledger/tests.zig", - "src/ledger/transaction_status.zig", - "src/net/echo.zig", - "src/net/net.zig", - "src/net/socket_utils.zig", - "src/prometheus/histogram.zig", - "src/prometheus/metric.zig", - "src/prometheus/registry.zig", - "src/rand/rand.zig", - "src/rpc/client.zig", - "src/rpc/client.zig", - "src/rpc/request.zig", - "src/rpc/request.zig", - "src/rpc/response.zig", - "src/shred_collector/repair_message.zig", + "src/accountsdb/fuzz_snapshot.zig", "src/shred_collector/repair_service.zig", - "src/shred_collector/service.zig", - "src/shred_collector/shred_processor.zig", - "src/shred_collector/shred_receiver.zig", - "src/shred_collector/shred_tracker.zig", - "src/shred_collector/shred_verifier.zig", - "src/sync/channel.zig", - "src/sync/channel.zig", - "src/sync/mux.zig", - "src/sync/once_cell.zig", - "src/sync/ref.zig", - "src/sync/ref.zig", - "src/sync/thread_pool.zig", - "src/sync/thread_pool.zig", - "src/tests.zig", - "src/time/time.zig", - "src/trace/log.zig", - "src/transaction_sender/leader_info.zig", - "src/transaction_sender/mock_transfer_generator.zig", - "src/transaction_sender/mock_transfer_generator.zig", "src/transaction_sender/service.zig", - "src/transaction_sender/service.zig", - "src/transaction_sender/transaction_info.zig", - "src/transaction_sender/transaction_pool.zig", + "src/gossip/fuzz_service.zig", + "src/sync/thread_pool.zig", "src/transaction_sender/transaction_pool.zig", - "src/utils/allocators.zig", - "src/utils/collections.zig", - "src/utils/fmt.zig", - "src/utils/fmt.zig", - "src/utils/tar.zig", - "src/utils/tar.zig", - "src/utils/thread.zig", - "src/utils/thread.zig", - "src/utils/types.zig", - "src/bloom/bit_vec.zig", - "src/bloom/bitvec.zig", - "src/bloom/bloom.zig", - "src/cmd/cmd.zig", - "src/cmd/config.zig", - "src/cmd/helpers.zig", - "src/core/account.zig", - "src/core/epoch_schedule.zig", - "src/core/hard_forks.zig", - "src/core/leader_schedule.zig", - "src/core/shred.zig", + "src/gossip/ping_pong.zig", + "src/accountsdb/download.zig", + "src/accountsdb/fuzz.zig", + "src/ledger/reader.zig", + "src/rpc/client.zig", + "src/accountsdb/index.zig", + "src/ledger/cleanup_service.zig", + "src/ledger/reed_solomon.zig", + "src/benchmarks.zig", + "src/transaction_sender/mock_transfer_generator.zig", "src/core/transaction.zig", - "src/crypto/base58.zig", - "src/geyser/core.zig", - "src/gossip/active_set.zig", + "src/net/net.zig", + "src/cmd/cmd.zig", + "src/bincode/bincode.zig", + "src/accountsdb/snapshots.zig", "src/gossip/data.zig", - "src/gossip/dump_service.zig", - "src/gossip/fuzz_service.zig", - "src/gossip/fuzz_table.zig", - "src/gossip/message.zig", - "src/gossip/ping_pong.zig", - "src/gossip/pull_request.zig", - "src/gossip/pull_response.zig", + "src/gossip/service.zig", + "src/accountsdb/db.zig", + "src/rand/rand.zig", + "src/ledger/reed_solomon_table.zig", + "src/ledger/shred.zig", + "src/ledger/test_shreds.zig", ] def line_length(args, files_to_check): """Enforces lines of code to be at most 100 characters long.""" - unique_files = [] + + # map relating file paths to the number of lines that are too long + unique_files = {} lines_found = 0 @@ -258,21 +202,28 @@ def line_length(args, files_to_check): with open(path) as f: lines = f.readlines() for i, line in enumerate(lines): + # ignore comments. these are lines where the first non-whitespace characters + # are "//" + if line.strip().startswith("//"): + continue if len(line) > MAX_LINE_LENGTH: print(f"{path}:{i + 1} is too long: {len(line)}") lines_found += 1 if path not in unique_files: - unique_files.append(path) + unique_files[path] = 1 + else: + unique_files[path] += 1 print(line) print("Files checked:", len(files_to_check)) print("Lines found:", lines_found) - for file in unique_files: - print(f'"{file}",') + # sorted_files = sorted(unique_files.items(), key=lambda x: x[1]) + # for file, num_lines in sorted_files: + # print(f'"{file}",') return lines_found -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/src/accountsdb/accounts_file.zig b/src/accountsdb/accounts_file.zig index 8e9c6c900..d1dba0b6a 100644 --- a/src/accountsdb/accounts_file.zig +++ b/src/accountsdb/accounts_file.zig @@ -185,7 +185,10 @@ pub const AccountInFile = struct { } } - pub fn toOwnedAccount(self: *const Self, allocator: std.mem.Allocator) std.mem.Allocator.Error!Account { + pub fn toOwnedAccount( + self: *const Self, + allocator: std.mem.Allocator, + ) std.mem.Allocator.Error!Account { const owned_data = try allocator.dupe(u8, self.data); return .{ .data = owned_data, @@ -312,7 +315,10 @@ pub const AccountFile = struct { /// get account without reading data (a lot faster if the data field isnt used anyway) /// (used when computing account hashes for snapshot validation) - pub fn getAccountHashAndLamports(self: *const Self, start_offset: usize) error{EOF}!struct { hash: *Hash, lamports: *u64 } { + pub fn getAccountHashAndLamports( + self: *const Self, + start_offset: usize, + ) error{EOF}!struct { hash: *Hash, lamports: *u64 } { var offset = start_offset; offset += @sizeOf(AccountInFile.StorageInfo); diff --git a/src/accountsdb/cache.zig b/src/accountsdb/cache.zig index b17b52ce0..efcdc9ca5 100644 --- a/src/accountsdb/cache.zig +++ b/src/accountsdb/cache.zig @@ -25,7 +25,11 @@ pub const AccountsCache = struct { /// Makes use of the fact that CachedAccount needs to live on the heap & shares its lifetime /// with .ref_count in order to allocate once instead of twice. - pub fn initCreate(allocator: std.mem.Allocator, account: Account, slot: Slot) error{OutOfMemory}!*CachedAccount { + pub fn initCreate( + allocator: std.mem.Allocator, + account: Account, + slot: Slot, + ) error{OutOfMemory}!*CachedAccount { const buf = try allocator.alignedAlloc( u8, @alignOf(CachedAccount), diff --git a/src/accountsdb/db.zig b/src/accountsdb/db.zig index 4a102a981..a5d625901 100644 --- a/src/accountsdb/db.zig +++ b/src/accountsdb/db.zig @@ -1907,7 +1907,7 @@ pub const AccountsDB = struct { // the queue if it deleted any accounts refs. const dead_accounts_counter, var dead_accounts_counter_lg = self.dead_accounts_counter.writeWithLock(); defer dead_accounts_counter_lg.unlock(); - const removed = dead_accounts_counter.fetchSwapRemove(slot) orelse unreachable; + const removed = dead_accounts_counter.fetchSwapRemove(slot).?; std.debug.assert(removed.value == accounts_dead_count); } } @@ -3150,7 +3150,7 @@ pub fn writeSnapshotTarWithFields( try snapgen.writeAccountsDirHeader(archive_writer_counted); const file_info_map = manifest.accounts_db_fields.file_map; for (file_info_map.keys(), file_info_map.values()) |file_slot, file_info| { - const account_file = file_map.getPtr(file_info.id) orelse unreachable; + const account_file = file_map.getPtr(file_info.id).?; std.debug.assert(account_file.id == file_info.id); std.debug.assert(account_file.length == file_info.length); diff --git a/src/bincode/hashmap.zig b/src/bincode/hashmap.zig index bcbaa44f1..3b1772225 100644 --- a/src/bincode/hashmap.zig +++ b/src/bincode/hashmap.zig @@ -33,8 +33,20 @@ pub fn hashMapFieldConfig( var iter = data.iterator(); while (iter.next()) |entry| { - try writeFieldWithConfig(key_info, config.key, writer, entry.key_ptr.*, params); - try writeFieldWithConfig(value_info, config.value, writer, entry.value_ptr.*, params); + try writeFieldWithConfig( + key_info, + config.key, + writer, + entry.key_ptr.*, + params, + ); + try writeFieldWithConfig( + value_info, + config.value, + writer, + entry.value_ptr.*, + params, + ); } } @@ -44,7 +56,8 @@ pub fn hashMapFieldConfig( params: Params, ) anyerror!HashMapType { const Size = if (hm_info.kind == .unordered) HashMapType.Size else usize; - const len = (try readIntAsLength(Size, reader, params)) orelse return error.HashMapTooBig; + const len = try readIntAsLength(Size, reader, params) orelse + return error.HashMapTooBig; var data: HashMapType = switch (hm_info.management) { .managed => HashMapType.init(allocator), @@ -60,10 +73,22 @@ pub fn hashMapFieldConfig( const key_field = std.meta.fieldInfo(HashMapType.KV, .key); const value_field = std.meta.fieldInfo(HashMapType.KV, .value); for (0..len) |_| { - const key = try readFieldWithConfig(allocator, reader, params, key_field, config.key); + const key = try readFieldWithConfig( + allocator, + reader, + params, + key_field, + config.key, + ); errdefer bincode.free(allocator, key); - const value = try readFieldWithConfig(allocator, reader, params, value_field, config.value); + const value = try readFieldWithConfig( + allocator, + reader, + params, + value_field, + config.value, + ); errdefer bincode.free(allocator, value); const gop = data.getOrPutAssumeCapacity(key); diff --git a/src/bincode/list.zig b/src/bincode/list.zig index 7c99416e4..3f6fd8636 100644 --- a/src/bincode/list.zig +++ b/src/bincode/list.zig @@ -13,7 +13,8 @@ pub fn valueEncodedAsSlice( reader: anytype, params: bincode.Params, ) anyerror!T { - const len = (try bincode.readIntAsLength(usize, reader, params)) orelse return Error.SingleElementSliceInvalidLength; + const len = (try bincode.readIntAsLength(usize, reader, params)) orelse + return Error.SingleElementSliceInvalidLength; if (len != 1) return Error.SingleElementSliceInvalidLength; if (config.deserializer) |deserialize| { return try deserialize(allocator, reader, params); diff --git a/src/bincode/varint.zig b/src/bincode/varint.zig index 2d5b3f84c..acdb81808 100644 --- a/src/bincode/varint.zig +++ b/src/bincode/varint.zig @@ -16,7 +16,11 @@ pub fn VarIntConfig(comptime VarInt: type) bincode.FieldConfig(VarInt) { try writer.writeByte(@as(u8, @intCast(v))); } - pub fn deserialize(allocator: std.mem.Allocator, reader: anytype, params: bincode.Params) !VarInt { + pub fn deserialize( + allocator: std.mem.Allocator, + reader: anytype, + params: bincode.Params, + ) !VarInt { _ = params; _ = allocator; diff --git a/src/cmd/cmd.zig b/src/cmd/cmd.zig index 487e68263..6c9ecf83c 100644 --- a/src/cmd/cmd.zig +++ b/src/cmd/cmd.zig @@ -64,7 +64,10 @@ pub fn run() !void { var gossip_host_option = cli.Option{ .long_name = "gossip-host", - .help = "IPv4 address for the validator to advertise in gossip - default: get from --entrypoint, fallback to 127.0.0.1", + .help = + \\IPv4 address for the validator to advertise in gossip + \\ - default: get from --entrypoint, fallback to 127.0.0.1" + , .value_ref = cli.mkRef(&config.current.gossip.host), .required = false, .value_name = "Gossip Host", @@ -261,7 +264,11 @@ pub fn run() !void { var accounts_per_file_estimate = cli.Option{ .long_name = "accounts-per-file-estimate", .short_alias = 'a', - .help = "number of accounts to estimate inside of account files (used for pre-allocation). Safer to set it larger than smaller (approx values we found work well testnet/devnet: 1_500, mainnet: 3_000).", + .help = + \\number of accounts to estimate inside of account files (used for pre-allocation). + \\Safer to set it larger than smaller. + \\(approx values we found work well testnet/devnet: 1_500, mainnet: 3_000)" + , .value_ref = cli.mkRef(&config.current.accounts_db.accounts_per_file_estimate), .required = false, .value_name = "accounts_per_file_estimate", @@ -420,9 +427,10 @@ pub fn run() !void { \\ NOTE: this means that this command *requires* a leader schedule to be provided \\ (which would usually be derived from the accountsdb snapshot). \\ - \\ NOTE: this command also requires `start_slot` (`--test-repair-for-slot`) to be given as well ( - \\ which is usually derived from the accountsdb snapshot). This can be done - \\ with `--test-repair-for-slot $(solana slot -u testnet)` for testnet or another `-u` for mainnet/devnet. + \\ NOTE: this command also requires `start_slot` (`--test-repair-for-slot`) to be given as well + \\ (which is usually derived from the accountsdb snapshot). + \\ This can be done with `--test-repair-for-slot $(solana slot -u testnet)` + \\ for testnet or another `-u` for mainnet/devnet. }, .options = &.{ // gossip @@ -800,7 +808,8 @@ fn shredCollector() !void { // This is a sort of hack to get the epoch of the leader schedule and then insert into the cache const start_slot, const leader_schedule = try getLeaderScheduleFromCli(allocator) orelse @panic("No leader schedule found"); - const leader_schedule_epoch = leader_schedule_cache.epoch_schedule.getEpoch(start_slot); // first_slot is non null iff leader schedule is built from cli + // first_slot is non null iff leader schedule is built from cli + const leader_schedule_epoch = leader_schedule_cache.epoch_schedule.getEpoch(start_slot); try leader_schedule_cache.put(leader_schedule_epoch, leader_schedule); const leader_provider = leader_schedule_cache.slotLeaderProvider(); @@ -1034,10 +1043,11 @@ fn printLeaderSchedule() !void { return err; } }; - _, const slot_index = loaded_snapshot.bank.bank_fields.epoch_schedule.getEpochAndSlotIndex(loaded_snapshot.bank.bank_fields.slot); + const bank_fields = loaded_snapshot.bank.bank_fields; + _, const slot_index = bank_fields.epoch_schedule.getEpochAndSlotIndex(bank_fields.slot); break :b .{ - loaded_snapshot.bank.bank_fields.slot - slot_index, - try loaded_snapshot.bank.bank_fields.leaderSchedule(allocator), + bank_fields.slot - slot_index, + try bank_fields.leaderSchedule(allocator), }; }; @@ -1066,7 +1076,8 @@ pub fn testTransactionSenderService() !void { const allocator = gpa_allocator; // read genesis (used for leader schedule) - const genesis_file_path = try config.current.genesisFilePath() orelse @panic("No genesis file path found: use -g or -n"); + const genesis_file_path = try config.current.genesisFilePath() orelse + @panic("No genesis file path found: use -g or -n"); const genesis_config = try readGenesisConfig(allocator, genesis_file_path); // start gossip (used to get TPU ports of leaders) @@ -1508,7 +1519,10 @@ fn loadSnapshot( // validate the status cache result.status_cache = readStatusCache(allocator, snapshot_dir) catch |err| { if (err == error.StatusCacheNotFound) { - logger.err().logf("status-cache.bin not found - expecting {s}/snapshots/status-cache to exist", .{snapshot_dir_str}); + logger.err().logf( + "status-cache.bin not found - expecting {s}/snapshots/status-cache to exist", + .{snapshot_dir_str}, + ); } return err; }; @@ -1702,7 +1716,10 @@ fn getOrDownloadSnapshots( timer.reset(); logger.info().logf("unpacking {s}...", .{snapshot_files.full_snapshot.snapshotNameStr().constSlice()}); { - const archive_file = try snapshot_dir.openFile(snapshot_files.full_snapshot.snapshotNameStr().constSlice(), .{}); + const archive_file = try snapshot_dir.openFile( + snapshot_files.full_snapshot.snapshotNameStr().constSlice(), + .{}, + ); defer archive_file.close(); try parallelUnpackZstdTarBall( allocator, diff --git a/src/common/lru.zig b/src/common/lru.zig index 6c6120e94..88b550d44 100644 --- a/src/common/lru.zig +++ b/src/common/lru.zig @@ -56,7 +56,10 @@ pub fn LruCacheCustom( return struct { mux: if (kind == .locking) Mutex else void, allocator: Allocator, - hashmap: if (K == []const u8) std.StringArrayHashMap(*Node) else std.AutoArrayHashMap(K, *Node), + hashmap: if (K == []const u8) + std.StringArrayHashMap(*Node) + else + std.AutoArrayHashMap(K, *Node), dbl_link_list: TailQueue(LruEntry), max_items: usize, len: usize = 0, @@ -104,7 +107,10 @@ pub fn LruCacheCustom( max_items: usize, deinit_context: DeinitContext, ) error{OutOfMemory}!Self { - const hashmap = if (K == []const u8) std.StringArrayHashMap(*Node).init(allocator) else std.AutoArrayHashMap(K, *Node).init(allocator); + const hashmap = if (K == []const u8) + std.StringArrayHashMap(*Node).init(allocator) + else + std.AutoArrayHashMap(K, *Node).init(allocator); var self = Self{ .allocator = allocator, .hashmap = hashmap, @@ -129,9 +135,14 @@ pub fn LruCacheCustom( self.hashmap.deinit(); } - /// Recycles an old node if LruCache capacity is full. If replaced, first element of tuple is replaced + /// Recycles an old node if LruCache capacity is full. + /// If replaced, first element of tuple is replaced. /// Entry (otherwise null) and second element of tuple is inserted Entry. - fn internalRecycleOrCreateNode(self: *Self, key: K, value: V) error{OutOfMemory}!struct { ?LruEntry, LruEntry } { + fn internalRecycleOrCreateNode( + self: *Self, + key: K, + value: V, + ) error{OutOfMemory}!struct { ?LruEntry, LruEntry } { if (self.dbl_link_list.len == self.max_items) { const recycled_node = self.dbl_link_list.popFirst().?; deinitFn(&recycled_node.data.value, self.deinit_context); @@ -163,11 +174,10 @@ pub fn LruCacheCustom( return existing_node.data; } - const replaced_and_created_node = self.internalRecycleOrCreateNode(key, value) catch |e| { + const replaced_node = self.internalRecycleOrCreateNode(key, value) catch |e| { std.debug.panic("recycle_or_create_node returned error: {any}", .{e}); }; - const new_lru_entry = replaced_and_created_node[1]; - return new_lru_entry; + return replaced_node[1]; } /// Inserts key/value if key doesn't exist, updates only value if it does. @@ -254,8 +264,9 @@ pub fn LruCacheCustom( return null; } - /// Puts a key-value pair into cache. If the key already exists in the cache, then it updates - /// the key's value and returns the old value. Otherwise, `null` is returned. + /// Puts a key-value pair into cache. If the key already exists in the cache, + /// then it updates the key's value and returns the old value. + /// Otherwise, `null` is returned. pub fn put(self: *Self, key: K, value: V) ?V { if (kind == .locking) self.mux.lock(); defer if (kind == .locking) self.mux.unlock(); diff --git a/src/core/account.zig b/src/core/account.zig index c1175b969..7ed1b1559 100644 --- a/src/core/account.zig +++ b/src/core/account.zig @@ -173,6 +173,11 @@ test "core.account: test account hash matches rust" { &pubkey.data, ); - const expected_hash: [32]u8 = .{ 170, 75, 87, 73, 60, 156, 174, 14, 105, 6, 129, 108, 167, 156, 166, 213, 28, 4, 163, 187, 252, 155, 24, 253, 158, 13, 86, 100, 103, 89, 232, 28 }; + const expected_hash: [32]u8 = .{ + 170, 75, 87, 73, 60, 156, 174, 14, 105, + 6, 129, 108, 167, 156, 166, 213, 28, 4, + 163, 187, 252, 155, 24, 253, 158, 13, 86, + 100, 103, 89, 232, 28, + }; try std.testing.expect(std.mem.eql(u8, &expected_hash, &hash.data)); } diff --git a/src/core/epoch_schedule.zig b/src/core/epoch_schedule.zig index 9b623ca10..e775964b0 100644 --- a/src/core/epoch_schedule.zig +++ b/src/core/epoch_schedule.zig @@ -55,7 +55,11 @@ pub const EpochSchedule = extern struct { return .{ epoch, slot_index }; } else { const normal_slot_index = slot -| self.first_normal_slot; - const normal_epoch_index = std.math.divTrunc(u64, normal_slot_index, self.slots_per_epoch) catch 0; + const normal_epoch_index = std.math.divTrunc( + u64, + normal_slot_index, + self.slots_per_epoch, + ) catch 0; const epoch = self.first_normal_epoch +| normal_epoch_index; const slot_index = std.math.rem(u64, normal_slot_index, self.slots_per_epoch) catch 0; @@ -80,7 +84,11 @@ pub const EpochSchedule = extern struct { ); } - pub fn custom(slots_per_epoch: u64, leader_schedule_slot_offset: u64, warmup: bool) !EpochSchedule { + pub fn custom( + slots_per_epoch: u64, + leader_schedule_slot_offset: u64, + warmup: bool, + ) !EpochSchedule { std.debug.assert(slots_per_epoch > MINIMUM_SLOTS_PER_EPOCH); var first_normal_epoch: Epoch = 0; var first_normal_slot: Slot = 0; diff --git a/src/core/hard_forks.zig b/src/core/hard_forks.zig index 8a171d2e7..6fe324993 100644 --- a/src/core/hard_forks.zig +++ b/src/core/hard_forks.zig @@ -21,7 +21,10 @@ pub const HardForks = struct { } else null; if (maybe_index) |index| { - self.hard_forks.items[index] = .{ .slot = new_slot, .count = self.hard_forks.items[index].count +| 1 }; + self.hard_forks.items[index] = .{ + .slot = new_slot, + .count = self.hard_forks.items[index].count +| 1, + }; } else { try self.hard_forks.append(.{ .slot = new_slot, .count = 1 }); } diff --git a/src/core/shred.zig b/src/core/shred.zig index daf642838..e952ff041 100644 --- a/src/core/shred.zig +++ b/src/core/shred.zig @@ -40,7 +40,11 @@ test "core.shred: test ShredVersion" { const Logger = @import("../trace/log.zig").Logger; const DirectPrintLogger = @import("../trace/log.zig").DirectPrintLogger; - var hash = Hash{ .data = [_]u8{ 180, 194, 54, 239, 216, 26, 164, 170, 3, 72, 104, 87, 32, 189, 12, 254, 9, 103, 99, 155, 117, 158, 241, 0, 95, 128, 64, 174, 42, 158, 205, 26 } }; + var hash = Hash{ .data = [_]u8{ + 180, 194, 54, 239, 216, 26, 164, 170, 3, 72, 104, 87, + 32, 189, 12, 254, 9, 103, 99, 155, 117, 158, 241, 0, + 95, 128, 64, 174, 42, 158, 205, 26, + } }; const version = ShredVersion.versionFromHash(&hash); try std.testing.expect(version == 44810); diff --git a/src/core/transaction.zig b/src/core/transaction.zig index 88ea34253..b2c7646d2 100644 --- a/src/core/transaction.zig +++ b/src/core/transaction.zig @@ -414,8 +414,10 @@ pub const CompiledKeys = struct { if (!account_meta_gopr.found_existing) { account_meta_gopr.value_ptr.* = CompiledKeyMeta.ALL_FALSE; } - account_meta_gopr.value_ptr.*.is_signer = account_meta_gopr.value_ptr.*.is_signer or account_meta.is_signer; - account_meta_gopr.value_ptr.*.is_writable = account_meta_gopr.value_ptr.*.is_writable or account_meta.is_writable; + account_meta_gopr.value_ptr.is_signer = account_meta_gopr.value_ptr.is_signer or + account_meta.is_signer; + account_meta_gopr.value_ptr.is_writable = account_meta_gopr.value_ptr.is_writable or + account_meta.is_writable; } if (maybe_payer) |payer| { @@ -436,10 +438,13 @@ pub const CompiledKeys = struct { /// Creates message header and account keys from the compiled keys. /// Account keys memory is allocated and owned by the caller. - pub fn intoMessageHeaderAndAccountKeys(self: *CompiledKeys, allocator: std.mem.Allocator) !struct { MessageHeader, []Pubkey } { - const account_keys_buf = try allocator.alloc(Pubkey, self.key_meta_map.count() - @intFromBool(self.maybe_payer == null)); + pub fn intoMessageHeaderAndAccountKeys( + self: *CompiledKeys, + allocator: std.mem.Allocator, + ) !struct { MessageHeader, []Pubkey } { + const account_keys_buf = try allocator.alloc(Pubkey, self.key_meta_map.count() - + @intFromBool(self.maybe_payer == null)); errdefer allocator.free(account_keys_buf); - var account_keys = std.ArrayListUnmanaged(Pubkey).initBuffer(account_keys_buf); var writable_signers_end: usize = 0; diff --git a/src/crypto/base58.zig b/src/crypto/base58.zig index eee4adcdb..17fa303ca 100644 --- a/src/crypto/base58.zig +++ b/src/crypto/base58.zig @@ -31,7 +31,10 @@ pub fn Base58Sized(decoded_size: usize) type { return result; } - pub fn encodeAlloc(data: [decoded_size]u8, allocator: Allocator) Allocator.Error![]const u8 { + pub fn encodeAlloc( + data: [decoded_size]u8, + allocator: Allocator, + ) Allocator.Error![]const u8 { const buf = try allocator.alloc(u8, max_encoded_size); const actual_size = encodeToSlice(data, buf[0..max_encoded_size]); return try allocator.realloc(buf, actual_size); diff --git a/src/fuzz.zig b/src/fuzz.zig index a7a7c7a38..e9315eb0e 100644 --- a/src/fuzz.zig +++ b/src/fuzz.zig @@ -54,7 +54,10 @@ pub fn main() !void { const maybe_filter = cli_args.next(); if (maybe_filter) |filter| { const parsed_filter = std.meta.stringToEnum(FuzzFilter, filter) orelse { - std.debug.print("Unknown filter. Supported values are: {s} ", .{std.meta.fieldNames(FuzzFilter)}); + std.debug.print( + "Unknown filter. Supported values are: {s} ", + .{std.meta.fieldNames(FuzzFilter)}, + ); return error.UnknownFilter; }; std.debug.print("filtering fuzz testing with prefix: {s}\n", .{filter}); diff --git a/src/geyser/main.zig b/src/geyser/main.zig index 5715b4b72..966e5d5f0 100644 --- a/src/geyser/main.zig +++ b/src/geyser/main.zig @@ -109,7 +109,9 @@ pub fn main() !void { try cli.run(&cli_app, std.heap.c_allocator); } -pub fn getOwnerFilters(allocator: std.mem.Allocator) !?std.AutoArrayHashMap(sig.core.Pubkey, void) { +pub fn getOwnerFilters( + allocator: std.mem.Allocator, +) !?std.AutoArrayHashMap(sig.core.Pubkey, void) { const owner_accounts_str = config.owner_accounts; if (owner_accounts_str.len == 0) { return null; @@ -127,7 +129,9 @@ pub fn getOwnerFilters(allocator: std.mem.Allocator) !?std.AutoArrayHashMap(sig. return owner_pubkeys; } -pub fn getAccountFilters(allocator: std.mem.Allocator) !?std.AutoArrayHashMap(sig.core.Pubkey, void) { +pub fn getAccountFilters( + allocator: std.mem.Allocator, +) !?std.AutoArrayHashMap(sig.core.Pubkey, void) { const accounts_str = config.accounts; if (accounts_str.len == 0) { return null; @@ -203,15 +207,11 @@ pub fn csvDump() !void { defer reader.deinit(); // preallocate memory for csv rows - const recycle_fba = try allocator.create(sig.utils.allocators.RecycleFBA(.{ .thread_safe = true })); - recycle_fba.* = try sig.utils.allocators.RecycleFBA(.{ .thread_safe = true }).init(.{ + var recycle_fba = try sig.utils.allocators.RecycleFBA(.{ .thread_safe = true }).init(.{ .records_allocator = allocator, .bytes_allocator = allocator, }, config.csv_buf_len); - defer { - recycle_fba.deinit(); - allocator.destroy(recycle_fba); - } + defer recycle_fba.deinit(); // setup thread to write to csv var io_channel = try sig.sync.Channel([]const u8).create(allocator); @@ -220,7 +220,12 @@ pub fn csvDump() !void { allocator.destroy(io_channel); } - const io_handle = try std.Thread.spawn(.{}, csvDumpIOWriter, .{ &exit, csv_file, io_channel, recycle_fba }); + const io_handle = try std.Thread.spawn(.{}, csvDumpIOWriter, .{ + &exit, + csv_file, + io_channel, + &recycle_fba, + }); defer io_handle.join(); errdefer exit.store(true, .release); @@ -232,8 +237,11 @@ pub fn csvDump() !void { switch (payload) { .AccountPayloadV1 => {}, .EndOfSnapshotLoading => { - // NOTE: since accounts-db isnt hooked up to the rest to the validator (svm, consensus, etc.) - // valid account state is only from snapshots. we can safely exit here because no new accounts + // NOTE: since accounts-db isnt hooked up + // to the rest to the validator (svm, consensus, etc.), + // valid account state is only from snapshots. + // + // we can safely exit here because no new accounts // are expected. logger.info().log("recv end of snapshot loading signal"); exit.store(true, .monotonic); @@ -277,7 +285,11 @@ pub fn csvDump() !void { } // build the csv row - const x = try std.fmt.bufPrint(csv_string[offset..], "{d};{s};{s};{any}\n", .{ account_payload.slot, pubkey, account.owner, account.data }); + const x = try std.fmt.bufPrint( + csv_string[offset..], + "{d};{s};{s};{any}\n", + .{ account_payload.slot, pubkey, account.owner, account.data }, + ); offset += x.len; } @@ -311,7 +323,9 @@ pub fn csvDumpIOWriter( // start time estimate on first payload written timer.reset(); } - if (payloads_written % 1_000 == 0 or total_payloads_estimate - payloads_written < 1_000) { + if (payloads_written % 1_000 == 0 or + total_payloads_estimate - payloads_written < 1_000) + { sig.time.estimate.printTimeEstimateStderr( &timer, total_payloads_estimate, diff --git a/src/gossip/active_set.zig b/src/gossip/active_set.zig index ced43d95b..ca23af15c 100644 --- a/src/gossip/active_set.zig +++ b/src/gossip/active_set.zig @@ -101,7 +101,10 @@ pub const ActiveSet = struct { origin: Pubkey, table: *const GossipTable, ) error{OutOfMemory}!std.ArrayList(EndPoint) { - var active_set_endpoints = try std.ArrayList(EndPoint).initCapacity(allocator, GOSSIP_PUSH_FANOUT); + var active_set_endpoints = try std.ArrayList(EndPoint).initCapacity( + allocator, + GOSSIP_PUSH_FANOUT, + ); errdefer active_set_endpoints.deinit(); var iter = self.peers.iterator(); diff --git a/src/gossip/dump_service.zig b/src/gossip/dump_service.zig index b02e35afb..0c109ddc5 100644 --- a/src/gossip/dump_service.zig +++ b/src/gossip/dump_service.zig @@ -89,6 +89,9 @@ pub const GossipDumpService = struct { // output results try file.writeAll("message_type,pubkey,hash,wallclock,gossip_addr,shred_version\n"); try file.writeAll(data.buf[0..data.buf_len]); - self.logger.info().logf("gossip table size at {}s: {}", .{ now -| start_time, data.table_len }); + self.logger.info().logf("gossip table size at {}s: {}", .{ + now -| start_time, + data.table_len, + }); } }; diff --git a/src/gossip/pull_response.zig b/src/gossip/pull_response.zig index c3f641047..c2e81e8b8 100644 --- a/src/gossip/pull_response.zig +++ b/src/gossip/pull_response.zig @@ -35,7 +35,11 @@ pub fn filterSignedGossipDatas( var bloom = filter.filter; - var match_indexs = try gossip_table.getBitmaskMatches(allocator, filter.mask, filter.mask_bits); + var match_indexs = try gossip_table.getBitmaskMatches( + allocator, + filter.mask, + filter.mask_bits, + ); defer match_indexs.deinit(); const output_size = @min(max_number_values, match_indexs.items.len); diff --git a/src/gossip/table.zig b/src/gossip/table.zig index b266f560e..cc4065317 100644 --- a/src/gossip/table.zig +++ b/src/gossip/table.zig @@ -221,7 +221,10 @@ pub const GossipTable = struct { .LegacyContactInfo => |*info| { try self.shred_versions.put(info.id, info.shred_version); const contact_info = try info.toContactInfo(self.allocator); - var old_info = try self.converted_contact_infos.fetchPut(info.id, contact_info); + var old_info = try self.converted_contact_infos.fetchPut( + info.id, + contact_info, + ); old_info.?.value.deinit(); }, .Vote => { @@ -230,12 +233,16 @@ pub const GossipTable = struct { try self.votes.put(self.cursor, entry_index); }, .EpochSlots => { - const did_remove = self.epoch_slots.swapRemove(old_entry.cursor_on_insertion); + const did_remove = self.epoch_slots.swapRemove( + old_entry.cursor_on_insertion, + ); std.debug.assert(did_remove); try self.epoch_slots.put(self.cursor, entry_index); }, .DuplicateShred => { - const did_remove = self.duplicate_shreds.swapRemove(old_entry.cursor_on_insertion); + const did_remove = self.duplicate_shreds.swapRemove( + old_entry.cursor_on_insertion, + ); std.debug.assert(did_remove); try self.duplicate_shreds.put(self.cursor, entry_index); }, @@ -364,7 +371,8 @@ pub const GossipTable = struct { if (self.store.get(label)) |v| { return ThreadSafeContactInfo.fromContactInfo(v.value.data.ContactInfo); } else { - return ThreadSafeContactInfo.fromContactInfo(self.converted_contact_infos.get(pubkey) orelse return null); + const contact_info = self.converted_contact_infos.get(pubkey) orelse return null; + return ThreadSafeContactInfo.fromContactInfo(contact_info); } } @@ -501,7 +509,7 @@ pub const GossipTable = struct { const value = &self.values[index]; if (value.timestamp_on_insertion >= self.minimum_insertion_timestamp) { return switch (value.value.data) { - .LegacyContactInfo => |*lci| self.converted_contact_infos.getPtr(lci.id) orelse unreachable, + .LegacyContactInfo => |*lci| self.converted_contact_infos.getPtr(lci.id).?, .ContactInfo => |*ci| ci, else => unreachable, }; @@ -523,7 +531,11 @@ pub const GossipTable = struct { } // ** helper functions ** - pub fn checkMatchingShredVersion(self: *const Self, pubkey: Pubkey, expected_shred_version: u16) bool { + pub fn checkMatchingShredVersion( + self: *const Self, + pubkey: Pubkey, + expected_shred_version: u16, + ) bool { if (self.shred_versions.get(pubkey)) |pubkey_shred_version| { if (pubkey_shred_version == expected_shred_version) { return true; @@ -546,7 +558,11 @@ pub const GossipTable = struct { /// TODO: implement a safer approach to avoid dangling pointers, such as: /// - removal buffer that is populated here and freed later /// - reference counting for all gossip values - pub fn remove(self: *Self, label: GossipKey, now: u64) error{ LabelNotFound, OutOfMemory }!void { + pub fn remove( + self: *Self, + label: GossipKey, + now: u64, + ) error{ LabelNotFound, OutOfMemory }!void { const maybe_entry = self.store.getEntry(label); if (maybe_entry == null) return error.LabelNotFound; @@ -579,6 +595,8 @@ pub const GossipTable = struct { try self.purged.insert(hash, now); self.shards.remove(entry_index, &hash); + const cursor_on_insertion = versioned_value.cursor_on_insertion; + switch (versioned_value.value.data) { .ContactInfo => { const did_remove = self.contact_infos.swapRemove(entry_index); @@ -591,22 +609,22 @@ pub const GossipTable = struct { contact_info.deinit(); }, .Vote => { - const did_remove = self.votes.swapRemove(versioned_value.cursor_on_insertion); + const did_remove = self.votes.swapRemove(cursor_on_insertion); std.debug.assert(did_remove); }, .EpochSlots => { - const did_remove = self.epoch_slots.swapRemove(versioned_value.cursor_on_insertion); + const did_remove = self.epoch_slots.swapRemove(cursor_on_insertion); std.debug.assert(did_remove); }, .DuplicateShred => { - const did_remove = self.duplicate_shreds.swapRemove(versioned_value.cursor_on_insertion); + const did_remove = self.duplicate_shreds.swapRemove(cursor_on_insertion); std.debug.assert(did_remove); }, else => {}, } { - const did_remove = self.entries.swapRemove(versioned_value.cursor_on_insertion); + const did_remove = self.entries.swapRemove(cursor_on_insertion); std.debug.assert(did_remove); } @@ -836,7 +854,10 @@ pub const HashTimeQueue = struct { // remove values up to i if (i > 0) { - var new_queue = try std.ArrayList(HashAndTime).initCapacity(self.allocator, length - i); + var new_queue = try std.ArrayList(HashAndTime).initCapacity( + self.allocator, + length - i, + ); new_queue.appendSliceAssumeCapacity(self.queue.items[i..length]); self.queue.deinit(); diff --git a/src/ledger/cleanup_service.zig b/src/ledger/cleanup_service.zig index d4b174e48..e75609ff0 100644 --- a/src/ledger/cleanup_service.zig +++ b/src/ledger/cleanup_service.zig @@ -182,7 +182,6 @@ fn findSlotsToClean( // it guarantees num_slots >= 1 for the subsequent division. const num_slots = highest_slot - lowest_slot + 1; const mean_shreds_per_slot = num_shreds / num_slots; - // std.debug.print("num_shreds: {d}, num_slots: {d}, mean_shreds_per_slot: {d}\n", .{num_shreds, num_slots, mean_shreds_per_slot}); if (num_shreds <= max_ledger_shreds) { return .{ .should_clean = false, .highest_slot_to_purge = 0, .total_shreds = num_shreds }; @@ -236,13 +235,26 @@ fn writePurgeRange(write_batch: *BlockstoreDB.WriteBatch, from_slot: Slot, to_sl try purgeRangeWithCount(write_batch, schema.dead_slots, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.duplicate_slots, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.rooted_slots, from_slot, to_slot, &delete_count); - try purgeRangeWithCount(write_batch, schema.erasure_meta, .{ .slot = from_slot, .erasure_set_index = 0 }, .{ .slot = to_slot, .erasure_set_index = 0 }, &delete_count); + try purgeRangeWithCount( + write_batch, + schema.erasure_meta, + .{ .slot = from_slot, .erasure_set_index = 0 }, + .{ .slot = to_slot, .erasure_set_index = 0 }, + &delete_count, + ); try purgeRangeWithCount(write_batch, schema.orphan_slots, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.index, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.data_shred, .{ from_slot, 0 }, .{ to_slot, 0 }, &delete_count); try purgeRangeWithCount(write_batch, schema.code_shred, .{ from_slot, 0 }, .{ to_slot, 0 }, &delete_count); - try purgeRangeWithCount(write_batch, schema.transaction_status, .{ Signature.default(), from_slot }, .{ Signature.default(), to_slot }, &delete_count); - // NOTE: for `address_signatures`, agave doesnt key based on slot for some reason (permalink comment seems incorrect?) + try purgeRangeWithCount( + write_batch, + schema.transaction_status, + .{ Signature.default(), from_slot }, + .{ Signature.default(), to_slot }, + &delete_count, + ); + // NOTE: for `address_signatures`, agave doesnt key based on slot for some reason + // (permalink comment seems incorrect) // https://github.com/anza-xyz/agave/blob/da029625d180dd1d396d26b74a5c281b7786e8c9/ledger/src/blockstore_db.rs#L962 try purgeRangeWithCount( write_batch, @@ -251,7 +263,13 @@ fn writePurgeRange(write_batch: *BlockstoreDB.WriteBatch, from_slot: Slot, to_sl .{ .slot = to_slot, .address = Pubkey.ZEROES, .transaction_index = 0, .signature = Signature.default() }, &delete_count, ); - try purgeRangeWithCount(write_batch, schema.transaction_memos, .{ Signature.default(), from_slot }, .{ Signature.default(), to_slot }, &delete_count); + try purgeRangeWithCount( + write_batch, + schema.transaction_memos, + .{ Signature.default(), from_slot }, + .{ Signature.default(), to_slot }, + &delete_count, + ); try purgeRangeWithCount(write_batch, schema.transaction_status_index, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.rewards, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.blocktime, from_slot, to_slot, &delete_count); @@ -259,7 +277,13 @@ fn writePurgeRange(write_batch: *BlockstoreDB.WriteBatch, from_slot: Slot, to_sl try purgeRangeWithCount(write_batch, schema.block_height, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.bank_hash, from_slot, to_slot, &delete_count); try purgeRangeWithCount(write_batch, schema.optimistic_slots, from_slot, to_slot, &delete_count); - try purgeRangeWithCount(write_batch, schema.merkle_root_meta, .{ .slot = from_slot, .erasure_set_index = 0 }, .{ .slot = to_slot, .erasure_set_index = 0 }, &delete_count); + try purgeRangeWithCount( + write_batch, + schema.merkle_root_meta, + .{ .slot = from_slot, .erasure_set_index = 0 }, + .{ .slot = to_slot, .erasure_set_index = 0 }, + &delete_count, + ); // slot is not indexed in this method, so this is a full purge // NOTE: do we want to do this? why not just keep the data, since it will be updated/put-back eventually try purgeRangeWithCount(write_batch, schema.program_costs, Pubkey.ZEROES, Pubkey.ZEROES, &delete_count); @@ -293,13 +317,26 @@ fn purgeFilesInRange(db: *BlockstoreDB, from_slot: Slot, to_slot: Slot) !void { try purgeFileRangeWithCount(db, schema.dead_slots, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.duplicate_slots, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.rooted_slots, from_slot, to_slot, &delete_count); - try purgeFileRangeWithCount(db, schema.erasure_meta, .{ .slot = from_slot, .erasure_set_index = 0 }, .{ .slot = to_slot, .erasure_set_index = 0 }, &delete_count); + try purgeFileRangeWithCount( + db, + schema.erasure_meta, + .{ .slot = from_slot, .erasure_set_index = 0 }, + .{ .slot = to_slot, .erasure_set_index = 0 }, + &delete_count, + ); try purgeFileRangeWithCount(db, schema.orphan_slots, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.index, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.data_shred, .{ from_slot, 0 }, .{ to_slot, 0 }, &delete_count); try purgeFileRangeWithCount(db, schema.code_shred, .{ from_slot, 0 }, .{ to_slot, 0 }, &delete_count); - try purgeFileRangeWithCount(db, schema.transaction_status, .{ Signature.default(), from_slot }, .{ Signature.default(), to_slot }, &delete_count); - // NOTE: for `address_signatures`, agave doesnt key based on slot for some reason (permalink comment seems incorrect?) + try purgeFileRangeWithCount( + db, + schema.transaction_status, + .{ Signature.default(), from_slot }, + .{ Signature.default(), to_slot }, + &delete_count, + ); + // NOTE: for `address_signatures`, agave doesnt key based on slot for some reason + // (permalink comment seems incorrect?) // https://github.com/anza-xyz/agave/blob/da029625d180dd1d396d26b74a5c281b7786e8c9/ledger/src/blockstore_db.rs#L962 try purgeFileRangeWithCount( db, @@ -308,7 +345,13 @@ fn purgeFilesInRange(db: *BlockstoreDB, from_slot: Slot, to_slot: Slot) !void { .{ .slot = to_slot, .address = Pubkey.ZEROES, .transaction_index = 0, .signature = Signature.default() }, &delete_count, ); - try purgeFileRangeWithCount(db, schema.transaction_memos, .{ Signature.default(), from_slot }, .{ Signature.default(), to_slot }, &delete_count); + try purgeFileRangeWithCount( + db, + schema.transaction_memos, + .{ Signature.default(), from_slot }, + .{ Signature.default(), to_slot }, + &delete_count, + ); try purgeFileRangeWithCount(db, schema.transaction_status_index, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.rewards, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.blocktime, from_slot, to_slot, &delete_count); @@ -316,10 +359,22 @@ fn purgeFilesInRange(db: *BlockstoreDB, from_slot: Slot, to_slot: Slot) !void { try purgeFileRangeWithCount(db, schema.block_height, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.bank_hash, from_slot, to_slot, &delete_count); try purgeFileRangeWithCount(db, schema.optimistic_slots, from_slot, to_slot, &delete_count); - try purgeFileRangeWithCount(db, schema.merkle_root_meta, .{ .slot = from_slot, .erasure_set_index = 0 }, .{ .slot = to_slot, .erasure_set_index = 0 }, &delete_count); + try purgeFileRangeWithCount( + db, + schema.merkle_root_meta, + .{ .slot = from_slot, .erasure_set_index = 0 }, + .{ .slot = to_slot, .erasure_set_index = 0 }, + &delete_count, + ); // slot is not indexed in this method, so this is a full purge // NOTE: do we want to do this? why not just keep the data, since it will be updated/put-back eventually - try purgeFileRangeWithCount(db, schema.program_costs, Pubkey.ZEROES, Pubkey.ZEROES, &delete_count); + try purgeFileRangeWithCount( + db, + schema.program_costs, + Pubkey.ZEROES, + Pubkey.ZEROES, + &delete_count, + ); // make sure we covered all the column families std.debug.assert(delete_count == ledger.schema.list.len); @@ -371,8 +426,16 @@ test "findSlotsToClean" { { var write_batch = try db.initWriteBatch(); defer write_batch.deinit(); - try write_batch.put(ledger.schema.schema.slot_meta, lowest_slot_meta.slot, lowest_slot_meta); - try write_batch.put(ledger.schema.schema.slot_meta, highest_slot_meta.slot, highest_slot_meta); + try write_batch.put( + ledger.schema.schema.slot_meta, + lowest_slot_meta.slot, + lowest_slot_meta, + ); + try write_batch.put( + ledger.schema.schema.slot_meta, + highest_slot_meta.slot, + highest_slot_meta, + ); try db.commit(&write_batch); } diff --git a/src/ledger/database/interface.zig b/src/ledger/database/interface.zig index f2b125f41..e903317e9 100644 --- a/src/ledger/database/interface.zig +++ b/src/ledger/database/interface.zig @@ -128,11 +128,20 @@ pub fn Database(comptime Impl: type) type { return try self.impl.put(cf, key, value); } - pub fn delete(self: *WriteBatch, comptime cf: ColumnFamily, key: cf.Key) anyerror!void { + pub fn delete( + self: *WriteBatch, + comptime cf: ColumnFamily, + key: cf.Key, + ) anyerror!void { return try self.impl.delete(cf, key); } - pub fn deleteRange(self: *WriteBatch, comptime cf: ColumnFamily, start: cf.Key, end: cf.Key) anyerror!void { + pub fn deleteRange( + self: *WriteBatch, + comptime cf: ColumnFamily, + start: cf.Key, + end: cf.Key, + ) anyerror!void { return try self.impl.deleteRange(cf, start, end); } }; diff --git a/src/ledger/meta.zig b/src/ledger/meta.zig index 65518edf6..630512500 100644 --- a/src/ledger/meta.zig +++ b/src/ledger/meta.zig @@ -66,7 +66,10 @@ pub const SlotMeta = struct { } pub fn clone(self: Self, allocator: Allocator) Allocator.Error!Self { - var child_slots = try std.ArrayList(Slot).initCapacity(allocator, self.child_slots.items.len); + var child_slots = try std.ArrayList(Slot).initCapacity( + allocator, + self.child_slots.items.len, + ); child_slots.appendSliceAssumeCapacity(self.child_slots.items); return .{ .slot = self.slot, diff --git a/src/ledger/shred.zig b/src/ledger/shred.zig index 1652a7020..0d6cd292f 100644 --- a/src/ledger/shred.zig +++ b/src/ledger/shred.zig @@ -634,7 +634,7 @@ fn calculateMerkleRoot(start_index: usize, start_node: Hash, proof: MerkleProofE var index = start_index; var node = start_node; for (0..proof.len) |i| { - const other = proof.get(i) orelse unreachable; + const other = proof.get(i).?; node = if (index % 2 == 0) joinNodes(&node.data, other[0..]) else @@ -1302,7 +1302,7 @@ test "merkle tree round trip" { try makeMerkleTree(&tree); const root = tree.items[tree.items.len - 1]; for (0..size) |index| { - const owned_proof = try makeMerkleProof(allocator, index, size, tree.items) orelse unreachable; + const owned_proof = (try makeMerkleProof(allocator, index, size, tree.items)).?; defer owned_proof.deinit(allocator); for (nodes.items, 0..) |node, k| { if (k == index) { diff --git a/src/ledger/shred_inserter/recovery.zig b/src/ledger/shred_inserter/recovery.zig index f2a3312a4..3d47c5c50 100644 --- a/src/ledger/shred_inserter/recovery.zig +++ b/src/ledger/shred_inserter/recovery.zig @@ -458,10 +458,12 @@ test "recover mainnet shreds - construct shreds from shards" { const expected_metadata = blk: { @setEvalBranchQuota(10_000); + break :blk RecoveryMetadata{ .common_header = CommonHeader{ .leader_signature = Signature.fromString( - "ksnjzXzraR5hWthnKAWVgJkDBUoRX8CHpLttYs2sAmhPFvh6Ga6HMTLMKRi45p1PfLevfm272ANmwTBEvGwW19m", + "ksnjzXzraR5hWthnKAWVgJkDBUoRX8CHpLttYs2s" ++ + "AmhPFvh6Ga6HMTLMKRi45p1PfLevfm272ANmwTBEvGwW19m", ) catch unreachable, .variant = .{ .shred_type = .code, diff --git a/src/ledger/shred_inserter/shred_inserter.zig b/src/ledger/shred_inserter/shred_inserter.zig index 19d7854f3..5a26fae30 100644 --- a/src/ledger/shred_inserter/shred_inserter.zig +++ b/src/ledger/shred_inserter/shred_inserter.zig @@ -336,7 +336,7 @@ pub const ShredInserter = struct { .shred_type = .code, }; // unreachable: Erasure meta was just created, initial shred must exist - const shred = state.just_inserted_shreds.get(shred_id) orelse unreachable; + const shred = state.just_inserted_shreds.get(shred_id).?; // TODO: agave discards the result here. should we also? _ = try merkle_root_validator.checkForwardChaining( shred.code, @@ -365,7 +365,7 @@ pub const ShredInserter = struct { .shred_type = merkle_root_meta.first_received_shred_type, }; // unreachable: Merkle root meta was just created, initial shred must exist - const shred = state.just_inserted_shreds.get(shred_id) orelse unreachable; + const shred = state.just_inserted_shreds.get(shred_id).?; // TODO: agave discards the result here. should we also? _ = try merkle_root_validator.checkBackwardChaining(shred, state.erasureMetas()); } diff --git a/src/ledger/shred_inserter/slot_chaining.zig b/src/ledger/shred_inserter/slot_chaining.zig index a90bbb346..ff2907114 100644 --- a/src/ledger/shred_inserter/slot_chaining.zig +++ b/src/ledger/shred_inserter/slot_chaining.zig @@ -55,7 +55,14 @@ pub fn handleChaining( var new_chained_slots = AutoHashMap(u64, SlotMeta).init(allocator); defer deinitMapRecursive(&new_chained_slots); for (keys[0..keep_i]) |slot| { - try handleChainingForSlot(allocator, db, write_batch, working_set, &new_chained_slots, slot); + try handleChainingForSlot( + allocator, + db, + write_batch, + working_set, + &new_chained_slots, + slot, + ); } // Write all the newly changed slots in new_chained_slots to the write_batch diff --git a/src/ledger/shred_inserter/working_state.zig b/src/ledger/shred_inserter/working_state.zig index 16e356817..11edced48 100644 --- a/src/ledger/shred_inserter/working_state.zig +++ b/src/ledger/shred_inserter/working_state.zig @@ -560,7 +560,7 @@ pub fn isNewlyCompletedSlot(slot_meta: *const SlotMeta, backup_slot_meta: *const return slot_meta.isFull() and ( // backup_slot_meta.* == null or slot_meta.consecutive_received_from_0 != - (backup_slot_meta.* orelse unreachable).consecutive_received_from_0); + (backup_slot_meta.*.?).consecutive_received_from_0); // TODO unreachable: explain or fix } diff --git a/src/ledger/transaction_status.zig b/src/ledger/transaction_status.zig index 430678388..bd584a960 100644 --- a/src/ledger/transaction_status.zig +++ b/src/ledger/transaction_status.zig @@ -133,9 +133,11 @@ pub const Rewards = std.ArrayList(Reward); pub const Reward = struct { pubkey: []const u8, lamports: i64, - post_balance: u64, // Account balance in lamports after `lamports` was applied + /// Account balance in lamports after `lamports` was applied + post_balance: u64, reward_type: ?RewardType, - commission: ?u8, // Vote account commission when the reward was credited, only present for voting and staking rewards + /// Vote account commission when the reward was credited, only present for voting and staking rewards + commission: ?u8, pub fn deinit(self: @This(), allocator: Allocator) void { allocator.free(self.pubkey); diff --git a/src/net/socket_utils.zig b/src/net/socket_utils.zig index dbe59b2ce..6ef4cfa4e 100644 --- a/src/net/socket_utils.zig +++ b/src/net/socket_utils.zig @@ -23,7 +23,10 @@ pub fn readSocket( idx: if (needs_exit_order) usize else void, ) !void { defer { - logger.info().logf("leaving with: {}, {}, {}", .{ incoming_channel.len(), counter.load(.acquire), idx }); + logger.info().logf( + "leaving with: {}, {}, {}", + .{ incoming_channel.len(), counter.load(.acquire), idx }, + ); if (needs_exit_order) { counter.store(idx + 1, .release); } @@ -174,7 +177,11 @@ pub const BenchmarkPacketProcessing = struct { counter.store(true, .release); handle.join(); } - var recv_handle = try std.Thread.spawn(.{}, benchmarkChannelRecv, .{ &channel, n_packets }); + var recv_handle = try std.Thread.spawn( + .{}, + benchmarkChannelRecv, + .{ &channel, n_packets }, + ); var prng = std.rand.DefaultPrng.init(0); var packet_buf: [PACKET_DATA_SIZE]u8 = undefined; diff --git a/src/prometheus/registry.zig b/src/prometheus/registry.zig index 1369e6b49..27afc2e6f 100644 --- a/src/prometheus/registry.zig +++ b/src/prometheus/registry.zig @@ -297,7 +297,7 @@ pub fn Registry(comptime options: RegistryOptions) type { // Write each metric in key order for (keys) |key| { - var value = map.get(key) orelse unreachable; + var value = map.get(key).?; try value.metric.write(allocator, writer, key); } } diff --git a/src/rpc/response.zig b/src/rpc/response.zig index dc3c8eaae..5c6fb01a9 100644 --- a/src/rpc/response.zig +++ b/src/rpc/response.zig @@ -13,7 +13,10 @@ pub fn Response(comptime T: type) type { parsed: ParsedResponse(T), parse_options: std.json.ParseOptions, - pub fn init(allocator: std.mem.Allocator, parse_options: std.json.ParseOptions) !Response(T) { + pub fn init( + allocator: std.mem.Allocator, + parse_options: std.json.ParseOptions, + ) !Response(T) { const arena = try allocator.create(std.heap.ArenaAllocator); arena.* = std.heap.ArenaAllocator.init(allocator); return .{ diff --git a/src/shred_collector/repair_service.zig b/src/shred_collector/repair_service.zig index d01cbd157..1381ca73c 100644 --- a/src/shred_collector/repair_service.zig +++ b/src/shred_collector/repair_service.zig @@ -515,7 +515,12 @@ test "RepairService sends repair request to gossip peer" { }; try peer_socket.bind(peer_endpoint); try peer_socket.setReadTimeout(100_000); - var peer_contact_info = ContactInfo.init(allocator, Pubkey.fromPublicKey(&peer_keypair.public_key), wallclock, my_shred_version.load(.acquire)); + var peer_contact_info = ContactInfo.init( + allocator, + Pubkey.fromPublicKey(&peer_keypair.public_key), + wallclock, + my_shred_version.load(.acquire), + ); try peer_contact_info.setSocket(.serve_repair, SocketAddr.fromEndpoint(&peer_endpoint)); try peer_contact_info.setSocket(.turbine_recv, SocketAddr.fromEndpoint(&peer_endpoint)); _ = try gossip.insert(SignedGossipData.initSigned(&peer_keypair, .{ .ContactInfo = peer_contact_info }), wallclock); @@ -611,7 +616,8 @@ test "RepairPeerProvider selects correct peers" { var observed_peers = std.AutoHashMap(RepairPeer, void).init(allocator); defer observed_peers.deinit(); for (0..10) |_| { - try observed_peers.put(try peers.getRandomPeer(13579) orelse unreachable, {}); + const peer = (try peers.getRandomPeer(13579)).?; + try observed_peers.put(peer, {}); } // assertions diff --git a/src/shred_collector/shred_receiver.zig b/src/shred_collector/shred_receiver.zig index 0631b68b9..83e556dd8 100644 --- a/src/shred_collector/shred_receiver.zig +++ b/src/shred_collector/shred_receiver.zig @@ -132,7 +132,12 @@ pub const ShredReceiver = struct { /// Handle a ping message and returns the repair message. fn handlePing(self: *const Self, packet: *const Packet) !?Packet { - const repair_ping = bincode.readFromSlice(self.allocator, RepairPing, &packet.data, .{}) catch { + const repair_ping = bincode.readFromSlice( + self.allocator, + RepairPing, + &packet.data, + .{}, + ) catch { self.metrics.ping_deserialize_fail_count.inc(); return null; }; diff --git a/src/shred_collector/shred_tracker.zig b/src/shred_collector/shred_tracker.zig index 64f31480b..2f2c50ea1 100644 --- a/src/shred_collector/shred_tracker.zig +++ b/src/shred_collector/shred_tracker.zig @@ -114,7 +114,10 @@ pub const BasicShredTracker = struct { } /// returns whether it makes sense to send any repair requests - pub fn identifyMissing(self: *Self, slot_reports: *MultiSlotReport) (Allocator.Error || SlotOutOfBounds)!bool { + pub fn identifyMissing( + self: *Self, + slot_reports: *MultiSlotReport, + ) (Allocator.Error || SlotOutOfBounds)!bool { if (self.start_slot == null) return false; self.mux.lock(); defer self.mux.unlock(); @@ -125,7 +128,9 @@ pub const BasicShredTracker = struct { const last_slot_to_check = @max(self.max_slot_processed, self.current_bottom_slot); for (self.current_bottom_slot..last_slot_to_check + 1) |slot| { const monitored_slot = try self.getMonitoredSlot(slot); - if (monitored_slot.first_received_timestamp_ms + MIN_SLOT_AGE_TO_REPORT_AS_MISSING > timestamp) { + if (monitored_slot.first_received_timestamp_ms + + MIN_SLOT_AGE_TO_REPORT_AS_MISSING > timestamp) + { continue; } var slot_report = try slot_reports.addOne(); @@ -138,9 +143,15 @@ pub const BasicShredTracker = struct { } if (!found_an_incomplete_slot) { if (slot % 20 == 0) { - self.logger.info().logf("shred tracker: received all shreds up to slot {}", .{slot}); + self.logger.info().logf( + "shred tracker: received all shreds up to slot {}", + .{slot}, + ); } else { - self.logger.debug().logf("shred tracker: received all shreds up to slot {}", .{slot}); + self.logger.debug().logf( + "shred tracker: received all shreds up to slot {}", + .{slot}, + ); } self.current_bottom_slot = @max(self.current_bottom_slot, slot + 1); self.metrics.finished_slots_through.set(slot); diff --git a/src/sync/channel.zig b/src/sync/channel.zig index 32726800b..dc557ad8b 100644 --- a/src/sync/channel.zig +++ b/src/sync/channel.zig @@ -539,7 +539,10 @@ pub const BenchmarkChannel = struct { const receivers_count = argss.n_receivers; var timer = try sig.time.Timer.start(); - const allocator = if (@import("builtin").is_test) std.testing.allocator else std.heap.c_allocator; + const allocator = if (@import("builtin").is_test) + std.testing.allocator + else + std.heap.c_allocator; var channel = try Channel(usize).init(allocator); defer channel.deinit(); @@ -548,11 +551,17 @@ pub const BenchmarkChannel = struct { var thread_index: usize = 0; while (thread_index < senders_count) : (thread_index += 1) { - thread_handles[thread_index] = try std.Thread.spawn(.{}, testUsizeSender, .{ &channel, sends_per_sender }); + thread_handles[thread_index] = try std.Thread.spawn(.{}, testUsizeSender, .{ + &channel, + sends_per_sender, + }); } while (thread_index < receivers_count + senders_count) : (thread_index += 1) { - thread_handles[thread_index] = try std.Thread.spawn(.{}, testUsizeReceiver, .{ &channel, receives_per_receiver }); + thread_handles[thread_index] = try std.Thread.spawn(.{}, testUsizeReceiver, .{ + &channel, + receives_per_receiver, + }); } for (0..thread_handles.len) |i| { @@ -583,11 +592,17 @@ pub const BenchmarkChannel = struct { var thread_index: usize = 0; while (thread_index < senders_count) : (thread_index += 1) { - thread_handles[thread_index] = try std.Thread.spawn(.{}, testPacketSender, .{ &channel, sends_per_sender }); + thread_handles[thread_index] = try std.Thread.spawn(.{}, testPacketSender, .{ + &channel, + sends_per_sender, + }); } while (thread_index < receivers_count + senders_count) : (thread_index += 1) { - thread_handles[thread_index] = try std.Thread.spawn(.{}, testPacketReceiver, .{ &channel, receives_per_receiver }); + thread_handles[thread_index] = try std.Thread.spawn(.{}, testPacketReceiver, .{ + &channel, + receives_per_receiver, + }); } for (0..thread_handles.len) |i| { diff --git a/src/sync/mux.zig b/src/sync/mux.zig index 3b47ec64b..627b7f998 100644 --- a/src/sync/mux.zig +++ b/src/sync/mux.zig @@ -276,7 +276,10 @@ pub fn RwMux(comptime T: type) type { return .{ t, lock_guard }; } - pub fn readField(self: *Self, comptime field: []const u8) @TypeOf(@field(self.private.v, field)) { + pub fn readField( + self: *Self, + comptime field: []const u8, + ) @TypeOf(@field(self.private.v, field)) { self.private.r.lockShared(); const value = @field(self.private.v, field); self.private.r.unlockShared(); diff --git a/src/sync/once_cell.zig b/src/sync/once_cell.zig index e3f7a70e8..ed3932849 100644 --- a/src/sync/once_cell.zig +++ b/src/sync/once_cell.zig @@ -25,7 +25,11 @@ pub fn OnceCell(comptime T: type) type { /// Initializes the inner value and returns pointer to it. /// Returns error if it was already initialized. /// Blocks while other threads are in the process of initialization. - pub fn initialize(self: *Self, initLogic: anytype, init_args: anytype) error{AlreadyInitialized}!*T { + pub fn initialize( + self: *Self, + initLogic: anytype, + init_args: anytype, + ) error{AlreadyInitialized}!*T { if (!self.acquire()) return error.AlreadyInitialized; self.value = @call(.auto, initLogic, init_args); self.finished.store(true, .release); diff --git a/src/sync/ref.zig b/src/sync/ref.zig index 1deb98633..34147e55b 100644 --- a/src/sync/ref.zig +++ b/src/sync/ref.zig @@ -28,7 +28,8 @@ const builtin = @import("builtin"); /// This variable is `true` if an atomic reference-counter is used for `Arc`, `false` otherwise. /// /// If the target is single-threaded, `Arc` is optimized to a regular `Rc`. -pub const atomic_arc = !builtin.single_threaded or (builtin.target.isWasm() and std.Target.wasm.featureSetHas(builtin.cpu.features, .atomics)); +pub const atomic_arc = !builtin.single_threaded or + (builtin.target.isWasm() and std.Target.wasm.featureSetHas(builtin.cpu.features, .atomics)); /// A single threaded, strong reference to a reference-counted value. pub fn Rc(comptime T: type) type { @@ -60,7 +61,10 @@ pub fn Rc(comptime T: type) type { /// Constructs a new `Rc` while giving you a `Weak` to the allocation, /// to allow you to construct a `T` which holds a weak pointer to itself. - pub fn initCyclic(alloc: std.mem.Allocator, comptime data_fn: fn (*Weak) T) error{OutOfMemory}!Self { + pub fn initCyclic( + alloc: std.mem.Allocator, + comptime data_fn: fn (*Weak) T, + ) error{OutOfMemory}!Self { const inner = try alloc.create(Inner); inner.* = Inner{ .strong = 0, .weak = 1, .value = undefined }; @@ -301,7 +305,10 @@ pub fn Arc(comptime T: type) type { /// Constructs a new `Arc` while giving you a `weak` to the allocation, /// to allow you to construct a `T` which holds a weak pointer to itself. - pub fn initCyclic(alloc: std.mem.Allocator, comptime data_fn: fn (*Weak) T) error{OutOfMemory}!Self { + pub fn initCyclic( + alloc: std.mem.Allocator, + comptime data_fn: fn (*Weak) T, + ) error{OutOfMemory}!Self { const inner = try alloc.create(Inner); inner.* = Inner{ .strong = 0, .weak = 1, .value = undefined }; @@ -464,7 +471,14 @@ pub fn Arc(comptime T: type) type { return null; } - if (@cmpxchgStrong(usize, &ptr.strong, prev, prev + 1, .acquire, .monotonic) == null) { + if (@cmpxchgStrong( + usize, + &ptr.strong, + prev, + prev + 1, + .acquire, + .monotonic, + ) == null) { return Arc(T){ .value = &ptr.value, .alloc = self.alloc, diff --git a/src/sync/thread_pool.zig b/src/sync/thread_pool.zig index fcb287b69..79ab47c76 100644 --- a/src/sync/thread_pool.zig +++ b/src/sync/thread_pool.zig @@ -707,7 +707,7 @@ pub const ThreadPool = struct { var num_threads: u32 = @as(Sync, @bitCast(thread_pool.sync.load(.monotonic))).spawned; while (num_threads > 0) : (num_threads -= 1) { // Traverse the stack of registered threads on the thread pool - const target = self.target orelse thread_pool.threads.load(.acquire) orelse unreachable; + const target = self.target orelse thread_pool.threads.load(.acquire).?; self.target = target.next; // Try to steal from their queue first to avoid contention (the target steal's from queue last). diff --git a/src/tests.zig b/src/tests.zig index 8efb0228e..f14b9855c 100644 --- a/src/tests.zig +++ b/src/tests.zig @@ -19,7 +19,11 @@ pub inline fn refAllDeclsRecursive(comptime T: type, comptime depth: usize) void inline for (comptime std.meta.declarations(T)) |decl| { if (@TypeOf(@field(T, decl.name)) == type) { switch (@typeInfo(@field(T, decl.name))) { - .Struct, .Enum, .Union, .Opaque => refAllDeclsRecursive(@field(T, decl.name), depth - 1), + .Struct, + .Enum, + .Union, + .Opaque, + => refAllDeclsRecursive(@field(T, decl.name), depth - 1), else => {}, } } diff --git a/src/transaction_sender/leader_info.zig b/src/transaction_sender/leader_info.zig index ef312b279..5c3979e43 100644 --- a/src/transaction_sender/leader_info.zig +++ b/src/transaction_sender/leader_info.zig @@ -73,7 +73,8 @@ pub const LeaderInfo = struct { } if (leader_addresses.items.len <= @divFloor(self.config.max_leaders_to_send_to, 2)) { - const gossip_table: *const GossipTable, var gossip_table_lg = self.gossip_table_rw.readWithLock(); + const gossip_table: *const GossipTable, var gossip_table_lg = + self.gossip_table_rw.readWithLock(); defer gossip_table_lg.unlock(); var unique_leaders = try self.leader_schedule_cache.uniqueLeaders(self.allocator); @@ -82,7 +83,11 @@ pub const LeaderInfo = struct { for (unique_leaders.keys()) |leader| { const contact_info = gossip_table.getThreadSafeContactInfo(leader); if (contact_info == null or contact_info.?.tpu_addr == null) continue; - try self.leader_addresses_cache.put(self.allocator, leader, contact_info.?.tpu_addr.?); + try self.leader_addresses_cache.put( + self.allocator, + leader, + contact_info.?.tpu_addr.?, + ); } } @@ -96,7 +101,10 @@ pub const LeaderInfo = struct { self.leader_schedule_cache.epoch_schedule.getEpochAndSlotIndex(slot); const leader_schedule = self.getLeaderSchedule(slot) catch |e| { - self.logger.err().logf("Error getting leader schedule via rpc for slot {}: {}", .{ slot, e }); + self.logger.err().logf( + "Error getting leader schedule via rpc for slot {}: {}", + .{ slot, e }, + ); return e; }; diff --git a/src/transaction_sender/transaction_info.zig b/src/transaction_sender/transaction_info.zig index bae3f2409..dceeaf09d 100644 --- a/src/transaction_sender/transaction_info.zig +++ b/src/transaction_sender/transaction_info.zig @@ -36,7 +36,11 @@ pub const TransactionInfo = struct { .retries = 0, .last_sent_time = null, }; - const written = try sig.bincode.writeToSlice(&transaction_info.wire_transaction, transaction, .{}); + const written = try sig.bincode.writeToSlice( + &transaction_info.wire_transaction, + transaction, + .{}, + ); transaction_info.wire_transaction_size = written.len; return transaction_info; } diff --git a/src/utils/allocators.zig b/src/utils/allocators.zig index 7f2dc28b1..c73b9bf2e 100644 --- a/src/utils/allocators.zig +++ b/src/utils/allocators.zig @@ -259,7 +259,8 @@ pub const DiskMemoryAllocator = struct { std.debug.assert(self.mmap_ratio != 0); const alignment = @as(usize, 1) << @intCast(log2_align); - std.debug.assert(alignment <= std.mem.page_size); // the allocator interface shouldn't allow this (aside from the *Raw methods). + // the allocator interface shouldn't allow this (aside from the *Raw methods). + std.debug.assert(alignment <= std.mem.page_size); const file_aligned_size = alignedFileSize(size); const aligned_mmap_size = alignedMmapSize(file_aligned_size, self.mmap_ratio); @@ -313,7 +314,8 @@ pub const DiskMemoryAllocator = struct { std.debug.assert(self.mmap_ratio != 0); const alignment = @as(usize, 1) << @intCast(log2_align); - std.debug.assert(alignment <= std.mem.page_size); // the allocator interface shouldn't allow this (aside from the *Raw methods). + // the allocator interface shouldn't allow this (aside from the *Raw methods). + std.debug.assert(alignment <= std.mem.page_size); const old_file_aligned_size = alignedFileSize(buf.len); const new_file_aligned_size = alignedFileSize(new_size); @@ -323,7 +325,8 @@ pub const DiskMemoryAllocator = struct { } const buf_ptr: [*]align(std.mem.page_size) u8 = @alignCast(buf.ptr); - const metadata: Metadata = @bitCast(buf_ptr[old_file_aligned_size - @sizeOf(Metadata) ..][0..@sizeOf(Metadata)].*); + const offset = old_file_aligned_size - @sizeOf(Metadata); + const metadata: Metadata = @bitCast(buf_ptr[offset..][0..@sizeOf(Metadata)].*); if (new_file_aligned_size > metadata.mmap_size) { return false; @@ -354,7 +357,8 @@ pub const DiskMemoryAllocator = struct { std.debug.assert(buf.len != 0); // should be ensured by the allocator interface const alignment = @as(usize, 1) << @intCast(log2_align); - std.debug.assert(alignment <= std.mem.page_size); // the allocator interface shouldn't allow this (aside from the *Raw methods). + // the allocator interface shouldn't allow this (aside from the *Raw methods). + std.debug.assert(alignment <= std.mem.page_size); const file_aligned_size = alignedFileSize(buf.len); const mmap_aligned_size = alignedMmapSize(file_aligned_size, self.mmap_ratio); diff --git a/src/utils/collections.zig b/src/utils/collections.zig index 50c30fdd5..f747b6c53 100644 --- a/src/utils/collections.zig +++ b/src/utils/collections.zig @@ -176,7 +176,12 @@ pub fn SortedMapCustom( if (self.count() != other.count()) return false; self.sort(); other.sort(); - for (self.inner.keys(), self.inner.values(), other.inner.keys(), other.inner.values()) |sk, sv, ok, ov| { + for ( + self.inner.keys(), + self.inner.values(), + other.inner.keys(), + other.inner.values(), + ) |sk, sv, ok, ov| { if (sk != ok or sv != ov) return false; } return true;