Skip to content
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
76 changes: 44 additions & 32 deletions src/main/java/org/tron/core/actuator/UnfreezeBalanceActuator.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
}

AccountCapsule receiverCapsule = dbManager.getAccountStore().get(receiverAddress);
if (receiverAddressIsValid(receiverCapsule)) {
if (dbManager.getDynamicPropertiesStore().getAllowTvmConstantinople() == 0 ||
(receiverCapsule != null && receiverCapsule.getType() != AccountType.Contract)) {
switch (unfreezeBalanceContract.getResource()) {
case BANDWIDTH:
receiverCapsule.addAcquiredDelegatedFrozenBalanceForBandwidth(-unfreezeBalance);
Expand Down Expand Up @@ -205,10 +206,6 @@ public boolean execute(TransactionResultCapsule ret) throws ContractExeException
return true;
}

private boolean receiverAddressIsValid(AccountCapsule receiverCapsule) {
return receiverCapsule != null && receiverCapsule.getType() != AccountType.Contract;
}

@Override
public boolean validate() throws ContractValidateException {
if (this.contract == null) {
Expand Down Expand Up @@ -255,16 +252,11 @@ public boolean validate() throws ContractValidateException {
}

AccountCapsule receiverCapsule = dbManager.getAccountStore().get(receiverAddress);
if (receiverCapsule == null) {
if (dbManager.getDynamicPropertiesStore().getAllowTvmConstantinople() == 0
&& receiverCapsule == null) {
String readableReceiverAddress = StringUtil.createReadableString(receiverAddress);
if (dbManager.getDynamicPropertiesStore().getAllowTvmConstantinople() != 1) {
throw new ContractValidateException(
"Account[" + readableReceiverAddress + "] not exists");
} else {
logger.warn(
"Account[" + readableReceiverAddress + "] not exists,may be deleted");
}

throw new ContractValidateException(
"Receiver Account[" + readableReceiverAddress + "] not exists");
}

byte[] key = DelegatedResourceCapsule
Expand All @@ -282,16 +274,26 @@ public boolean validate() throws ContractValidateException {
if (delegatedResourceCapsule.getFrozenBalanceForBandwidth() <= 0) {
throw new ContractValidateException("no delegatedFrozenBalance(BANDWIDTH)");
}
if (receiverAddressIsValid(receiverCapsule)
&& receiverCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth()
< delegatedResourceCapsule.getFrozenBalanceForBandwidth()) {

throw new ContractValidateException(
"AcquiredDelegatedFrozenBalanceForBandwidth[" + receiverCapsule
.getAcquiredDelegatedFrozenBalanceForBandwidth() + "] < delegatedBandwidth["
+ delegatedResourceCapsule.getFrozenBalanceForBandwidth()
+ "],this should never happen");

if (dbManager.getDynamicPropertiesStore().getAllowTvmConstantinople() == 0) {
if (receiverCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth()
< delegatedResourceCapsule.getFrozenBalanceForBandwidth()) {
throw new ContractValidateException(
"AcquiredDelegatedFrozenBalanceForBandwidth[" + receiverCapsule
.getAcquiredDelegatedFrozenBalanceForBandwidth() + "] < delegatedBandwidth["
+ delegatedResourceCapsule.getFrozenBalanceForBandwidth()
+ "],this should never happen");
}
} else {
if (receiverCapsule != null && receiverCapsule.getType() != AccountType.Contract
&& receiverCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth()
< delegatedResourceCapsule.getFrozenBalanceForBandwidth()) {
throw new ContractValidateException(
"AcquiredDelegatedFrozenBalanceForBandwidth[" + receiverCapsule
.getAcquiredDelegatedFrozenBalanceForBandwidth() + "] < delegatedBandwidth["
+ delegatedResourceCapsule.getFrozenBalanceForBandwidth()
+ "],this should never happen");
}
}

if (delegatedResourceCapsule.getExpireTimeForBandwidth() > now) {
Expand All @@ -302,15 +304,25 @@ public boolean validate() throws ContractValidateException {
if (delegatedResourceCapsule.getFrozenBalanceForEnergy() <= 0) {
throw new ContractValidateException("no delegateFrozenBalance(Energy)");
}
if (receiverAddressIsValid(receiverCapsule)
&& receiverCapsule.getAcquiredDelegatedFrozenBalanceForEnergy()
< delegatedResourceCapsule.getFrozenBalanceForEnergy()) {
throw new ContractValidateException(
"AcquiredDelegatedFrozenBalanceForEnergy[" + receiverCapsule
.getAcquiredDelegatedFrozenBalanceForEnergy() + "] < delegatedEnergy["
+ delegatedResourceCapsule.getFrozenBalanceForEnergy() +
"],this should never happen");

if (dbManager.getDynamicPropertiesStore().getAllowTvmConstantinople() == 0) {
if (receiverCapsule.getAcquiredDelegatedFrozenBalanceForEnergy()
< delegatedResourceCapsule.getFrozenBalanceForEnergy()) {
throw new ContractValidateException(
"AcquiredDelegatedFrozenBalanceForEnergy[" + receiverCapsule
.getAcquiredDelegatedFrozenBalanceForEnergy() + "] < delegatedEnergy["
+ delegatedResourceCapsule.getFrozenBalanceForEnergy() +
"],this should never happen");
}
} else {
if (receiverCapsule != null && receiverCapsule.getType() != AccountType.Contract
&& receiverCapsule.getAcquiredDelegatedFrozenBalanceForEnergy()
< delegatedResourceCapsule.getFrozenBalanceForEnergy()) {
throw new ContractValidateException(
"AcquiredDelegatedFrozenBalanceForEnergy[" + receiverCapsule
.getAcquiredDelegatedFrozenBalanceForEnergy() + "] < delegatedEnergy["
+ delegatedResourceCapsule.getFrozenBalanceForEnergy() +
"],this should never happen");
}
}

if (delegatedResourceCapsule.getExpireTimeForEnergy(dbManager) > now) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public void testUnfreezeDelegatedBalanceForBandwidthWithDeletedReceiver() {
actuator.validate();
actuator.execute(ret);
} catch (ContractValidateException e) {
Assert.assertEquals(e.getMessage(),"Account[a0abd4b9367799eaa3197fecb144eb71de1e049150] not exists");
Assert.assertEquals(e.getMessage(),"Receiver Account[a0abd4b9367799eaa3197fecb144eb71de1e049150] not exists");
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
Expand Down Expand Up @@ -583,7 +583,7 @@ public void testUnfreezeDelegatedBalanceForCpuWithDeletedReceiver() {
actuator.validate();
actuator.execute(ret);
} catch (ContractValidateException e) {
Assert.assertEquals(e.getMessage(),"Account[a0abd4b9367799eaa3197fecb144eb71de1e049150] not exists");
Assert.assertEquals(e.getMessage(),"Receiver Account[a0abd4b9367799eaa3197fecb144eb71de1e049150] not exists");
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
Expand Down