Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release_v4.7.0' into feature/tvm…
Browse files Browse the repository at this point in the history
…_stake_2.0

# Conflicts:
#	framework/src/main/java/org/tron/core/net/P2pEventHandlerImpl.java
  • Loading branch information
Liulei committed Dec 27, 2022
2 parents 5d9b2fb + 504db6b commit 3cfd401
Show file tree
Hide file tree
Showing 35 changed files with 584 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public boolean execute(Object result) throws ContractExeException {

accountStore.put(ownerAddress, accountCapsule);

ret.setUnfreezeAmount(unfreezeBalance);
ret.setWithdrawExpireAmount(unfreezeAmount);
ret.setStatus(fee, code.SUCESS);
return true;
Expand Down
14 changes: 13 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID]");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID] is only allowed to be 1");
}
break;
}

default:
break;
Expand Down Expand Up @@ -676,7 +687,8 @@ public enum ProposalType { // current value, value range
ALLOW_NEW_REWARD(67), // 0, 1
MEMO_FEE(68), // 0, [0, 1000_000_000]
ALLOW_DELEGATE_OPTIMIZATION(69),
UNFREEZE_DELAY_DAYS(70); // 0, [1, 365]
UNFREEZE_DELAY_DAYS(70), // 0, [1, 365]
ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID(71); // 0, 1

private long code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public static long estimateConsumeBandWidthSize(
final AccountCapsule ownerCapsule,
ChainBaseManager chainBaseManager) {
DelegateResourceContract.Builder builder = DelegateResourceContract.newBuilder()
.setLock(true)
.setBalance(ownerCapsule.getFrozenV2BalanceForBandwidth());
TransactionCapsule fakeTransactionCapsule = new TransactionCapsule(builder.build()
, ContractType.DelegateResourceContract);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static void load(StoreFactory storeFactory) {
VMConfig.initAllowHigherLimitForMaxCpuTimeOfOneTx(
ds.getAllowHigherLimitForMaxCpuTimeOfOneTx());
VMConfig.initAllowTvmFreezeV2(ds.supportUnfreezeDelay() ? 1 : 0);
VMConfig.initAllowOptimizedReturnValueOfChainId(
ds.getAllowOptimizedReturnValueOfChainId());
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/config/VMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class VMConfig {

private static boolean ALLOW_TVM_FREEZE_V2 = false;

private static boolean ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID = false;

private VMConfig() {
}

Expand Down Expand Up @@ -100,6 +102,10 @@ public static void initAllowTvmFreezeV2(long allow) {
ALLOW_TVM_FREEZE_V2 = allow == 1;
}

public static void initAllowOptimizedReturnValueOfChainId(long allow) {
ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID = allow == 1;
}

public static boolean getEnergyLimitHardFork() {
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
}
Expand Down Expand Up @@ -151,4 +157,8 @@ public static boolean allowHigherLimitForMaxCpuTimeOfOneTx() {
public static boolean allowTvmFreezeV2() {
return ALLOW_TVM_FREEZE_V2;
}

public static boolean allowOptimizedReturnValueOfChainId() {
return ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ public DataWord getCallerAddress() {

public DataWord getChainId() {
byte[] chainId = getContractState().getBlockByNum(0).getBlockId().getBytes();
if (VMConfig.allowTvmCompatibleEvm()) {
if (VMConfig.allowTvmCompatibleEvm() || VMConfig.allowOptimizedReturnValueOfChainId()) {
chainId = Arrays.copyOfRange(chainId, chainId.length - 4, chainId.length);
}
return new DataWord(chainId).clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
@Slf4j(topic = "DB")
public class SnapshotManager implements RevokingDatabase {

public static final int DEFAULT_MAX_FLUSH_COUNT = 500;
public static final int DEFAULT_MIN_FLUSH_COUNT = 1;
private static final int DEFAULT_STACK_MAX_SIZE = 256;
private static final long ONE_MINUTE_MILLS = 60*1000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] ALLOW_DELEGATE_OPTIMIZATION =
"ALLOW_DELEGATE_OPTIMIZATION".getBytes();


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

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

@Autowired
private DynamicPropertiesStore(@Value("properties") String dbName) {
super(dbName);
Expand Down Expand Up @@ -899,6 +901,14 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
CommonParameter.getInstance().getUnfreezeDelayDays()
);
}

try {
this.getAllowOptimizedReturnValueOfChainId();
} catch (IllegalArgumentException e) {
this.saveAllowOptimizedReturnValueOfChainId(
CommonParameter.getInstance().getAllowOptimizedReturnValueOfChainId()
);
}
}

public String intArrayToString(int[] a) {
Expand Down Expand Up @@ -2647,6 +2657,20 @@ public void saveUnfreezeDelayDays(long value) {
this.put(UNFREEZE_DELAY_DAYS, new BytesCapsule(ByteArray.fromLong(value)));
}

public void saveAllowOptimizedReturnValueOfChainId(long value) {
this.put(ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID,
new BytesCapsule(ByteArray.fromLong(value)));
}

public long getAllowOptimizedReturnValueOfChainId() {
String msg = "not found ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID";
return Optional.ofNullable(getUnchecked(ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElseThrow(
() -> new IllegalArgumentException(msg));
}

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 @@ -582,6 +582,10 @@ public class CommonParameter {
@Setter
public long unfreezeDelayDays = 0L;

@Getter
@Setter
public long allowOptimizedReturnValueOfChainId = 0L;

private static double calcMaxTimeRatio() {
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
return 5.0;
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ public class Constant {
public static final String COMMITTEE_ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX =
"committee.allowHigherLimitForMaxCpuTimeOfOneTx";
public static final String COMMITTEE_ALLOW_NEW_REWARD_ALGORITHM = "committee.allowNewRewardAlgorithm";
public static final String COMMITTEE_ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID =
"committee.allowOptimizedReturnValueOfChainId";


public static final String METRICS_STORAGE_ENABLE = "node.metrics.storageEnable";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Storage {
private static final int DEFAULT_CHECKPOINT_VERSION = 1;
private static final boolean DEFAULT_CHECKPOINT_SYNC = true;
private static final int DEFAULT_ESTIMATED_TRANSACTIONS = 1000;
private static final int DEFAULT_SNAPSHOT_MAX_FLUSH_COUNT = 500;
private static final int DEFAULT_SNAPSHOT_MAX_FLUSH_COUNT = 1;
private Config storage;

/**
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tronprotocol/centos7
FROM tronprotocol/centos7:0.2

ENV TMP_DIR="/tron-build"
ENV JDK_TAR="jdk-8u202-linux-x64.tar.gz"
Expand All @@ -24,7 +24,7 @@ RUN set -o errexit -o nounset \
&& git checkout master \
&& ./gradlew build -x test \
&& cd build/distributions \
&& unzip -o java-tron-1.0.0.zip \
&& 7za x -y java-tron-1.0.0.zip \
&& mv java-tron-1.0.0 $BASE_DIR \
&& rm -rf $TMP_DIR \
&& rm -rf ~/.gradle \
Expand Down
8 changes: 8 additions & 0 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,9 @@ public GrpcAPI.CanDelegatedMaxSizeResponseMessage getCanDelegatedMaxSize(
canDelegatedMaxSize = this.calcCanDelegatedEnergyMaxSize(ownerAddress);
}

if (canDelegatedMaxSize < TRX_PRECISION) {
canDelegatedMaxSize = 0L;
}
builder.setMaxSize(canDelegatedMaxSize);
return builder.build();
}
Expand Down Expand Up @@ -1284,6 +1287,11 @@ public Protocol.ChainParameters getChainParameters() {
.setValue(dbManager.getDynamicPropertiesStore().getUnfreezeDelayDays())
.build());

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

return builder.build();
}

Expand Down
4 changes: 4 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ public static void setParam(final String[] args, final String confFileName) {
config.hasPath(Constant.COMMITTEE_ALLOW_NEW_REWARD_ALGORITHM) ? config
.getInt(Constant.COMMITTEE_ALLOW_NEW_REWARD_ALGORITHM) : 0;

PARAMETER.allowOptimizedReturnValueOfChainId =
config.hasPath(Constant.COMMITTEE_ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID) ? config
.getInt(Constant.COMMITTEE_ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID) : 0;

initBackupProperty(config);
if (Constant.ROCKSDB.equalsIgnoreCase(CommonParameter
.getInstance().getStorage().getDbEngine())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveAllowDelegateOptimization(entry.getValue());
break;
}
case ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID: {
manager.getDynamicPropertiesStore()
.saveAllowOptimizedReturnValueOfChainId(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
80 changes: 65 additions & 15 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.bouncycastle.util.encoders.Hex;
import org.quartz.CronExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.api.GrpcAPI.TransactionInfoList;
Expand Down Expand Up @@ -537,21 +538,14 @@ public void init() {
//initActuatorCreator
ActuatorCreator.init();
TransactionRegister.registerActuator();

long exitHeight = CommonParameter.getInstance().getShutdownBlockHeight();
long exitCount = CommonParameter.getInstance().getShutdownBlockCount();

if (exitCount > 0 && (exitHeight < 0 || exitHeight > headNum + exitCount)) {
CommonParameter.getInstance().setShutdownBlockHeight(headNum + exitCount);
// init auto-stop
try {
initAutoStop();
} catch (IllegalArgumentException e) {
logger.error("Auto-stop params error: {}", e.getMessage());
System.exit(1);
}

if (CommonParameter.getInstance().getShutdownBlockHeight() < headNum) {
logger.info("ShutDownBlockHeight {} is less than headNum {}, ignored.",
CommonParameter.getInstance().getShutdownBlockHeight(), headNum);
CommonParameter.getInstance().setShutdownBlockHeight(-1);
}
// init
latestSolidityNumShutDown = CommonParameter.getInstance().getShutdownBlockHeight();
maxFlushCount = CommonParameter.getInstance().getStorage().getMaxFlushCount();
}

Expand Down Expand Up @@ -677,6 +671,62 @@ private void initWitness() {
});
}

/**
* init auto-stop, check params
*/
private void initAutoStop() {
final long headNum = chainBaseManager.getHeadBlockNum();
final long headTime = chainBaseManager.getHeadBlockTimeStamp();
final long exitHeight = CommonParameter.getInstance().getShutdownBlockHeight();
final long exitCount = CommonParameter.getInstance().getShutdownBlockCount();
final CronExpression blockTime = Args.getInstance().getShutdownBlockTime();

if (exitHeight > 0 && exitHeight < headNum) {
throw new IllegalArgumentException(
String.format("shutDownBlockHeight %d is less than headNum %d", exitHeight, headNum));
}

if (exitCount == 0) {
throw new IllegalArgumentException(
String.format("shutDownBlockCount %d is less than 1", exitCount));
}

if (blockTime != null && blockTime.getNextValidTimeAfter(new Date(headTime)) == null) {
throw new IllegalArgumentException(
String.format("shutDownBlockTime %s is illegal", blockTime));
}

if (exitHeight > 0 && exitCount > 0) {
throw new IllegalArgumentException(
String.format("shutDownBlockHeight %d and shutDownBlockCount %d set both",
exitHeight, exitCount));
}

if (exitHeight > 0 && blockTime != null) {
throw new IllegalArgumentException(
String.format("shutDownBlockHeight %d and shutDownBlockTime %s set both",
exitHeight, blockTime));
}

if (exitCount > 0 && blockTime != null) {
throw new IllegalArgumentException(
String.format("shutDownBlockCount %d and shutDownBlockTime %s set both",
exitCount, blockTime));
}

if (exitHeight == headNum) {
logger.info("Auto-stop hit: shutDownBlockHeight: {}, currentHeaderNum: {}, exit now",
exitHeight, headNum);
System.exit(0);
}

if (exitCount > 0) {
CommonParameter.getInstance().setShutdownBlockHeight(headNum + exitCount);
}
// init
latestSolidityNumShutDown = CommonParameter.getInstance().getShutdownBlockHeight();
}

public AccountStore getAccountStore() {
return chainBaseManager.getAccountStore();
}
Expand Down Expand Up @@ -964,12 +1014,12 @@ private void applyBlock(BlockCapsule block, List<TransactionCapsule> txs)
revokingStore.setMaxFlushCount(maxFlushCount);
if (Args.getInstance().getShutdownBlockTime() != null
&& Args.getInstance().getShutdownBlockTime().getNextValidTimeAfter(
new Date(block.getTimeStamp() - SnapshotManager.DEFAULT_MAX_FLUSH_COUNT * 1000 * 3))
new Date(block.getTimeStamp() - maxFlushCount * 1000 * 3L))
.compareTo(new Date(block.getTimeStamp())) <= 0) {
revokingStore.setMaxFlushCount(SnapshotManager.DEFAULT_MIN_FLUSH_COUNT);
}
if (latestSolidityNumShutDown > 0 && latestSolidityNumShutDown - block.getNum()
<= SnapshotManager.DEFAULT_MAX_FLUSH_COUNT) {
<= maxFlushCount) {
revokingStore.setMaxFlushCount(SnapshotManager.DEFAULT_MIN_FLUSH_COUNT);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ public class TronNetDelegate {

private Thread hitThread;

// for Test
@Setter
private volatile boolean test = false;
private volatile boolean exit = true;

private Cache<BlockId, Long> freshBlockId = CacheBuilder.newBuilder()
.maximumSize(blockIdCacheSize).expireAfterWrite(1, TimeUnit.HOURS)
Expand All @@ -107,7 +106,7 @@ public void init() {
hitThread = new Thread(() -> {
LockSupport.park();
// to Guarantee Some other thread invokes unpark with the current thread as the target
if (hitDown && !test) {
if (hitDown && exit) {
System.exit(0);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public String log() {
+ "remainNum:%d\n"
+ "syncChainRequested:%d\n"
+ "blockInProcess:%d\n",
channel.getInetAddress(),
channel.getInetSocketAddress(),
(now - channel.getStartTime()) / Constant.ONE_THOUSAND,
channel.getLatency(),
fastForwardBlock != null ? fastForwardBlock.getNum() : blockBothHave.getNum(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public static void init() {

public static void close() {
try {
peers.forEach(p -> {
for (PeerConnection p : new ArrayList<>(peers)) {
if (!p.isDisconnect()) {
p.getChannel().close();
}
});
}
executor.shutdownNow();
} catch (Exception e) {
logger.error("Peer manager shutdown failed", e);
Expand Down
Loading

0 comments on commit 3cfd401

Please sign in to comment.