-
Notifications
You must be signed in to change notification settings - Fork 876
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
Conversation
|
final Transaction transaction = | ||
block.getBody().getTransactions().get(location.getTransactionIndex()); | ||
final List<Transaction> transactions = block.getBody().getTransactions(); | ||
final Transaction transaction = transactions.get(location.getTransactionIndex()); |
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.
As a "fix it now" patch this seems like a reasonable solution. However there will be performance implications with large blocks. I think a longer term solution would be to add the log index into the TransactionLocation
and save that when calculating the location. The data can be written so the value may be missing, and when it is we use this logic. Creating a seamless transition. We also could add a DB migration to re-build the transaction locations in the background.
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.
How to initiate re-building transaction locations?
Do I just add a similar section to migrateVariables
?
Lines 152 to 167 in be5cc68
get(VARIABLES_PREFIX, CHAIN_HEAD_HASH.getBytes()) | |
.map(this::bytesToHash) | |
.ifPresent( | |
bch -> | |
variablesStorage | |
.getChainHead() | |
.ifPresentOrElse( | |
vch -> { | |
if (!vch.equals(bch)) { | |
logInconsistencyAndFail(CHAIN_HEAD_HASH, bch, vch); | |
} | |
}, | |
() -> { | |
variablesUpdater.setChainHead(bch); | |
LOG.info("Migrated key {} to variables storage", CHAIN_HEAD_HASH); | |
})); |
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.
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.
@Wetitpig migrateVariables
was much easier to implement, since it only had to move few keys around, and did it synchronously, while for this re-build an asynchronous tasks is needed, with all the consequences of making it not hurting the overall Besu performance.
My proposal for this is to:
- first support saving the location for newly imported blocks
- then for already imported blocks, that miss this data, calculate it and save on demand
Have not yet looking into the code, to understand how much it, but would like to hear what you think.
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.
Given that most transaction receipts may not be queried for multiple times I am not sure if it is worth to save the logIndexOffset
for each transaction.
Probably I am going to try removing parallel()
and see how much the performance impact really is.
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.
if calculating that data at runtime is good enough for the moment, we can postpone the work to persist that data until more performance is needed.
76779eb
to
845f134
Compare
Signed-off-by: Wetitpig <[email protected]>
Add to bug fixes. Signed-off-by: Wetitpig <[email protected]>
Signed-off-by: Wetitpig <[email protected]>
Signed-off-by: Wetitpig <[email protected]>
Signed-off-by: Wetitpig <[email protected]>
Signed-off-by: Wetitpig <[email protected]>
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.
LGTM, just a check on the use of parallel stream or not for the sum
IntStream.range(0, transactionIndex) | ||
.parallel() | ||
.map(i -> transactionReceipts.get(i).getLogs().size()) | ||
.sum(); |
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.
since usually we only have few hundreds txs in a block, have you any number to confirm that doing the sum in parallel is faster than doing it serially?
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.
Not really any numbers there. I am just thinking that it does not hurt to map and sum the numbers in parallel.
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.
just thinking that a quick JMH test could be enough to spot the difference in performance, between serial/parallel
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.
I have no idea how to do a JMH benchmark, but I tried the query with time curl
and deducting the user
and sys
time
query {
blocks (from: 18676591 to: 18676640) {
transactions { gasUsed }
}
}
Every time GraphQL transverses into a transaction it would first obtain the receipt for the amount of gas used, thus running the code for obtaining log indices in the receipt.
So with 8235 transactions in these 50 blocks the results are as follows:
.parallel() |
Time averaged over 10 queries |
---|---|
with | 8.5605 s |
without | 8.6308 s |
So it may not be worth the hassle to parallelise
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.
Ok, indeed for small lists there should not be a big difference.
Just for reference, an example of a JMH test in Besu is RLPBench
Signed-off-by: Wetitpig <[email protected]>
Signed-off-by: Wetitpig <[email protected]>
.map(BlockWithMetadata::getTransactions) | ||
.map(List::size) | ||
.orElse(-1)); | ||
return blockchain.getBlockHashByNumber(blockNumber).map(this::getTransactionCount); |
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!
@@ -1079,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 comment
The reason will be displayed to describe this comment to others. Learn more.
nice opt
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
* [hyperledger#6204] Fix log index in transaction receipt Signed-off-by: Wetitpig <[email protected]> * Update CHANGELOG.md Add to bug fixes. Signed-off-by: Wetitpig <[email protected]> * Update tests Signed-off-by: Wetitpig <[email protected]> * Directly sum log size with known index Signed-off-by: Wetitpig <[email protected]> * Minor change to gasUsed Signed-off-by: Wetitpig <[email protected]> * Place hash and index first Signed-off-by: Wetitpig <[email protected]> * Test without parallel() Signed-off-by: Wetitpig <[email protected]> * Rewrite header hash as map chain Signed-off-by: Wetitpig <[email protected]> --------- Signed-off-by: Wetitpig <[email protected]> Signed-off-by: Justin Florentine <[email protected]>
* [hyperledger#6204] Fix log index in transaction receipt Signed-off-by: Wetitpig <[email protected]> * Update CHANGELOG.md Add to bug fixes. Signed-off-by: Wetitpig <[email protected]> * Update tests Signed-off-by: Wetitpig <[email protected]> * Directly sum log size with known index Signed-off-by: Wetitpig <[email protected]> * Minor change to gasUsed Signed-off-by: Wetitpig <[email protected]> * Place hash and index first Signed-off-by: Wetitpig <[email protected]> * Test without parallel() Signed-off-by: Wetitpig <[email protected]> * Rewrite header hash as map chain Signed-off-by: Wetitpig <[email protected]> --------- Signed-off-by: Wetitpig <[email protected]>
* [hyperledger#6204] Fix log index in transaction receipt Signed-off-by: Wetitpig <[email protected]> * Update CHANGELOG.md Add to bug fixes. Signed-off-by: Wetitpig <[email protected]> * Update tests Signed-off-by: Wetitpig <[email protected]> * Directly sum log size with known index Signed-off-by: Wetitpig <[email protected]> * Minor change to gasUsed Signed-off-by: Wetitpig <[email protected]> * Place hash and index first Signed-off-by: Wetitpig <[email protected]> * Test without parallel() Signed-off-by: Wetitpig <[email protected]> * Rewrite header hash as map chain Signed-off-by: Wetitpig <[email protected]> --------- Signed-off-by: Wetitpig <[email protected]> Signed-off-by: Justin Florentine <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
* [hyperledger#6204] Fix log index in transaction receipt Signed-off-by: Wetitpig <[email protected]> * Update CHANGELOG.md Add to bug fixes. Signed-off-by: Wetitpig <[email protected]> * Update tests Signed-off-by: Wetitpig <[email protected]> * Directly sum log size with known index Signed-off-by: Wetitpig <[email protected]> * Minor change to gasUsed Signed-off-by: Wetitpig <[email protected]> * Place hash and index first Signed-off-by: Wetitpig <[email protected]> * Test without parallel() Signed-off-by: Wetitpig <[email protected]> * Rewrite header hash as map chain Signed-off-by: Wetitpig <[email protected]> --------- Signed-off-by: Wetitpig <[email protected]> Signed-off-by: Gabriel Fukushima <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
Forgot to replace in [hyperledger#6206] Signed-off-by: Wetitpig <[email protected]>
PR description
Assign log index to transaction receipt according to position in block instead of in transaction.
Fixed Issue(s)
fixes #6204