Skip to content

Commit

Permalink
Merge branch 'main' into 2531-telemetry-local-payments
Browse files Browse the repository at this point in the history
  • Loading branch information
beniaminmunteanu committed Apr 2, 2024
2 parents 566e1be + 88ae1d4 commit 5e5b8f9
Show file tree
Hide file tree
Showing 39 changed files with 274 additions and 181 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lint_test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ jobs:

- name: Setup hosts
run: |
echo "127.0.0.1 host.docker.internal" | sudo tee -a /etc/hosts
echo "127.0.0.1 cloud-nine-wallet-test-backend" | sudo tee -a /etc/hosts
echo "127.0.0.1 cloud-nine-wallet-test-auth" | sudo tee -a /etc/hosts
echo "127.0.0.1 happy-life-bank-test-backend" | sudo tee -a /etc/hosts
echo "127.0.0.1 happy-life-bank-test-auth" | sudo tee -a /etc/hosts
- name: Build dependencies
run: pnpm --filter integration build:deps
Expand Down
2 changes: 1 addition & 1 deletion aws/lambdas/exchange-rates/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.1

require (
github.com/aws/aws-lambda-go v1.46.0
github.com/aws/aws-sdk-go v1.51.5
github.com/aws/aws-sdk-go v1.51.9
)

require github.com/jmespath/go-jmespath v0.4.0 // indirect
2 changes: 2 additions & 0 deletions aws/lambdas/exchange-rates/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/aws/aws-sdk-go v1.51.2 h1:Ruwgz5aqIXin5Yfcgc+PCzoqW5tEGb9aDL/JWDsre7k
github.com/aws/aws-sdk-go v1.51.2/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.51.5 h1:tUHg/ZJgS2Hog4Wl4xpbBqCrmFg6AYv7gPVaCs4v0+s=
github.com/aws/aws-sdk-go v1.51.5/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.51.9 h1:w6ZlyFX7l4+ZNVPmWw7LwOHSaBDDQuP22l1gh7OYu7w=
github.com/aws/aws-sdk-go v1.51.9/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
Expand Down
8 changes: 4 additions & 4 deletions infrastructure/helm/rafiki/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
dependencies:
- name: redis
repository: https://charts.bitnami.com/bitnami
version: 18.19.4
version: 19.0.1
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 14.3.3
version: 15.1.4
- name: rafiki-auth
repository: https://interledger.github.io/helm-charts
version: 0.4.0
Expand All @@ -14,5 +14,5 @@ dependencies:
- name: rafiki-frontend
repository: https://interledger.github.io/helm-charts
version: 0.4.0
digest: sha256:272dc69d4e5c3b37660ca38d5d959dc33e75c91c507c3af6df406f885dd90fad
generated: "2024-03-18T18:03:39.549030166Z"
digest: sha256:3aadc4eef1a8667d4e2f3406e08b919501fb1073feb5bff0d2339719ce3904a6
generated: "2024-03-26T09:20:34.879805696Z"
4 changes: 2 additions & 2 deletions infrastructure/helm/rafiki/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ appVersion: 'v1.0.0-alpha.1'

dependencies:
- name: redis
version: "18.19.4"
version: "19.0.1"
repository: "https://charts.bitnami.com/bitnami"
- name: postgresql
version: '14.3.3'
version: '15.1.4'
repository: 'https://charts.bitnami.com/bitnami'
- name: rafiki-auth
version: '0.4.0'
Expand Down
4 changes: 2 additions & 2 deletions localenv/mock-account-servicing-entity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"typecheck": "tsc"
},
"dependencies": {
"@apollo/client": "^3.9.8",
"@apollo/client": "^3.9.9",
"@interledger/http-signature-utils": "2.0.2",
"@remix-run/node": "^2.6.0",
"@remix-run/react": "^2.6.0",
Expand All @@ -26,7 +26,7 @@
},
"devDependencies": {
"@remix-run/dev": "^2.6.0",
"@types/react": "^18.2.67",
"@types/react": "^18.2.73",
"@types/react-dom": "^18.2.22"
},
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
FROM base AS prod-deps

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY packages/auth/knexfile.js ./packages/auth/knexfile.js
COPY packages/auth/package.json ./packages/auth/package.json
COPY packages/token-introspection/package.json ./packages/token-introspection/package.json

Expand Down Expand Up @@ -51,10 +52,10 @@ COPY --from=prod-deps /home/rafiki/packages/auth/node_modules ./packages/auth/no
COPY --from=prod-deps /home/rafiki/packages/auth/package.json ./packages/auth/package.json
COPY --from=prod-deps /home/rafiki/packages/token-introspection/node_modules ./packages/token-introspection/node_modules
COPY --from=prod-deps /home/rafiki/packages/token-introspection/package.json ./packages/token-introspection/package.json
COPY --from=prod-deps /home/rafiki/packages/auth/knexfile.js ./packages/auth/knexfile.js

