Skip to content

Commit

Permalink
feat: add connect relay server
Browse files Browse the repository at this point in the history
  • Loading branch information
horsefacts committed Dec 6, 2023
0 parents commit 45e43ed
Show file tree
Hide file tree
Showing 32 changed files with 7,455 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**/node_modules/
**/.git
**/README.md
**/LICENSE
**/.vscode
**/npm-debug.log
**/coverage
**/.env
**/.editorconfig
**/.aws
**/.github
**/build
**/.husky
**/dist
**/Dockerfile*
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**What is the bug?**
A concise, high level description of the bug and how it affects you

**How can it be reproduced? (optional)**
Include steps, code samples, replits, screenshots and anything else that would be helpful to reproduce the problem.

**Additional context (optional)**
Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Feature
about: "Opening new feature requests "
title: "feat: "
labels: ""
assignees: ""
---

**What is the feature you would like to implement?**
A concise, high level summary of the feature

**Why is this feature important?**
An argument for why this feature should be build and how it should be prioritized

**How should this feature be built? (optional)**
A design for the implementation of the feature

**Additional context**
Add any other context or screenshots about the feature request here.
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Motivation

Describe why this issue should be fixed and link to any relevant design docs, issues or other relevant items.

## Change Summary

Describe the changes being made in 1-2 concise sentences.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time before submitting for review_

- [ ] PR title adheres to the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [ ] PR has a changeset
- [ ] PR has been tagged with a change label(s) (i.e. documentation, feature, bugfix, or chore)
- [ ] PR includes documentation if necessary
- [ ] All commits have been signed

## Additional Context

If this is a relatively large or complex change, provide more details here that will help reviewers
123 changes: 123 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: CI
on:
# CI is run on main because new branches can only access caches from master, not previous branches.
# So building on master allows new PR's to get the cache from before.
push:
branches: [main]
pull_request:
branches: [main]

# prevent multiple simultaneous test runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
build-image:
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Docker buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
id: docker-image
uses: docker/build-push-action@v4
with:
cache-from: type=gha
cache-to: type=gha,type=inline
context: .
file: Dockerfile.hubble
load: true
tags: farcasterxyz/hubble:test

- name: Run Hubble
shell: bash
run: docker run --name hub --detach -p2282:2282 -p2283:2283 farcasterxyz/hubble:test sh -c 'node build/cli.js identity create && node build/cli.js start --rpc-port 2283 --ip 0.0.0.0 --gossip-port 2282 --eth-mainnet-rpc-url "https://eth-mainnet.g.alchemy.com/v2/8cz__IXnQ5FK_GNYDlfooLzYhBAW7ta0" --l2-rpc-url "https://opt-mainnet.g.alchemy.com/v2/3xWX-cWV-an3IPXmVCRXX51PpQzc-8iJ" --network 3 --allowed-peers none'

- name: Download grpcurl
shell: bash
run: curl -L https://github.com/fullstorydev/grpcurl/releases/download/v1.8.7/grpcurl_1.8.7_linux_x86_64.tar.gz -o - | tar -xzf -

- name: Check that gRPC server is running
uses: nick-fields/retry@v2
with:
timeout_seconds: 10
retry_wait_seconds: 5
max_attempts: 10
shell: bash
command: ./grpcurl -plaintext -import-path protobufs/schemas -proto protobufs/schemas/rpc.proto 127.0.0.1:2283 HubService.GetInfo
on_retry_command: docker logs hub

analyze:
timeout-minutes: 10
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: '20'

- name: Restore cached dependencies for Node modules.
id: module-cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}--node--${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
run: yarn install

# - name: Run audit
# run: yarn audit

- name: Run build
run: yarn build

- name: Run linter
run: yarn lint:ci

test:
timeout-minutes: 10
runs-on: 'buildjet-4vcpu-ubuntu-2204'

strategy:
matrix:
node_version: [18, 20]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}

- name: Restore cached dependencies for Node modules.
id: module-cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}--node--${{ matrix.node_version}}--${{ hashFiles('**/yarn.lock') }}

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
# Pinning until https://github.com/foundry-rs/foundry/issues/5749 is fixed
version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d

- name: Install dependencies
run: yarn install

- name: Run build
run: yarn build

- name: Run tests
run: yarn test:ci

- name: Upload coverage results
uses: codecov/codecov-action@v3
21 changes: 21 additions & 0 deletions .github/workflows/label_issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Label Issues

on:
issues:
types: [opened]

jobs:
label_issues:
runs-on: ubuntu-latest
steps:
- name: Add label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['s-triage']
})
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Logs
yarn-debug.log*
yarn-error.log*

.DS_Store
**/.DS_Store

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
build
.history
.hub_history

# Dependency directories
node_modules/

# TypeScript cache
*.tsbuildinfo

# Environment variables
.env

.eslintcache
depot.json

.console-history

# Code Coverage Reports
coverage/

# Turborepo
.turbo
out

dist

# Editor Cache
.vscode
.idea
.fleet
**/.vitepress/cache/
**/.vitepress/dist/
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry: https://registry.npmjs.org/
1 change: 1 addition & 0 deletions apps/relay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
21 changes: 21 additions & 0 deletions apps/relay/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "../../node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": false
},
"formatter": {
"enabled": true,
"indentSize": 2,
"indentStyle": "space",
"lineWidth": 120
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"useLiteralKeys": "off"
}
}
}
}
20 changes: 20 additions & 0 deletions apps/relay/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.9"

services:
redis:
image: "redis:7.2-alpine"
restart: unless-stopped
command: --save 1 1 --loglevel warning --maxmemory-policy noeviction
volumes:
- redis-data:/data
ports:
- "6379:6379"
healthcheck:
test: ["CMD-SHELL", "redis-cli", "ping"]
interval: 10s
timeout: 10s
retries: 3
start_period: 5s

volumes:
redis-data:
10 changes: 10 additions & 0 deletions apps/relay/fastify.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FastifyRequest as DefaultFastifyRequest } from "fastify";
import { RelaySession } from "./src/handlers";
import { ChannelStore } from "./src/channels";

declare module "fastify" {
export interface FastifyRequest extends DefaultFastifyRequest {
channelToken: string;
channels: ChannelStore<RelaySession>;
}
}
21 changes: 21 additions & 0 deletions apps/relay/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Config } from "jest";

const jestConfig: Config = {
testEnvironment: "node",
coveragePathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/node_modules/"],
testPathIgnorePatterns: ["<rootDir>/build", "<rootDir>/node_modules"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
/**
* For high performance with minimal configuration transform with TS with swc.
* @see https://github.com/farcasterxyz/hub/issues/314
*/
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
maxWorkers: "50%",
};

export default jestConfig;
Loading

0 comments on commit 45e43ed

Please sign in to comment.