Skip to content

Commit d07e897

Browse files
committed
fix(grpc): use usePlaintext
2 parents 5caa628 + 2b3b9e6 commit d07e897

226 files changed

Lines changed: 5245 additions & 6673 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/utils/TransactionUtil.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.tron.protos.Protocol.Transaction;
5050
import org.tron.protos.Protocol.Transaction.Contract;
5151
import org.tron.protos.Protocol.Transaction.Result.contractResult;
52-
import org.tron.protos.Protocol.TransactionSign;
5352
import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;
5453
import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
5554
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
@@ -184,21 +183,6 @@ public static String makeUpperCamelMethod(String originName) {
184183
.replace("_", "");
185184
}
186185

187-
public static TransactionCapsule getTransactionSign(TransactionSign transactionSign) {
188-
byte[] privateKey = transactionSign.getPrivateKey().toByteArray();
189-
TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction());
190-
trx.sign(privateKey);
191-
return trx;
192-
}
193-
194-
public TransactionCapsule addSign(TransactionSign transactionSign)
195-
throws PermissionException, SignatureException, SignatureFormatException {
196-
byte[] privateKey = transactionSign.getPrivateKey().toByteArray();
197-
TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction());
198-
trx.addSign(privateKey, chainBaseManager.getAccountStore());
199-
return trx;
200-
}
201-
202186
public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
203187
TransactionSignWeight.Builder tswBuilder = TransactionSignWeight.newBuilder();
204188
TransactionExtention.Builder trxExBuilder = TransactionExtention.newBuilder();

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
}

actuator/src/main/java/org/tron/core/vm/nativecontract/DelegateResourceProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void validate(DelegateResourceParam param, Repository repo) throws Contra
9696
break;
9797
default:
9898
throw new ContractValidateException(
99-
"ResourceCode error, valid ResourceCode[BANDWIDTH、ENERGY]");
99+
"Unknown ResourceCode, valid ResourceCode[BANDWIDTH、ENERGY]");
100100
}
101101

102102
byte[] receiverAddress = param.getReceiverAddress();

actuator/src/main/java/org/tron/core/vm/nativecontract/FreezeBalanceProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void validate(FreezeBalanceParam param, Repository repo) throws ContractV
4848
break;
4949
default:
5050
throw new ContractValidateException(
51-
"ResourceCode error,valid ResourceCode[BANDWIDTH、ENERGY]");
51+
"Unknown ResourceCode, valid ResourceCode[BANDWIDTH、ENERGY]");
5252
}
5353

5454
// validate for delegating resource

actuator/src/main/java/org/tron/core/vm/nativecontract/FreezeBalanceV2Processor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.tron.core.vm.nativecontract;
22

3+
import static org.tron.core.actuator.ActuatorConstant.ACCOUNT_EXCEPTION_STR;
4+
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
5+
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
6+
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
7+
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;
8+
39
import lombok.extern.slf4j.Slf4j;
410
import org.tron.common.utils.DecodeUtil;
511
import org.tron.common.utils.StringUtil;
@@ -9,12 +15,6 @@
915
import org.tron.core.vm.nativecontract.param.FreezeBalanceV2Param;
1016
import org.tron.core.vm.repository.Repository;
1117

12-
import static org.tron.core.actuator.ActuatorConstant.ACCOUNT_EXCEPTION_STR;
13-
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
14-
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
15-
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
16-
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;
17-
1818
@Slf4j(topic = "VMProcessor")
1919
public class FreezeBalanceV2Processor {
2020

@@ -50,16 +50,16 @@ public void validate(FreezeBalanceV2Param param, Repository repo) throws Contrac
5050
case TRON_POWER:
5151
if (!repo.getDynamicPropertiesStore().supportAllowNewResourceModel()) {
5252
throw new ContractValidateException(
53-
"ResourceCode error, valid ResourceCode[BANDWIDTH、ENERGY]");
53+
"Unknown ResourceCode, valid ResourceCode[BANDWIDTH、ENERGY]");
5454
}
5555
break;
5656
default:
5757
if (repo.getDynamicPropertiesStore().supportAllowNewResourceModel()) {
5858
throw new ContractValidateException(
59-
"ResourceCode error, valid ResourceCode[BANDWIDTH、ENERGY、TRON_POWER]");
59+
"Unknown ResourceCode, valid ResourceCode[BANDWIDTH、ENERGY、TRON_POWER]");
6060
} else {
6161
throw new ContractValidateException(
62-
"ResourceCode error, valid ResourceCode[BANDWIDTH、ENERGY]");
62+
"Unknown ResourceCode, valid ResourceCode[BANDWIDTH、ENERGY]");
6363
}
6464
}
6565
}

0 commit comments

Comments
 (0)