Skip to content

Commit a4f1e05

Browse files
authored
Merge pull request #5120 from yanghang8612/fix/dirty_receipt_origin_usage
opt(receipt): drop the dirty field for tx receipt
2 parents 3cc5a59 + 043fdbf commit a4f1e05

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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/db/TransactionTrace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public void pay() throws BalanceInsufficientException {
255255
AccountCapsule origin = accountStore.get(originAccount);
256256
AccountCapsule caller = accountStore.get(callerAccount);
257257
if (dynamicPropertiesStore.supportUnfreezeDelay()
258-
&& receipt.getReceipt().getResult().equals(contractResult.SUCCESS)) {
258+
&& getRuntimeResult().getException() == null && !getRuntimeResult().isRevert()) {
259259

260260
// just fo caller is not origin, we set the related field for origin account
261261
if (origin != null && !caller.getAddress().equals(origin.getAddress())) {

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)