Skip to content

Commit

Permalink
Merge branch 'refs/heads/release_v4.7.5' into feature/implement-TIP653
Browse files Browse the repository at this point in the history
# Conflicts:
#	actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
#	chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java
#	common/src/main/java/org/tron/common/parameter/CommonParameter.java
#	framework/src/main/java/org/tron/core/Wallet.java
#	framework/src/main/java/org/tron/core/consensus/ProposalService.java
  • Loading branch information
yanghang8612 committed May 30, 2024
2 parents 3aa94e0 + fd3d8f6 commit 4412177
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 35 deletions.
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 @@ -763,6 +765,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 @@ -840,7 +856,8 @@ public enum ProposalType { // current value, value range
ALLOW_CANCEL_ALL_UNFREEZE_V2(77), // 0, 1
MAX_DELEGATE_LOCK_PERIOD(78), // (86400, 10512000]
ALLOW_OLD_REWARD_OPT(79), // 0, 1
ALLOW_ENERGY_ADJUSTMENT(81); // 0, 1
ALLOW_ENERGY_ADJUSTMENT(81), // 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 @@ -221,6 +221,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>

private static final byte[] ALLOW_ENERGY_ADJUSTMENT = "ALLOW_ENERGY_ADJUSTMENT".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 @@ -2863,6 +2865,18 @@ public long getAllowEnergyAdjustment() {
.orElse(CommonParameter.getInstance().getAllowEnergyAdjustment());
}

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 @@ -670,6 +670,10 @@ public class CommonParameter {
@Setter
public long allowEnergyAdjustment;

@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 @@ -26,13 +26,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: 5 additions & 0 deletions consensus/src/main/java/org/tron/consensus/dpos/DposTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ private State produceBlock() {
try {
synchronized (dposService.getBlockHandle().getLock()) {

state = stateManager.getState();
if (!State.OK.equals(state)) {
return state;
}

long slot = dposSlot.getSlot(System.currentTimeMillis() + 50);
if (slot == 0) {
return State.NOT_TIME_YET;
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 @@ -1339,6 +1339,11 @@ public Protocol.ChainParameters getChainParameters() {
.setValue(dbManager.getDynamicPropertiesStore().getAllowEnergyAdjustment())
.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 @@ -363,6 +363,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveAllowEnergyAdjustment(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 @@ -61,6 +61,18 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep
BlockMessage blockMessage = (BlockMessage) msg;
BlockId blockId = blockMessage.getBlockId();

BlockCapsule blockCapsule = blockMessage.getBlockCapsule();
if (blockCapsule.getInstance().getSerializedSize() > maxBlockSize) {
logger.error("Receive bad block {} from peer {}, block size over limit",
blockMessage.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "block size over limit");
}
long gap = blockCapsule.getTimeStamp() - System.currentTimeMillis();
if (gap >= BLOCK_PRODUCED_INTERVAL) {
logger.error("Receive bad block {} from peer {}, block time error",
blockMessage.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "block time error");
}
if (!fastForward && !peer.isRelayPeer()) {
check(peer, blockMessage);
}
Expand Down Expand Up @@ -109,18 +121,6 @@ private void check(PeerConnection peer, BlockMessage msg) throws P2pException {
msg.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "no request");
}
BlockCapsule blockCapsule = msg.getBlockCapsule();
if (blockCapsule.getInstance().getSerializedSize() > maxBlockSize) {
logger.error("Receive bad block {} from peer {}, block size over limit",
msg.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "block size over limit");
}
long gap = blockCapsule.getTimeStamp() - System.currentTimeMillis();
if (gap >= BLOCK_PRODUCED_INTERVAL) {
logger.error("Receive bad block {} from peer {}, block time error",
msg.getBlockId(), peer.getInetSocketAddress());
throw new P2pException(TypeEnum.BAD_MESSAGE, "block time error");
}
}

private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pException {
Expand Down Expand Up @@ -150,14 +150,7 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc

try {
tronNetDelegate.processBlock(block, false);

witnessProductBlockService.validWitnessProductTwoBlock(block);

tronNetDelegate.getActivePeer().forEach(p -> {
if (p.getAdvInvReceive().getIfPresent(blockId) != null) {
p.setBlockBothHave(blockId);
}
});
} catch (Exception e) {
logger.warn("Process adv block {} from peer {} failed. reason: {}",
blockId, peer.getInetAddress(), e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public void broadcast(Message msg) {
logger.info("Ready to broadcast block {}", blockMsg.getBlockId().getString());
blockMsg.getBlockCapsule().getTransactions().forEach(transactionCapsule -> {
Sha256Hash tid = transactionCapsule.getTransactionId();
invToSpread.remove(tid);
trxCache.put(new Item(tid, InventoryType.TRX),
new TransactionMessage(transactionCapsule.getInstance()));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public void fetchBlock(List<Sha256Hash> sha256HashList, PeerConnection peer) {
sha256HashList.stream().filter(sha256Hash -> new BlockCapsule.BlockId(sha256Hash).getNum()
== chainBaseManager.getHeadBlockNum() + 1)
.findFirst().ifPresent(sha256Hash -> {
fetchBlockInfo = new FetchBlockInfo(sha256Hash, peer, System.currentTimeMillis());
long now = System.currentTimeMillis();
fetchBlockInfo = new FetchBlockInfo(sha256Hash, peer, now);
logger.info("Set fetchBlockInfo, block: {}, peer: {}, time: {}", sha256Hash,
fetchBlockInfo.getPeer().getInetAddress(), fetchBlockInfo.getTime());
peer.getInetAddress(), now);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ private void processSyncBlock(BlockCapsule block, PeerConnection peerConnection)
}

for (PeerConnection peer : tronNetDelegate.getActivePeer()) {
if (blockId.equals(peer.getSyncBlockToFetch().peek())) {
peer.getSyncBlockToFetch().pop();
BlockId bid = peer.getSyncBlockToFetch().peek();
if (blockId.equals(bid)) {
peer.getSyncBlockToFetch().remove(bid);
if (flag) {
peer.setBlockBothHave(blockId);
if (peer.getSyncBlockToFetch().isEmpty() && peer.isFetchAble()) {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/main/java/org/tron/program/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Version {

public static final String VERSION_NAME = "GreatVoyage-v4.7.3.1-78-ge84a9e778";
public static final String VERSION_CODE = "18260";
private static final String VERSION = "4.7.4";
private static final String VERSION = "4.7.5";

public static String getVersion() {
return VERSION;
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
Loading

0 comments on commit 4412177

Please sign in to comment.