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 <jiri.peinlich@gmail.com>
pull/5008/head
Jiri Peinlich 2 years ago committed by GitHub
parent 949e3fe491
commit d92909f245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java
  2. 18
      datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java
  3. 44
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java
  4. 6
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java
  5. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java

@ -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 {}

@ -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 {}

@ -49,6 +49,7 @@ import java.util.stream.Collectors;
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 @@ public class Transaction
final Optional<BigInteger> chainId,
final Optional<List<AccessListEntry>> accessList,
final List<Hash> 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);
}

@ -21,6 +21,7 @@ import static org.hyperledger.besu.ethereum.core.Transaction.REPLAY_PROTECTED_V_
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.bytes.Bytes;
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 class TransactionDecoder {
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 class TransactionDecoder {
builder.kzgBlobs(payload.getKzgCommitments(), payload.getBlobs(), payload.getKzgProof());
} else {
LOG.trace("Decoding TransactionNetworkPayload.SingedBlobTransaction");
signedBlobTransaction = new TransactionNetworkPayload.SingedBlobTransaction();
signedBlobTransaction.populateFromReader(input);
}

@ -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.bytes.Bytes;
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 @@ public class TransactionEncoder {
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 class TransactionEncoder {
}
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);

Loading…
Cancel
Save