Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
18 changes: 17 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 @@ -871,6 +871,21 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_TVM_OSAKA: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_2)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_TVM_OSAKA]");
}
if (dynamicPropertiesStore.getAllowTvmOsaka() == 1) {
throw new ContractValidateException(
"[ALLOW_TVM_OSAKA] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_TVM_OSAKA] is only allowed to be 1");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -955,7 +970,8 @@ public enum ProposalType { // current value, value range
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
ALLOW_TVM_BLOB(89), // 0, 1
PROPOSAL_EXPIRE_TIME(92), // (0, 31536003000)
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94); // 0, 1
ALLOW_TVM_SELFDESTRUCT_RESTRICTION(94), // 0, 1
ALLOW_TVM_OSAKA(96); // 0, 1

private long code;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
package org.tron.core.utils;

import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
import org.reflections.Reflections;
import org.tron.core.actuator.AbstractActuator;
import org.tron.core.exception.TronError;

@Slf4j(topic = "TransactionRegister")
public class TransactionRegister {

private static final AtomicBoolean REGISTERED = new AtomicBoolean(false);
private static final String PACKAGE_NAME = "org.tron.core.actuator";

public static void registerActuator() {
Reflections reflections = new Reflections("org.tron");
Set<Class<? extends AbstractActuator>> subTypes = reflections
.getSubTypesOf(AbstractActuator.class);
for (Class _class : subTypes) {
try {
_class.newInstance();
} catch (Exception e) {
logger.error("{} contract actuator register fail!", _class, e);
if (REGISTERED.get()) {
logger.debug("Actuator already registered.");
return;
}

synchronized (TransactionRegister.class) {
if (REGISTERED.get()) {
logger.debug("Actuator already registered.");
return;
}
logger.debug("Register actuator start.");
Reflections reflections = new Reflections(PACKAGE_NAME);
Set<Class<? extends AbstractActuator>> subTypes = reflections
.getSubTypesOf(AbstractActuator.class);

for (Class<? extends AbstractActuator> clazz : subTypes) {
try {
logger.debug("Registering actuator: {} start", clazz.getName());
clazz.getDeclaredConstructor().newInstance();
logger.debug("Registering actuator: {} done", clazz.getName());
} catch (Exception e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
String detail = cause.getMessage() != null ? cause.getMessage() : cause.toString();
throw new TronError(clazz.getName() + ": " + detail,
e, TronError.ErrCode.ACTUATOR_REGISTER);
}
}

REGISTERED.set(true);
logger.debug("Register actuator done, total {}.", subTypes.size());
}
}

static boolean isRegistered() {
return REGISTERED.get();
}

// For testing only — resets registration state between tests.
static void resetForTesting() {
REGISTERED.set(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ public static class ModExp extends PrecompiledContract {

private static final int ARGS_OFFSET = 32 * 3; // addresses length part

private static final int UPPER_BOUND = 1024;

@Override
public long getEnergyForData(byte[] data) {

Expand Down Expand Up @@ -660,6 +662,11 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
int expLen = parseLen(data, 1);
int modLen = parseLen(data, 2);

if (VMConfig.allowTvmOsaka()
&& (baseLen > UPPER_BOUND || expLen > UPPER_BOUND || modLen > UPPER_BOUND)) {
return Pair.of(false, EMPTY_BYTE_ARRAY);
}

BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);
BigInteger exp = parseArg(data, addSafely(ARGS_OFFSET, baseLen), expLen);
BigInteger mod = parseArg(data, addSafely(addSafely(ARGS_OFFSET, baseLen), expLen), modLen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void load(StoreFactory storeFactory) {
VMConfig.initDisableJavaLangMath(ds.getConsensusLogicOptimization());
VMConfig.initAllowTvmBlob(ds.getAllowTvmBlob());
VMConfig.initAllowTvmSelfdestructRestriction(ds.getAllowTvmSelfdestructRestriction());
VMConfig.initAllowTvmOsaka(ds.getAllowTvmOsaka());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] ALLOW_TVM_SELFDESTRUCT_RESTRICTION =
"ALLOW_TVM_SELFDESTRUCT_RESTRICTION".getBytes();

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

@Autowired
private DynamicPropertiesStore(@Value("properties") String dbName) {
super(dbName);
Expand Down Expand Up @@ -2980,6 +2982,17 @@ public long getProposalExpireTime() {
.orElse(CommonParameter.getInstance().getProposalExpireTime());
}

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

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

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

@Getter
@Setter
public long allowTvmOsaka;

private static double calcMaxTimeRatio() {
return 5.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public HttpRateLimiterItem(ConfigObject asset) {
strategy = asset.get("strategy").unwrapped().toString();
params = asset.get("paramString").unwrapped().toString();
}

public HttpRateLimiterItem(String component, String strategy, String params) {
this.component = component;
this.strategy = strategy;
this.params = params;
}
}


Expand All @@ -93,5 +99,11 @@ public RpcRateLimiterItem(ConfigObject asset) {
strategy = asset.get("strategy").unwrapped().toString();
params = asset.get("paramString").unwrapped().toString();
}

public RpcRateLimiterItem(String component, String strategy, String params) {
this.component = component;
this.strategy = strategy;
this.params = params;
}
}
}
3 changes: 2 additions & 1 deletion common/src/main/java/org/tron/core/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static com.typesafe.config.Config getByFileName(

private static void resolveConfigFile(String fileName, File confFile) {
if (confFile.exists()) {
config = ConfigFactory.parseFile(confFile);
config = ConfigFactory.parseFile(confFile)
.withFallback(ConfigFactory.defaultReference());
} else if (Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)
!= null) {
config = ConfigFactory.load(fileName);
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 @@ -28,7 +28,8 @@ public enum ForkBlockVersionEnum {
VERSION_4_7_7(31, 1596780000000L, 80),
VERSION_4_8_0(32, 1596780000000L, 80),
VERSION_4_8_0_1(33, 1596780000000L, 70),
VERSION_4_8_1(34, 1596780000000L, 80);
VERSION_4_8_1(34, 1596780000000L, 80),
VERSION_4_8_2(35, 1596780000000L, 80);
// if add a version, modify BLOCK_VERSION simultaneously

@Getter
Expand Down Expand Up @@ -77,7 +78,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 = 34;
public static final int BLOCK_VERSION = 35;
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
55 changes: 55 additions & 0 deletions common/src/main/java/org/tron/core/config/args/BlockConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.tron.core.config.args;

import static org.tron.core.Constant.DEFAULT_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.exception.TronError.ErrCode.PARAMETER_INIT;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigBeanFactory;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.tron.core.exception.TronError;

/**
* Block configuration bean. Field names match config.conf keys under the "block" section.
*/
@Slf4j
@Getter
@Setter
public class BlockConfig {

private boolean needSyncCheck = false;
private long maintenanceTimeInterval = 21600000L;
private long proposalExpireTime = DEFAULT_PROPOSAL_EXPIRE_TIME;
private int checkFrozenTime = 1;

// Defaults come from reference.conf (loaded globally via Configuration.java)

/**
* Create BlockConfig from the "block" section of the application config.
* Also checks that committee.proposalExpireTime is not used (must use block.proposalExpireTime).
*/
public static BlockConfig fromConfig(Config config) {
// Reject legacy committee.proposalExpireTime location
if (config.hasPath("committee.proposalExpireTime")) {
throw new TronError("It is not allowed to configure committee.proposalExpireTime in "
+ "config.conf, please set the value in block.proposalExpireTime.", PARAMETER_INIT);
}

Config blockSection = config.getConfig("block");
BlockConfig blockConfig = ConfigBeanFactory.create(blockSection, BlockConfig.class);
blockConfig.postProcess();
return blockConfig;
}

private void postProcess() {
if (proposalExpireTime <= MIN_PROPOSAL_EXPIRE_TIME
|| proposalExpireTime >= MAX_PROPOSAL_EXPIRE_TIME) {
throw new TronError("The value[block.proposalExpireTime] is only allowed to "
+ "be greater than " + MIN_PROPOSAL_EXPIRE_TIME + " and less than "
+ MAX_PROPOSAL_EXPIRE_TIME + "!", PARAMETER_INIT);
}
}
}
Loading
Loading