Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for Subnet Configuration Generator v1 release #70

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 0 additions & 2 deletions backend/Dockerfile.mac
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion backend/src/client/parentchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion backend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
export const CORS_ALLOW_ORIGIN = process.env.CORS_ALLOW_ORIGIN || '';

export const STATS_PORT = process.env.STATS_PORT || '5213';
5 changes: 3 additions & 2 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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(`=================================`);
});
14 changes: 11 additions & 3 deletions backend/src/services/block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/info-cards/InfoCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion frontend/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
serve -s dist -l 5214
Loading