update dgb系列全网报块入库---修改测试完成

This commit is contained in:
yyb 2025-05-27 17:50:20 +08:00
parent 6b72064d5c
commit 65bd4c90c1
6 changed files with 181 additions and 13 deletions

View File

@ -227,4 +227,26 @@ public interface PoolMapper {
*/
@HashRateDB
List<MinerMhsDto> getMinerPowerFor30min(@Param("coin") String coin, @Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);
/**
* 查询dgb系列各币种对应的全网报块信息
* @param tableName
* @return
*/
BlockInfoDto getDgbSeriesBlock(@Param("tableName") String tableName);
/**
* 获取dgb 系列币总的最新高度
* @return
*/
Integer getDgbTotalHeight();
/**
* 向dgb表中插入最新新的高度
* @param height
* @return
*/
Integer insertDgbTotalHeight(@Param("height") Long height);
}

View File

@ -487,6 +487,7 @@ public class DataTask {
//查询一段时间段内全网平均算力
DateBigDecimalDto avgPowerForNet = poolMapper.getAvgPowerForNet(coin, start, end);
log.info("{}币种 {} 到 {} 时间段内,矿池平均算力为{},全网平均算力为{}",coin,start,end,avgPowerForPool.getValue(),avgPowerForNet.getValue());
if(avgPowerForNet.getValue().equals(BigDecimal.ZERO)){
return BigDecimal.ZERO;
}
@ -2911,18 +2912,17 @@ public class DataTask {
Date start30d = DateUtils.addDays(end,-30);
Date start90d = DateUtils.addDays(end,-90);
//获取全网实际90天内的报块数(v2)
List<BlockInfoDto> blockPerDays = poolMapper.selectNetBlock("rxd_net_block");
boolean useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start3d);
//获取3天内全网的实际报块数
BlockTimeAndNumberDto blockData = blockDataContext.getBlockData("rxd",start3d, end,blockPerDays, useAggregated);
//3天矿池理论报块数
BigDecimal throreticalBlocks= getTheoreticalBlocks("rxd",PoolUnits.RXD.gethRate(),start3d, end, blockData);
log.info("全网实际报块数{},矿池理论报块数{}",blockData.getHeight(),throreticalBlocks);
//3天矿池实际报块数
int actualBlocks = poolMapper.selectPoolBlock(start3d, end,"rxd",3);
//3天幸运值

View File

@ -3,6 +3,7 @@ package com.m2pool.pool.task;
import com.m2pool.common.core.utils.DateUtils;
import com.m2pool.common.core.utils.StringUtils;
import com.m2pool.common.redis.service.RedisService;
import com.m2pool.pool.dto.BlockInfoDto;
import com.m2pool.pool.entity.BlockInfo;
import com.m2pool.pool.mapper.PoolMapper;
import com.m2pool.pool.utils.NodeRpc;
@ -14,8 +15,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
@ -36,6 +41,10 @@ public class NodeTask {
@Autowired
private RedisService redisService;
@Autowired
private TransactionTemplate transactionTemplate;
//@Scheduled(cron = "0 0/2 * * * ?")
@Scheduled(cron = "5 0,30 * * * ?")
public void NEXABlockInfoToRedisAndDB(){
@ -492,17 +501,28 @@ public class NodeTask {
* 全网报块高度入库
*/
@Scheduled(cron = "0 2 0/1 * * ?")
@Async("customTaskThreadPool")
//@Scheduled(cron = "0 0/2 * * * ?")
public void insertNetBlock(){
insertBlockWithRetry("nexa", "nexa_net_block", 10);
insertBlockWithRetry("dgbq", "dgbq_net_block", 10);
insertBlockWithRetry("dgbo", "dgbo_net_block", 10);
insertBlockWithRetry("dgbs", "dgbs_net_block", 10);
insertBlockWithRetry("mona", "mona_net_block", 10);
insertBlockWithRetry("rxd", "rxd_net_block", 10);
insertBlockWithRetry("grs", "grs_net_block", 10);
Date now = new Date();
now.setMinutes( 0);
now.setSeconds(0);
String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now);
insertBlockWithRetry("nexa", "nexa_net_block", 5);
insertBlockWithRetry("mona", "mona_net_block", 5);
insertBlockWithRetry("rxd", "rxd_net_block", 5);
insertBlockWithRetry("grs", "grs_net_block", 5);
//下列三种币 高度是共用的
insertBlockWithDgbSeries(5);
}
/**
* nexa,mona,rxd,grs 币种高度入库
* @param blockName
* @param tableName
* @param maxRetries
*/
private void insertBlockWithRetry(String blockName, String tableName, int maxRetries) {
int retryCount = 0;
while (retryCount < maxRetries) {
@ -526,4 +546,84 @@ public class NodeTask {
}
}
}
/**
* dgb 系列odo,qubit,skein,scrypt,sha256d币种高度入库
* @param maxRetries
*/
private void insertBlockWithDgbSeries(int maxRetries) {
int retryCount = 0;
while (retryCount < maxRetries) {
try {
//这里随便填一个dgb 的算法类型 dgb 共用一个高度
String height = NodeRpc.getHeight("dgbq");
//需要记录每次的dgb 总的高度方便下次循环遍历
Integer lastHeight = poolMapper.getDgbTotalHeight();
if (lastHeight != null){
// 从数据库获取dgb系列的币种的最新高度(因为这是新接口是从0开始计算的高度)
BlockInfoDto dgbqHeight = poolMapper.getDgbSeriesBlock("dgbq_net_block");
BlockInfoDto dgbsHeight = poolMapper.getDgbSeriesBlock("dgbs_net_block");
BlockInfoDto dgboHeight = poolMapper.getDgbSeriesBlock("dgbo_net_block");
long dgbqIncrement = 0;
long dgbsIncrement = 0;
long dgboIncrement = 0;
//总高度 - 上次的总高度 然后循环遍历这些块高度来判断该块的算法类型,
for (int i = Integer.parseInt(height) ; i > lastHeight ; i--){
String hashBlock = NodeRpc.getBlockHash("dgbq", i);
String dgbType = NodeRpc.getBlockInfoByHash("dgbq", hashBlock);
if("qubit".equals(dgbType)){
dgbqIncrement++;
}else if ("odo".equals(dgbType)){
dgboIncrement++;
}else if("skein".equals(dgbType)){
dgbsIncrement++;
}
}
long dgbqincr = dgbqHeight == null ? 0 : dgbqHeight.getHeight() + dgbqIncrement;
long dgbsincr = dgbsHeight == null ? 0 : dgbsHeight.getHeight() + dgbsIncrement;
long dgboincr = dgboHeight == null ? 0 : dgboHeight.getHeight() + dgboIncrement;
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
poolMapper.insertDgbTotalHeight(Long.valueOf(height));
poolMapper.insertNetBlock("dgbq_net_block", dgbqincr);
poolMapper.insertNetBlock("dgbs_net_block", dgbsincr);
poolMapper.insertNetBlock("dgbo_net_block", dgboincr);
} catch (Exception e) {
// 回滚事务
status.setRollbackOnly();
throw e;
}
}
});
log.info("插入币种 dgbs最新高度:{} ,dgbq最新高度:{},dgbo最新高度:{}", dgbsHeight,dgbqHeight,dgboHeight);
}else {
poolMapper.insertDgbTotalHeight(Long.valueOf(height));
log.info("首次插入dgb系列的最新高度值为---{}",height);
}
return;
} catch (Exception e) {
retryCount++;
if (retryCount >= maxRetries) {
log.error("插入区块dgb数据失败重试 {} 次后仍失败",maxRetries, e);
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
break;
}
}
}
}
}

