From cb1837267d449abdc7ff009a30450816cf60e04c Mon Sep 17 00:00:00 2001 From: Asuka Date: Wed, 2 Apr 2025 17:54:20 +0800 Subject: [PATCH 1/2] func(event): optimize energy price querying method --- .../tron/core/services/event/BlockEventGet.java | 15 ++------------- .../org/tron/core/event/BlockEventGetTest.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) 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 be15a499d3..bf668a3e0b 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/test/java/org/tron/core/event/BlockEventGetTest.java b/framework/src/test/java/org/tron/core/event/BlockEventGetTest.java index 704dc9ddc4..b6835cfcf8 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(); } From 37800882a86597096946d8bf34eece2a4c2af01e Mon Sep 17 00:00:00 2001 From: Asuka Date: Wed, 2 Apr 2025 19:31:25 +0800 Subject: [PATCH 2/2] func(cfg): add saveCancelAllUnfreezeV2Details switch description to the configuration file --- framework/src/main/resources/config.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/framework/src/main/resources/config.conf b/framework/src/main/resources/config.conf index 3236573a88..d434d9c720 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