diff --git a/docker-compose-k6.account.yaml b/docker-compose-k6.account.yaml index 7eb2e29c..d5cb4258 100644 --- a/docker-compose-k6.account.yaml +++ b/docker-compose-k6.account.yaml @@ -18,8 +18,7 @@ services: account-service-webhook: condition: service_healthy environment: - PROVIDER_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service' - WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks' + WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service' account-service-worker: pull_policy: never @@ -32,8 +31,7 @@ services: - redis - ipfs environment: - PROVIDER_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service' - WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks' + WEBHOOK_BASE_URL: 'http://account-service-webhook:3001/webhooks/account-service' account-service-webhook: image: rust:1.80.0 diff --git a/services/account/ENVIRONMENT.md b/services/account/ENVIRONMENT.md index 511b7914..dc2fcc02 100644 --- a/services/account/ENVIRONMENT.md +++ b/services/account/ENVIRONMENT.md @@ -15,7 +15,7 @@ This application recognizes the following environment variables: | `HEALTH_CHECK_SUCCESS_THRESHOLD` | Minimum number of consecutive successful calls to the provider webhook `/health` endpoint before it is marked up again | > 0 | | 10 | | `PROVIDER_ACCESS_TOKEN` | An optional bearer token authentication to the provider webhook | string | | | | `PROVIDER_ACCOUNT_SEED_PHRASE` | Seed phrase for provider MSA control key | string | Y | | -| `PROVIDER_BASE_URL` | Base URL for provider webhook endpoints | URL | Y | | +| `WEBHOOK_BASE_URL` | Base URL for provider webhook endpoints | URL | Y | | | `PROVIDER_ID` | Provider MSA ID | integer | Y | | | `REDIS_URL` | Connection URL for Redis | URL | Y | | | `WEBHOOK_FAILURE_THRESHOLD` | Number of failures allowing in the provider webhook before the service is marked down | > 0 | | 3 | diff --git a/services/account/README.md b/services/account/README.md index 32063073..b5160a85 100644 --- a/services/account/README.md +++ b/services/account/README.md @@ -180,17 +180,6 @@ In order to run this project you need: - [Node.js](https://nodejs.org) - [Docker](https://docs.docker.com/get-docker/) -### Setup - -Clone this repository to your desired folder: - -Example commands: - -```sh - git clone git@github.com:ProjectLibertyLabs/account-service.git - cd account-service -``` - ### Environment Variables Modify any environment variables in the `.env` file as needed. The complete set of environment variables is documented [here](./ENVIRONMENT.md), and a sample environment file is provided [here](./env.template). @@ -209,6 +198,7 @@ Install NPM Dependencies: ```sh npm install + npm install -g @nestjs/cli ``` ### Usage @@ -257,7 +247,7 @@ In order to run the `account-service` in development mode without containers, yo Run the following command to start the account service api and worker containers. This will start the account service api and worker in development mode. ```sh - docker-compose up -d api worker + docker-compose up -d account-service-api account-service-worker ``` #### 4. Check the job in [BullUI](http://0.0.0.0:3000/queues/), to monitor job progress based on defined tests @@ -276,7 +266,7 @@ In order to run the `account-service` in development mode without containers, yo ### Swagger UI -Check out the Swagger UI hosted on the app instance at [http://localhost:3000/api/docs/swagger](http://localhost:3000/api/docs/swagger) to view the API documentation and submit requests to the service. +Check out the Swagger UI hosted on the app instance at [http://localhost:3000/api/docs/swagger](http://localhost:3000/docs/swagger) to view the API documentation and submit requests to the service. ### Queue Management diff --git a/services/account/apps/api/src/build-openapi.ts b/services/account/apps/api/src/build-openapi.ts index a3e98dda..0cd410b1 100644 --- a/services/account/apps/api/src/build-openapi.ts +++ b/services/account/apps/api/src/build-openapi.ts @@ -14,7 +14,7 @@ process.env.FREQUENCY_HTTP_URL = 'http://127.0.0.1'; process.env.PROVIDER_ACCOUNT_SEED_PHRASE = 'offer debate skin describe light badge fish turtle actual inject struggle border'; process.env.PROVIDER_ID = '0'; -process.env.PROVIDER_BASE_URL = 'http://127.0.0.1'; +process.env.WEBHOOK_BASE_URL = 'http://127.0.0.1'; process.env.CAPACITY_LIMIT = '{"type":"amount","value":0}'; // eslint-disable-next-line diff --git a/services/account/apps/api/src/services/api.service.ts b/services/account/apps/api/src/services/api.service.ts index de600443..77fa9251 100644 --- a/services/account/apps/api/src/services/api.service.ts +++ b/services/account/apps/api/src/services/api.service.ts @@ -15,13 +15,4 @@ export class ApiService implements OnApplicationShutdown { this.logger.error(`Error during cleanup on shutdown: ${e}`); } } - - // async watchGraphs(watchGraphsDto: WatchGraphsDto): Promise { - // watchGraphsDto.msaIds.forEach(async (msaId) => { - // const redisKey = `${QueueConstants.REDIS_WATCHER_PREFIX}:${msaId}`; - // const redisValue = watchGraphsDto.webhookEndpoint; - // // eslint-disable-next-line no-await-in-loop - // await this.redis.rpush(redisKey, redisValue); - // }); - // } } diff --git a/services/account/apps/worker/src/transaction_notifier/notifier.service.ts b/services/account/apps/worker/src/transaction_notifier/notifier.service.ts index f889be4e..989b1f0d 100644 --- a/services/account/apps/worker/src/transaction_notifier/notifier.service.ts +++ b/services/account/apps/worker/src/transaction_notifier/notifier.service.ts @@ -257,6 +257,6 @@ export class TxnNotifierService } async getWebhook(): Promise { - return this.configService.providerBaseUrl.toString(); + return this.configService.webhookBaseUrl.toString(); } } diff --git a/services/account/env.template b/services/account/env.template index cee27b7d..13d7ca8b 100644 --- a/services/account/env.template +++ b/services/account/env.template @@ -17,8 +17,8 @@ FREQUENCY_HTTP_URL=http://0.0.0.0:9944 PROVIDER_ID=1 # Base URL for provider webhook endpoints -#PROVIDER_BASE_URL=http://localhost:5555/api/v3 -PROVIDER_BASE_URL=http://host.docker.internal:5555/api/v3/webhook +#WEBHOOK_BASE_URL=http://localhost:5555/api/v3 +WEBHOOK_BASE_URL=http://host.docker.internal:5555/api/v3/webhook # Redis URL REDIS_URL=redis://0.0.0.0:6379 @@ -26,10 +26,12 @@ REDIS_URL=redis://0.0.0.0:6379 # How many seconds to delay between successive scans of the chain # for new content (after end of chain is reached) -BLOCKCHAIN_SCAN_INTERVAL_SECONDS=12 +BLOCKCHAIN_SCAN_INTERVAL_SECONDS=3 # Whether to examine blocks that have not been finalized when tracking extrinsic completion -TRUST_UNFINALIZED_BLOCKS=false +# Trusting unfinalized blocks is faster but in the unlikely event of a chain reorganization +# it may result in incorrect data. If set to false, the service will wait for blocks to be finalized +TRUST_UNFINALIZED_BLOCKS=true # An optional bearer token authentication to the provider webhook PROVIDER_ACCESS_TOKEN=some-token @@ -59,7 +61,7 @@ HEALTH_CHECK_SUCCESS_THRESHOLD=10 CAPACITY_LIMIT='{"type":"percentage", "value":80}' # URL for the Sign-In With Frequency UI -SIWF_URL=https://projectlibertylabs.github.io/siwf/ui +SIWF_URL=https://ProjectLibertyLabs.github.io/siwf/ui # Domain for the Sign-in with Frequency login payload SIWF_DOMAIN=localhost diff --git a/services/account/libs/common/src/blockchain/blockchain.service.spec.ts b/services/account/libs/common/src/blockchain/blockchain.service.spec.ts index e001c13f..611edf57 100644 --- a/services/account/libs/common/src/blockchain/blockchain.service.spec.ts +++ b/services/account/libs/common/src/blockchain/blockchain.service.spec.ts @@ -15,7 +15,7 @@ describe('BlockchainService', () => { const configService = { logger: jest.fn(), nestConfigService: jest.fn(), - providerBaseUrl: jest.fn(), + webhookBaseUrl: jest.fn(), providerApiToken: jest.fn(), getProviderId: jest.fn(), getQueueHighWater: jest.fn(), diff --git a/services/account/libs/common/src/config/config.service.spec.ts b/services/account/libs/common/src/config/config.service.spec.ts index f30650b1..e602ab3b 100644 --- a/services/account/libs/common/src/config/config.service.spec.ts +++ b/services/account/libs/common/src/config/config.service.spec.ts @@ -46,7 +46,7 @@ describe('AccountSericeConfig', () => { PROVIDER_ID: undefined, SIWF_URL: undefined, SIWF_DOMAIN: undefined, - PROVIDER_BASE_URL: undefined, + WEBHOOK_BASE_URL: undefined, PROVIDER_ACCESS_TOKEN: undefined, WEBHOOK_FAILURE_THRESHOLD: undefined, HEALTH_CHECK_SUCCESS_THRESHOLD: undefined, @@ -186,7 +186,7 @@ describe('AccountSericeConfig', () => { }); it('should get provider base url', () => { - expect(accountServiceConfig.providerBaseUrl?.toString()).toStrictEqual(ALL_ENV.PROVIDER_BASE_URL?.toString()); + expect(accountServiceConfig.webhookBaseUrl?.toString()).toStrictEqual(ALL_ENV.WEBHOOK_BASE_URL?.toString()); }); it('should get provider api token', () => { diff --git a/services/account/libs/common/src/config/config.service.ts b/services/account/libs/common/src/config/config.service.ts index 5017cafd..8e05e8b8 100644 --- a/services/account/libs/common/src/config/config.service.ts +++ b/services/account/libs/common/src/config/config.service.ts @@ -13,7 +13,7 @@ export interface ConfigEnvironmentVariables { PROVIDER_ID: string; SIWF_URL: string; SIWF_DOMAIN: string; - PROVIDER_BASE_URL: string; + WEBHOOK_BASE_URL: string; PROVIDER_ACCESS_TOKEN: string; WEBHOOK_FAILURE_THRESHOLD: number; HEALTH_CHECK_SUCCESS_THRESHOLD: number; @@ -40,8 +40,8 @@ export class ConfigService { return this.nestConfigService.get('TRUST_UNFINALIZED_BLOCKS') ?? false; } - public get providerBaseUrl(): URL { - return this.nestConfigService.get('PROVIDER_BASE_URL')!; + public get webhookBaseUrl(): URL { + return this.nestConfigService.get('WEBHOOK_BASE_URL')!; } public get providerApiToken(): string | undefined { diff --git a/services/account/libs/common/src/config/env.config.ts b/services/account/libs/common/src/config/env.config.ts index 4465afbc..caf18679 100644 --- a/services/account/libs/common/src/config/env.config.ts +++ b/services/account/libs/common/src/config/env.config.ts @@ -22,7 +22,7 @@ export const configModuleOptions: ConfigModuleOptions = { } return value; }), - PROVIDER_BASE_URL: Joi.string().uri().required(), + WEBHOOK_BASE_URL: Joi.string().uri().required(), PROVIDER_ACCESS_TOKEN: Joi.string().default(''), WEBHOOK_FAILURE_THRESHOLD: Joi.number().min(1).default(3), WEBHOOK_RETRY_INTERVAL_SECONDS: Joi.number().min(1).default(10), diff --git a/services/account/libs/common/src/services/provider-webhook.service.ts b/services/account/libs/common/src/services/provider-webhook.service.ts index b37a587c..6c0befd9 100644 --- a/services/account/libs/common/src/services/provider-webhook.service.ts +++ b/services/account/libs/common/src/services/provider-webhook.service.ts @@ -34,7 +34,7 @@ export class ProviderWebhookService implements OnModuleDestroy { ) { this.logger = new Logger(this.constructor.name); this.webhook = axios.create({ - baseURL: this.configService.providerBaseUrl.toString(), + baseURL: this.configService.webhookBaseUrl.toString(), }); this.webhook.defaults.headers.common.Authorization = this.configService.providerApiToken; @@ -61,7 +61,7 @@ export class ProviderWebhookService implements OnModuleDestroy { if (this.failedHealthChecks > 0) { if (this.failedHealthChecks >= this.configService.healthCheckMaxRetries) { this.logger.error( - `FATAL ERROR: Failed to connect to provider webhook at '${this.configService.providerBaseUrl}' after ${this.failedHealthChecks} attempts.`, + `FATAL ERROR: Failed to connect to provider webhook at '${this.configService.webhookBaseUrl}' after ${this.failedHealthChecks} attempts.`, ); this.eventEmitter.emit('shutdown'); return; diff --git a/services/account/scripts/docker-clean-up.sh b/services/account/scripts/docker-clean-up.sh index 3cb66eca..72690827 100755 --- a/services/account/scripts/docker-clean-up.sh +++ b/services/account/scripts/docker-clean-up.sh @@ -2,12 +2,13 @@ # Stop and remove containers, networks echo "Stopping and removing containers, networks..." -docker compose down +docker compose down frequency redis account-service-api account-service-worker # Remove specified volumes echo "Removing specified volumes..." -docker volume rm account-service_redis_data -docker volume rm account-service_chainstorage +docker volume rm gateway_redis_data +docker volume rm gateway_chainstorage +docker volume rm gateway_account_node_cache # Remove account-service images echo "Removing account-service image..." diff --git a/services/account/scripts/restart-chain-docker.sh b/services/account/scripts/restart-chain-docker.sh index 44bb8268..f8fc00c9 100755 --- a/services/account/scripts/restart-chain-docker.sh +++ b/services/account/scripts/restart-chain-docker.sh @@ -22,8 +22,8 @@ echo "Running make setup to provision Provider with capacity, etc..." make setup # Start all services in detached mode -echo "Starting all services..." -docker compose up -d +echo "Starting account-service, api and worker apps..." +docker compose up -d account-service-api account-service-worker # Start the mock web server echo "Please run 'make mock-webhook' in a separate terminal..."