Bladeren bron

容错,不会炸

skyfffire 3 jaren geleden
bovenliggende
commit
926028056b
3 gewijzigde bestanden met toevoegingen van 94 en 91 verwijderingen
  1. 43 41
      scripts/lp/lpGenerate.ts
  2. 30 28
      scripts/lp/lpMaintenance.ts
  3. 21 22
      scripts/path/level2Generate.ts

+ 43 - 41
scripts/lp/lpGenerate.ts

@@ -237,52 +237,54 @@ export class LpGenerate {
 
     while (true) {
       for (const routerObj of routerList) {
-        let pairsLength = 0
-
-        const factoryAddress = routerObj.factory
-        // 获取当前pull状态
-        let position = await this.handlePosition(routerObj)
-        let v2Factory = undefined
-        let v3PositionManager = undefined
-        // v2,v3分开处理
-        if (routerObj.type === 'univ2') {
-          // 获取工厂实例
-          v2Factory = this.parseFactory(routerObj, v2FactoryAbi, factoryAddress)
-          // 获取当前pairsLength
-          pairsLength = await v2Factory.methods.allPairsLength().call()
-        } else if (routerObj.type === 'univ3') {
-          // 获取positionManager
-          v3PositionManager = this.parsePositionManager(routerObj, positionManagerAbi)
-          pairsLength = await this.getPositionLength(v3PositionManager)
-        }
-        // 如果有未获取的池子
-        const haveNewLp = position < pairsLength
-
-        // 打印信息
-        if (haveNewLp) {
-          logger.debug(`Router address: ${routerObj.router}`)
+        try {
+          let pairsLength = 0
+
+          const factoryAddress = routerObj.factory
+          // 获取当前pull状态
+          let position = await this.handlePosition(routerObj)
+          let v2Factory = undefined
+          let v3PositionManager = undefined
+          // v2,v3分开处理
           if (routerObj.type === 'univ2') {
-            logger.debug(`factory: ${factoryAddress}, ${position} / ${pairsLength}.`)
-          } else {
-            logger.debug(`position: ${routerObj.position}, ${position} / ${pairsLength}.`)
+            // 获取工厂实例
+            v2Factory = this.parseFactory(routerObj, v2FactoryAbi, factoryAddress)
+            // 获取当前pairsLength
+            pairsLength = await v2Factory.methods.allPairsLength().call()
+          } else if (routerObj.type === 'univ3') {
+            // 获取positionManager
+            v3PositionManager = this.parsePositionManager(routerObj, positionManagerAbi)
+            pairsLength = await this.getPositionLength(v3PositionManager)
+          }
+          // 如果有未获取的池子
+          const haveNewLp = position < pairsLength
+
+          // 打印信息
+          if (haveNewLp) {
+            logger.debug(`Router address: ${routerObj.router}`)
+            if (routerObj.type === 'univ2') {
+              logger.debug(`factory: ${factoryAddress}, ${position} / ${pairsLength}.`)
+            } else {
+              logger.debug(`position: ${routerObj.position}, ${position} / ${pairsLength}.`)
+            }
           }
-        }
 
-        // 挨个处理lp信息
-        for (; position < pairsLength; position++) {
-          await this.handleLp(position, pairsLength, routerObj, v2ToolBy410, v3Tool, v3PositionManager)
-        }
+          // 挨个处理lp信息
+          for (; position < pairsLength; position++) {
+            await this.handleLp(position, pairsLength, routerObj, v2ToolBy410, v3Tool, v3PositionManager)
+          }
 
-        if (haveNewLp) {
-          if (routerObj.type === 'univ2') {
-            await History.appendOrUpdate('UNIV2DEX', routerObj.factory, {"next": position})
-          } else if (routerObj.type === 'univ3') {
-            await History.appendOrUpdate('UNIV3DEX', routerObj.router + '_router', {"next": position})
+          if (haveNewLp) {
+            if (routerObj.type === 'univ2') {
+              await History.appendOrUpdate('UNIV2DEX', routerObj.factory, {"next": position})
+            } else if (routerObj.type === 'univ3') {
+              await History.appendOrUpdate('UNIV3DEX', routerObj.router + '_router', {"next": position})
+            }
+            logger.debug('')
+            logger.debug('')
+            logger.debug('')
           }
-          logger.debug('')
-          logger.debug('')
-          logger.debug('')
-        }
+        } catch (e) {}
       }
     }
   }

+ 30 - 28
scripts/lp/lpMaintenance.ts

@@ -128,35 +128,37 @@ export class LpMaintenance {
     while (true) {
       this.showMemory('a loop...')
 
-      const topLpPullRst = await History.findByBlock('topLp')
-      if (!topLpPullRst.state) continue
-      const topLpList = topLpPullRst.data
-      const lpPullRst = await History.findByBlock('lp')
-      if (!lpPullRst.state) continue
-      const lpList = lpPullRst.data
-      const normalLpPullRst = await History.findByBlock('normalLp')
-      if (!normalLpPullRst.state) continue
-      const normalLpList = normalLpPullRst.data
-
-      const allTypeLpList: any = topLpList.concat(lpList).concat(normalLpList)
-      const lpAddressList: any = this.generateAddressListByLpList(allTypeLpList)
-      // logger.debug(`${lpAddressList.length}`)
-
-      // 集中拉取r0,r1并更新本地的
-      const size = 2000
-      for (let from = 0; from < allTypeLpList.length; from += size) {
-        // logger.debug(`${from}, ${allTypeLpList.length}`)
-        const lpR0R1Info: any = await v2ToolBy410.methods.getPairSBalance(lpAddressList.slice(from, from + size)).call()
-        const r0s = lpR0R1Info.amounts0
-        const r1s = lpR0R1Info.amounts1
-
-        this.updateLocalLpListR0R1(allTypeLpList.slice(from, from + size), r0s, r1s)
-      }
+      try {
+        const topLpPullRst = await History.findByBlock('topLp')
+        if (!topLpPullRst.state) continue
+        const topLpList = topLpPullRst.data
+        const lpPullRst = await History.findByBlock('lp')
+        if (!lpPullRst.state) continue
+        const lpList = lpPullRst.data
+        const normalLpPullRst = await History.findByBlock('normalLp')
+        if (!normalLpPullRst.state) continue
+        const normalLpList = normalLpPullRst.data
+
+        const allTypeLpList: any = topLpList.concat(lpList).concat(normalLpList)
+        const lpAddressList: any = this.generateAddressListByLpList(allTypeLpList)
+        // logger.debug(`${lpAddressList.length}`)
+
+        // 集中拉取r0,r1并更新本地的
+        const size = 2000
+        for (let from = 0; from < allTypeLpList.length; from += size) {
+          // logger.debug(`${from}, ${allTypeLpList.length}`)
+          const lpR0R1Info: any = await v2ToolBy410.methods.getPairSBalance(lpAddressList.slice(from, from + size)).call()
+          const r0s = lpR0R1Info.amounts0
+          const r1s = lpR0R1Info.amounts1
+
+          this.updateLocalLpListR0R1(allTypeLpList.slice(from, from + size), r0s, r1s)
+        }
 
-      // 将lp类型有变动的全部更新
-      for (const lpDbObj of allTypeLpList) {
-        await this.handleLp(lpDbObj.dataObj, lpDbObj.block)
-      }
+        // 将lp类型有变动的全部更新
+        for (const lpDbObj of allTypeLpList) {
+          await this.handleLp(lpDbObj.dataObj, lpDbObj.block)
+        }
+      } catch (e) {}
     }
   }
 }

+ 21 - 22
scripts/path/level2Generate.ts

@@ -76,28 +76,27 @@ class Level2Generate {
   async run() {
     logger.debug('Level2 maintenance start.')
     while (true) {
-      if (this.maxMemoryChanged) {
-        this.showMemory('Level2 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.concat(normalLpList)
-
-      // 将原始data构造成dataObj
-      this.buildLpObj(allTypeLpList)
-      // 根据Sum构造Lp索引
-      this.buildSumObjGroupBySum2(allTypeLpList)
-      // 生成路径并更新到库
-      await this.generatePathAndUpdate()
+      this.showMemory('Level2 a loop...')
+
+      try {
+        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.concat(normalLpList)
+
+        // 将原始data构造成dataObj
+        this.buildLpObj(allTypeLpList)
+        // 根据Sum构造Lp索引
+        this.buildSumObjGroupBySum2(allTypeLpList)
+        // 生成路径并更新到库
+        await this.generatePathAndUpdate()
+      } catch (e) {}
     }
   }
 }