mirror of
https://github.com/lklynet/hypermind.git
synced 2026-05-03 17:40:29 +00:00
feat(p2p): increase max relay hops and improve gossip algorithm
Increase MAX_RELAY_HOPS from 2 to 5 for better message propagation. Update gossip algorithm to scale with connection count, using a minimum of 6 or 25% of eligible peers.
This commit is contained in:
@@ -18,7 +18,7 @@ const VERIFICATION_POW_PREFIX = "0000";
|
||||
|
||||
const MAX_PEERS = parseInt(process.env.MAX_PEERS) || 50000;
|
||||
const MAX_MESSAGE_SIZE = parseInt(process.env.MAX_MESSAGE_SIZE) || 2048;
|
||||
const MAX_RELAY_HOPS = parseInt(process.env.MAX_RELAY_HOPS) || 2;
|
||||
const MAX_RELAY_HOPS = parseInt(process.env.MAX_RELAY_HOPS) || 5;
|
||||
const MAX_CONNECTIONS = parseInt(process.env.MAX_CONNECTIONS) || 15;
|
||||
|
||||
const HEARTBEAT_INTERVAL = parseInt(process.env.HEARTBEAT_INTERVAL) || 30000;
|
||||
|
||||
+7
-5
@@ -2,13 +2,15 @@ const relayMessage = (msg, sourceSocket, swarm, diagnostics) => {
|
||||
const data = JSON.stringify(msg) + "\n";
|
||||
|
||||
// Gossip Subsampling:
|
||||
// Instead of flooding everyone (which causes massive bandwidth usage with 50 connections),
|
||||
// we relay to a random subset of peers (e.g., 6).
|
||||
// This maintains "Epidemic" reach (O(log N)) while capping bandwidth.
|
||||
|
||||
const TARGET_GOSSIP_COUNT = 6;
|
||||
// We relay to a subset of peers to prevent flooding, but scale with connection count.
|
||||
// We use a minimum of 6 or 25% of eligible peers, whichever is larger.
|
||||
|
||||
const allSockets = Array.from(swarm.connections);
|
||||
const eligible = allSockets.filter((s) => s !== sourceSocket);
|
||||
|
||||
const MIN_GOSSIP_COUNT = 6;
|
||||
const GOSSIP_FACTOR = 0.25; // Relay to 25% of peers
|
||||
const TARGET_GOSSIP_COUNT = Math.max(MIN_GOSSIP_COUNT, Math.ceil(eligible.length * GOSSIP_FACTOR));
|
||||
|
||||
let targets = eligible;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user