update dgb系列全网报块入库---修改测试完成
This commit is contained in:
parent
6b72064d5c
commit
65bd4c90c1
|
@ -227,4 +227,26 @@ public interface PoolMapper {
|
||||||
*/
|
*/
|
||||||
@HashRateDB
|
@HashRateDB
|
||||||
List<MinerMhsDto> getMinerPowerFor30min(@Param("coin") String coin, @Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,6 +487,7 @@ public class DataTask {
|
||||||
//查询一段时间段内全网平均算力
|
//查询一段时间段内全网平均算力
|
||||||
DateBigDecimalDto avgPowerForNet = poolMapper.getAvgPowerForNet(coin, start, end);
|
DateBigDecimalDto avgPowerForNet = poolMapper.getAvgPowerForNet(coin, start, end);
|
||||||
|
|
||||||
|
log.info("{}币种 {} 到 {} 时间段内,矿池平均算力为{},全网平均算力为{}",coin,start,end,avgPowerForPool.getValue(),avgPowerForNet.getValue());
|
||||||
if(avgPowerForNet.getValue().equals(BigDecimal.ZERO)){
|
if(avgPowerForNet.getValue().equals(BigDecimal.ZERO)){
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
@ -2911,18 +2912,17 @@ public class DataTask {
|
||||||
Date start30d = DateUtils.addDays(end,-30);
|
Date start30d = DateUtils.addDays(end,-30);
|
||||||
Date start90d = DateUtils.addDays(end,-90);
|
Date start90d = DateUtils.addDays(end,-90);
|
||||||
|
|
||||||
|
|
||||||
//获取全网实际90天内的报块数(v2)
|
//获取全网实际90天内的报块数(v2)
|
||||||
List<BlockInfoDto> blockPerDays = poolMapper.selectNetBlock("rxd_net_block");
|
List<BlockInfoDto> blockPerDays = poolMapper.selectNetBlock("rxd_net_block");
|
||||||
|
|
||||||
|
|
||||||
boolean useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start3d);
|
boolean useAggregated = blockPerDays.get(blockPerDays.size()-1).getDate().before(start3d);
|
||||||
//获取3天内全网的实际报块数
|
//获取3天内全网的实际报块数
|
||||||
|
|
||||||
|
|
||||||
BlockTimeAndNumberDto blockData = blockDataContext.getBlockData("rxd",start3d, end,blockPerDays, useAggregated);
|
BlockTimeAndNumberDto blockData = blockDataContext.getBlockData("rxd",start3d, end,blockPerDays, useAggregated);
|
||||||
//3天矿池理论报块数
|
//3天矿池理论报块数
|
||||||
BigDecimal throreticalBlocks= getTheoreticalBlocks("rxd",PoolUnits.RXD.gethRate(),start3d, end, blockData);
|
BigDecimal throreticalBlocks= getTheoreticalBlocks("rxd",PoolUnits.RXD.gethRate(),start3d, end, blockData);
|
||||||
|
log.info("全网实际报块数{},矿池理论报块数{}",blockData.getHeight(),throreticalBlocks);
|
||||||
//3天矿池实际报块数
|
//3天矿池实际报块数
|
||||||
int actualBlocks = poolMapper.selectPoolBlock(start3d, end,"rxd",3);
|
int actualBlocks = poolMapper.selectPoolBlock(start3d, end,"rxd",3);
|
||||||
//3天幸运值
|
//3天幸运值
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.m2pool.pool.task;
|
||||||
import com.m2pool.common.core.utils.DateUtils;
|
import com.m2pool.common.core.utils.DateUtils;
|
||||||
import com.m2pool.common.core.utils.StringUtils;
|
import com.m2pool.common.core.utils.StringUtils;
|
||||||
import com.m2pool.common.redis.service.RedisService;
|
import com.m2pool.common.redis.service.RedisService;
|
||||||
|
import com.m2pool.pool.dto.BlockInfoDto;
|
||||||
import com.m2pool.pool.entity.BlockInfo;
|
import com.m2pool.pool.entity.BlockInfo;
|
||||||
import com.m2pool.pool.mapper.PoolMapper;
|
import com.m2pool.pool.mapper.PoolMapper;
|
||||||
import com.m2pool.pool.utils.NodeRpc;
|
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.Async;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
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.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +41,10 @@ public class NodeTask {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TransactionTemplate transactionTemplate;
|
||||||
|
|
||||||
//@Scheduled(cron = "0 0/2 * * * ?")
|
//@Scheduled(cron = "0 0/2 * * * ?")
|
||||||
@Scheduled(cron = "5 0,30 * * * ?")
|
@Scheduled(cron = "5 0,30 * * * ?")
|
||||||
public void NEXABlockInfoToRedisAndDB(){
|
public void NEXABlockInfoToRedisAndDB(){
|
||||||
|
@ -492,17 +501,28 @@ public class NodeTask {
|
||||||
* 全网报块高度入库
|
* 全网报块高度入库
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 2 0/1 * * ?")
|
@Scheduled(cron = "0 2 0/1 * * ?")
|
||||||
@Async("customTaskThreadPool")
|
//@Scheduled(cron = "0 0/2 * * * ?")
|
||||||
public void insertNetBlock(){
|
public void insertNetBlock(){
|
||||||
insertBlockWithRetry("nexa", "nexa_net_block", 10);
|
Date now = new Date();
|
||||||
insertBlockWithRetry("dgbq", "dgbq_net_block", 10);
|
now.setMinutes( 0);
|
||||||
insertBlockWithRetry("dgbo", "dgbo_net_block", 10);
|
now.setSeconds(0);
|
||||||
insertBlockWithRetry("dgbs", "dgbs_net_block", 10);
|
|
||||||
insertBlockWithRetry("mona", "mona_net_block", 10);
|
String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now);
|
||||||
insertBlockWithRetry("rxd", "rxd_net_block", 10);
|
insertBlockWithRetry("nexa", "nexa_net_block", 5);
|
||||||
insertBlockWithRetry("grs", "grs_net_block", 10);
|
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) {
|
private void insertBlockWithRetry(String blockName, String tableName, int maxRetries) {
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
while (retryCount < maxRetries) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,8 @@ public class NodeRpc{
|
||||||
.body();
|
.body();
|
||||||
|
|
||||||
|
|
||||||
JSONObject jsonObject = JSON.parseObject(body);
|
|
||||||
|
|
||||||
|
JSONObject jsonObject = JSON.parseObject(body);
|
||||||
|
|
||||||
String result = jsonObject.getString("result");
|
String result = jsonObject.getString("result");
|
||||||
String error = jsonObject.getString("error");
|
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) {
|
public static String getHeight(String coin) {
|
||||||
String result = getResult(coin, "getblockcount",null);
|
String result = getResult(coin, "getblockcount",null);
|
||||||
//处理result
|
//处理result
|
||||||
|
@ -730,7 +765,6 @@ public class NodeRpc{
|
||||||
//return blockInfo;
|
//return blockInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Map<String,BlockInfo> getDGBBlock() {
|
public static Map<String,BlockInfo> getDGBBlock() {
|
||||||
//dgb(qubit)、dgb(skein)、dgb(odo)实质都是dgb 高度始终一致、奖励也是
|
//dgb(qubit)、dgb(skein)、dgb(odo)实质都是dgb 高度始终一致、奖励也是
|
||||||
String coin = "dgbq";
|
String coin = "dgbq";
|
||||||
|
|
|
@ -5,6 +5,9 @@ server:
|
||||||
mime-types: application/json
|
mime-types: application/json
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
mvc:
|
||||||
|
pathmatch:
|
||||||
|
matching-strategy: ant-path-matcher
|
||||||
#邮箱基本配置
|
#邮箱基本配置
|
||||||
mail:
|
mail:
|
||||||
# 配置在limit_time内,用户可以发送limit次验证码
|
# 配置在limit_time内,用户可以发送limit次验证码
|
||||||
|
|
|
@ -885,6 +885,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<insert id="insertNetBlock">
|
<insert id="insertNetBlock">
|
||||||
insert into ${tableName} (`height`) values(#{height}) ON DUPLICATE KEY UPDATE `height` = VALUES(`height`)
|
insert into ${tableName} (`height`) values(#{height}) ON DUPLICATE KEY UPDATE `height` = VALUES(`height`)
|
||||||
</insert>
|
</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 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 `date`,height FROM ${tableName} WHERE `date` >= DATE_SUB(now(),INTERVAL 90 DAY) ORDER BY `date` DESC
|
||||||
</select>
|
</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}
|
select `date`,`user`,sum(mhs30m) mhs30m from ${coin}_mhsv2 where `date` >= #{startTime} and `date` <![CDATA[ <= ]]> #{endTime}
|
||||||
group by `date`,`user`
|
group by `date`,`user`
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue