diff --git a/src/main/java/org/tron/core/actuator/UnfreezeBalanceActuator.java b/src/main/java/org/tron/core/actuator/UnfreezeBalanceActuator.java index e24f09d825a..1be62db319d 100755 --- a/src/main/java/org/tron/core/actuator/UnfreezeBalanceActuator.java +++ b/src/main/java/org/tron/core/actuator/UnfreezeBalanceActuator.java @@ -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); @@ -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) { @@ -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 @@ -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) { @@ -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) { diff --git a/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java b/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java index f0a9e686a00..1a4f1d291db 100644 --- a/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java +++ b/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java @@ -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); } @@ -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); }