Skip to content

Commit

Permalink
Merge pull request #315 from bnb-chain/fix/0211
Browse files Browse the repository at this point in the history
fix: Prevent api failure by sending too many requests in a short time…
  • Loading branch information
wenty22 authored Feb 11, 2025
2 parents c0a3ade + af80b18 commit 70c6a78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/canonical-bridge-server/src/common/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export async function sleep(duration = 1000) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(null);
}, duration);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EVM_NATIVE_TOKEN_ADDRESS,
} from '@bnb-chain/canonical-bridge-sdk';
import { UtilService } from '@/shared/util/util.service';
import { sleep } from '@/common/utils';

@Processor(Queues.SyncBridge)
export class BridgeProcessor extends WorkerHost {
Expand Down Expand Up @@ -60,11 +61,16 @@ export class BridgeProcessor extends WorkerHost {
if (!config) return;

const tokenMap: Record<string, IDeBridgeToken[]> = {};
const preConfig = await this.cache.get<IDeBridgeTransferConfig>(`${CACHE_KEY.DEBRIDGE_CONFIG}`);

for (const chain of config.chains) {
// Prevent failure by sending too many requests in a short time
await sleep(2000);
const data = await this.web3Service.getDebridgeChainTokens(chain.chainId);
if (data) {
tokenMap[chain.chainId] = Object.values(data.tokens);
} else {
tokenMap[chain.chainId] = preConfig?.tokens?.[chain.chainId]; // use old data
}
}

Expand Down

0 comments on commit 70c6a78

Please sign in to comment.