Skip to content

Commit 68a3728

Browse files
committed
Merge remote-tracking branch 'upstream/release_v4.7.5' into feature/remove_redundant_ret
# Conflicts: # common/src/main/java/org/tron/core/Constant.java # framework/src/main/java/org/tron/core/db/Manager.java # framework/src/test/java/org/tron/core/db/ManagerTest.java
2 parents 271e3d0 + b089ca0 commit 68a3728

File tree

26 files changed

+234
-38
lines changed

26 files changed

+234
-38
lines changed

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.tron.core.utils;
22

3+
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE;
4+
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE;
35
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
46
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
57
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;
@@ -748,6 +750,20 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
748750
}
749751
break;
750752
}
753+
case MAX_CREATE_ACCOUNT_TX_SIZE: {
754+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_5)) {
755+
throw new ContractValidateException(
756+
"Bad chain parameter id [MAX_CREATE_ACCOUNT_TX_SIZE]");
757+
}
758+
if (value < CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE
759+
|| value > CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE) {
760+
throw new ContractValidateException(
761+
"This value[MAX_CREATE_ACCOUNT_TX_SIZE] is only allowed to be greater than or equal "
762+
+ "to " + CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE + " and less than or equal to "
763+
+ CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE + "!");
764+
}
765+
break;
766+
}
751767
default:
752768
break;
753769
}
@@ -824,7 +840,8 @@ public enum ProposalType { // current value, value range
824840
ALLOW_TVM_SHANGHAI(76), // 0, 1
825841
ALLOW_CANCEL_ALL_UNFREEZE_V2(77), // 0, 1
826842
MAX_DELEGATE_LOCK_PERIOD(78), // (86400, 10512000]
827-
ALLOW_OLD_REWARD_OPT(79); // 0, 1
843+
ALLOW_OLD_REWARD_OPT(79), // 0, 1
844+
MAX_CREATE_ACCOUNT_TX_SIZE(82); // [500, 10000]
828845

829846
private long code;
830847

chainbase/src/main/java/org/tron/core/capsule/TransactionCapsule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {
115115
@Getter
116116
@Setter
117117
private boolean isTransactionCreate = false;
118+
@Getter
119+
@Setter
120+
private boolean isInBlock = false;
118121

119122
public byte[] getOwnerAddress() {
120123
if (this.ownerAddress == null) {

chainbase/src/main/java/org/tron/core/db/BandwidthProcessor.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.tron.core.db;
22

3+
import static org.tron.core.Constant.PER_SIGN_LENGTH;
34
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
45
import static org.tron.protos.Protocol.Transaction.Contract.ContractType.ShieldedTransferContract;
56
import static org.tron.protos.Protocol.Transaction.Contract.ContractType.TransferAssetContract;
7+
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
68

79
import com.google.protobuf.ByteString;
810
import java.util.HashMap;
@@ -19,13 +21,12 @@
1921
import org.tron.core.capsule.TransactionCapsule;
2022
import org.tron.core.exception.AccountResourceInsufficientException;
2123
import org.tron.core.exception.ContractValidateException;
24+
import org.tron.core.exception.TooBigTransactionException;
2225
import org.tron.core.exception.TooBigTransactionResultException;
2326
import org.tron.protos.Protocol.Transaction.Contract;
2427
import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract;
2528
import org.tron.protos.contract.BalanceContract.TransferContract;
2629

27-
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
28-
2930
@Slf4j(topic = "DB")
3031
public class BandwidthProcessor extends ResourceProcessor {
3132

@@ -95,7 +96,7 @@ public void updateUsage(AssetIssueCapsule assetIssueCapsule, long now) {
9596
@Override
9697
public void consume(TransactionCapsule trx, TransactionTrace trace)
9798
throws ContractValidateException, AccountResourceInsufficientException,
98-
TooBigTransactionResultException {
99+
TooBigTransactionResultException, TooBigTransactionException {
99100
List<Contract> contracts = trx.getInstance().getRawData().getContractList();
100101
long resultSizeWithMaxContractRet = trx.getResultSizeWithMaxContractRet();
101102
if (!trx.isInBlock() && resultSizeWithMaxContractRet >
@@ -134,6 +135,17 @@ public void consume(TransactionCapsule trx, TransactionTrace trace)
134135
}
135136
long now = chainBaseManager.getHeadSlot();
136137
if (contractCreateNewAccount(contract)) {
138+
if (!trx.isInBlock()) {
139+
long maxCreateAccountTxSize = dynamicPropertiesStore.getMaxCreateAccountTxSize();
140+
int signatureCount = trx.getInstance().getSignatureCount();
141+
long createAccountBytesSize = trx.getInstance().toBuilder().clearRet()
142+
.build().getSerializedSize() - (signatureCount * PER_SIGN_LENGTH);
143+
if (createAccountBytesSize > maxCreateAccountTxSize) {
144+
throw new TooBigTransactionException(String.format(
145+
"Too big new account transaction, TxId %s, the size is %d bytes, maxTxSize %d",
146+
trx.getTransactionId(), createAccountBytesSize, maxCreateAccountTxSize));
147+
}
148+
}
137149
consumeForCreateNewAccount(accountCapsule, bytesSize, now, trace);
138150
continue;
139151
}

chainbase/src/main/java/org/tron/core/db/ResourceProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.tron.core.exception.AccountResourceInsufficientException;
1212
import org.tron.core.exception.BalanceInsufficientException;
1313
import org.tron.core.exception.ContractValidateException;
14+
import org.tron.core.exception.TooBigTransactionException;
1415
import org.tron.core.exception.TooBigTransactionResultException;
1516
import org.tron.core.store.AccountStore;
1617
import org.tron.core.store.DynamicPropertiesStore;
@@ -35,7 +36,7 @@ protected ResourceProcessor(DynamicPropertiesStore dynamicPropertiesStore,
3536
}
3637

3738
abstract void consume(TransactionCapsule trx, TransactionTrace trace)
38-
throws ContractValidateException, AccountResourceInsufficientException, TooBigTransactionResultException;
39+
throws ContractValidateException, AccountResourceInsufficientException, TooBigTransactionResultException, TooBigTransactionException;
3940

4041
protected long increase(long lastUsage, long usage, long lastTime, long now) {
4142
return increase(lastUsage, usage, lastTime, now, windowSize);

chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
219219

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

222+
private static final byte[] MAX_CREATE_ACCOUNT_TX_SIZE = "MAX_CREATE_ACCOUNT_TX_SIZE".getBytes();
223+
222224
@Autowired
223225
private DynamicPropertiesStore(@Value("properties") String dbName) {
224226
super(dbName);
@@ -2850,6 +2852,18 @@ public long getAllowOldRewardOpt() {
28502852
.orElse(CommonParameter.getInstance().getAllowOldRewardOpt());
28512853
}
28522854

2855+
public void saveMaxCreateAccountTxSize(long maxCreateAccountTxSize) {
2856+
this.put(MAX_CREATE_ACCOUNT_TX_SIZE,
2857+
new BytesCapsule(ByteArray.fromLong(maxCreateAccountTxSize)));
2858+
}
2859+
2860+
public long getMaxCreateAccountTxSize() {
2861+
return Optional.ofNullable(getUnchecked(MAX_CREATE_ACCOUNT_TX_SIZE))
2862+
.map(BytesCapsule::getData)
2863+
.map(ByteArray::toLong)
2864+
.orElse(CommonParameter.getInstance().getMaxCreateAccountTxSize());
2865+
}
2866+
28532867
private static class DynamicResourceProperties {
28542868

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

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ public class CommonParameter {
666666
@Setter
667667
public long allowOldRewardOpt;
668668

669+
@Getter
670+
@Setter
671+
public long maxCreateAccountTxSize = 1000L;
672+
669673
private static double calcMaxTimeRatio() {
670674
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
671675
return 5.0;

common/src/main/java/org/tron/core/Constant.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ public class Constant {
2424

2525
// config for transaction
2626
public static final long TRANSACTION_MAX_BYTE_SIZE = 500 * 1_024L;
27+
public static final int CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE = 500;
28+
public static final int CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE = 10000;
2729
public static final long MAXIMUM_TIME_UNTIL_EXPIRATION = 24 * 60 * 60 * 1_000L; //one day
2830
public static final long TRANSACTION_DEFAULT_EXPIRATION_TIME = 60 * 1_000L; //60 seconds
2931
public static final long TRANSACTION_FEE_POOL_PERIOD = 1; //1 blocks
3032
// config for smart contract
3133
public static final long SUN_PER_ENERGY = 100; // 1 us = 100 SUN = 100 * 10^-6 TRX
3234
public static final long ENERGY_LIMIT_IN_CONSTANT_TX = 3_000_000L; // ref: 1 us = 1 energy
3335
public static final long MAX_RESULT_SIZE_IN_TX = 64; // max 8 * 8 items in result
36+
public static final long PER_SIGN_LENGTH = 65L;
3437
public static final long MAX_CONTRACT_RESULT_SIZE = 2L;
3538
public static final long PB_DEFAULT_ENERGY_LIMIT = 0L;
3639
public static final long CREATOR_DEFAULT_ENERGY_LIMIT = 1000 * 10_000L;

common/src/main/java/org/tron/core/config/Parameter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public enum ForkBlockVersionEnum {
2323
VERSION_4_7(26, 1596780000000L, 80),
2424
VERSION_4_7_1(27, 1596780000000L, 80),
2525
VERSION_4_7_2(28, 1596780000000L, 80),
26-
VERSION_4_7_4(29, 1596780000000L, 80);
26+
VERSION_4_7_4(29, 1596780000000L, 80),
27+
VERSION_4_7_5(30, 1596780000000L, 80);
2728
// if add a version, modify BLOCK_VERSION simultaneously
2829

2930
@Getter
@@ -72,7 +73,7 @@ public class ChainConstant {
7273
public static final int SINGLE_REPEAT = 1;
7374
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
7475
public static final int MAX_FROZEN_NUMBER = 1;
75-
public static final int BLOCK_VERSION = 29;
76+
public static final int BLOCK_VERSION = 30;
7677
public static final long FROZEN_PERIOD = 86_400_000L;
7778
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
7879
public static final long TRX_PRECISION = 1000_000L;

consensus/src/main/java/org/tron/consensus/dpos/DposTask.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ private State produceBlock() {
9191
try {
9292
synchronized (dposService.getBlockHandle().getLock()) {
9393

94+
state = stateManager.getState();
95+
if (!State.OK.equals(state)) {
96+
return state;
97+
}
98+
9499
long slot = dposSlot.getSlot(System.currentTimeMillis() + 50);
95100
if (slot == 0) {
96101
return State.NOT_TIME_YET;

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,11 @@ public Protocol.ChainParameters getChainParameters() {
13321332
.setValue(dbManager.getDynamicPropertiesStore().getAllowOldRewardOpt())
13331333
.build());
13341334

1335+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
1336+
.setKey("getMaxCreateAccountTxSize")
1337+
.setValue(dbManager.getDynamicPropertiesStore().getMaxCreateAccountTxSize())
1338+
.build());
1339+
13351340
return builder.build();
13361341
}
13371342

0 commit comments

Comments
 (0)