Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
List<TransactionCapsule> 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;
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}

Expand Down
44 changes: 44 additions & 0 deletions plugins/src/test/java/org/tron/plugins/utils/ByteArrayTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}