Skip to content

Commit 9b58a57

Browse files
authored
Merge pull request #6017 from 317787106/feature/print_sr_queue_size
feat(log): print transaction size from pending and repush after generating block
2 parents cdbbb0a + 450763b commit 9b58a57

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

framework/src/main/java/org/tron/core/db/Manager.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
15691569
List<TransactionCapsule> toBePacked = new ArrayList<>();
15701570
long currentSize = blockCapsule.getInstance().getSerializedSize();
15711571
boolean isSort = Args.getInstance().isOpenTransactionSort();
1572+
int[] logSize = new int[] {pendingTransactions.size(), rePushTransactions.size(), 0, 0};
15721573
while (pendingTransactions.size() > 0 || rePushTransactions.size() > 0) {
15731574
boolean fromPending = false;
15741575
TransactionCapsule trx;
@@ -1644,6 +1645,11 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
16441645
tmpSession.merge();
16451646
toBePacked.add(trx);
16461647
currentSize += trxPackSize;
1648+
if (fromPending) {
1649+
logSize[2] += 1;
1650+
} else {
1651+
logSize[3] += 1;
1652+
}
16471653
} catch (Exception e) {
16481654
logger.warn("Process trx {} failed when generating block {}, {}.", trx.getTransactionId(),
16491655
blockCapsule.getNum(), e.getMessage());
@@ -1660,11 +1666,14 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
16601666
BlockCapsule capsule = new BlockCapsule(blockCapsule.getInstance());
16611667
capsule.generatedByMyself = true;
16621668
Metrics.histogramObserve(timer);
1663-
logger.info("Generate block {} success, trxs:{}, pendingCount: {}, rePushCount: {},"
1664-
+ " postponedCount: {}, blockSize: {} B",
1665-
capsule.getNum(), capsule.getTransactions().size(),
1666-
pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount,
1667-
capsule.getSerializedSize());
1669+
logger.info("Generate block {} success, trxs:{}, before pendingCount: {}, rePushCount: {}, "
1670+
+ "from pending: {}, rePush: {}, after pendingCount: {}, rePushCount: {}, "
1671+
+ "postponedCount: {}, blockSize: {} B",
1672+
capsule.getNum(), capsule.getTransactions().size(),
1673+
logSize[0], logSize[1], logSize[2], logSize[3],
1674+
pendingTransactions.size(), rePushTransactions.size(), postponedTrxCount,
1675+
capsule.getSerializedSize());
1676+
16681677
return capsule;
16691678
}
16701679

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.tron.plugins.utils;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
@Slf4j
8+
public class ByteArrayTest {
9+
10+
@Test
11+
public void testToStrToInt() {
12+
String test = "abc";
13+
byte[] testBytes = test.getBytes();
14+
Assert.assertEquals(test, ByteArray.toStr(testBytes));
15+
16+
int i = 5;
17+
Assert.assertEquals(ByteArray.toInt(ByteArray.fromInt(i)), 5);
18+
}
19+
20+
@Test
21+
public void testFromHexString() {
22+
Assert.assertArrayEquals(ByteArray.EMPTY_BYTE_ARRAY, ByteArray.fromHexString(null));
23+
24+
Assert.assertArrayEquals(ByteArray.fromHexString("12"), ByteArray.fromHexString("0x12"));
25+
26+
Assert.assertArrayEquals(ByteArray.fromHexString("0x2"), ByteArray.fromHexString("0x02"));
27+
}
28+
29+
@Test
30+
public void testCompareUnsigned() {
31+
byte[] a = new byte[] {1, 2};
32+
Assert.assertEquals(0, ByteArray.compareUnsigned(a, a));
33+
Assert.assertEquals(-1, ByteArray.compareUnsigned(null, a));
34+
Assert.assertEquals(1, ByteArray.compareUnsigned(a, null));
35+
36+
byte[] b = new byte[] {1, 3};
37+
Assert.assertEquals(-1, ByteArray.compareUnsigned(a, b));
38+
Assert.assertEquals(1, ByteArray.compareUnsigned(b, a));
39+
40+
byte[] c = new byte[] {1, 2, 3};
41+
Assert.assertEquals(-1, ByteArray.compareUnsigned(a, c));
42+
Assert.assertEquals(1, ByteArray.compareUnsigned(c, a));
43+
}
44+
}

0 commit comments

Comments
 (0)