Skip to content

Commit

Permalink
feat: ensure hub networks match when syncing with peers (#837)
Browse files Browse the repository at this point in the history
* feat: ensure hub networks match when syncing with peers

* send the network when gossiping
  • Loading branch information
sanjayprabhu authored Apr 7, 2023
1 parent d12ed86 commit edea195
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/eighty-buckets-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@farcaster/core': patch
'@farcaster/hubble': patch
---

Ensure hub networks match when syncing with peers
8 changes: 6 additions & 2 deletions apps/hubble/src/hubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ export class Hub implements HubInterface {
excludedHashes: snapshot.excludedHashes,
count: snapshot.numMessages,
hubVersion: FARCASTER_VERSION,
network: this.options.network,
});
});
}
Expand Down Expand Up @@ -546,8 +547,11 @@ export class Hub implements HubInterface {
// Ignore peers that are below the minimum supported version.
const theirVersion = message.hubVersion;
const versionCheckResult = ensureAboveMinFarcasterVersion(theirVersion);
if (versionCheckResult.isErr()) {
log.warn({ peerId, theirVersion }, 'Peer is running an invalid or outdated version, ignoring');
if (versionCheckResult.isErr() || message.network !== this.options.network) {
log.warn(
{ peerId, theirVersion, theirNetwork: message.network },
'Peer is running an invalid or outdated version, ignoring'
);
await this.gossipNode.removePeerFromAddressBook(peerId);
this.syncEngine.removeContactInfoForPeerId(peerId.toString());
return;
Expand Down
18 changes: 16 additions & 2 deletions packages/core/src/protobufs/generated/gossip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import _m0 from 'protobufjs/minimal';
import { IdRegistryEvent } from './id_registry_event';
import { Message } from './message';
import { FarcasterNetwork, farcasterNetworkFromJSON, farcasterNetworkToJSON, Message } from './message';

export enum GossipVersion {
V1 = 0,
Expand Down Expand Up @@ -39,6 +39,7 @@ export interface ContactInfoContent {
excludedHashes: string[];
count: number;
hubVersion: string;
network: FarcasterNetwork;
}

export interface GossipMessage {
Expand Down Expand Up @@ -148,7 +149,7 @@ export const GossipAddressInfo = {
};

function createBaseContactInfoContent(): ContactInfoContent {
return { gossipAddress: undefined, rpcAddress: undefined, excludedHashes: [], count: 0, hubVersion: '' };
return { gossipAddress: undefined, rpcAddress: undefined, excludedHashes: [], count: 0, hubVersion: '', network: 0 };
}

export const ContactInfoContent = {
Expand All @@ -168,6 +169,9 @@ export const ContactInfoContent = {
if (message.hubVersion !== '') {
writer.uint32(42).string(message.hubVersion);
}
if (message.network !== 0) {
writer.uint32(48).int32(message.network);
}
return writer;
},

Expand Down Expand Up @@ -213,6 +217,13 @@ export const ContactInfoContent = {

message.hubVersion = reader.string();
continue;
case 6:
if (tag != 48) {
break;
}

message.network = reader.int32() as any;
continue;
}
if ((tag & 7) == 4 || tag == 0) {
break;
Expand All @@ -229,6 +240,7 @@ export const ContactInfoContent = {
excludedHashes: Array.isArray(object?.excludedHashes) ? object.excludedHashes.map((e: any) => String(e)) : [],
count: isSet(object.count) ? Number(object.count) : 0,
hubVersion: isSet(object.hubVersion) ? String(object.hubVersion) : '',
network: isSet(object.network) ? farcasterNetworkFromJSON(object.network) : 0,
};
},

Expand All @@ -245,6 +257,7 @@ export const ContactInfoContent = {
}
message.count !== undefined && (obj.count = Math.round(message.count));
message.hubVersion !== undefined && (obj.hubVersion = message.hubVersion);
message.network !== undefined && (obj.network = farcasterNetworkToJSON(message.network));
return obj;
},

Expand All @@ -265,6 +278,7 @@ export const ContactInfoContent = {
message.excludedHashes = object.excludedHashes?.map((e) => e) || [];
message.count = object.count ?? 0;
message.hubVersion = object.hubVersion ?? '';
message.network = object.network ?? 0;
return message;
},
};
Expand Down
1 change: 1 addition & 0 deletions protobufs/schemas/gossip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ message ContactInfoContent {
repeated string excluded_hashes = 3;
uint32 count = 4;
string hub_version = 5;
FarcasterNetwork network = 6;
}

message GossipMessage {
Expand Down

0 comments on commit edea195

Please sign in to comment.