From d92909f24572702659bcf9a74df24eb615a200bb Mon Sep 17 00:00:00 2001 From: Jiri Peinlich Date: Thu, 26 Jan 2023 11:59:52 +0100 Subject: [PATCH] Adding trace logs to mention ssz transaction encoding/deconding in logs (#5003) * Adding trace logs to mention ssz transaction encoding/deconding in logs * ssz encoding should go int keccak256 of blob transaction Signed-off-by: Jiri Peinlich --- .../org/hyperledger/besu/datatypes/Blob.java | 18 -------- .../besu/datatypes/KZGCommitment.java | 18 -------- .../besu/ethereum/core/Transaction.java | 44 +++++++++++-------- .../core/encoding/TransactionDecoder.java | 6 +++ .../core/encoding/TransactionEncoder.java | 5 +++ 5 files changed, 36 insertions(+), 55 deletions(-) delete mode 100644 datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java delete mode 100644 datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java deleted file mode 100644 index 70b22d58691..00000000000 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Hyperledger Besu Contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.hyperledger.besu.datatypes; - -public class Blob {} diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java deleted file mode 100644 index 3ccffa485e2..00000000000 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Hyperledger Besu Contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.hyperledger.besu.datatypes; - -public class KZGCommitment {} 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 224d2c9d5ab..c7bc673ec1a 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 @@ -49,6 +49,7 @@ import com.google.common.primitives.Longs; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.ssz.SSZ; import org.apache.tuweni.ssz.SSZFixedSizeTypeList; import org.apache.tuweni.units.bigints.UInt256; import org.apache.tuweni.units.bigints.UInt256s; @@ -1015,25 +1016,30 @@ private static Bytes blobPreimage( final Optional chainId, final Optional> accessList, final List versionedHashes) { - final Bytes encoded = - RLP.encode( - rlpOutput -> { - rlpOutput.startList(); - eip1559PreimageFields( - nonce, - maxPriorityFeePerGas, - maxFeePerGas, - gasLimit, - to, - value, - payload, - chainId, - accessList, - rlpOutput); - rlpOutput.writeUInt256Scalar(maxFeePerDataGas); - TransactionEncoder.writeBlobVersionedHashes(rlpOutput, versionedHashes); - rlpOutput.endList(); - }); + + var blobTransaction = new TransactionNetworkPayload.SingedBlobTransaction.BlobTransaction(); + chainId.ifPresent(id -> blobTransaction.setChainId(UInt256.valueOf(id))); + blobTransaction.setNonce(nonce); + blobTransaction.setMaxPriorityFeePerGas(maxPriorityFeePerGas.toUInt256()); + blobTransaction.setMaxFeePerGas(maxFeePerGas.toUInt256()); + blobTransaction.setMaxFeePerDataGas(maxFeePerDataGas.toUInt256()); + blobTransaction.setGas(gasLimit); + blobTransaction.setAddress(to); + blobTransaction.setValue(value.toUInt256()); + blobTransaction.setData(payload); + accessList.ifPresent( + al -> { + var list = blobTransaction.getAccessList(); + al.forEach( + accessListEntry -> { + var tuple = new TransactionNetworkPayload.SingedBlobTransaction.AccessTuple(); + tuple.setAddress(accessListEntry.getAddress()); + tuple.setStorageKeys(accessListEntry.getStorageKeys()); + list.add(tuple); + }); + }); + blobTransaction.setBlobVersionedHashes(versionedHashes); + Bytes encoded = SSZ.encode(blobTransaction::writeTo); return Bytes.concatenate(Bytes.of(TransactionType.BLOB.getSerializedType()), encoded); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java index d0bdfe90dd2..7189ac34901 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java @@ -21,6 +21,7 @@ import static org.hyperledger.besu.ethereum.core.Transaction.REPLAY_UNPROTECTED_V_BASE; import static org.hyperledger.besu.ethereum.core.Transaction.REPLAY_UNPROTECTED_V_BASE_PLUS_1; import static org.hyperledger.besu.ethereum.core.Transaction.TWO; +import static org.slf4j.LoggerFactory.getLogger; import org.hyperledger.besu.config.GoQuorumOptions; import org.hyperledger.besu.crypto.SECPSignature; @@ -47,11 +48,14 @@ import org.apache.tuweni.ssz.SSZ; import org.apache.tuweni.ssz.SSZReader; import org.apache.tuweni.units.bigints.UInt32; +import org.slf4j.Logger; public class TransactionDecoder { private static final UInt32 BLOB_TRANSACTION_OFFSET = UInt32.fromHexString("0x3c000000"); + private static final Logger LOG = getLogger(TransactionDecoder.class); + @FunctionalInterface interface Decoder { Transaction decode(final Bytes input); @@ -90,6 +94,7 @@ public static Transaction decodeBlob(final SSZReader input, final UInt32 firstOf TransactionNetworkPayload.SingedBlobTransaction signedBlobTransaction; if (firstOffset.equals(BLOB_TRANSACTION_OFFSET)) { + LOG.trace("Decoding TransactionNetworkPayload"); TransactionNetworkPayload payload = new TransactionNetworkPayload(); payload.populateFromReader(input); @@ -97,6 +102,7 @@ public static Transaction decodeBlob(final SSZReader input, final UInt32 firstOf builder.kzgBlobs(payload.getKzgCommitments(), payload.getBlobs(), payload.getKzgProof()); } else { + LOG.trace("Decoding TransactionNetworkPayload.SingedBlobTransaction"); signedBlobTransaction = new TransactionNetworkPayload.SingedBlobTransaction(); signedBlobTransaction.populateFromReader(input); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java index bb956f431f2..ab257b77960 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.core.encoding; import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; @@ -35,8 +36,10 @@ import org.apache.tuweni.ssz.SSZ; import org.apache.tuweni.ssz.SSZWriter; import org.apache.tuweni.units.bigints.UInt256; +import org.slf4j.Logger; public class TransactionEncoder { + private static final Logger LOG = getLogger(Encoder.class); @FunctionalInterface interface Encoder { @@ -73,6 +76,7 @@ interface SSZEncoder { TransactionType.BLOB, Encoder.sszEncoder(TransactionEncoder::encodeWithBlobs)); public static void encodeWithBlobs(final Transaction transaction, final SSZWriter rlpOutput) { + LOG.trace("Encoding transaction with blobs {}", transaction); var payload = new TransactionNetworkPayload(); var blobsWithCommitments = transaction.getBlobsWithCommitments(); if (blobsWithCommitments.isPresent()) { @@ -88,6 +92,7 @@ public static void encodeWithBlobs(final Transaction transaction, final SSZWrite } public static void encodeWithoutBlobs(final Transaction transaction, final SSZWriter rlpOutput) { + LOG.trace("Encoding transaction without blobs {}", transaction); var signedBlobTransaction = new TransactionNetworkPayload.SingedBlobTransaction(); populatedSignedBlobTransaction(transaction, signedBlobTransaction); signedBlobTransaction.writeTo(rlpOutput);