diff --git a/backend/Dockerfile b/backend/Dockerfile index 6d8aed0..19b14c1 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -12,8 +12,6 @@ RUN npm install --legacy-peer-deps # Set Env ENV NODE_ENV production -EXPOSE 3000 -EXPOSE 443 # Cmd script CMD ["npm", "run", "start"] diff --git a/backend/Dockerfile.mac b/backend/Dockerfile.mac index 97c1225..65e0bbc 100644 --- a/backend/Dockerfile.mac +++ b/backend/Dockerfile.mac @@ -13,8 +13,6 @@ RUN npm install --legacy-peer-deps # Set Env ENV NODE_ENV production -EXPOSE 3000 -EXPOSE 443 # Cmd script CMD ["npm", "run", "start"] diff --git a/backend/Makefile b/backend/Makefile index d901316..bd08f51 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -30,7 +30,7 @@ build-dev: ## Build the container image - Dvelopment -f Dockerfile.dev . run: ## Run the container image - docker run -d -it -p 3000:3000 ${APP_NAME} + docker run -d -it -p 5213:5213 ${APP_NAME} pause: ## Pause the containers docker container rm -f ${APP_NAME} diff --git a/backend/src/client/parentchain/index.ts b/backend/src/client/parentchain/index.ts index 5b48768..3886455 100644 --- a/backend/src/client/parentchain/index.ts +++ b/backend/src/client/parentchain/index.ts @@ -73,7 +73,9 @@ export class ParentChainClient { * @param committedSubnetBlockHash WARNING: This method only check against the block has that has already been committed, otherwise always 0 * @returns The full block header that hosted the transaction submitted by relayer (i.e the tx for committing the subnet block into parentchain) */ - async getParentChainBlockBySubnetHash(committedSubnetBlockHash: string) { + async getParentChainBlockBySubnetHash(committedSubnetBlockHash: string) { + // TODO: check if this is possible, how can parentchain block num be known in SC + // TODO: also SC is returning subnet block height not parentnet height try { const { mainnet_num } = await this.smartContractInstance.methods.getHeader(committedSubnetBlockHash).call(); if (!mainnet_num) { diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 6745564..b0c33d5 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -19,4 +19,6 @@ if (!PARENTNET_WALLET || !CHECKPOINT_CONTRACT) { export const { NODE_ENV, LOG_FORMAT, STATS_SECRET } = process.env; -export const CORS_ALLOW_ORIGIN = process.env.CORS_ALLOW_ORIGIN || ''; \ No newline at end of file +export const CORS_ALLOW_ORIGIN = process.env.CORS_ALLOW_ORIGIN || ''; + +export const STATS_PORT = process.env.STATS_PORT || '5213'; diff --git a/backend/src/server.ts b/backend/src/server.ts index 5036c1d..0c6753c 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -1,4 +1,5 @@ import http from 'http'; +import { STATS_PORT } from './config'; import { App } from './app'; import { Route } from './routes'; import { EventsHandler } from './events'; @@ -9,9 +10,9 @@ const app = new App([new Route()]); const server = http.createServer(app.getServer()); const eventHandler = new EventsHandler(server); -server.listen(3000, () => { +server.listen(STATS_PORT, () => { eventHandler.init(); logger.info(`=================================`); - logger.info('🚀 Subnet Stats Service listening on the port 3000'); + logger.info(`🚀 Subnet Stats Service listening on the port ${STATS_PORT}`); logger.info(`=================================`); }); diff --git a/backend/src/services/block.service.ts b/backend/src/services/block.service.ts index 5b7e6b6..c2a091b 100644 --- a/backend/src/services/block.service.ts +++ b/backend/src/services/block.service.ts @@ -7,6 +7,8 @@ import { BaseBlockResponse, BlockResponse } from '../interfaces/output/blocksRes import { SubnetClient } from '../client/subnet'; import { HttpException } from '@/exceptions/httpException'; import { NUM_OF_BLOCKS_RETURN } from '../config'; +import { logger } from '../utils/logger'; + @Service() export class BlockService { @@ -211,10 +213,16 @@ export class BlockService { const { smartContractHeight, smartContractCommittedHash } = await this.getAndSetLastSubmittedBlockInfo(); const mode = await this.parentChainClient.mode(); const { timestamp } = await this.parentChainClient.getParentChainBlockBySubnetHash(smartContractCommittedHash); + const { number: subnetCommittedNumber } = await this.subnetClient.getLatestCommittedBlockInfo(); - const timeDiff = new Date().getTime() / 1000 - parseInt(timestamp.toString()); - - const isProcessing = (mode == 'full' && timeDiff < 120) || (mode == 'lite' && timeDiff < 1000); + let isProcessing = true; + const blockDiff = subnetCommittedNumber - smartContractHeight; + if (mode == 'lite' && blockDiff > 1000) { + isProcessing = false; + } + if (mode == 'full' && blockDiff > 100) { + isProcessing = false; + } return { processedUntil: smartContractHeight, diff --git a/frontend/src/components/info-cards/InfoCards.tsx b/frontend/src/components/info-cards/InfoCards.tsx index 7ff56c8..03d0391 100644 --- a/frontend/src/components/info-cards/InfoCards.tsx +++ b/frontend/src/components/info-cards/InfoCards.tsx @@ -50,7 +50,7 @@ export default function InfoCards(props: InfoCardsProps) { } function getRelayerStatus(): InfoListHealth { - if (Number(loaderData.relayer?.account.balance) < 1) { + if (Number(loaderData.relayer?.account.balance) < 100) { return "Low funds"; } if (loaderData.relayer?.health.status === "UP") { diff --git a/frontend/start.sh b/frontend/start.sh index 49a5907..6819799 100755 --- a/frontend/start.sh +++ b/frontend/start.sh @@ -2,4 +2,4 @@ set -o errexit #force exit if 'yarn run build' fails yarn run build yarn global add serve -serve -s dist -l 5555 \ No newline at end of file +serve -s dist -l 5214