Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
chore: tune latest median tx to 50
Browse files Browse the repository at this point in the history
  • Loading branch information
RetricSu authored and Flouse committed Jul 12, 2022
1 parent 7741a62 commit 6548aa4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/api-server/src/db/constant.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const DEFAULT_MAX_QUERY_NUMBER = 10000;
export const DEFAULT_MAX_QUERY_TIME_MILSECS = 1000 * 10; // 10 seconds
export const DEFAULT_MAX_QUERY_ROUNDS = 100;

export const LATEST_MEDIAN_GAS_PRICE = 50;
5 changes: 3 additions & 2 deletions packages/api-server/src/db/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import Knex, { Knex as KnexType } from "knex";
import { LogQueryOption } from "./types";
import { envConfig } from "../base/env-config";
import { LATEST_MEDIAN_GAS_PRICE } from "./constant";
import { QUERY_OFFSET_REACHED_END } from "../methods/constant";
import {
formatDecimal,
Expand Down Expand Up @@ -426,10 +427,10 @@ export class Query {
throw new Error("invalid params!");
}

// Latest 500 transactions median gas_price
// Latest ${LATEST_MEDIAN_GAS_PRICE} transactions median gas_price
async getMedianGasPrice(): Promise<bigint> {
const sql = `SELECT (PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY gas_price)) AS median FROM (SELECT gas_price FROM transactions ORDER BY id DESC LIMIT ?) AS gas_price;`;
const result = await this.knex.raw(sql, [500]);
const result = await this.knex.raw(sql, [LATEST_MEDIAN_GAS_PRICE]);

const median = result.rows[0]?.median;
if (median == null) {
Expand Down

0 comments on commit 6548aa4

Please sign in to comment.