From 1f5f5627e3124ec1c67548d7310122563ec861a0 Mon Sep 17 00:00:00 2001 From: June <2571240520@qq.com> Date: Fri, 29 Dec 2023 15:26:02 +0800 Subject: [PATCH] fix a synchronization bug & some display issues. --- src/main/java/io/xdag/consensus/XdagSync.java | 6 ++++++ .../io/xdag/db/mysql/TransactionHistoryStoreImpl.java | 8 ++++++-- .../io/xdag/rpc/modules/xdag/XdagModuleChainBase.java | 10 +++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/xdag/consensus/XdagSync.java b/src/main/java/io/xdag/consensus/XdagSync.java index 614b4ac3..167e55cc 100644 --- a/src/main/java/io/xdag/consensus/XdagSync.java +++ b/src/main/java/io/xdag/consensus/XdagSync.java @@ -142,6 +142,12 @@ private void getBlocks() { if (i >= size) { break; } + //when the synchronization process channel is removed and reset, update the channel + if (!xc.isActive()){ + log.debug("sync channel need to update"); + return; + } + long time = syncWindow.get(i); sendGetBlocks(xc, time, sf); if (i == 30) lastRequestTime = time; diff --git a/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java b/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java index 28efd34e..230e275b 100644 --- a/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java +++ b/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java @@ -40,6 +40,8 @@ import java.util.Date; import java.util.List; +import static io.xdag.config.Constants.MIN_GAS; +import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_INPUT; import static io.xdag.utils.BasicUtils.hash2Address; import static io.xdag.utils.BasicUtils.hash2byte; import static io.xdag.utils.WalletUtils.checkAddress; @@ -87,7 +89,8 @@ public boolean saveTxHistory(TxHistory txHistory) { pstmt.setString(1, addr); pstmt.setInt(2, address.getIsAddress() ? WALLET_ADDRESS_FLAG : BLOCK_ADDRESS_FLAG); pstmt.setString(3, txHistory.getHash()); - pstmt.setBigDecimal(4, address.getAmount().toDecimal(9, XUnit.XDAG)); + pstmt.setBigDecimal(4, address.getType().equals(XDAG_FIELD_INPUT) ? address.getAmount().subtract(MIN_GAS).toDecimal(9, XUnit.XDAG) : + address.getAmount().toDecimal(9, XUnit.XDAG)); pstmt.setInt(5, address.getType().asByte()); pstmt.setString(6, txHistory.getRemark() != null ? txHistory.getRemark().trim() : ""); pstmt.setTimestamp(7, @@ -123,7 +126,8 @@ public boolean batchSaveTxHistory(TxHistory txHistory, int... cacheNum) { pstmtBatch.setString(1, addr); pstmtBatch.setInt(2, address.getIsAddress() ? WALLET_ADDRESS_FLAG : BLOCK_ADDRESS_FLAG); pstmtBatch.setString(3, txHistory.getHash()); - pstmtBatch.setBigDecimal(4, address.getAmount().toDecimal(9, XUnit.XDAG)); + pstmtBatch.setBigDecimal(4, address.getType().equals(XDAG_FIELD_INPUT) ? address.getAmount().subtract(MIN_GAS).toDecimal(9, XUnit.XDAG) : + address.getAmount().toDecimal(9, XUnit.XDAG)); pstmtBatch.setInt(5, address.getType().asByte()); pstmtBatch.setString(6, txHistory.getRemark() != null ? txHistory.getRemark().trim() : ""); pstmtBatch.setTimestamp(7, diff --git a/src/main/java/io/xdag/rpc/modules/xdag/XdagModuleChainBase.java b/src/main/java/io/xdag/rpc/modules/xdag/XdagModuleChainBase.java index 9a865f41..96351eab 100644 --- a/src/main/java/io/xdag/rpc/modules/xdag/XdagModuleChainBase.java +++ b/src/main/java/io/xdag/rpc/modules/xdag/XdagModuleChainBase.java @@ -296,7 +296,7 @@ private List getTxLinks(Block block, int page, Object... parameters) { remark = new String(block.getInfo().getRemark(), StandardCharsets.UTF_8).trim(); } XAmount earnFee = kernel.getBlockStore().getBlockInfoByHash(block.getHashLow()).getFee(); - if (block.getInfo().getAmount().equals(XAmount.ZERO)){ earnFee = XAmount.ZERO;} //when block amount is zero, fee also should make zero. + // if (block.getInfo().getAmount().equals(XAmount.ZERO)){ earnFee = XAmount.ZERO;} //when block amount is zero, fee also should make zero. txLinkBuilder.address(hash2Address(block.getHashLow())) .hashlow(block.getHashLow().toUnprefixedHexString()) .amount(String.format("%s", blockchain.getReward(block.getInfo().getHeight()).add(earnFee).toDecimal(9, XUnit.XDAG).toPlainString())) @@ -341,14 +341,10 @@ private List getTxHistory(String address, int page, Object... parameters if ((blockInfo.flags & BI_APPLIED) == 0) { continue; } - //这里查账户,账户的input是扣手续费的(角色是to),output才不扣(角色是from) - XAmount Amount =txHistory.getAddress().getAmount(); - if (txHistory.getAddress().getType().equals(XDAG_FIELD_INPUT)){ - Amount = Amount.subtract(MIN_GAS); - } + txLinkBuilder.address(hash2Address(txHistory.getAddress().getAddress())) .hashlow(txHistory.getAddress().getAddress().toUnprefixedHexString()) - .amount(String.format("%s", Amount.toDecimal(9, XUnit.XDAG).toPlainString())) + .amount(String.format("%s", txHistory.getAddress().getAmount().toDecimal(9, XUnit.XDAG).toPlainString())) .direction(txHistory.getAddress().getType().equals(XDAG_FIELD_INPUT) ? 0 : txHistory.getAddress().getType().equals(XDAG_FIELD_OUTPUT) ? 1 : txHistory.getAddress().getType().equals(XDAG_FIELD_COINBASE) ? 2 : 3)