From 40593b05d6d86911916153087cc6d9a29cb7a92d Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 9 Jan 2025 10:58:10 +1100 Subject: [PATCH 1/2] Fix guess type for code delegation transactions Signed-off-by: Gabriel-Trintinalia --- .../besu/ethereum/core/Transaction.java | 6 +-- .../ethereum/core/TransactionBuilderTest.java | 50 +++++++++++++++---- 2 files changed, 44 insertions(+), 12 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 e3fde4c32be..8ada82c19f6 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 @@ -1300,14 +1300,14 @@ public Builder versionedHashes(final List versionedHashes) { } public Builder guessType() { - if (versionedHashes != null && !versionedHashes.isEmpty()) { + if (codeDelegationAuthorizations.isPresent()) { + transactionType = TransactionType.DELEGATE_CODE; + } else if (versionedHashes != null && !versionedHashes.isEmpty()) { transactionType = TransactionType.BLOB; } else if (maxPriorityFeePerGas != null || maxFeePerGas != null) { transactionType = TransactionType.EIP1559; } else if (accessList.isPresent()) { transactionType = TransactionType.ACCESS_LIST; - } else if (codeDelegationAuthorizations.isPresent()) { - transactionType = TransactionType.DELEGATE_CODE; } else { transactionType = TransactionType.FRONTIER; } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java index e56b9bc0e8a..b80e3e95d45 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java @@ -14,15 +14,17 @@ */ package org.hyperledger.besu.ethereum.core; -import static java.util.stream.Collectors.toUnmodifiableSet; import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.datatypes.VersionedHash.DEFAULT_VERSIONED_HASH; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.crypto.SignatureAlgorithm; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.AccessListEntry; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; @@ -30,7 +32,6 @@ import java.math.BigInteger; import java.util.List; import java.util.Optional; -import java.util.Set; import java.util.function.Supplier; import java.util.stream.Stream; @@ -45,20 +46,51 @@ class TransactionBuilderTest { @Test void guessTypeCanGuessAllTypes() { final BlockDataGenerator gen = new BlockDataGenerator(); + final List accessList = + List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32()))); + final Transaction.Builder frontierBuilder = Transaction.builder(); - final Transaction.Builder eip1559Builder = Transaction.builder().maxFeePerGas(Wei.of(5)); - final Transaction.Builder accessListBuilder = + final Transaction.Builder accessListBuilder = Transaction.builder().accessList(accessList); + + final Transaction.Builder eip1559Builder = + Transaction.builder().accessList(accessList).maxFeePerGas(Wei.of(5)); + + final Transaction.Builder blobBuilder = + Transaction.builder() + .accessList(accessList) + .maxFeePerGas(Wei.of(5)) + .versionedHashes(List.of(DEFAULT_VERSIONED_HASH)); + + final CodeDelegation codeDelegation = + new CodeDelegation( + BigInteger.ZERO, + Address.ZERO, + 0, + new SECPSignature(BigInteger.ZERO, BigInteger.ZERO, (byte) 0)); + + final Transaction.Builder delegateCodeBuilder = Transaction.builder() - .accessList(List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32())))); + .accessList(accessList) + .maxFeePerGas(Wei.of(5)) + .codeDelegations(List.of(codeDelegation)); - final Set guessedTypes = - Stream.of(frontierBuilder, eip1559Builder, accessListBuilder) + final List guessedTypes = + Stream.of( + frontierBuilder, + accessListBuilder, + eip1559Builder, + blobBuilder, + delegateCodeBuilder) .map(transactionBuilder -> transactionBuilder.guessType().getTransactionType()) - .collect(toUnmodifiableSet()); + .toList(); assertThat(guessedTypes) .containsExactlyInAnyOrder( - TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559); + TransactionType.FRONTIER, + TransactionType.ACCESS_LIST, + TransactionType.EIP1559, + TransactionType.BLOB, + TransactionType.DELEGATE_CODE); } @Test From 4e76c9320488d84dbd7236a94aee8ad607fd54b8 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 9 Jan 2025 11:21:47 +1100 Subject: [PATCH 2/2] The order matters Signed-off-by: Gabriel-Trintinalia --- .../hyperledger/besu/ethereum/core/TransactionBuilderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java index b80e3e95d45..2fcdecdb124 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java @@ -85,7 +85,7 @@ void guessTypeCanGuessAllTypes() { .toList(); assertThat(guessedTypes) - .containsExactlyInAnyOrder( + .containsExactly( TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559,