COPY --from=builder /home/rafiki/packages/auth/migrations/ ./packages/auth/migrations
COPY --from=builder /home/rafiki/packages/auth/dist ./packages/auth/dist
COPY --from=builder /home/rafiki/packages/token-introspection/dist ./packages/token-introspection/dist


CMD ["node", "/home/rafiki/packages/auth/dist/index.js"]
9 changes: 8 additions & 1 deletion packages/auth/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { knex } = require('knex')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { GenericContainer } = require('testcontainers')
const { GenericContainer, Wait } = require('testcontainers')

const POSTGRES_PORT = 5432

Expand All @@ -20,6 +20,13 @@ module.exports = async (globalConfig) => {
.withEnvironment({
POSTGRES_PASSWORD: 'password'
})
.withHealthCheck({
test: ['CMD-SHELL', 'pg_isready -d testing'],
interval: 10000,
timeout: 5000,
retries: 5
})
.withWaitStrategy(Wait.forHealthCheck())
.start()

process.env.AUTH_DATABASE_URL = `postgresql://postgres:password@localhost:${postgresContainer.getMappedPort(
Expand Down
6 changes: 1 addition & 5 deletions packages/auth/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ module.exports = {

production: {
client: 'postgresql',
connection: {
database: 'my_auth_db',
user: 'username',
password: 'password'
},
connection: process.env.AUTH_DATABASE_URL,
pool: {
min: 2,
max: 10
Expand Down
8 changes: 4 additions & 4 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@adonisjs/fold": "^8.2.0",
"@apollo/server": "^4.10.1",
"@apollo/server": "^4.10.2",
"@as-integrations/koa": "^1.1.1",
"@escape.tech/graphql-armor": "^2.4.0",
"@graphql-tools/graphql-file-loader": "^8.0.1",
Expand All @@ -38,7 +38,7 @@
"dotenv": "^16.4.5",
"graphql": "^16.8.1",
"knex": "^3.1.0",
"koa": "^2.15.1",
"koa": "^2.15.2",
"koa-bodyparser": "^4.4.1",
"koa-session": "^6.4.0",
"objection": "^3.1.4",
Expand All @@ -49,7 +49,7 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"@apollo/client": "^3.9.8",
"@apollo/client": "^3.9.9",
"@faker-js/faker": "^8.4.1",
"@graphql-codegen/cli": "5.0.2",
"@graphql-codegen/introspection": "4.0.3",
Expand All @@ -66,7 +66,7 @@
"nock": "^13.5.4",
"node-mocks-http": "^1.14.1",
"openapi-types": "^12.1.3",
"pino-pretty": "^10.3.1",
"pino-pretty": "^11.0.0",
"testcontainers": "^10.7.2"
}
}
1 change: 1 addition & 0 deletions packages/auth/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const Config = {
introspectionPort: envInt('INTROSPECTION_PORT', 3007),
env: envString('NODE_ENV', 'development'),
trustProxy: envBool('TRUST_PROXY', false),
enableManualMigrations: envBool('ENABLE_MANUAL_MIGRATIONS', false),
databaseUrl:
process.env.NODE_ENV === 'test'
? `${process.env.AUTH_DATABASE_URL}_${process.env.JEST_WORKER_ID}`
Expand Down
16 changes: 10 additions & 6 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,22 @@ export const start = async (
}
})

const config = await container.use('config')

// Do migrations
const knex = await container.use('knex')
// Needs a wrapped inline function
await callWithRetry(async () => {
await knex.migrate.latest({
directory: __dirname + '/../migrations'

if (!config.enableManualMigrations) {
// Needs a wrapped inline function
await callWithRetry(async () => {
await knex.migrate.latest({
directory: __dirname + '/../migrations'
})
})
})
}

Model.knex(knex)

const config = await container.use('config')
await app.boot()

await app.startAdminServer(config.adminPort)
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
FROM base AS prod-deps

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY packages/backend/knexfile.js ./packages/backend/knexfile.js
COPY packages/backend/package.json ./packages/backend/package.json
COPY packages/token-introspection/package.json ./packages/token-introspection/package.json

Expand Down Expand Up @@ -51,10 +52,11 @@ COPY --from=prod-deps /home/rafiki/packages/backend/node_modules ./packages/back
COPY --from=prod-deps /home/rafiki/packages/backend/package.json ./packages/backend/package.json
COPY --from=prod-deps /home/rafiki/packages/token-introspection/node_modules ./packages/token-introspection/node_modules
COPY --from=prod-deps /home/rafiki/packages/token-introspection/package.json ./packages/token-introspection/package.json
COPY --from=prod-deps /home/rafiki/packages/backend/knexfile.js ./packages/backend/knexfile.js

COPY --from=builder /home/rafiki/packages/backend/migrations/ ./packages/backend/migrations
COPY --from=builder /home/rafiki/packages/backend/dist ./packages/backend/dist
COPY --from=builder /home/rafiki/packages/token-introspection/dist ./packages/token-introspection/dist

COPY --from=builder /home/rafiki/packages/backend/knexfile.js ./packages/backend/knexfile.js

CMD ["node", "/home/rafiki/packages/backend/dist/index.js"]
6 changes: 1 addition & 5 deletions packages/backend/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ module.exports = {

production: {
client: 'postgresql',
connection: {
database: 'my_db',
user: 'username',
password: 'password'
},
connection: process.env.DATABASE_URL,
pool: {
min: 2,
max: 10
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"postinstall": "pnpm copy-op-schemas"
},
"devDependencies": {
"@apollo/client": "^3.9.8",
"@apollo/client": "^3.9.9",
"@graphql-codegen/cli": "5.0.2",
"@graphql-codegen/introspection": "4.0.3",
"@graphql-codegen/typescript": "4.0.6",
Expand Down Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"@adonisjs/fold": "^8.2.0",
"@apollo/server": "^4.10.1",
"@apollo/server": "^4.10.2",
"@as-integrations/koa": "^1.1.1",
"@escape.tech/graphql-armor": "^2.4.0",
"@faker-js/faker": "^8.4.1",
Expand Down Expand Up @@ -78,7 +78,7 @@
"ioredis": "^5.3.2",
"json-canonicalize": "^1.0.6",
"knex": "^3.1.0",
"koa": "^2.15.1",
"koa": "^2.15.2",
"koa-bodyparser": "^4.4.1",
"lodash": "^4.17.21",
"luxon": "^3.4.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/accounting/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function createAccountToAccountTransfer(
const balance = await getAccountBalance(account.id)

if (balance === undefined) {
throw new Error()
throw new Error('undefined account balance')
}

await account.onDebit({
Expand All @@ -185,7 +185,7 @@ export async function createAccountToAccountTransfer(
const totalReceived = await getAccountReceived(destinationAccount.id)

if (totalReceived === undefined) {
throw new Error()
throw new Error('total received is undefined')
}

await destinationAccount.onCredit({
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/accounting/tigerbeetle/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function toTigerbeetleId(id: AccountId): bigint {
return id
}
if (!validateId(id)) {
throw new Error()
throw new Error('wrong format of id')
}

return uuidToBigInt(id)
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const Config = {
connectorPort: envInt('CONNECTOR_PORT', 3002),
autoPeeringServerPort: envInt('AUTO_PEERING_SERVER_PORT', 3005),
enableAutoPeering: envBool('ENABLE_AUTO_PEERING', false),
enableManualMigrations: envBool('ENABLE_MANUAL_MIGRATIONS', false),
databaseUrl:
process.env.NODE_ENV === 'test'
? `${process.env.DATABASE_URL}_${process.env.JEST_WORKER_ID}`
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/graphql/resolvers/liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export const depositEventLiquidity: MutationResolvers<ApolloContext>['depositEve
return responses[LiquidityError.InvalidId]
}
if (!event.data.debitAmount) {
throw new Error()
throw new Error('missing debit amount')
}
const outgoingPaymentService = await ctx.container.use(
'outgoingPaymentService'
Expand Down Expand Up @@ -434,7 +434,7 @@ export const withdrawEventLiquidity: MutationResolvers<ApolloContext>['withdrawE
const assetService = await ctx.container.use('assetService')
const asset = await assetService.get(event.withdrawal.assetId)
if (!asset) {
throw new Error()
throw new Error('asset id does not map to asset')
}
const accountingService = await ctx.container.use('accountingService')
const error = await accountingService.createWithdrawal({
Expand Down
16 changes: 10 additions & 6 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,18 +569,22 @@ export const start = async (
}
})

const config = await container.use('config')

// Do migrations
const knex = await container.use('knex')
// Needs a wrapped inline function
await callWithRetry(async () => {
await knex.migrate.latest({
directory: __dirname + '/../migrations'

if (!config.enableManualMigrations) {
// Needs a wrapped inline function
await callWithRetry(async () => {
await knex.migrate.latest({
directory: __dirname + '/../migrations'
})
})
})
}

Model.knex(knex)

const config = await container.use('config')
await app.boot()
await app.startAdminServer(config.adminPort)
logger.info(`Admin listening on ${app.getAdminPort()}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async function handleDeactivated(
incomingPayment: IncomingPayment
): Promise<void> {
if (!incomingPayment.processAt) {
throw new Error()
throw new Error('processAt field is not defined')
}
try {
const amountReceived = await deps.accountingService.getTotalReceived(
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/open_payments/quote/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class Quote extends WalletAddressSubresource {
Pay.Int.from(this.highEstimatedExchangeRateDenominator) as Pay.PositiveInt
)
if (!highEstimatedExchangeRate.isPositive()) {
throw new Error()
throw new Error('high estimated exchange rate is not positive')
}
return highEstimatedExchangeRate
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/tests/outgoingPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function createOutgoingPayment(
quoteId: quote.id
})
if (isOutgoingPaymentError(outgoingPaymentOrError)) {
throw new Error()
throw new Error(outgoingPaymentOrError)
}

const accountingService = await deps.use('accountingService')
Expand Down
Loading

0 comments on commit 5e5b8f9

Please sign in to comment.