Skip to content

Commit

Permalink
fix and improve condition for abnormal relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
wanwiset25 committed Oct 2, 2024
1 parent fdebfdc commit 20a785b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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
13 changes: 10 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,15 @@ 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') {
if (blockDiff > 1000) isProcessing = false;
} else if (mode == 'full') {
if (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

0 comments on commit 20a785b

Please sign in to comment.