From d636e7f1bccef56b12090d9b65d4b23929026844 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 10 Jan 2024 09:25:04 +0100 Subject: [PATCH] Copy also computed fields, when doing a Transaction detached copy (#6329) Signed-off-by: Fabio Di Fabio --- .../besu/ethereum/core/Transaction.java | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java index 79261159498..529661d5098 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java @@ -1007,24 +1007,33 @@ public Transaction detachedCopy() { withCommitments -> blobsWithCommitmentsDetachedCopy(withCommitments, detachedVersionedHashes.get())); - return new Transaction( - true, - transactionType, - nonce, - gasPrice, - maxPriorityFeePerGas, - maxFeePerGas, - maxFeePerBlobGas, - gasLimit, - detachedTo, - value, - signature, - payload.copy(), - detachedAccessList, - sender, - chainId, - detachedVersionedHashes, - detachedBlobsWithCommitments); + final var copiedTx = + new Transaction( + true, + transactionType, + nonce, + gasPrice, + maxPriorityFeePerGas, + maxFeePerGas, + maxFeePerBlobGas, + gasLimit, + detachedTo, + value, + signature, + payload.copy(), + detachedAccessList, + sender, + chainId, + detachedVersionedHashes, + detachedBlobsWithCommitments); + + // copy also the computed fields, to avoid to recompute them + copiedTx.sender = this.sender; + copiedTx.hash = this.hash; + copiedTx.hashNoSignature = this.hashNoSignature; + copiedTx.size = this.size; + + return copiedTx; } private AccessListEntry accessListDetachedCopy(final AccessListEntry accessListEntry) {