diff --git a/framework/src/main/java/org/tron/core/services/event/BlockEventGet.java b/framework/src/main/java/org/tron/core/services/event/BlockEventGet.java index be15a499d3f..bf668a3e0b6 100644 --- a/framework/src/main/java/org/tron/core/services/event/BlockEventGet.java +++ b/framework/src/main/java/org/tron/core/services/event/BlockEventGet.java @@ -39,6 +39,7 @@ import org.tron.core.exception.BadItemException; import org.tron.core.services.event.bo.BlockEvent; import org.tron.core.services.event.bo.SmartContractTrigger; +import org.tron.core.services.jsonrpc.JsonRpcApiUtil; import org.tron.core.store.StoreFactory; import org.tron.protos.Protocol; import org.tron.protos.contract.SmartContractOuterClass; @@ -373,19 +374,7 @@ public List getTransactionLogTrigger(BlockCapsule public long getEnergyPrice(long blockTime) { String energyPriceHistory = manager.getDynamicPropertiesStore().getEnergyPriceHistory(); - - String[] energyPrices = energyPriceHistory.split(","); - String[] lastPrice = energyPrices[energyPrices.length - 1].split(":"); - long energyPrice = Long.parseLong(lastPrice[1]); - - for (int i = 1; i < energyPrices.length; i++) { - long effectiveTime = Long.parseLong(energyPrices[i].split(":")[0]); - if (blockTime < effectiveTime) { - energyPrice = Long.parseLong(energyPrices[i - 1].split(":")[1]); - break; - } - } - return energyPrice; + return JsonRpcApiUtil.parseEnergyFee(blockTime, energyPriceHistory); } public List getTransactionTriggers(BlockCapsule block, diff --git a/framework/src/main/resources/config.conf b/framework/src/main/resources/config.conf index 3236573a889..d434d9c7203 100644 --- a/framework/src/main/resources/config.conf +++ b/framework/src/main/resources/config.conf @@ -611,6 +611,9 @@ vm = { # Indicates whether the node stores featured internal transactions, such as freeze, vote and so on # saveFeaturedInternalTx = false + # Indicates whether the node stores the details of the internal transactions generated by the CANCELALLUNFREEZEV2 opcode, such as bandwidth/energy/tronpower cancel amount. + # saveCancelAllUnfreezeV2Details = false + # In rare cases, transactions that will be within the specified maximum execution time (default 10(ms)) are re-executed and packaged # longRunningTime = 10 diff --git a/framework/src/test/java/org/tron/core/event/BlockEventGetTest.java b/framework/src/test/java/org/tron/core/event/BlockEventGetTest.java index 704dc9ddc49..b6835cfcf82 100644 --- a/framework/src/test/java/org/tron/core/event/BlockEventGetTest.java +++ b/framework/src/test/java/org/tron/core/event/BlockEventGetTest.java @@ -150,6 +150,11 @@ public void test() throws Exception { }); manager.pushBlock(blockCapsule); + // Set energy price history to test boundary cases + manager.getDynamicPropertiesStore().saveEnergyPriceHistory( + manager.getDynamicPropertiesStore().getEnergyPriceHistory() + + "," + time + ":210"); + EventPluginConfig config = new EventPluginConfig(); config.setSendQueueLength(1000); config.setBindPort(5555); @@ -187,6 +192,12 @@ public void test() throws Exception { try { BlockEvent blockEvent = blockEventGet.getBlockEvent(1); Assert.assertNotNull(blockEvent); + Assert.assertEquals(1, blockEvent.getTransactionLogTriggerCapsules().size()); + + // Here energy unit price should be 100 not 210, + // cause block time is equal to 210`s effective time + Assert.assertEquals(100, blockEvent.getTransactionLogTriggerCapsules() + .get(0).getTransactionLogTrigger().getEnergyUnitPrice()); } catch (Exception e) { Assert.fail(); }