Skip to content

Commit

Permalink
Adding trace logs to mention ssz transaction encoding/deconding in lo…
Browse files Browse the repository at this point in the history
…gs (#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>
(cherry picked from commit d92909f)
(cherry picked from commit 42ba8192139c1f4fabad40e3085e158ca99a9156)
  • Loading branch information
gezero authored and jflo committed Jun 16, 2023
1 parent 84af0ec commit 2b5eefa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 55 deletions.
18 changes: 0 additions & 18 deletions datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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;
Expand Down Expand Up @@ -1008,25 +1009,30 @@ private static Bytes blobPreimage(
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
Expand All @@ -44,11 +45,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);
Expand Down Expand Up @@ -87,13 +91,15 @@ 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);
signedBlobTransaction = payload.getSignedBlobTransaction();

builder.kzgBlobs(payload.getKzgCommitments(), payload.getBlobs(), payload.getKzgProof());
} else {
LOG.trace("Decoding TransactionNetworkPayload.SingedBlobTransaction");
signedBlobTransaction = new TransactionNetworkPayload.SingedBlobTransaction();
signedBlobTransaction.populateFromReader(input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down

0 comments on commit 2b5eefa

Please sign in to comment.