Răsfoiți Sursa

sum2上线测试

skyfffire 3 ani în urmă
părinte
comite
df3adf3c59
3 a modificat fișierele cu 82 adăugiri și 7 ștergeri
  1. 1 1
      hardhat.config.ts
  2. 7 5
      scripts/lp/lpMaintenance.ts
  3. 74 1
      scripts/path/level2Maintenance.ts

+ 1 - 1
hardhat.config.ts

@@ -1,10 +1,10 @@
 import { HardhatUserConfig, extendEnvironment } from "hardhat/config";
+import {HardhatRuntimeEnvironment} from "hardhat/types";
 import "@nomicfoundation/hardhat-toolbox";
 
 import deployer from './.secret'
 import logger from './utils/logger'
 import debug from './utils/debug'
-import {HardhatRuntimeEnvironment} from "hardhat/types";
 
 const ETH_RPC = 'http://3.227.34.41:8545'
 const ETH_W_RPC = 'http://3.227.34.41:18545'

+ 7 - 5
scripts/lp/lpMaintenance.ts

@@ -68,7 +68,12 @@ export class LpMaintenance {
       this.maxMemoryOfByte = memoryUsage.rss
       this.maxMemoryChanged = true
     }
-    logger.debug(`${mainInfo}  ${this.format(memoryUsage.rss)}/${this.format(this.maxMemoryOfByte)}`)
+
+    if (this.maxMemoryChanged) {
+      logger.debug(`${mainInfo}  ${this.format(memoryUsage.rss)}/${this.format(this.maxMemoryOfByte)}`)
+
+      this.maxMemoryChanged = false
+    }
   }
 
   format (bytes: any) {
@@ -96,10 +101,7 @@ export class LpMaintenance {
   async run() {
     logger.debug('LP maintenance start.')
     while (true) {
-      if (this.maxMemoryChanged) {
-        this.showMemory('a loop...')
-      }
-      this.maxMemoryChanged = false
+      this.showMemory('a loop...')
 
       const topLpPullRst = await history.findByBlock('topLp')
       if (!topLpPullRst.state) continue

+ 74 - 1
scripts/path/level2Maintenance.ts

@@ -1,7 +1,80 @@
 import logger from "../../utils/logger";
+import history from "../interface/history";
+import SwapPath from "../interface/swapPath";
 
-async function main() {
+class Level2Maintenance {
+  maxMemoryOfByte: number = 0
+  maxMemoryChanged: boolean = true
+  lpSumObj: any = {}
+
+  buildLpObj (lpList: any) {
+    for (const lp of lpList) {
+      lp.dataObj = JSON.parse(lp.data)
+    }
+  }
+
+  showMemory (mainInfo: string) {
+    const memoryUsage = process.memoryUsage()
+    if (this.maxMemoryOfByte < memoryUsage.rss) {
+      this.maxMemoryOfByte = memoryUsage.rss
+      this.maxMemoryChanged = true
+    }
+
+    if (this.maxMemoryChanged) {
+      logger.debug(`${mainInfo}  ${this.format(memoryUsage.rss)}/${this.format(this.maxMemoryOfByte)}`)
+
+      this.maxMemoryChanged = false
+    }
+  }
+
+  format (bytes: any) {
+    return (bytes / 1024 / 1024).toFixed(2) + ' MB';
+  }
+
+  async run() {
+    logger.debug('LP maintenance start.')
+    while (true) {
+      if (this.maxMemoryChanged) {
+        this.showMemory('a loop...')
+      }
+      this.maxMemoryChanged = false
+
+      this.lpSumObj = {}
 
+      const topLpPullRst = await history.findByBlock('topLp')
+      if (!topLpPullRst.state) continue
+      const topLpList = topLpPullRst.data
+      // const normalLpPullRst = await history.findByBlock('normalLp')
+      // if (!normalLpPullRst.state) continue
+      // const normalLpList = normalLpPullRst.data
+
+      const allTypeLpList: any = topLpList
+      this.buildLpObj(allTypeLpList)
+      logger.debug(`${allTypeLpList.length}`)
+
+      // 构造sum
+      logger.debug(`generate sum group by sum...`)
+      for (const lpDbObj of allTypeLpList) {
+        if (this.lpSumObj[lpDbObj.dataObj.sum2]) {
+          this.lpSumObj[lpDbObj.dataObj.sum2].push(lpDbObj.dataObj)
+        } else {
+          this.lpSumObj[lpDbObj.dataObj.sum2] = [lpDbObj.dataObj]
+        }
+      }
+
+      // 更新所有sum
+      logger.debug(`update sum...`)
+      for (const sum2 of Object.keys(this.lpSumObj)) {
+        const lpList = this.lpSumObj[sum2]
+
+        await SwapPath.appendOrUpdate(sum2, '2', lpList)
+      }
+    }
+  }
+}
+
+async function main() {
+  await new Level2Maintenance().run()
 }
 
 main().catch((error) => {