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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum ErrCode {
RATE_LIMITER_INIT(1),
SOLID_NODE_INIT(0),
PARAMETER_INIT(1),
ACTUATOR_REGISTER(1),
JDK_VERSION(1);

private final int code;
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/org/tron/core/vm/config/VMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class VMConfig {

private static boolean ALLOW_TVM_SELFDESTRUCT_RESTRICTION = false;

private static boolean ALLOW_TVM_OSAKA = false;

private VMConfig() {
}

Expand Down Expand Up @@ -172,6 +174,10 @@ public static void initAllowTvmSelfdestructRestriction(long allow) {
ALLOW_TVM_SELFDESTRUCT_RESTRICTION = allow == 1;
}

public static void initAllowTvmOsaka(long allow) {
ALLOW_TVM_OSAKA = allow == 1;
}

public static boolean getEnergyLimitHardFork() {
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
}
Expand Down Expand Up @@ -271,4 +277,8 @@ public static boolean allowTvmBlob() {
public static boolean allowTvmSelfdestructRestriction() {
return ALLOW_TVM_SELFDESTRUCT_RESTRICTION;
}

public static boolean allowTvmOsaka() {
return ALLOW_TVM_OSAKA;
}
}
14 changes: 8 additions & 6 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static def isWindows() {
return org.gradle.internal.os.OperatingSystem.current().isWindows()
}

task version(type: Exec) {
tasks.register('version', Exec) {
commandLine 'bash', '-c', '../ver.sh'
}

Expand Down Expand Up @@ -78,7 +78,7 @@ checkstyleMain {
source = 'src/main/java'
}

task lint(type: Checkstyle) {
tasks.register('lint', Checkstyle) {
// Cleaning the old log because of the creation of the new ones (not sure if totaly needed)
delete fileTree(dir: "${project.rootDir}/app/build/reports")
source 'src'
Expand Down Expand Up @@ -123,10 +123,10 @@ def configureTestTask = { Task t ->
t.exclude 'org/tron/core/ShieldedTRC20BuilderTest.class'
t.exclude 'org/tron/common/runtime/vm/WithdrawRewardTest.class'
}
t.maxHeapSize = "1024m"
t.maxHeapSize = "512m"
t.maxParallelForks = Math.max(1, Math.min(4, Runtime.runtime.availableProcessors()))
t.doFirst {
t.forkEvery = 100
t.jvmArgs "-XX:MetaspaceSize=128m", "-XX:MaxMetaspaceSize=256m", "-XX:+UseG1GC"
}
}

Expand All @@ -150,7 +150,7 @@ test {
}
}

task testWithRocksDb(type: Test) {
tasks.register('testWithRocksDb', Test) {
description = 'Run tests with RocksDB engine'
group = 'verification'
configureTestTask(it)
Expand Down Expand Up @@ -197,7 +197,9 @@ def binaryRelease(taskName, jarName, mainClass) {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"

// for service SPI loader for dnsjava
// see https://issues.apache.org/jira/browse/HADOOP-19288
exclude "META-INF/services/java.net.spi.InetAddressResolverProvider"
manifest {
attributes "Main-Class": "${mainClass}"
}
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 @@ -1509,6 +1509,11 @@ public Protocol.ChainParameters getChainParameters() {
.setValue(dbManager.getDynamicPropertiesStore().getProposalExpireTime())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getAllowTvmOsaka")
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmOsaka())
.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 @@ -1037,6 +1037,10 @@ public static void applyConfigParams(
config.hasPath(ConfigKey.COMMITTEE_ALLOW_TVM_BLOB) ? config
.getInt(ConfigKey.COMMITTEE_ALLOW_TVM_BLOB) : 0;

PARAMETER.allowTvmOsaka =
config.hasPath(ConfigKey.COMMITTEE_ALLOW_TVM_OSAKA) ? config
.getInt(ConfigKey.COMMITTEE_ALLOW_TVM_OSAKA) : 0;

logConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ private ConfigKey() {
public static final String COMMITTEE_ALLOW_TVM_CANCUN = "committee.allowTvmCancun";
public static final String COMMITTEE_ALLOW_TVM_BLOB = "committee.allowTvmBlob";
public static final String COMMITTEE_PROPOSAL_EXPIRE_TIME = "committee.proposalExpireTime";
public static final String COMMITTEE_ALLOW_TVM_OSAKA = "committee.allowTvmOsaka";
public static final String ALLOW_ACCOUNT_ASSET_OPTIMIZATION =
"committee.allowAccountAssetOptimization";
public static final String ALLOW_ASSET_OPTIMIZATION = "committee.allowAssetOptimization";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveProposalExpireTime(entry.getValue());
break;
}
case ALLOW_TVM_OSAKA: {
manager.getDynamicPropertiesStore().saveAllowTvmOsaka(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
1 change: 1 addition & 0 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ committee = {
# allowTvmBlob = 0
# consensusLogicOptimization = 0
# allowOptimizedReturnValueOfChainId = 0
# allowTvmOsaka = 0
}

event.subscribe = {
Expand Down
Loading
Loading