Skip to content
Open
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
13 changes: 10 additions & 3 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2268,10 +2268,17 @@ private void postBlockFilter(final BlockCapsule blockCapsule, boolean solidified

private void postLogsFilter(final BlockCapsule blockCapsule, boolean solidified,
boolean removed) {
long blockNumber = blockCapsule.getNum();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 For better scoping, consider moving the declaration of blockNumber inside the following if block, as it is only used there.

if (!blockCapsule.getTransactions().isEmpty()) {
long blockNumber = blockCapsule.getNum();
List<TransactionInfo> transactionInfoList
= getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
List<TransactionInfo> transactionInfoList;
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 There's a typo in the method name getTransactioninfoList. Based on Java conventions and likely protobuf generated code, it should be getTransactionInfoList with a capital 'I'. This will cause a compilation error.

Suggested change
// Avoids re-querying the database for data just written.
transactionInfoList = blockCapsule.getResult().getInstance().getTransactionInfoList();

if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
Comment on lines +2274 to +2279

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 For better readability and to avoid multiple calls to getResult(), you can store the result of blockCapsule.getResult() in a local variable.

Suggested change
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
List<TransactionInfo> transactionInfoList;
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.
var blockResult = blockCapsule.getResult();
if (blockResult != null) {
transactionInfoList = blockResult.getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}

transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}
Comment on lines +2275 to +2281

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The comment in the `else` block is redundant because the code is self-explanatory. Consider removing it to make the code cleaner.
Suggested change
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
// Fallback to querying from DB if not available in memory.
transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}
List<TransactionInfo> transactionInfoList;
// Optimization: If the block result is already in memory, use it directly.
// Avoids re-querying the database for data just written.
if (blockCapsule.getResult() != null) {
transactionInfoList = blockCapsule.getResult().getInstance().getTransactioninfoList();
} else {
transactionInfoList = getTransactionInfoByBlockNum(blockNumber).getTransactionInfoList();
}

LogsFilterCapsule logsFilterCapsule = new LogsFilterCapsule(blockNumber,
blockCapsule.getBlockId().toString(), blockCapsule.getBloom(), transactionInfoList,
solidified, removed);
Expand Down
Loading