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

feat: refactor protobufs and utils to remove grpc-js dependency #798

Merged
merged 12 commits into from
Apr 4, 2023
10 changes: 10 additions & 0 deletions .changeset/honest-news-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@farcaster/protobufs': minor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally it's major change for protobufs and utils (interface not backward compatible). However, it seems that we haven't released major version of protobufs & utils yet, so I made it minor.

'@farcaster/hub-web': minor
'@farcaster/utils': minor
'@farcaster/hub-nodejs': patch
'@farcaster/hubble': patch
---

remove grpc-js dependency from protobufs, refactor hubble to use hub-nodejs
hub-web to use @farcaster/protobufs and utils
3 changes: 1 addition & 2 deletions apps/hubble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
"dependencies": {
"@chainsafe/libp2p-gossipsub": "6.1.0",
"@chainsafe/libp2p-noise": "^11.0.0 ",
"@farcaster/protobufs": "0.1.11",
"@farcaster/utils": "0.4.0",
"@farcaster/hub-nodejs": "^0.6.0",
Copy link
Contributor Author

@PangZhi PangZhi Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the process for package release here? We need to release and update dependency to new version in order:
protobuf, utils, hub-nodejs & hub-web, hubble app

Do we need to break this PR into multiple PRs for release purpose?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use changesets for version control, so we can run yarn changeset version and it will update all of these correctly.

"@grpc/grpc-js": "~1.8.7",
"@libp2p/interface-connection": "^3.0.2",
"@libp2p/interface-peer-id": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/hubble/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { FarcasterNetwork } from '@farcaster/protobufs';
import { FarcasterNetwork } from '@farcaster/hub-nodejs';
import { PeerId } from '@libp2p/interface-peer-id';
import { createEd25519PeerId, createFromProtobuf, exportToProtobuf } from '@libp2p/peer-id-factory';
import { Command } from 'commander';
Expand Down
7 changes: 3 additions & 4 deletions apps/hubble/src/console/adminCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as protobufs from '@farcaster/protobufs';
import { AdminRpcClient } from '@farcaster/utils';
import { AdminRpcClient, Empty } from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

export class AdminCommand implements ConsoleCommandInterface {
Expand All @@ -21,15 +20,15 @@ export class AdminCommand implements ConsoleCommandInterface {
object() {
return {
rebuildSyncTrie: async () => {
const result = await this.adminClient.rebuildSyncTrie(protobufs.Empty.create());
const result = await this.adminClient.rebuildSyncTrie(Empty.create());
return result.match(
() => '',
(e) => `Error: ${e}`
);
},

deleteAllMessagesFromDb: async () => {
const result = await this.adminClient.deleteAllMessagesFromDb(protobufs.Empty.create());
const result = await this.adminClient.deleteAllMessagesFromDb(Empty.create());
return result.match(
() => '',
(e) => `Error: ${e}`
Expand Down
10 changes: 8 additions & 2 deletions apps/hubble/src/console/console.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Empty, Metadata } from '@farcaster/protobufs';
import { getAdminRpcClient, getAuthMetadata, getInsecureHubRpcClient, getSSLHubRpcClient } from '@farcaster/utils';
import {
Empty,
Metadata,
getAdminRpcClient,
getAuthMetadata,
getInsecureHubRpcClient,
getSSLHubRpcClient,
} from '@farcaster/hub-nodejs';
import path from 'path';
import * as repl from 'repl';
import { ADMIN_SERVER_PORT } from '~/rpc/adminServer';
Expand Down
19 changes: 13 additions & 6 deletions apps/hubble/src/console/genCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as protobufs from '@farcaster/protobufs';
import { AdminRpcClient, Factories, getAuthMetadata, HubRpcClient } from '@farcaster/utils';
import {
AdminRpcClient,
Factories,
getAuthMetadata,
HubRpcClient,
Metadata,
FarcasterNetwork,
Message,
} from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

// We use console.log() in this file, so we disable the eslint rule. This is the REPL console, after all!
Expand Down Expand Up @@ -37,12 +44,12 @@ export class GenCommand implements ConsoleCommandInterface {
return {
submitMessages: async (
numMessages = 100,
network = protobufs.FarcasterNetwork.DEVNET,
username?: string | protobufs.Metadata,
network = FarcasterNetwork.DEVNET,
username?: string | Metadata,
password?: string
): Promise<string | SubmitStats> => {
// Submit messages might need a username/password
let metadata = new protobufs.Metadata();
let metadata = new Metadata();
if (username && typeof username !== 'string') {
metadata = username;
} else if (username && password) {
Expand Down Expand Up @@ -83,7 +90,7 @@ export class GenCommand implements ConsoleCommandInterface {
return `Failed to submit signer add message for fid ${fid}: ${signerResult.error}`;
}

const submitBatch = async (batch: protobufs.Message[]) => {
const submitBatch = async (batch: Message[]) => {
const promises = [];
for (const castAdd of batch) {
promises.push(this.rpcClient.submitMessage(castAdd, metadata));
Expand Down
6 changes: 3 additions & 3 deletions apps/hubble/src/console/protobufCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as protobufs from '@farcaster/protobufs';
import { Factories } from '@farcaster/utils';
import * as hub_nodejs from '@farcaster/hub-nodejs';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you camelCase this variable?

import { Factories } from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

export class ProtobufCommand implements ConsoleCommandInterface {
Expand All @@ -18,7 +18,7 @@ export class ProtobufCommand implements ConsoleCommandInterface {
`;
}
object() {
return protobufs;
return hub_nodejs;
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/hubble/src/console/rpcClientCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HubRpcClient } from '@farcaster/utils';
import { HubRpcClient } from '@farcaster/hub-nodejs';
import { ConsoleCommandInterface } from './console';

export class RpcClientCommand implements ConsoleCommandInterface {
Expand Down
Loading