From 5df91284de632ea43b31b4f940ed6d17b8590b5b Mon Sep 17 00:00:00 2001 From: Drew Nutter Date: Fri, 31 May 2024 18:21:50 -0400 Subject: [PATCH] refactor(shred_collector): consolidate config --- src/cmd/cmd.zig | 38 +++++++++++++++++++------------------- src/cmd/config.zig | 11 ++++++----- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/cmd/cmd.zig b/src/cmd/cmd.zig index bffbdfa10..042e0ed4c 100644 --- a/src/cmd/cmd.zig +++ b/src/cmd/cmd.zig @@ -82,7 +82,7 @@ var gossip_port_option = cli.Option{ var repair_port_option = cli.Option{ .long_name = "repair-port", .help = "The port to run tvu repair listener - default: 8002", - .value_ref = cli.mkRef(&config.current.tvu.repair_port), + .value_ref = cli.mkRef(&config.current.shred_collector.repair_port), .required = false, .value_name = "Repair Port", }; @@ -90,7 +90,7 @@ var repair_port_option = cli.Option{ var tvu_port_option = cli.Option{ .long_name = "tvu-port", .help = "The port to run turbine listener - default: 8003", - .value_ref = cli.mkRef(&config.current.tvu.tvu_port), + .value_ref = cli.mkRef(&config.current.shred_collector.tvu_port), .required = false, .value_name = "TVU Port", }; @@ -98,7 +98,7 @@ var tvu_port_option = cli.Option{ var test_repair_option = cli.Option{ .long_name = "test-repair-for-slot", .help = "Set a slot here to repeatedly send repair requests for shreds from this slot. This is only intended for use during short-lived tests of the repair service. Do not set this during normal usage.", - .value_ref = cli.mkRef(&config.current.tvu.test_repair_slot), + .value_ref = cli.mkRef(&config.current.shred_collector.start_slot), .required = false, .value_name = "slot number", }; @@ -399,8 +399,8 @@ fn validator() !void { defer entrypoints.deinit(); const ip_echo_data = try getMyDataFromIpEcho(logger, entrypoints.items); - const repair_port: u16 = config.current.tvu.repair_port; - const tvu_port: u16 = config.current.tvu.repair_port; + const repair_port: u16 = config.current.shred_collector.repair_port; + const tvu_port: u16 = config.current.shred_collector.repair_port; // gossip var gossip_service = try initGossip( @@ -419,20 +419,20 @@ fn validator() !void { const gossip_handle = try std.Thread.spawn(.{}, runGossipWithConfigValues, .{&gossip_service}); // shred collector - var shred_collector = try sig.shred_collector.start(.{ - .start_slot = if (config.current.tvu.test_repair_slot) |n| @intCast(n) else null, - .repair_port = repair_port, - .tvu_port = tvu_port, - }, .{ - .allocator = gpa_allocator, - .logger = logger, - .random = rand.random(), - .my_keypair = &my_keypair, - }, .{ - .exit = &exit, - .gossip_table_rw = &gossip_service.gossip_table_rw, - .my_shred_version = &gossip_service.my_shred_version, - }); + var shred_collector = try sig.shred_collector.start( + config.current.shred_collector, + .{ + .allocator = gpa_allocator, + .logger = logger, + .random = rand.random(), + .my_keypair = &my_keypair, + }, + .{ + .exit = &exit, + .gossip_table_rw = &gossip_service.gossip_table_rw, + .my_shred_version = &gossip_service.my_shred_version, + }, + ); defer shred_collector.deinit(); // accounts db diff --git a/src/cmd/config.zig b/src/cmd/config.zig index f09dee53f..c726096e0 100644 --- a/src/cmd/config.zig +++ b/src/cmd/config.zig @@ -1,9 +1,10 @@ const ACCOUNT_INDEX_BINS = @import("../accountsdb/db.zig").ACCOUNT_INDEX_BINS; +const ShredCollectorConfig = @import("../shred_collector/service.zig").ShredCollectorConfig; pub const Config = struct { identity: IdentityConfig = .{}, gossip: GossipConfig = .{}, - tvu: TvuConfig = .{}, + shred_collector: ShredCollectorConfig = shred_collector_defaults, accounts_db: AccountsDbConfig = .{}, // general config log_level: []const u8 = "debug", @@ -24,10 +25,10 @@ const GossipConfig = struct { trusted_validators: [][]const u8 = &.{}, }; -const TvuConfig = struct { - tvu_port: u16 = 8002, - repair_port: u16 = 8003, - test_repair_slot: ?u64 = null, +const shred_collector_defaults = ShredCollectorConfig{ + .tvu_port = 8002, + .repair_port = 8003, + .start_slot = null, }; const AccountsDbConfig = struct {