Skip to content

Commit

Permalink
read gateway ttl from config or constants
Browse files Browse the repository at this point in the history
  • Loading branch information
will pankiewicz authored and will pankiewicz committed Feb 19, 2024
1 parent 00688ab commit 0bdb4a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
28 changes: 3 additions & 25 deletions packages/common/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
/// 15% in per billion type.
export const FIFTEEN_PERCENT = 150000000;

/// 5% in per billion type.
export const FIVE_PERCENT = 50000000;

/// 10 KSM with decimals.
export const TEN_KSM: number = 10 * 10 ** 12;

/// 50 KSM with decimals.
export const FIFTY_KSM: number = 50 * 10 ** 12;

/// 10_000 DOT with decimals.
export const TEN_THOUSAND_DOT: number = 10 * 1000 * 10 ** 10;

/// 5_000 DOT with decimals.
export const FIVE_THOUSAND_DOT: number = 5 * 1000 * 10 ** 10;

/// One week in milliseconds.
export const WEEK = 7 * 24 * 60 * 60 * 1000;

/// The time a node has to make an upgrade to the latest release.
export const SIXTEEN_HOURS = 16 * 60 * 60 * 1000;

/// Percentage of one week that a validator could be offline.
export const UP_TIME = 0.02;
export const GATEWAY_CACHE_TTL = 18 * 1000;

/// Number of Eras in 4 days that a validator should have claimed all previous rewards except
export const KUSAMA_FOUR_DAYS_ERAS = 16;
Expand Down Expand Up @@ -79,8 +60,9 @@ export const LocalEndpoints = [
export const defaultExcludeLabels = [
// "Telemetry",
// "Location",
// "ValidatorPrefJob",
"ValidatorPrefJob",
"Block",
"Gateway",
];

/// Endpoint of the Kusama Thousand Validators backend. Used for the Polkadot program.
Expand All @@ -92,10 +74,6 @@ export const TIME_DELAY_BLOCKS = 10850;
// The number of blocks after a time delay proxy call was announced that we want to cancel the tx. Should be 36 hours
export const CANCEL_THRESHOLD = 21700;

export const KUSAMA_NOMINATOR_THRESHOLD = 2;

export const POLKADOT_NOMINATOR_THRESHOLD = 10;

// Monitor Cron job for checking if clients have upgraded. This runs ever 15 minutes by default
export const MONITOR_CRON = "0 */15 * * * *";

Expand Down
6 changes: 3 additions & 3 deletions packages/gateway/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Koa from "koa";
import bodyparser from "koa-bodyparser";
import cors from "koa2-cors";

import { Config, logger } from "@1kv/common";
import { Config, Constants, logger } from "@1kv/common";
import koaCash from "koa-cash";
import { KoaAdapter } from "@bull-board/koa";
import { createBullBoard } from "@bull-board/api";
Expand Down Expand Up @@ -32,15 +32,15 @@ export default class Server {
this.app = new Koa();
this.port = config?.server?.port;
this.enable = config?.server?.enable || true;
this.cache = config?.server?.cache || 180000;
this.cache = config?.server?.cache;

this.app.use(cors());
this.app.use(bodyparser());

logger.info(`Cache set to ${this.cache}`, { label: "Gateway" });

const cache = new LRUCache({
ttl: 18 * 1000, // Cache items will expire after 3 minutes
ttl: this.cache || Constants.GATEWAY_CACHE_TTL, // Cache items will expire after 3 minutes
max: 500, // Maximum number of items allowed in the cache
});
this.app.use(
Expand Down

0 comments on commit 0bdb4a9

Please sign in to comment.