Skip to content

Commit

Permalink
fix: validate the network in ethEventsProvider (#982)
Browse files Browse the repository at this point in the history
* fix: validate the network in ethEventsProvider

* changeset
  • Loading branch information
sanjayprabhu authored May 19, 2023
1 parent 30da04d commit 16ea9b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thin-rivers-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@farcaster/hubble': patch
---

Validate the eth network in ethEventsProvider
2 changes: 2 additions & 0 deletions apps/hubble/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Mainnet is Farcaster's production environment apps use and writing a message her

1. Update the `.env` file in your `apps/hubble` directory, substituting the relevant value for your `ETH_RPC_URL`:
```
# Note: this should still point to goerli and not eth mainnet
ETH_RPC_URL=your-ETH-RPC-URL
FC_NETWORK_ID=1
BOOTSTRAP_NODE=/dns/nemes.farcaster.xyz/tcp/2282
Expand Down Expand Up @@ -119,6 +120,7 @@ Mainnet is Farcaster's production environment apps use and writing a message her
1. Update the `.env` file in your `apps/hubble` directory, substituting the relevant value for your `ETH_RPC_URL`:
```
# Note: this should still point to goerli and not eth mainnet
ETH_RPC_URL=your-ETH-RPC-URL
FC_NETWORK_ID=1
BOOTSTRAP_NODE=/dns/nemes.farcaster.xyz/tcp/2282
Expand Down
13 changes: 12 additions & 1 deletion apps/hubble/src/eth/ethEventsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class GoerliEthConstants {
public static NameRegistryAddress = '0xe3be01d99baa8db9905b33a3ca391238234b79d1';
public static FirstBlock = 7648795;
public static ChunkSize = 10000;
public static chainId = BigInt(5);
}

type NameRegistryRenewEvent = Omit<NameRegistryEvent, 'to' | 'from'>;
Expand Down Expand Up @@ -205,14 +206,24 @@ export class EthEventsProvider {
return;
}

const network = await this.executeCallAsPromiseWithRetry(
() => this._jsonRpcProvider.getNetwork(),
(err) => err
);

if (network.isErr() || network.value.chainId !== GoerliEthConstants.chainId) {
log.error({ err: network.isErr() ? network.error : `Wrong network ${network.value.chainId}` }, 'Bad network');
return;
}

const latestBlock = latestBlockResult.value;

if (!latestBlock) {
log.error('failed to get the latest block from the RPC provider');
return;
}

log.info({ latestBlock: latestBlock.number }, 'connected to ethereum node');
log.info({ latestBlock: latestBlock.number, network: network.value.chainId }, 'connected to ethereum node');

// Find how how much we need to sync
let lastSyncedBlock = this._firstBlock;
Expand Down

0 comments on commit 16ea9b4

Please sign in to comment.