From 98b6f778fe4c4e153682664746b3d797bc3f23b2 Mon Sep 17 00:00:00 2001 From: Cassie Heart Date: Thu, 19 Oct 2023 17:28:31 -0700 Subject: [PATCH] pr feedback --- apps/hubble/src/hubble.ts | 32 ++++--------------- .../src/network/p2p/gossipNodeWorker.ts | 10 +++--- .../hubble/src/network/utils/networkConfig.ts | 21 ++++++++++-- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/apps/hubble/src/hubble.ts b/apps/hubble/src/hubble.ts index 81e0460505..eff1873e8f 100644 --- a/apps/hubble/src/hubble.ts +++ b/apps/hubble/src/hubble.ts @@ -93,28 +93,6 @@ export const FARCASTER_VERSIONS_SCHEDULE: VersionSchedule[] = [ const MAX_CONTACT_INFO_AGE_MS = GOSSIP_SEEN_TTL; -// Used temporarily while peer scoring is being vetted in the wild. Will be set to []. -const PEER_SCORE_IMMUNE_PEERS = [ - // hoyt.farcaster.xyz - "12D3KooWRnSZUxjVJjbSHhVKpXtvibMarSfLSKDBeMpfVaNm1Joo", - // lamia.farcaster.xyz - "12D3KooWJECuSHn5edaorpufE9ceAoqR5zcAuD4ThoyDzVaz77GV", - // nemes.farcaster.xyz - "12D3KooWMQrf6unpGJfLBmTGy3eKTo4cGcXktWRbgMnfbZLXqBbn", - // keats.farcaster.xyz - "12D3KooWBPXFPS656B76tCmbbX6PB4vunmQcd8F38MZjkR88ofBx", - // @v - "12D3KooWFbnaXtbD5fwbMGq2JRjPaj7C6EpZRgaxC8jdtcX7FJbZ", - // @sanjay - "12D3KooWPNDmUeNiGdCdoHp8iAf8Uay3c2C9n5QVygd3J1hfv65w", - // @deodad - "12D3KooWNMAd358HmUe7HgkLYasGmZDfLM9iEEthE4VhqBFEr8dv", - // @neynar - "12D3KooWNsC2vzuHdKDfSM6xnMZwMjWK8zZCYHyLXuhRMeVRebGK", - // @neynar - "12D3KooWH9ojvuodLfc6bVyWArFaVAPgaKFiLFqH4Em48KQpSfwL", -]; - export interface HubInterface { engine: Engine; identity: string; @@ -309,6 +287,7 @@ export class Hub implements HubInterface { private syncEngine: SyncEngine; private allowedPeerIds: string[] | undefined; private deniedPeerIds: string[]; + private allowlistedImmunePeers: string[] | undefined; private s3_snapshot_bucket: string; @@ -679,7 +658,7 @@ export class Hub implements HubInterface { allowedPeerIdStrs: this.allowedPeerIds, deniedPeerIdStrs: this.deniedPeerIds, directPeers: this.options.directPeers, - allowlistedImmunePeers: this.options.allowlistedImmunePeers ?? PEER_SCORE_IMMUNE_PEERS, + allowlistedImmunePeers: this.options.allowlistedImmunePeers, applicationScoreCap: this.options.applicationScoreCap, }); @@ -713,11 +692,12 @@ export class Hub implements HubInterface { /** Apply the new the network config. Will return true if the Hub should exit */ public applyNetworkConfig(networkConfig: NetworkConfig): boolean { - const { allowedPeerIds, deniedPeerIds, shouldExit } = applyNetworkConfig( + const { allowedPeerIds, deniedPeerIds, allowlistedImmunePeers, shouldExit } = applyNetworkConfig( networkConfig, this.allowedPeerIds, this.deniedPeerIds, this.options.network, + this.options.allowlistedImmunePeers, ); if (shouldExit) { @@ -729,7 +709,9 @@ export class Hub implements HubInterface { this.gossipNode.updateDeniedPeerIds(deniedPeerIds); this.deniedPeerIds = deniedPeerIds; - log.info({ allowedPeerIds, deniedPeerIds }, "Network config applied"); + this.allowlistedImmunePeers = allowlistedImmunePeers; + + log.info({ allowedPeerIds, deniedPeerIds, allowlistedImmunePeers }, "Network config applied"); return false; } diff --git a/apps/hubble/src/network/p2p/gossipNodeWorker.ts b/apps/hubble/src/network/p2p/gossipNodeWorker.ts index 52d78da2a0..76f440ce0b 100644 --- a/apps/hubble/src/network/p2p/gossipNodeWorker.ts +++ b/apps/hubble/src/network/p2p/gossipNodeWorker.ts @@ -124,18 +124,16 @@ export class LibP2PNode { scoreThresholds: { ...options.scoreThresholds }, scoreParams: { appSpecificScore: (peerId) => { + const score = this._peerScores?.get(peerId) ?? 0; if (options.allowlistedImmunePeers?.includes(peerId)) { - if ((this._peerScores?.get(peerId) ?? 0) < -100) { - log.warn({ peerId }, "GossipSub: Allowlisted peer would have been kicked out."); + if (score < -100) { + log.warn({ peerId, score }, "GossipSub: Allowlisted peer would have been kicked out."); } return options.applicationScoreCap ?? APPLICATION_SCORE_CAP_DEFAULT; } - return Math.min( - this._peerScores?.get(peerId) ?? 0, - options.applicationScoreCap ?? APPLICATION_SCORE_CAP_DEFAULT, - ); + return Math.min(score, options.applicationScoreCap ?? APPLICATION_SCORE_CAP_DEFAULT); }, }, }); diff --git a/apps/hubble/src/network/utils/networkConfig.ts b/apps/hubble/src/network/utils/networkConfig.ts index 2e8a794a96..1d6d4dcc0b 100644 --- a/apps/hubble/src/network/utils/networkConfig.ts +++ b/apps/hubble/src/network/utils/networkConfig.ts @@ -21,11 +21,13 @@ export type NetworkConfig = { storageRegistryAddress: `0x${string}` | undefined; keyRegistryAddress: `0x${string}` | undefined; idRegistryAddress: `0x${string}` | undefined; + allowlistedImmunePeers: string[] | undefined; }; export type NetworkConfigResult = { allowedPeerIds: string[] | undefined; deniedPeerIds: string[]; + allowlistedImmunePeers: string[] | undefined; shouldExit: boolean; }; @@ -81,10 +83,11 @@ export function applyNetworkConfig( allowedPeerIds: string[] | undefined, deniedPeerIds: string[], currentNetwork: number, + allowlistedImmunePeers: string[] | undefined, ): NetworkConfigResult { if (networkConfig.network !== currentNetwork) { log.error({ networkConfig, network: currentNetwork }, "network config mismatch"); - return { allowedPeerIds, deniedPeerIds, shouldExit: false }; + return { allowedPeerIds, deniedPeerIds, allowlistedImmunePeers, shouldExit: false }; } // Refuse to start if we are below the minAppVersion @@ -94,7 +97,7 @@ export function applyNetworkConfig( if (semver.lt(APP_VERSION, minAppVersion)) { const errMsg = "Hubble version is too old too start. Please update your node."; log.fatal({ minAppVersion, ourVersion: APP_VERSION }, errMsg); - return { allowedPeerIds, deniedPeerIds, shouldExit: true }; + return { allowedPeerIds, deniedPeerIds, allowlistedImmunePeers, shouldExit: true }; } } else { log.error({ networkConfig }, "invalid minAppVersion"); @@ -118,5 +121,17 @@ export function applyNetworkConfig( log.info({ networkConfig }, "network config does not contain 'deniedPeers'"); } - return { allowedPeerIds: newPeerIdList, deniedPeerIds: newDeniedPeerIdList, shouldExit: false }; + let newAllowlistedImmunePeers: string[] = []; + if (networkConfig.allowlistedImmunePeers) { + newAllowlistedImmunePeers = [ + ...new Set([...(allowlistedImmunePeers ?? []), ...networkConfig.allowlistedImmunePeers]), + ]; + } + + return { + allowedPeerIds: newPeerIdList, + deniedPeerIds: newDeniedPeerIdList, + allowlistedImmunePeers: newAllowlistedImmunePeers, + shouldExit: false, + }; }