11package org .tron .core .db ;
22
33import static org .tron .common .utils .Commons .adjustBalance ;
4+ import static org .tron .core .Constant .TRANSACTION_MAX_BYTE_SIZE ;
45import static org .tron .core .exception .BadBlockException .TypeEnum .CALC_MERKLE_ROOT_FAILED ;
56import static org .tron .protos .Protocol .Transaction .Contract .ContractType .TransferContract ;
67import static org .tron .protos .Protocol .Transaction .Result .contractResult .SUCCESS ;
@@ -793,6 +794,17 @@ void validateTapos(TransactionCapsule transactionCapsule) throws TaposException
793794
794795 void validateCommon (TransactionCapsule transactionCapsule )
795796 throws TransactionExpirationException , TooBigTransactionException {
797+ if (!transactionCapsule .isInBlock ()) {
798+ transactionCapsule .removeRedundantRet ();
799+ long generalBytesSize =
800+ transactionCapsule .getInstance ().toBuilder ().clearRet ().build ().getSerializedSize ()
801+ + Constant .MAX_RESULT_SIZE_IN_TX + Constant .MAX_RESULT_SIZE_IN_TX ;
802+ if (generalBytesSize > TRANSACTION_MAX_BYTE_SIZE ) {
803+ throw new TooBigTransactionException (String .format (
804+ "Too big transaction with result, TxId %s, the size is %d bytes, maxTxSize %d" ,
805+ transactionCapsule .getTransactionId (), generalBytesSize , TRANSACTION_MAX_BYTE_SIZE ));
806+ }
807+ }
796808 if (transactionCapsule .getData ().length > Constant .TRANSACTION_MAX_BYTE_SIZE ) {
797809 throw new TooBigTransactionException (String .format (
798810 "Too big transaction, the size is %d bytes" , transactionCapsule .getData ().length ));
@@ -1411,8 +1423,14 @@ public TransactionInfo processTransaction(final TransactionCapsule trxCap, Block
14111423 if (trxCap == null ) {
14121424 return null ;
14131425 }
1414- Contract contract = trxCap .getInstance ().getRawData ().getContract (0 );
14151426 Sha256Hash txId = trxCap .getTransactionId ();
1427+ if (trxCap .getInstance ().getRawData ().getContractList ().size () != 1 ) {
1428+ throw new ContractSizeNotEqualToOneException (
1429+ String .format (
1430+ "tx %s contract size should be exactly 1, this is extend feature ,actual :%d" ,
1431+ txId , trxCap .getInstance ().getRawData ().getContractList ().size ()));
1432+ }
1433+ Contract contract = trxCap .getInstance ().getRawData ().getContract (0 );
14161434 final Histogram .Timer requestTimer = Metrics .histogramStartTimer (
14171435 MetricKeys .Histogram .PROCESS_TRANSACTION_LATENCY ,
14181436 Objects .nonNull (blockCap ) ? MetricLabels .BLOCK : MetricLabels .TRX ,
@@ -1427,13 +1445,6 @@ public TransactionInfo processTransaction(final TransactionCapsule trxCap, Block
14271445 validateTapos (trxCap );
14281446 validateCommon (trxCap );
14291447
1430- if (trxCap .getInstance ().getRawData ().getContractList ().size () != 1 ) {
1431- throw new ContractSizeNotEqualToOneException (
1432- String .format (
1433- "tx %s contract size should be exactly 1, this is extend feature ,actual :%d" ,
1434- txId , trxCap .getInstance ().getRawData ().getContractList ().size ()));
1435- }
1436-
14371448 validateDup (trxCap );
14381449
14391450 if (!trxCap .validateSignature (chainBaseManager .getAccountStore (),
0 commit comments