@@ -1456,16 +1456,17 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
1456
1456
}
1457
1457
}
1458
1458
1459
- TransactionRetCapsule transactionRetCapsule = new TransactionRetCapsule (blockCapsule );
1460
-
1461
1459
Set <String > accountSet = new HashSet <>();
1462
1460
AtomicInteger shieldedTransCounts = new AtomicInteger (0 );
1461
+ List <TransactionCapsule > toBePacked = new ArrayList <>();
1462
+ long currentSize = blockCapsule .getInstance ().getSerializedSize ();
1463
+ boolean isSort = Args .getInstance ().isOpenTransactionSort ();
1463
1464
while (pendingTransactions .size () > 0 || rePushTransactions .size () > 0 ) {
1464
1465
boolean fromPending = false ;
1465
1466
TransactionCapsule trx ;
1466
1467
if (pendingTransactions .size () > 0 ) {
1467
1468
trx = pendingTransactions .peek ();
1468
- if (Args . getInstance (). isOpenTransactionSort () ) {
1469
+ if (isSort ) {
1469
1470
TransactionCapsule trxRepush = rePushTransactions .peek ();
1470
1471
if (trxRepush == null || trx .getOrder () >= trxRepush .getOrder ()) {
1471
1472
fromPending = true ;
@@ -1501,24 +1502,24 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
1501
1502
}
1502
1503
1503
1504
// check the block size
1504
- if ((blockCapsule .getInstance ().getSerializedSize () + trx .getSerializedSize () + 3 )
1505
- > ChainConstant .BLOCK_SIZE ) {
1505
+ if ((currentSize = currentSize + trx .getSerializedSize () + 3 ) > ChainConstant .BLOCK_SIZE ) {
1506
1506
postponedTrxCount ++;
1507
- continue ;
1507
+ break ;
1508
1508
}
1509
1509
//shielded transaction
1510
- if (isShieldedTransaction (trx .getInstance ())
1510
+ Transaction transaction = trx .getInstance ();
1511
+ if (isShieldedTransaction (transaction )
1511
1512
&& shieldedTransCounts .incrementAndGet () > SHIELDED_TRANS_IN_BLOCK_COUNTS ) {
1512
1513
continue ;
1513
1514
}
1514
1515
//multi sign transaction
1515
- Contract contract = trx . getInstance () .getRawData ().getContract (0 );
1516
+ Contract contract = transaction .getRawData ().getContract (0 );
1516
1517
byte [] owner = TransactionCapsule .getOwner (contract );
1517
1518
String ownerAddress = ByteArray .toHexString (owner );
1518
1519
if (accountSet .contains (ownerAddress )) {
1519
1520
continue ;
1520
1521
} else {
1521
- if (isMultiSignTransaction (trx . getInstance () )) {
1522
+ if (isMultiSignTransaction (transaction )) {
1522
1523
accountSet .add (ownerAddress );
1523
1524
}
1524
1525
}
@@ -1528,19 +1529,16 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
1528
1529
// apply transaction
1529
1530
try (ISession tmpSession = revokingStore .buildSession ()) {
1530
1531
accountStateCallBack .preExeTrans ();
1531
- TransactionInfo result = processTransaction (trx , blockCapsule );
1532
+ processTransaction (trx , blockCapsule );
1532
1533
accountStateCallBack .exeTransFinish ();
1533
1534
tmpSession .merge ();
1534
- blockCapsule .addTransaction (trx );
1535
- if (Objects .nonNull (result )) {
1536
- transactionRetCapsule .addTransactionInfo (result );
1537
- }
1535
+ toBePacked .add (trx );
1538
1536
} catch (Exception e ) {
1539
1537
logger .error ("Process trx {} failed when generating block: {}" , trx .getTransactionId (),
1540
1538
e .getMessage ());
1541
1539
}
1542
1540
}
1543
-
1541
+ blockCapsule . addAllTransactions ( toBePacked );
1544
1542
accountStateCallBack .executeGenerateFinish ();
1545
1543
1546
1544
session .reset ();
@@ -1641,18 +1639,21 @@ private void processBlock(BlockCapsule block, List<TransactionCapsule> txs)
1641
1639
try {
1642
1640
merkleContainer .resetCurrentMerkleTree ();
1643
1641
accountStateCallBack .preExecute (block );
1642
+ List <TransactionInfo > results = new ArrayList <>();
1643
+ long num = block .getNum ();
1644
1644
for (TransactionCapsule transactionCapsule : block .getTransactions ()) {
1645
- transactionCapsule .setBlockNum (block . getNum () );
1645
+ transactionCapsule .setBlockNum (num );
1646
1646
if (block .generatedByMyself ) {
1647
1647
transactionCapsule .setVerified (true );
1648
1648
}
1649
1649
accountStateCallBack .preExeTrans ();
1650
1650
TransactionInfo result = processTransaction (transactionCapsule , block );
1651
1651
accountStateCallBack .exeTransFinish ();
1652
1652
if (Objects .nonNull (result )) {
1653
- transactionRetCapsule . addTransactionInfo (result );
1653
+ results . add (result );
1654
1654
}
1655
1655
}
1656
+ transactionRetCapsule .addAllTransactionInfos (results );
1656
1657
accountStateCallBack .executePushFinish ();
1657
1658
} finally {
1658
1659
accountStateCallBack .exceptionFinish ();
0 commit comments