From ddccce40de79de2c1c1a1ca3e883fae0dbd54763 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Sep 2024 12:40:13 +0800 Subject: [PATCH 1/2] print trx size from pending and repush after generating block --- .../main/java/org/tron/core/db/Manager.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/framework/src/main/java/org/tron/core/db/Manager.java b/framework/src/main/java/org/tron/core/db/Manager.java index 66aeccdda39..43e5838d1d5 100644 --- a/framework/src/main/java/org/tron/core/db/Manager.java +++ b/framework/src/main/java/org/tron/core/db/Manager.java @@ -1569,6 +1569,7 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) { List toBePacked = new ArrayList<>(); long currentSize = blockCapsule.getInstance().getSerializedSize(); boolean isSort = Args.getInstance().isOpenTransactionSort(); + int[] logSize = new int[] {pendingTransactions.size(), rePushTransactions.size(), 0, 0}; while (pendingTransactions.size() > 0 || rePushTransactions.size() > 0) { boolean fromPending = false; TransactionCapsule trx; @@ -1644,6 +1645,11 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) { tmpSession.merge(); toBePacked.add(trx); currentSize += trxPackSize; + if (fromPending) { + logSize[2] += 1; + } else { + logSize[3] += 1; + } } catch (Exception e) { logger.warn("Process trx {} failed when generating block {}, {}.", trx.getTransactionId(), blockCapsule.getNum(), e.getMessage()); @@ -1660,11 +1666,14 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) { BlockCapsule capsule = new BlockCapsule(blockCapsule.getInstance()); capsule.generatedByMyself = true; Metrics.histogramObserve(timer); - logger.info("Generate block {} success, trxs:{}, pendingCount: {}, rePushCount: {}," - + " postponedCount: {}, blockSize: {} B", - capsule.getNum(), capsule.getTransactions().size(), - pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount, - capsule.getSerializedSize()); + logger.info("Generate block {} success, trxs:{}, before pendingCount: {}, rePushCount: {}, " + + "from pending: {}, rePush: {}, after pendingCount: {}, rePushCount: {}, " + + "postponedCount: {}, blockSize: {} B", + capsule.getNum(), capsule.getTransactions().size(), + logSize[0], logSize[1], logSize[2], logSize[3], + pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount, + capsule.getSerializedSize()); + return capsule; } From 450763b66d662ec854a99b702198dce9ecbace29 Mon Sep 17 00:00:00 2001 From: jiangyuanshu <317787106@qq.com> Date: Fri, 27 Sep 2024 17:37:40 +0800 Subject: [PATCH 2/2] add some test case --- .../org/tron/plugins/utils/ByteArrayTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 plugins/src/test/java/org/tron/plugins/utils/ByteArrayTest.java diff --git a/plugins/src/test/java/org/tron/plugins/utils/ByteArrayTest.java b/plugins/src/test/java/org/tron/plugins/utils/ByteArrayTest.java new file mode 100644 index 00000000000..300c983db3a --- /dev/null +++ b/plugins/src/test/java/org/tron/plugins/utils/ByteArrayTest.java @@ -0,0 +1,44 @@ +package org.tron.plugins.utils; + +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; + +@Slf4j +public class ByteArrayTest { + + @Test + public void testToStrToInt() { + String test = "abc"; + byte[] testBytes = test.getBytes(); + Assert.assertEquals(test, ByteArray.toStr(testBytes)); + + int i = 5; + Assert.assertEquals(ByteArray.toInt(ByteArray.fromInt(i)), 5); + } + + @Test + public void testFromHexString() { + Assert.assertArrayEquals(ByteArray.EMPTY_BYTE_ARRAY, ByteArray.fromHexString(null)); + + Assert.assertArrayEquals(ByteArray.fromHexString("12"), ByteArray.fromHexString("0x12")); + + Assert.assertArrayEquals(ByteArray.fromHexString("0x2"), ByteArray.fromHexString("0x02")); + } + + @Test + public void testCompareUnsigned() { + byte[] a = new byte[] {1, 2}; + Assert.assertEquals(0, ByteArray.compareUnsigned(a, a)); + Assert.assertEquals(-1, ByteArray.compareUnsigned(null, a)); + Assert.assertEquals(1, ByteArray.compareUnsigned(a, null)); + + byte[] b = new byte[] {1, 3}; + Assert.assertEquals(-1, ByteArray.compareUnsigned(a, b)); + Assert.assertEquals(1, ByteArray.compareUnsigned(b, a)); + + byte[] c = new byte[] {1, 2, 3}; + Assert.assertEquals(-1, ByteArray.compareUnsigned(a, c)); + Assert.assertEquals(1, ByteArray.compareUnsigned(c, a)); + } +}