From 6750bad09a6c2f88bc48274efc84c082fde44a2b Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Mon, 20 May 2024 14:05:45 +0800
Subject: [PATCH] 滑点监控

---
 src/main/java/cc/mrbird/febs/job/ChainListenerJob.java |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java b/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
index 504aa4b..476209e 100644
--- a/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
+++ b/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
@@ -7,14 +7,10 @@
 import cc.mrbird.febs.dapp.chain.ContractEventService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
-import javax.annotation.PostConstruct;
 import java.math.BigInteger;
 
 @Slf4j
@@ -38,6 +34,7 @@
         BigInteger blockNumber = ChainService.getInstance(ChainEnum.BSC_GFA.name()).blockNumber();
 
         redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM, blockNumber);
+        redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM_HUA_DIAN, blockNumber);
     }
 
     @Scheduled(cron = "0/2 * * * * ? ")
@@ -67,6 +64,33 @@
         redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, toIncrement);
     }
 
+    @Scheduled(cron = "0/2 * * * * ? ")
+    public void chainIncrementBlockHuaDian() {
+        Object newestBlockObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM_HUA_DIAN);
+        BigInteger newestBlock;
+        if (newestBlockObj == null) {
+            newestBlock = ChainService.getInstance(ChainEnum.BSC_GFA.name()).blockNumber();
+        } else {
+            newestBlock = (BigInteger) newestBlockObj;
+        }
+
+        Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM_HUA_DIAN);
+        BigInteger toIncrement;
+        if (incrementObj == null) {
+            toIncrement = newestBlock;
+        } else {
+            BigInteger incrementBlock = (BigInteger) incrementObj;
+
+            // 最新区块小于增加区块
+            if (newestBlock.compareTo(incrementBlock) <= 0) {
+                return;
+            }
+            toIncrement = incrementBlock.add(BigInteger.ONE);
+        }
+
+        redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM_HUA_DIAN, toIncrement);
+    }
+
 //    @Override
 //    public void run(ApplicationArguments args) throws Exception {
 //        long start = System.currentTimeMillis();

--
Gitblit v1.9.1