Optimistic parallelization of transactions to improve performance#7296
Optimistic parallelization of transactions to improve performance#7296ahamlat merged 49 commits intobesu-eth:mainfrom
Conversation
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Initialize ConcurrentHashMap used in the accumulator to avoid collisions Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
…pacity Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
46c7e3a to
69f36b6
Compare
64ed174 to
6baafdc
Compare
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
…ns and the number of conflicting transactions Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: ahamlat <ameziane.hamlat@consensys.net>
| final Wei coinbaseWeiDelta = | ||
| coinbaseCalculator.price(usedGas, transactionGasPrice, blockHeader.getBaseFee()); | ||
|
|
||
| operationTracer.traceBeforeRewardTransaction(worldUpdater, transaction, coinbaseWeiDelta); |
There was a problem hiding this comment.
This was a hint used by Karim to handle the miningBeneficiary case. He used the tracing feature to access the context of miningBeneficiary in ParallelizedConcurrentTransactionProcessor.runTransaction, and check if the address of the miner was touched before executing the transaction.
There was a problem hiding this comment.
Yes it is necessary for the PR and for conflict detection. I explain it in the comments normally
There was a problem hiding this comment.
In fact I use it to know if we touched the address of the beneficiary before paying the reward. If we touch it before it is a conflict if we touch it just for the reward it's ok
There was a problem hiding this comment.
Sorry for the late feedback here, but wouldn't paying the reward to the coinbase affect consensus? If one of the parallel transactions was from the coinbase, couldn't its result be affected by interim transaction rewards if the coinbase submitted a transaction that invoked BALANCE opcode?
I think we need to flatly ban coinbase from parallelization for this reason.
this ban exists already in the conflict detection, I just missed it because it was for miningBeneficiary and I was looking for coinbase
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
… common address is found Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: ahamlat <ameziane.hamlat@consensys.net>
Signed-off-by: ahamlat <ameziane.hamlat@consensys.net>
garyschulte
left a comment
There was a problem hiding this comment.
I think transactions sent from a coinbase are a problem, and they should be banned from parallelization period.
If I am wrong, I would love to see a test block that proved parallelized coinbase transactions which use BALANCE opcode are safe/deterministic.
| final Wei coinbaseWeiDelta = | ||
| coinbaseCalculator.price(usedGas, transactionGasPrice, blockHeader.getBaseFee()); | ||
|
|
||
| operationTracer.traceBeforeRewardTransaction(worldUpdater, transaction, coinbaseWeiDelta); |
There was a problem hiding this comment.
Sorry for the late feedback here, but wouldn't paying the reward to the coinbase affect consensus? If one of the parallel transactions was from the coinbase, couldn't its result be affected by interim transaction rewards if the coinbase submitted a transaction that invoked BALANCE opcode?
I think we need to flatly ban coinbase from parallelization for this reason.
this ban exists already in the conflict detection, I just missed it because it was for miningBeneficiary and I was looking for coinbase
A transaction that will interact with the coinbase to send, receive, or simply read or modify throughout the transaction will be in the accumulator at the time of this event #7296 (comment). Therefore, before paying the reward, If we detect this coinbase access, it will necessarily be banned from parallelization, and that's why we have this code. We track the state of the accumulator before paying the reward because it allows us to detect these transactions that need the correct state of the coinbase, and we ban them. This allows us to differentiate a simple payment of transaction fees, which will not impact the transaction's behavior, from a transaction whose behavior will depend on the coinbase. Then we pay the rewards in the sequential part to have the correct coinbase balance for the start of each transaction. Thus, if a transaction is banned due to its access to the coinbase, it will no longer have a problem when processed sequentially because the balance of a coinbase has been correctly updated by previous transactions during the sequential part Here is the part of the code where we ban transactions that have access to coinbase https://github.com/hyperledger/besu/pull/7296/files#diff-53805bb7138bc804441822c2d6acca3a1c72a26926563bc898b28eec5654c812R48 So unless I did not understand your remark for me it is already managed and was precisely an important element of the PR |
AFAIK, we do not need a transaction to directly interact with the coinbase in order to alter its state. My thinking is that each transaction pays coinbase some bit at its conclusion. In a serial execution context this just means that any future transactions in the block would see the coinbase with an increased balance. If in that same block, the coinbase is the originator of a transaction, nothing else would conflict with it because we are not considering coinbase reward as a conflict. If the coinbase transaction attempts to read its balance in isolation, without the tx rewards that might/would have accumulated before it executed its transaction, then a parallel coinbase tx would report a different value when executing the BALANCE opcode than if it had been executed serially. |
talking oob with Karim, he pointed out that the reason I didn't see the coinbase conflict detection is because I was searching for "coinbase", and the check is using "miningBeneficiary": |
We should add explicit test coverage before this gets out of experimental, but otherwise lgtm
| if (transactionCollisionDetector | ||
| .getAddressesTouchedByTransaction( | ||
| transaction, Optional.of(roundWorldStateUpdater)) | ||
| .contains(miningBeneficiary)) { | ||
| contextBuilder.isMiningBeneficiaryTouchedPreRewardByTransaction(true); | ||
| } | ||
| contextBuilder.miningBeneficiaryReward(miningReward); |
There was a problem hiding this comment.
Running gradle check with code coverage doesn't show this covered. Definitely would be nice to have this covered in test
fab-10
left a comment
There was a problem hiding this comment.
The idea behind this feature make sense, and as first step looks good to me, and I have nothing else to add, just waiting for the approval from @garyschulte since he has much more knowledge on this part.
Signed-off-by: ahamlat <ameziane.hamlat@consensys.net>
garyschulte
left a comment
There was a problem hiding this comment.
Lets merge and continue to test 👍
…su-eth#7296) Optimistic transaction parallelization execution during block processing to improve the performances. This feature can enabled with a flag --Xbonsai-parallel-tx-processing-enabled=true Signed-off-by: Karim Taam <karim.t2am@gmail.com> Co-authored-by: Ameziane H <ameziane.hamlat@consensys.net> Co-authored-by: garyschulte <garyschulte@gmail.com> Signed-off-by: gconnect <agatevureglory@gmail.com>
PR description
The idea of this PR is to create a system for parallelizing transactions in an optimistic way. What's the parallelization mechanism we're proposing?
We plan to execute all transactions within a block in parallel, without checking for conflicts between them. We're starting with the assumption that everything can be parallelized. Then, without waiting for the results of these background executions, we'll process the block sequentially and fix conflict.