-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix log index in transaction receipt #6206
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8dd1b65
[#6204] Fix log index in transaction receipt
Wetitpig 0adf18c
Update CHANGELOG.md
Wetitpig 74c5494
Update tests
Wetitpig 9cbd5bd
Directly sum log size with known index
Wetitpig c11be71
Minor change to gasUsed
Wetitpig 8055b47
Place hash and index first
Wetitpig f1c4448
Test without parallel()
Wetitpig b8f4ed7
Rewrite header hash as map chain
Wetitpig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,8 +183,7 @@ public Optional<BlockHeader> safeBlockHeader() { | |
*/ | ||
public Optional<UInt256> storageAt( | ||
final Address address, final UInt256 storageIndex, final long blockNumber) { | ||
final Hash blockHash = | ||
getBlockHeaderByNumber(blockNumber).map(BlockHeader::getHash).orElse(Hash.EMPTY); | ||
final Hash blockHash = getBlockHashByNumber(blockNumber).orElse(Hash.EMPTY); | ||
|
||
return storageAt(address, storageIndex, blockHash); | ||
} | ||
|
@@ -211,8 +210,7 @@ public Optional<UInt256> storageAt( | |
* @return The balance of the account in Wei. | ||
*/ | ||
public Optional<Wei> accountBalance(final Address address, final long blockNumber) { | ||
final Hash blockHash = | ||
getBlockHeaderByNumber(blockNumber).map(BlockHeader::getHash).orElse(Hash.EMPTY); | ||
final Hash blockHash = getBlockHashByNumber(blockNumber).orElse(Hash.EMPTY); | ||
|
||
return accountBalance(address, blockHash); | ||
} | ||
|
@@ -236,8 +234,7 @@ public Optional<Wei> accountBalance(final Address address, final Hash blockHash) | |
* @return The code associated with this address. | ||
*/ | ||
public Optional<Bytes> getCode(final Address address, final long blockNumber) { | ||
final Hash blockHash = | ||
getBlockHeaderByNumber(blockNumber).map(BlockHeader::getHash).orElse(Hash.EMPTY); | ||
final Hash blockHash = getBlockHashByNumber(blockNumber).orElse(Hash.EMPTY); | ||
|
||
return getCode(address, blockHash); | ||
} | ||
|
@@ -263,13 +260,7 @@ public Optional<Integer> getTransactionCount(final long blockNumber) { | |
if (outsideBlockchainRange(blockNumber)) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of( | ||
blockchain | ||
.getBlockHashByNumber(blockNumber) | ||
.flatMap(this::blockByHashWithTxHashes) | ||
.map(BlockWithMetadata::getTransactions) | ||
.map(List::size) | ||
.orElse(-1)); | ||
return blockchain.getBlockHashByNumber(blockNumber).map(this::getTransactionCount); | ||
} | ||
|
||
/** | ||
|
@@ -624,22 +615,25 @@ public Optional<TransactionReceiptWithMetadata> transactionReceiptByTransactionH | |
// getTransactionLocation should not return if the TX or block doesn't exist, so throwing | ||
// on a missing optional is appropriate. | ||
final TransactionLocation location = maybeLocation.get(); | ||
final Block block = blockchain.getBlockByHash(location.getBlockHash()).orElseThrow(); | ||
final Transaction transaction = | ||
block.getBody().getTransactions().get(location.getTransactionIndex()); | ||
|
||
final Hash blockhash = location.getBlockHash(); | ||
final int transactionIndex = location.getTransactionIndex(); | ||
|
||
final Block block = blockchain.getBlockByHash(blockhash).orElseThrow(); | ||
final Transaction transaction = block.getBody().getTransactions().get(transactionIndex); | ||
|
||
final BlockHeader header = block.getHeader(); | ||
final List<TransactionReceipt> transactionReceipts = | ||
blockchain.getTxReceipts(blockhash).orElseThrow(); | ||
final TransactionReceipt transactionReceipt = | ||
transactionReceipts.get(location.getTransactionIndex()); | ||
final TransactionReceipt transactionReceipt = transactionReceipts.get(transactionIndex); | ||
|
||
long gasUsed = transactionReceipt.getCumulativeGasUsed(); | ||
if (location.getTransactionIndex() > 0) { | ||
gasUsed = | ||
gasUsed | ||
- transactionReceipts.get(location.getTransactionIndex() - 1).getCumulativeGasUsed(); | ||
int logIndexOffset = 0; | ||
if (transactionIndex > 0) { | ||
gasUsed -= transactionReceipts.get(transactionIndex - 1).getCumulativeGasUsed(); | ||
logIndexOffset = | ||
IntStream.range(0, transactionIndex) | ||
.map(i -> transactionReceipts.get(i).getLogsList().size()) | ||
.sum(); | ||
} | ||
|
||
Optional<Long> maybeBlobGasUsed = | ||
|
@@ -653,13 +647,14 @@ public Optional<TransactionReceiptWithMetadata> transactionReceiptByTransactionH | |
transactionReceipt, | ||
transaction, | ||
transactionHash, | ||
location.getTransactionIndex(), | ||
transactionIndex, | ||
gasUsed, | ||
header.getBaseFee(), | ||
blockhash, | ||
header.getNumber(), | ||
maybeBlobGasUsed, | ||
maybeBlobGasPrice)); | ||
maybeBlobGasPrice, | ||
logIndexOffset)); | ||
} | ||
|
||
/** | ||
|
@@ -1075,7 +1070,7 @@ private int logIndexOffset( | |
break; | ||
} | ||
|
||
logIndexOffset += receipts.get(i).getLogs().size(); | ||
logIndexOffset += receipts.get(i).getLogsList().size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice opt |
||
} | ||
|
||
return logIndexOffset; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks better now!