Skip to content

Commit

Permalink
Merge pull request #5120 from yanghang8612/fix/dirty_receipt_origin_u…
Browse files Browse the repository at this point in the history
…sage

opt(receipt): drop the dirty field for tx receipt
  • Loading branch information
yanghang8612 authored Apr 11, 2023
2 parents 3cc5a59 + 043fdbf commit a4f1e05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public void payEnergyBill(DynamicPropertiesStore dynamicPropertiesStore,
AccountCapsule caller,
long percent, long originEnergyLimit, EnergyProcessor energyProcessor, long now)
throws BalanceInsufficientException {

// Reset origin energy usage here! Because after stake 2.0, this field are reused for
// recording pre-merge frozen energy for origin account. If total energy usage is zero, this
// field will be a dirty record.
this.setOriginEnergyUsage(0);

if (receipt.getEnergyUsageTotal() <= 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void pay() throws BalanceInsufficientException {
AccountCapsule origin = accountStore.get(originAccount);
AccountCapsule caller = accountStore.get(callerAccount);
if (dynamicPropertiesStore.supportUnfreezeDelay()
&& receipt.getReceipt().getResult().equals(contractResult.SUCCESS)) {
&& getRuntimeResult().getException() == null && !getRuntimeResult().isRevert()) {

// just fo caller is not origin, we set the related field for origin account
if (origin != null && !caller.getAddress().equals(origin.getAddress())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.tron.core.db.TransactionStore;
import org.tron.core.db.TronStoreWithRevoking;
import org.tron.core.exception.BadItemException;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.TransactionInfo;

@Slf4j(topic = "DB")
Expand Down Expand Up @@ -54,6 +55,17 @@ public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemExcep
ByteString id = ByteString.copyFrom(key);
for (TransactionInfo transactionResultInfo : result.getInstance().getTransactioninfoList()) {
if (transactionResultInfo.getId().equals(id)) {
Protocol.ResourceReceipt receipt = transactionResultInfo.getReceipt();
// If query a result with dirty origin usage in receipt, we just reset it.
if (receipt.getEnergyUsageTotal() == 0 && receipt.getOriginEnergyUsage() > 0) {
transactionResultInfo =
transactionResultInfo.toBuilder()
.setReceipt(
receipt.toBuilder()
.clearOriginEnergyUsage()
.build())
.build();
}
return new TransactionInfoCapsule(transactionResultInfo);
}
}
Expand Down

0 comments on commit a4f1e05

Please sign in to comment.