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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -373,19 +374,7 @@ public List<TransactionLogTriggerCapsule> 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<TransactionLogTriggerCapsule> getTransactionTriggers(BlockCapsule block,
Expand Down
3 changes: 3 additions & 0 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions framework/src/test/java/org/tron/core/event/BlockEventGetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down