Skip to content

Commit 3bf1186

Browse files
authored
Merge pull request #1393 from tronprotocol/set_out_of_time
Set out of time
2 parents a8b62a2 + 58eb7f9 commit 3bf1186

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

src/main/java/org/tron/core/capsule/TransactionCapsule.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
7777
import org.tron.protos.Protocol.Transaction.Result;
7878
import org.tron.protos.Protocol.Transaction.Result.contractResult;
79+
import org.tron.protos.Protocol.Transaction.raw;
7980

8081
@Slf4j
8182
public class TransactionCapsule implements ProtoCapsule<Transaction> {
@@ -159,6 +160,11 @@ public TransactionCapsule(ParticipateAssetIssueContract participateAssetIssueCon
159160
createTransaction(participateAssetIssueContract, ContractType.ParticipateAssetIssueContract);
160161
}
161162

163+
public TransactionCapsule(raw rawData, List<ByteString> signatureList) {
164+
this.transaction = Transaction.newBuilder().setRawData(rawData).addAllSignature(signatureList)
165+
.build();
166+
}
167+
162168
public void resetResult() {
163169
if (this.getInstance().getRetCount() > 0) {
164170
this.transaction = this.getInstance().toBuilder().clearRet().build();
@@ -601,10 +607,9 @@ private void setResultCode(contractResult code) {
601607
}
602608

603609
public contractResult getContractRet() {
604-
Result ret = this.transaction.getRet(0);
605-
if (Objects.isNull(ret)) {
610+
if (this.transaction.getRetCount() <= 0) {
606611
return null;
607612
}
608-
return ret.getContractRet();
613+
return this.transaction.getRet(0).getContractRet();
609614
}
610615
}

src/main/java/org/tron/core/capsule/TransactionResultCapsule.java

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

3-
import com.google.protobuf.ByteString;
43
import com.google.protobuf.InvalidProtocolBufferException;
54
import lombok.extern.slf4j.Slf4j;
65
import org.tron.core.exception.BadItemException;
76
import org.tron.protos.Protocol.Transaction;
87
import org.tron.protos.Protocol.Transaction.Result;
8+
import org.tron.protos.Protocol.Transaction.Result.contractResult;
99

1010
@Slf4j
1111
public class TransactionResultCapsule implements ProtoCapsule<Transaction.Result> {
@@ -31,6 +31,10 @@ public TransactionResultCapsule() {
3131
this.transactionResult = Transaction.Result.newBuilder().build();
3232
}
3333

34+
public TransactionResultCapsule(contractResult code) {
35+
this.transactionResult = Transaction.Result.newBuilder().setContractRet(code).build();
36+
}
37+
3438
public TransactionResultCapsule(Transaction.Result.code code, long fee) {
3539
this.transactionResult = Transaction.Result.newBuilder().setRet(code).setFee(fee).build();
3640
}

src/main/java/org/tron/core/db/BandwidthProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public void consume(TransactionCapsule trx, TransactionResultCapsule ret,
5353
throws ContractValidateException, AccountResourceInsufficientException {
5454
List<Contract> contracts =
5555
trx.getInstance().getRawData().getContractList();
56-
56+
TransactionCapsule transactionCapsule = new TransactionCapsule(trx.getInstance().getRawData(),
57+
trx.getInstance().getSignatureList());
5758
for (Contract contract : contracts) {
58-
long bytes = trx.getSerializedSize();
59+
long bytes = transactionCapsule.getSerializedSize();
5960
logger.debug("trxId {},bandwidth cost :{}", trx.getTransactionId(), bytes);
6061
trace.setNetBill(bytes, 0);
6162
byte[] address = TransactionCapsule.getOwner(contract);

src/main/java/org/tron/core/db/Manager.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.stereotype.Component;
4040
import org.tron.common.overlay.discover.node.Node;
4141
import org.tron.common.runtime.Runtime;
42+
import org.tron.common.runtime.config.SystemProperties;
4243
import org.tron.common.runtime.vm.program.invoke.ProgramInvokeFactoryImpl;
4344
import org.tron.common.storage.DepositImpl;
4445
import org.tron.common.utils.ByteArray;
@@ -1039,6 +1040,12 @@ public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule
10391040
// Fixme Wrong exception
10401041
throw new UnsupportVMException("cannot call constant method ");
10411042
}
1043+
// if (SystemProperties.getInstance().vmOn()) {
1044+
// if(trxCap.getInstance().getRetCount()<=0){
1045+
// trxCap.setResult(new TransactionResultCapsule(contractResult.UNKNOWN));
1046+
// }
1047+
// }
1048+
10421049
consumeBandwidth(trxCap, runtime.getResult().getRet(), trace);
10431050

10441051
trace.init();
@@ -1053,15 +1060,18 @@ public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule
10531060
trace.exec(runtime);
10541061

10551062
if (Objects.nonNull(blockCap)) {
1056-
trace.setResult(runtime);
1063+
trace.setResult(runtime);
10571064
if (!blockCap.generatedByMyself) {
10581065
trace.check();
10591066
}
10601067
}
10611068

10621069
trace.finalization(runtime);
1063-
1064-
trxCap.setResult(runtime);
1070+
if (Objects.nonNull(blockCap)) {
1071+
if (SystemProperties.getInstance().vmOn()) {
1072+
trxCap.setResult(runtime);
1073+
}
1074+
}
10651075
transactionStore.put(trxCap.getTransactionId().getBytes(), trxCap);
10661076

10671077
ReceiptCapsule traceReceipt = trace.getReceipt();

src/main/java/org/tron/core/db/TransactionTrace.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public void init() throws TransactionTraceException {
8989
}
9090

9191
//set bill
92-
public void setBill(long energyUseage) {
93-
receipt.setEnergyUsageTotal(energyUseage);
92+
public void setBill(long energyUsage) {
93+
receipt.setEnergyUsageTotal(energyUsage);
9494
}
9595

9696
//set net bill
@@ -100,7 +100,7 @@ public void setNetBill(long netUsage, long netFee) {
100100
}
101101

102102
public void exec(Runtime runtime)
103-
throws ContractExeException, ContractValidateException, ReceiptCheckErrException {
103+
throws ContractExeException, ContractValidateException {
104104
/** VM execute **/
105105
runtime.execute();
106106
runtime.go();
@@ -167,6 +167,9 @@ public ReceiptCapsule getReceipt() {
167167
}
168168

169169
public void setResult(Runtime runtime) {
170+
if (!needVM()) {
171+
return;
172+
}
170173
RuntimeException exception = runtime.getResult().getException();
171174
if (Objects.isNull(exception) && StringUtils
172175
.isEmpty(runtime.getRuntimeError()) && !runtime.getResult().isRevert()) {

src/test/java/org/tron/core/db/TransactionTraceTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.tron.core.config.args.Args;
4343
import org.tron.core.exception.ContractExeException;
4444
import org.tron.core.exception.ContractValidateException;
45-
import org.tron.core.exception.ReceiptCheckErrException;
4645
import org.tron.protos.Contract.CreateSmartContract;
4746
import org.tron.protos.Contract.TriggerSmartContract;
4847
import org.tron.protos.Protocol.Account;
@@ -162,8 +161,6 @@ public void testUseFee() throws InvalidProtocolBufferException {
162161
e.printStackTrace();
163162
} catch (ContractValidateException e) {
164163
e.printStackTrace();
165-
} catch (ReceiptCheckErrException e) {
166-
e.printStackTrace();
167164
}
168165
}
169166

@@ -197,8 +194,6 @@ public void testUseUsage() throws InvalidProtocolBufferException {
197194
e.printStackTrace();
198195
} catch (ContractValidateException e) {
199196
e.printStackTrace();
200-
} catch (ReceiptCheckErrException e) {
201-
e.printStackTrace();
202197
}
203198
}
204199

0 commit comments

Comments
 (0)