|
1 | 1 | package org.tron.core.db; |
2 | 2 |
|
| 3 | +import static org.tron.core.Constant.PER_SIGN_LENGTH; |
3 | 4 | import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION; |
4 | 5 | import static org.tron.protos.Protocol.Transaction.Contract.ContractType.ShieldedTransferContract; |
5 | 6 | import static org.tron.protos.Protocol.Transaction.Contract.ContractType.TransferAssetContract; |
| 7 | +import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH; |
6 | 8 |
|
7 | 9 | import com.google.protobuf.ByteString; |
8 | 10 | import java.util.HashMap; |
|
19 | 21 | import org.tron.core.capsule.TransactionCapsule; |
20 | 22 | import org.tron.core.exception.AccountResourceInsufficientException; |
21 | 23 | import org.tron.core.exception.ContractValidateException; |
| 24 | +import org.tron.core.exception.TooBigTransactionException; |
22 | 25 | import org.tron.core.exception.TooBigTransactionResultException; |
23 | 26 | import org.tron.protos.Protocol.Transaction.Contract; |
24 | 27 | import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract; |
25 | 28 | import org.tron.protos.contract.BalanceContract.TransferContract; |
26 | 29 |
|
27 | | -import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH; |
28 | | - |
29 | 30 | @Slf4j(topic = "DB") |
30 | 31 | public class BandwidthProcessor extends ResourceProcessor { |
31 | 32 |
|
@@ -95,7 +96,7 @@ public void updateUsage(AssetIssueCapsule assetIssueCapsule, long now) { |
95 | 96 | @Override |
96 | 97 | public void consume(TransactionCapsule trx, TransactionTrace trace) |
97 | 98 | throws ContractValidateException, AccountResourceInsufficientException, |
98 | | - TooBigTransactionResultException { |
| 99 | + TooBigTransactionResultException, TooBigTransactionException { |
99 | 100 | List<Contract> contracts = trx.getInstance().getRawData().getContractList(); |
100 | 101 | if (trx.getResultSerializedSize() > Constant.MAX_RESULT_SIZE_IN_TX * contracts.size()) { |
101 | 102 | throw new TooBigTransactionResultException(); |
@@ -127,6 +128,17 @@ public void consume(TransactionCapsule trx, TransactionTrace trace) |
127 | 128 | } |
128 | 129 | long now = chainBaseManager.getHeadSlot(); |
129 | 130 | if (contractCreateNewAccount(contract)) { |
| 131 | + if (!trx.isInBlock()) { |
| 132 | + long maxCreateAccountTxSize = dynamicPropertiesStore.getMaxCreateAccountTxSize(); |
| 133 | + int signatureCount = trx.getInstance().getSignatureCount(); |
| 134 | + long createAccountBytesSize = trx.getInstance().toBuilder().clearRet() |
| 135 | + .build().getSerializedSize() - (signatureCount * PER_SIGN_LENGTH); |
| 136 | + if (createAccountBytesSize > maxCreateAccountTxSize) { |
| 137 | + throw new TooBigTransactionException(String.format( |
| 138 | + "Too big new account transaction, TxId %s, the size is %d bytes, maxTxSize %d", |
| 139 | + trx.getTransactionId(), createAccountBytesSize, maxCreateAccountTxSize)); |
| 140 | + } |
| 141 | + } |
130 | 142 | consumeForCreateNewAccount(accountCapsule, bytesSize, now, trace); |
131 | 143 | continue; |
132 | 144 | } |
|
0 commit comments