View File

@ -54,8 +54,8 @@ public class NodeRpc{
.body();
JSONObject jsonObject = JSON.parseObject(body);
JSONObject jsonObject = JSON.parseObject(body);
String result = jsonObject.getString("result");
String error = jsonObject.getString("error");
@ -146,6 +146,41 @@ public class NodeRpc{
}
}
/**
* 根据高度获取该高度对应的hash块
* @param coin
* @param height
* @return
*/
public static String getBlockHash(String coin,Integer height){
Integer[] params = {height};
String result = getResultTest(coin, "getblockhash",params);
return result;
}
/**
* 根据hash 块的hash值获取该块的详细信息
* @param coin
* @param hash
* @return
*/
public static String getBlockInfoByHash(String coin,String hash){
String[] params = {hash};
String result = getResult(coin, "getblock",params);
if(StringUtils.isBlank(result)){
System.out.println("查询哈希块详细信息结果为空"+result);
return result;
}
if(result.contains("error:")){
System.out.println("查询哈希块详细信息包含错误:"+result);
return result;
}
JSONObject jsonObject = JSON.parseObject(result);
String powAlgo = jsonObject.getString("pow_algo");
return powAlgo;
}
public static String getHeight(String coin) {
String result = getResult(coin, "getblockcount",null);
//处理result
@ -730,7 +765,6 @@ public class NodeRpc{
//return blockInfo;
}
public static Map<String,BlockInfo> getDGBBlock() {
//dgb(qubit)dgb(skein)dgb(odo)实质都是dgb 高度始终一致奖励也是
String coin = "dgbq";

View File

@ -5,6 +5,9 @@ server:
mime-types: application/json
spring:
mvc:
pathmatch:
matching-strategy: ant-path-matcher
#邮箱基本配置
mail:
# 配置在limit_time内用户可以发送limit次验证码

View File

@ -885,6 +885,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertNetBlock">
insert into ${tableName} (`height`) values(#{height}) ON DUPLICATE KEY UPDATE `height` = VALUES(`height`)
</insert>
<insert id="insertDgbTotalHeight">
insert into nexa_dgb_total_block (`height`) values(#{height}) ON DUPLICATE KEY UPDATE `height` = VALUES(`height`)
</insert>
<select id="selectNetBlock" resultType="com.m2pool.pool.dto.BlockInfoDto">
SELECT `date`,height FROM ${tableName} WHERE `date` >= DATE_SUB(now(),INTERVAL 90 DAY) ORDER BY `date` DESC
</select>
@ -902,6 +905,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select `date`,`user`,sum(mhs30m) mhs30m from ${coin}_mhsv2 where `date` >= #{startTime} and `date` <![CDATA[ <= ]]> #{endTime}
group by `date`,`user`
</select>
<select id="getDgbSeriesBlock" resultType="com.m2pool.pool.dto.BlockInfoDto">
select `date`, MAX(height) height from ${tableName};
</select>
<select id="getDgbTotalHeight" resultType="java.lang.Integer">
select height from nexa_dgb_total_block order by `date` DESC LIMIT 1;
</select>
</mapper>