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: 18 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.tron.core.utils;

import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE;
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;
Expand Down Expand Up @@ -748,6 +750,20 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case MAX_CREATE_ACCOUNT_TX_SIZE: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_5)) {
throw new ContractValidateException(
"Bad chain parameter id [MAX_CREATE_ACCOUNT_TX_SIZE]");
}
if (value < CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE
|| value > CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE) {
throw new ContractValidateException(
"This value[MAX_CREATE_ACCOUNT_TX_SIZE] is only allowed to be greater than or equal "
+ "to " + CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE + " and less than or equal to "
+ CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE + "!");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -824,7 +840,8 @@ public enum ProposalType { // current value, value range
ALLOW_TVM_SHANGHAI(76), // 0, 1
ALLOW_CANCEL_ALL_UNFREEZE_V2(77), // 0, 1
MAX_DELEGATE_LOCK_PERIOD(78), // (86400, 10512000]
ALLOW_OLD_REWARD_OPT(79); // 0, 1
ALLOW_OLD_REWARD_OPT(79), // 0, 1
MAX_CREATE_ACCOUNT_TX_SIZE(82); // [500, 10000]

private long code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {
@Getter
@Setter
private boolean isTransactionCreate = false;
@Getter
@Setter
private boolean isInBlock = false;

public byte[] getOwnerAddress() {
if (this.ownerAddress == null) {
Expand Down
18 changes: 15 additions & 3 deletions chainbase/src/main/java/org/tron/core/db/BandwidthProcessor.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.tron.core.db;

import static org.tron.core.Constant.PER_SIGN_LENGTH;
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
import static org.tron.protos.Protocol.Transaction.Contract.ContractType.ShieldedTransferContract;
import static org.tron.protos.Protocol.Transaction.Contract.ContractType.TransferAssetContract;
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;

import com.google.protobuf.ByteString;
import java.util.HashMap;
Expand All @@ -19,13 +21,12 @@
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.exception.AccountResourceInsufficientException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.TooBigTransactionException;
import org.tron.core.exception.TooBigTransactionResultException;
import org.tron.protos.Protocol.Transaction.Contract;
import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract;
import org.tron.protos.contract.BalanceContract.TransferContract;

import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;

@Slf4j(topic = "DB")
public class BandwidthProcessor extends ResourceProcessor {

Expand Down Expand Up @@ -95,7 +96,7 @@ public void updateUsage(AssetIssueCapsule assetIssueCapsule, long now) {
@Override
public void consume(TransactionCapsule trx, TransactionTrace trace)
throws ContractValidateException, AccountResourceInsufficientException,
TooBigTransactionResultException {
TooBigTransactionResultException, TooBigTransactionException {
List<Contract> contracts = trx.getInstance().getRawData().getContractList();
if (trx.getResultSerializedSize() > Constant.MAX_RESULT_SIZE_IN_TX * contracts.size()) {
throw new TooBigTransactionResultException();
Expand Down Expand Up @@ -127,6 +128,17 @@ public void consume(TransactionCapsule trx, TransactionTrace trace)
}
long now = chainBaseManager.getHeadSlot();
if (contractCreateNewAccount(contract)) {
if (!trx.isInBlock()) {
long maxCreateAccountTxSize = dynamicPropertiesStore.getMaxCreateAccountTxSize();
int signatureCount = trx.getInstance().getSignatureCount();
long createAccountBytesSize = trx.getInstance().toBuilder().clearRet()
.build().getSerializedSize() - (signatureCount * PER_SIGN_LENGTH);
if (createAccountBytesSize > maxCreateAccountTxSize) {
throw new TooBigTransactionException(String.format(
"Too big new account transaction, TxId %s, the size is %d bytes, maxTxSize %d",
trx.getTransactionId(), createAccountBytesSize, maxCreateAccountTxSize));
}
}
consumeForCreateNewAccount(accountCapsule, bytesSize, now, trace);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.tron.core.exception.AccountResourceInsufficientException;
import org.tron.core.exception.BalanceInsufficientException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.TooBigTransactionException;
import org.tron.core.exception.TooBigTransactionResultException;
import org.tron.core.store.AccountStore;
import org.tron.core.store.DynamicPropertiesStore;
Expand All @@ -35,7 +36,7 @@ protected ResourceProcessor(DynamicPropertiesStore dynamicPropertiesStore,
}

abstract void consume(TransactionCapsule trx, TransactionTrace trace)
throws ContractValidateException, AccountResourceInsufficientException, TooBigTransactionResultException;
throws ContractValidateException, AccountResourceInsufficientException, TooBigTransactionResultException, TooBigTransactionException;

protected long increase(long lastUsage, long usage, long lastTime, long now) {
return increase(lastUsage, usage, lastTime, now, windowSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>

private static final byte[] ALLOW_OLD_REWARD_OPT = "ALLOW_OLD_REWARD_OPT".getBytes();

private static final byte[] MAX_CREATE_ACCOUNT_TX_SIZE = "MAX_CREATE_ACCOUNT_TX_SIZE".getBytes();

@Autowired
private DynamicPropertiesStore(@Value("properties") String dbName) {
super(dbName);
Expand Down Expand Up @@ -2850,6 +2852,18 @@ public long getAllowOldRewardOpt() {
.orElse(CommonParameter.getInstance().getAllowOldRewardOpt());
}

public void saveMaxCreateAccountTxSize(long maxCreateAccountTxSize) {
this.put(MAX_CREATE_ACCOUNT_TX_SIZE,
new BytesCapsule(ByteArray.fromLong(maxCreateAccountTxSize)));
}

public long getMaxCreateAccountTxSize() {
return Optional.ofNullable(getUnchecked(MAX_CREATE_ACCOUNT_TX_SIZE))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElse(CommonParameter.getInstance().getMaxCreateAccountTxSize());
}

private static class DynamicResourceProperties {

private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ public class CommonParameter {
@Setter
public long allowOldRewardOpt;

@Getter
@Setter
public long maxCreateAccountTxSize = 1000L;

private static double calcMaxTimeRatio() {
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
return 5.0;
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ public class Constant {

// config for transaction
public static final long TRANSACTION_MAX_BYTE_SIZE = 500 * 1_024L;
public static final int CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE = 500;
public static final int CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE = 10000;
public static final long MAXIMUM_TIME_UNTIL_EXPIRATION = 24 * 60 * 60 * 1_000L; //one day
public static final long TRANSACTION_DEFAULT_EXPIRATION_TIME = 60 * 1_000L; //60 seconds
public static final long TRANSACTION_FEE_POOL_PERIOD = 1; //1 blocks
// config for smart contract
public static final long SUN_PER_ENERGY = 100; // 1 us = 100 SUN = 100 * 10^-6 TRX
public static final long ENERGY_LIMIT_IN_CONSTANT_TX = 3_000_000L; // ref: 1 us = 1 energy
public static final long MAX_RESULT_SIZE_IN_TX = 64; // max 8 * 8 items in result
public static final long PER_SIGN_LENGTH = 65L;
public static final long PB_DEFAULT_ENERGY_LIMIT = 0L;
public static final long CREATOR_DEFAULT_ENERGY_LIMIT = 1000 * 10_000L;

Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/org/tron/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum ForkBlockVersionEnum {
VERSION_4_7(26, 1596780000000L, 80),
VERSION_4_7_1(27, 1596780000000L, 80),
VERSION_4_7_2(28, 1596780000000L, 80),
VERSION_4_7_4(29, 1596780000000L, 80);
VERSION_4_7_4(29, 1596780000000L, 80),
VERSION_4_7_5(30, 1596780000000L, 80);
// if add a version, modify BLOCK_VERSION simultaneously

@Getter
Expand Down Expand Up @@ -72,7 +73,7 @@ public class ChainConstant {
public static final int SINGLE_REPEAT = 1;
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
public static final int MAX_FROZEN_NUMBER = 1;
public static final int BLOCK_VERSION = 29;
public static final int BLOCK_VERSION = 30;
public static final long FROZEN_PERIOD = 86_400_000L;
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
public static final long TRX_PRECISION = 1000_000L;
Expand Down
5 changes: 5 additions & 0 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,11 @@ public Protocol.ChainParameters getChainParameters() {
.setValue(dbManager.getDynamicPropertiesStore().getAllowOldRewardOpt())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getMaxCreateAccountTxSize")
.setValue(dbManager.getDynamicPropertiesStore().getMaxCreateAccountTxSize())
.build());

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveAllowOldRewardOpt(entry.getValue());
break;
}
case MAX_CREATE_ACCOUNT_TX_SIZE: {
manager.getDynamicPropertiesStore().saveMaxCreateAccountTxSize(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
3 changes: 2 additions & 1 deletion framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ public void consumeMemoFee(TransactionCapsule trx, TransactionTrace trace)

public void consumeBandwidth(TransactionCapsule trx, TransactionTrace trace)
throws ContractValidateException, AccountResourceInsufficientException,
TooBigTransactionResultException {
TooBigTransactionResultException, TooBigTransactionException {
BandwidthProcessor processor = new BandwidthProcessor(chainBaseManager);
processor.consume(trx, trace);
}
Expand Down Expand Up @@ -1422,6 +1422,7 @@ public TransactionInfo processTransaction(final TransactionCapsule trxCap, Block

if (Objects.nonNull(blockCap)) {
chainBaseManager.getBalanceTraceStore().initCurrentTransactionBalanceTrace(trxCap);
trxCap.setInBlock(true);
}

validateTapos(trxCap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.tron.core.exception.AccountResourceInsufficientException;
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.TooBigTransactionException;
import org.tron.core.exception.TooBigTransactionResultException;
import org.tron.core.exception.TronException;
import org.tron.core.exception.VMIllegalException;
Expand Down Expand Up @@ -154,7 +155,8 @@ public void testSuccess() {

private byte[] createContract()
throws ContractValidateException, AccountResourceInsufficientException,
TooBigTransactionResultException, ContractExeException, VMIllegalException {
TooBigTransactionResultException, ContractExeException, VMIllegalException,
TooBigTransactionException {
AccountCapsule owner = dbManager.getAccountStore()
.get(Commons.decodeFromBase58Check(OwnerAddress));
long energy = owner.getEnergyUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.ReceiptCheckErrException;
import org.tron.core.exception.TooBigTransactionException;
import org.tron.core.exception.TooBigTransactionResultException;
import org.tron.core.exception.TronException;
import org.tron.core.exception.VMIllegalException;
Expand Down Expand Up @@ -156,7 +157,8 @@ public void testSuccess() {

private byte[] createContract()
throws ContractValidateException, AccountResourceInsufficientException,
TooBigTransactionResultException, ContractExeException, VMIllegalException {
TooBigTransactionResultException, ContractExeException, VMIllegalException,
TooBigTransactionException {
AccountCapsule owner = dbManager.getAccountStore()
.get(Commons.decodeFromBase58Check(OwnerAddress));
long energy = owner.getEnergyUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.tron.core.exception.AccountResourceInsufficientException;
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.TooBigTransactionException;
import org.tron.core.exception.TooBigTransactionResultException;
import org.tron.core.exception.TronException;
import org.tron.core.exception.VMIllegalException;
Expand Down Expand Up @@ -186,7 +187,8 @@ public void testSuccessNoBandd() {

private byte[] createContract()
throws ContractValidateException, AccountResourceInsufficientException,
TooBigTransactionResultException, ContractExeException, VMIllegalException {
TooBigTransactionResultException, ContractExeException, VMIllegalException,
TooBigTransactionException {
AccountCapsule owner = dbManager.getAccountStore()
.get(Commons.decodeFromBase58Check(OwnerAddress));
long energy = owner.getEnergyUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.ReceiptCheckErrException;
import org.tron.core.exception.TooBigTransactionException;
import org.tron.core.exception.TooBigTransactionResultException;
import org.tron.core.exception.TronException;
import org.tron.core.exception.VMIllegalException;
Expand Down Expand Up @@ -198,7 +199,7 @@ public void testSuccessNoBandWidth() {
private byte[] createContract()
throws ContractValidateException, AccountResourceInsufficientException,
TooBigTransactionResultException, ContractExeException, ReceiptCheckErrException,
VMIllegalException {
VMIllegalException, TooBigTransactionException {
AccountCapsule owner = dbManager.getAccountStore()
.get(Commons.decodeFromBase58Check(OwnerAddress));
long energy = owner.getEnergyUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.tron.core.db.TransactionTrace;
import org.tron.core.exception.AccountResourceInsufficientException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.TooBigTransactionException;
import org.tron.core.exception.TooBigTransactionResultException;
import org.tron.core.store.StoreFactory;
import org.tron.protos.Protocol;
Expand Down Expand Up @@ -646,6 +647,8 @@ public void sameTokenNameCloseConsumeSuccess() {
Assert.assertFalse(e instanceof TooBigTransactionResultException);
} catch (AccountResourceInsufficientException e) {
Assert.assertFalse(e instanceof AccountResourceInsufficientException);
} catch (TooBigTransactionException e) {
Assert.fail();
} finally {
chainBaseManager.getAccountStore().delete(ByteArray.fromHexString(OWNER_ADDRESS));
chainBaseManager.getAccountStore().delete(ByteArray.fromHexString(TO_ADDRESS));
Expand Down Expand Up @@ -752,6 +755,8 @@ public void sameTokenNameOpenConsumeSuccess() {
Assert.assertFalse(e instanceof TooBigTransactionResultException);
} catch (AccountResourceInsufficientException e) {
Assert.assertFalse(e instanceof AccountResourceInsufficientException);
} catch (TooBigTransactionException e) {
Assert.fail();
} finally {
chainBaseManager.getAccountStore().delete(ByteArray.fromHexString(OWNER_ADDRESS));
chainBaseManager.getAccountStore().delete(ByteArray.fromHexString(TO_ADDRESS));
Expand Down Expand Up @@ -821,6 +826,8 @@ public void sameTokenNameCloseTransferToAccountNotExist() {
Assert.assertFalse(e instanceof TooBigTransactionResultException);
} catch (AccountResourceInsufficientException e) {
Assert.assertFalse(e instanceof AccountResourceInsufficientException);
} catch (TooBigTransactionException e) {
Assert.fail();
} finally {
chainBaseManager.getAccountStore().delete(ByteArray.fromHexString(OWNER_ADDRESS));
chainBaseManager.getAccountStore().delete(ByteArray.fromHexString(TO_ADDRESS));
Expand Down
Loading