Skip to content

Commit aec6820

Browse files
committed
Merge branch 'release_v4.7.2' into develop
2 parents f94355b + 70825eb commit aec6820

657 files changed

Lines changed: 5251 additions & 5870 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,17 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
681681
}
682682
break;
683683
}
684+
case ALLOW_TVM_SHANGHAI: {
685+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_2)) {
686+
throw new ContractValidateException(
687+
"Bad chain parameter id [ALLOW_TVM_SHANGHAI]");
688+
}
689+
if (value != 1) {
690+
throw new ContractValidateException(
691+
"This value[ALLOW_TVM_SHANGHAI] is only allowed to be 1");
692+
}
693+
break;
694+
}
684695
default:
685696
break;
686697
}
@@ -753,7 +764,8 @@ public enum ProposalType { // current value, value range
753764
ALLOW_DYNAMIC_ENERGY(72), // 0, 1
754765
DYNAMIC_ENERGY_THRESHOLD(73), // 0, [0, LONG]
755766
DYNAMIC_ENERGY_INCREASE_FACTOR(74), // 0, [0, 10_000]
756-
DYNAMIC_ENERGY_MAX_FACTOR(75); // 0, [0, 100_000]
767+
DYNAMIC_ENERGY_MAX_FACTOR(75), // 0, [0, 100_000]
768+
ALLOW_TVM_SHANGHAI(76); // 0, 1
757769

758770
private long code;
759771

actuator/src/main/java/org/tron/core/vm/Op.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public class Op {
148148

149149
/* Push Operations */
150150
// Place item on stack
151+
public static final int PUSH0 = 0x5f;
151152
public static final int PUSH1 = 0x60;
152153
public static final int PUSH2 = 0x61;
153154
public static final int PUSH3 = 0x62;

actuator/src/main/java/org/tron/core/vm/OperationActions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@ public static void jumpDestAction(Program program) {
643643
program.step();
644644
}
645645

646+
public static void push0Action(Program program) {
647+
program.stackPush(DataWord.ZERO());
648+
program.step();
649+
}
650+
646651
public static void pushAction(Program program) {
647652
int n = program.getCurrentOpIntValue() - Op.PUSH1 + 1;
648653
program.step();

actuator/src/main/java/org/tron/core/vm/OperationRegistry.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum Version {
1111
TRON_V1_0,
1212
TRON_V1_1,
1313
TRON_V1_2,
14+
TRON_V1_3,
1415
// add more
1516
// TRON_V2,
1617
// ETH
@@ -22,6 +23,7 @@ public enum Version {
2223
tableMap.put(Version.TRON_V1_0, newTronV10OperationSet());
2324
tableMap.put(Version.TRON_V1_1, newTronV11OperationSet());
2425
tableMap.put(Version.TRON_V1_2, newTronV12OperationSet());
26+
tableMap.put(Version.TRON_V1_3, newTronV13OperationSet());
2527
}
2628

2729
public static JumpTable newTronV10OperationSet() {
@@ -47,12 +49,18 @@ public static JumpTable newTronV12OperationSet() {
4749
return table;
4850
}
4951

52+
public static JumpTable newTronV13OperationSet() {
53+
JumpTable table = newTronV12OperationSet();
54+
appendShangHaiOperations(table);
55+
return table;
56+
}
57+
5058
// Just for warming up class to avoid out_of_time
5159
public static void init() {}
5260

5361
public static JumpTable getTable() {
5462
// always get the table which has the newest version
55-
JumpTable table = tableMap.get(Version.TRON_V1_2);
63+
JumpTable table = tableMap.get(Version.TRON_V1_3);
5664

5765
// next make the corresponding changes, exclude activating opcode
5866
if (VMConfig.allowHigherLimitForMaxCpuTimeOfOneTx()) {
@@ -617,4 +625,14 @@ public static void appendDelegateOperations(JumpTable table) {
617625
OperationActions::unDelegateResourceAction,
618626
proposal));
619627
}
628+
629+
public static void appendShangHaiOperations(JumpTable table) {
630+
BooleanSupplier proposal = VMConfig::allowTvmShanghai;
631+
632+
table.set(new Operation(
633+
Op.PUSH0, 0, 1,
634+
EnergyCost::getBaseTierCost,
635+
OperationActions::push0Action,
636+
proposal));
637+
}
620638
}

actuator/src/main/java/org/tron/core/vm/config/ConfigLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static void load(StoreFactory storeFactory) {
3838
VMConfig.initDynamicEnergyThreshold(ds.getDynamicEnergyThreshold());
3939
VMConfig.initDynamicEnergyIncreaseFactor(ds.getDynamicEnergyIncreaseFactor());
4040
VMConfig.initDynamicEnergyMaxFactor(ds.getDynamicEnergyMaxFactor());
41+
VMConfig.initAllowTvmShangHai(ds.getAllowTvmShangHai());
4142
}
4243
}
4344
}

actuator/src/main/java/org/tron/core/vm/config/VMConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class VMConfig {
4747

4848
private static long DYNAMIC_ENERGY_MAX_FACTOR = 0L;
4949

50+
private static boolean ALLOW_TVM_SHANGHAI = false;
51+
5052
private VMConfig() {
5153
}
5254

@@ -130,6 +132,10 @@ public static void initDynamicEnergyMaxFactor(long maxFactor) {
130132
DYNAMIC_ENERGY_MAX_FACTOR = maxFactor;
131133
}
132134

135+
public static void initAllowTvmShangHai(long allow) {
136+
ALLOW_TVM_SHANGHAI = allow == 1;
137+
}
138+
133139
public static boolean getEnergyLimitHardFork() {
134140
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
135141
}
@@ -201,4 +207,8 @@ public static long getDynamicEnergyIncreaseFactor() {
201207
public static long getDynamicEnergyMaxFactor() {
202208
return DYNAMIC_ENERGY_MAX_FACTOR;
203209
}
210+
211+
public static boolean allowTvmShanghai() {
212+
return ALLOW_TVM_SHANGHAI;
213+
}
204214
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ public void payEnergyBill(DynamicPropertiesStore dynamicPropertiesStore,
192192
AccountCapsule caller,
193193
long percent, long originEnergyLimit, EnergyProcessor energyProcessor, long now)
194194
throws BalanceInsufficientException {
195+
196+
// Reset origin energy usage here! Because after stake 2.0, this field are reused for
197+
// recording pre-merge frozen energy for origin account. If total energy usage is zero, this
198+
// field will be a dirty record.
199+
this.setOriginEnergyUsage(0);
200+
195201
if (receipt.getEnergyUsageTotal() <= 0) {
196202
return;
197203
}

chainbase/src/main/java/org/tron/core/db2/core/SnapshotManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Map;
1717
import java.util.Objects;
1818
import java.util.concurrent.ExecutionException;
19+
import java.util.concurrent.ExecutorService;
1920
import java.util.concurrent.Executors;
2021
import java.util.concurrent.Future;
2122
import java.util.concurrent.ScheduledExecutorService;
@@ -122,6 +123,7 @@ public void close() {
122123
exitThread.interrupt();
123124
// help GC
124125
exitThread = null;
126+
flushServices.values().forEach(ExecutorService::shutdown);
125127
} catch (Exception e) {
126128
logger.warn("exitThread interrupt error", e);
127129
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
206206
private static final byte[] ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID =
207207
"ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID".getBytes();
208208

209+
private static final byte[] ALLOW_TVM_SHANGHAI = "ALLOW_TVM_SHANGHAI".getBytes();
210+
209211
@Autowired
210212
private DynamicPropertiesStore(@Value("properties") String dbName) {
211213
super(dbName);
@@ -2755,6 +2757,18 @@ public long getAllowOptimizedReturnValueOfChainId() {
27552757
() -> new IllegalArgumentException(msg));
27562758
}
27572759

2760+
public void saveAllowTvmShangHai(long allowTvmShangHai) {
2761+
this.put(DynamicPropertiesStore.ALLOW_TVM_SHANGHAI,
2762+
new BytesCapsule(ByteArray.fromLong(allowTvmShangHai)));
2763+
}
2764+
2765+
public long getAllowTvmShangHai() {
2766+
return Optional.ofNullable(getUnchecked(ALLOW_TVM_SHANGHAI))
2767+
.map(BytesCapsule::getData)
2768+
.map(ByteArray::toLong)
2769+
.orElse(CommonParameter.getInstance().getAllowTvmShangHai());
2770+
}
2771+
27582772
private static class DynamicResourceProperties {
27592773

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.tron.core.db.TransactionStore;
1515
import org.tron.core.db.TronStoreWithRevoking;
1616
import org.tron.core.exception.BadItemException;
17+
import org.tron.protos.Protocol;
1718
import org.tron.protos.Protocol.TransactionInfo;
1819

1920
@Slf4j(topic = "DB")
@@ -54,6 +55,17 @@ public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemExcep
5455
ByteString id = ByteString.copyFrom(key);
5556
for (TransactionInfo transactionResultInfo : result.getInstance().getTransactioninfoList()) {
5657
if (transactionResultInfo.getId().equals(id)) {
58+
Protocol.ResourceReceipt receipt = transactionResultInfo.getReceipt();
59+
// If query a result with dirty origin usage in receipt, we just reset it.
60+
if (receipt.getEnergyUsageTotal() == 0 && receipt.getOriginEnergyUsage() > 0) {
61+
transactionResultInfo =
62+
transactionResultInfo.toBuilder()
63+
.setReceipt(
64+
receipt.toBuilder()
65+
.clearOriginEnergyUsage()
66+
.build())
67+
.build();
68+
}
5769
return new TransactionInfoCapsule(transactionResultInfo);
5870
}
5971
}

0 commit comments

Comments
 (0)