Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt(receipt): drop the dirty field for tx receipt #5120

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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