Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(gossip): improved init flow #407

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/accountsdb/download.zig
Original file line number Diff line number Diff line change
Expand Up @@ -538,16 +538,14 @@ pub fn downloadFile(
}
}

const ThreadPool = sig.sync.thread_pool.ThreadPool;
const LegacyContactInfo = sig.gossip.data.LegacyContactInfo;
const SignedGossipData = sig.gossip.data.SignedGossipData;

const KeyPair = std.crypto.sign.Ed25519.KeyPair;

test "accounts_db.download: test remove untrusted peers" {
const allocator = std.testing.allocator;
var thread_pool = ThreadPool.init(.{});
var table = try GossipTable.init(allocator, &thread_pool);
var table = try GossipTable.init(allocator);
defer table.deinit();

var prng = std.rand.DefaultPrng.init(0);
Expand Down Expand Up @@ -623,8 +621,7 @@ test "accounts_db.download: test remove untrusted peers" {

test "accounts_db.download: test finding peers" {
const allocator = std.testing.allocator;
var thread_pool = ThreadPool.init(.{});
var table = try GossipTable.init(allocator, &thread_pool);
var table = try GossipTable.init(allocator);
defer table.deinit();

var prng = std.rand.DefaultPrng.init(0);
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/cmd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,7 @@ fn startGossip(
.{},
);

const service = try manager.arena.allocator().create(GossipService);
service.* = try GossipService.init(
const service = try GossipService.create(
gpa_allocator,
gossip_value_gpa_allocator,
contact_info,
Expand Down
4 changes: 1 addition & 3 deletions src/gossip/active_set.zig
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ pub const ActiveSet = struct {
test "init/denit" {
const alloc = std.testing.allocator;

const ThreadPool = @import("../sync/thread_pool.zig").ThreadPool;
var tp = ThreadPool.init(.{});
var table = try GossipTable.init(alloc, &tp);
var table = try GossipTable.init(alloc);
defer table.deinit();

// insert some contacts
Expand Down
12 changes: 6 additions & 6 deletions src/gossip/fuzz_service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
const client_pubkey = Pubkey.fromPublicKey(&client_keypair.public_key);
var client_contact_info = ContactInfo.init(allocator, client_pubkey, 0, 19);
try client_contact_info.setSocket(.gossip, client_address);
var gossip_service_client = try GossipService.init(
const gossip_service_client = try GossipService.create(
gossip_alloc,
gossip_alloc,
client_contact_info,
Expand All @@ -267,13 +267,13 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
);

const client_handle = try std.Thread.spawn(.{}, GossipService.run, .{
&gossip_service_client, .{
gossip_service_client, .{
.spy_node = true,
.dump = false,
},
});
// this is used to respond to pings
var gossip_service_fuzzer = try GossipService.init(
const gossip_service_fuzzer = try GossipService.create(
allocator,
allocator,
fuzz_contact_info,
Expand All @@ -286,7 +286,7 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
// this is mainly used to just send packets through the fuzzer
// but we also want to respond to pings so we need to run the full gossip service
const fuzz_handle = try std.Thread.spawn(.{}, GossipService.run, .{
&gossip_service_fuzzer, .{
gossip_service_fuzzer, .{
.spy_node = true,
.dump = false,
},
Expand All @@ -295,7 +295,7 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {

break :blk .{ gossip_service_client, gossip_service_client.packet_incoming_channel, client_handle };
} else {
var gossip_service_fuzzer = try GossipService.init(
const gossip_service_fuzzer = try GossipService.create(
allocator,
allocator,
fuzz_contact_info,
Expand All @@ -308,7 +308,7 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
// this is mainly used to just send packets through the fuzzer
// but we also want to respond to pings so we need to run the full gossip service
const fuzz_handle = try std.Thread.spawn(.{}, GossipService.run, .{
&gossip_service_fuzzer, .{
gossip_service_fuzzer, .{
.spy_node = true,
.dump = false,
},
Expand Down
17 changes: 1 addition & 16 deletions src/gossip/fuzz_table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ const SignedGossipData = sig.gossip.data.SignedGossipData;
const GossipData = sig.gossip.data.GossipData;
const GossipKey = sig.gossip.data.GossipKey;
const Signature = sig.core.Signature;
const ThreadPool = sig.sync.thread_pool.ThreadPool;
const Duration = sig.time.Duration;
const StandardErrLogger = sig.trace.ChannelPrintLogger;
const Level = sig.trace.Level;

const TRIM_INTERVAL = Duration.fromSecs(2);
const MAX_N_THREADS = 2;

pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
const maybe_max_actions_string = args.next();
Expand Down Expand Up @@ -48,21 +46,8 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
const random = prng.random();

// init gossip table
// MAX: 2 threads
const n_threads = @min(@as(u32, @truncate(std.Thread.getCpuCount() catch 1)), MAX_N_THREADS);
const thread_pool = try allocator.create(ThreadPool);
defer {
thread_pool.shutdown();
thread_pool.deinit();
allocator.destroy(thread_pool);
}
thread_pool.* = ThreadPool.init(.{
.max_threads = n_threads,
.stack_size = 2 * 1024 * 1024,
});

const gossip_table = try allocator.create(GossipTable);
gossip_table.* = try GossipTable.init(allocator, thread_pool);
gossip_table.* = try GossipTable.init(allocator);
defer {
gossip_table.deinit();
allocator.destroy(gossip_table);
Expand Down
4 changes: 1 addition & 3 deletions src/gossip/pull_request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,8 @@ pub fn hashToU64(hash: *const Hash) u64 {

test "building pull filters" {
const LegacyContactInfo = sig.gossip.data.LegacyContactInfo;
const ThreadPool = sig.sync.ThreadPool;

var tp = ThreadPool.init(.{});
var gossip_table = try GossipTable.init(std.testing.allocator, &tp);
var gossip_table = try GossipTable.init(std.testing.allocator);
defer gossip_table.deinit();

// insert a some value
Expand Down
4 changes: 1 addition & 3 deletions src/gossip/pull_response.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ pub fn filterSignedGossipDatas(
const LegacyContactInfo = sig.gossip.data.LegacyContactInfo;

test "gossip.pull_response: test filtering values works" {
const ThreadPool = @import("../sync/thread_pool.zig").ThreadPool;
var tp = ThreadPool.init(.{});
const gossip_table = try GossipTable.init(std.testing.allocator, &tp);
const gossip_table = try GossipTable.init(std.testing.allocator);
var gossip_table_rw = RwMux(GossipTable).init(gossip_table);
defer {
var lg = gossip_table_rw.write();
Expand Down
Loading