Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
CassOnMars committed Oct 20, 2023
1 parent 66e624c commit 98b6f77
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
32 changes: 7 additions & 25 deletions apps/hubble/src/hubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
10 changes: 4 additions & 6 deletions apps/hubble/src/network/p2p/gossipNodeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
},
});
Expand Down
21 changes: 18 additions & 3 deletions apps/hubble/src/network/utils/networkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand All @@ -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,
};
}

0 comments on commit 98b6f77

Please sign in to comment.