diff --git a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestSigningPrivateMarkerTransactionFactory.java b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestSigningPrivateMarkerTransactionFactory.java index e62e496a5b..b5fb65e2ef 100644 --- a/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestSigningPrivateMarkerTransactionFactory.java +++ b/acceptance-tests/test-plugins/src/main/java/org/hyperledger/besu/tests/acceptance/plugins/privacy/TestSigningPrivateMarkerTransactionFactory.java @@ -25,7 +25,6 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.plugin.data.PrivateTransaction; import org.hyperledger.besu.plugin.data.UnsignedPrivateMarkerTransaction; import org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java index 09d82c4f63..7428c6dff4 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/TxParseSubCommand.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.cli.subcommands.TxParseSubCommand.COMMAND_NAM import org.hyperledger.besu.cli.util.VersionProvider; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -29,7 +30,6 @@ import java.nio.file.Paths; import java.util.stream.Stream; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; import picocli.CommandLine; /** diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java index 8d7c3fe8da..5afeae6cac 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSucces import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; public class DebugGetRawTransaction implements JsonRpcMethod { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java index a465c4a16f..ef4d74a8f0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResultFactory.java @@ -95,8 +95,7 @@ public class BlockResultFactory { public EngineGetPayloadResultV1 payloadTransactionCompleteV1(final Block block) { final List txs = block.getBody().getTransactions().stream() - .map( - RlpTransactionProvider::encodeOpaqueBytes) + .map(RlpTransactionProvider::encodeOpaqueBytes) .map(Bytes::toHexString) .collect(Collectors.toList()); @@ -107,8 +106,7 @@ public class BlockResultFactory { final var blockWithReceipts = payload.blockWithReceipts(); final List txs = blockWithReceipts.getBlock().getBody().getTransactions().stream() - .map( - RlpTransactionProvider::encodeOpaqueBytes) + .map(RlpTransactionProvider::encodeOpaqueBytes) .map(Bytes::toHexString) .collect(Collectors.toList()); @@ -132,8 +130,7 @@ public class BlockResultFactory { final var blockWithReceipts = payload.blockWithReceipts(); final List txs = blockWithReceipts.getBlock().getBody().getTransactions().stream() - .map( - RlpTransactionProvider::encodeOpaqueBytes) + .map(RlpTransactionProvider::encodeOpaqueBytes) .map(Bytes::toHexString) .collect(Collectors.toList()); @@ -151,8 +148,7 @@ public class BlockResultFactory { final var blockWithReceipts = payload.blockWithReceipts(); final List txs = blockWithReceipts.getBlock().getBody().getTransactions().stream() - .map( - RlpTransactionProvider::encodeOpaqueBytes) + .map(RlpTransactionProvider::encodeOpaqueBytes) .map(Bytes::toHexString) .collect(Collectors.toList()); final Optional> requestsWithoutRequestId = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadBodiesResultV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadBodiesResultV1.java index 9ce81dddfa..40b2253886 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadBodiesResultV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadBodiesResultV1.java @@ -52,8 +52,7 @@ public class EngineGetPayloadBodiesResultV1 { public PayloadBody(final BlockBody blockBody) { this.transactions = blockBody.getTransactions().stream() - .map( - RlpTransactionProvider::encodeOpaqueBytes) + .map(RlpTransactionProvider::encodeOpaqueBytes) .map(Bytes::toHexString) .collect(Collectors.toList()); this.withdrawals = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java index 94818708d3..619fc12596 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; - import java.util.List; import com.fasterxml.jackson.annotation.JsonGetter; @@ -102,9 +101,7 @@ public class TransactionPendingResult implements TransactionResult { this.input = transaction.getPayload().toString(); this.nonce = Quantity.create(transaction.getNonce()); this.publicKey = transaction.getPublicKey().orElse(null); - this.raw = - RlpPooledTransactionProvider.encodeOpaqueBytes(transaction) - .toString(); + this.raw = RlpPooledTransactionProvider.encodeOpaqueBytes(transaction).toString(); this.to = transaction.getTo().map(Address::toHexString).orElse(null); if (transactionType == TransactionType.FRONTIER) { this.type = Quantity.create(0); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java index 3fb9f404c5..8981725926 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java @@ -28,7 +28,7 @@ public class DomainObjectDecodeUtils { throws InvalidJsonRpcRequestException { try { Bytes txnBytes = Bytes.fromHexString(rawTransaction); - return RlpPooledTransactionProvider.decodeOpaqueBytes(txnBytes); + return RlpPooledTransactionProvider.decodeOpaqueBytes(txnBytes); } catch (final IllegalArgumentException e) { throw new InvalidJsonRpcRequestException( "Invalid raw transaction hex", RpcErrorType.INVALID_TRANSACTION_PARAMS, e); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHashTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHashTest.java index a268701979..ca07774091 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHashTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHashTest.java @@ -109,8 +109,7 @@ class EthGetTransactionByHashTest { @Test void shouldReturnPendingTransactionWhenTransactionExistsAndIsPending() { final org.hyperledger.besu.ethereum.core.Transaction transaction = - RlpTransactionProvider.readFrom( - Bytes.fromHexString(VALID_TRANSACTION)); + RlpTransactionProvider.readFrom(Bytes.fromHexString(VALID_TRANSACTION)); when(transactionPool.getTransactionByHash(transaction.getHash())) .thenReturn(Optional.of(transaction)); @@ -132,8 +131,7 @@ class EthGetTransactionByHashTest { @Test void shouldReturnCompleteTransactionWhenTransactionExistsInBlockchain() { final org.hyperledger.besu.ethereum.core.Transaction transaction = - RlpTransactionProvider.readFrom( - Bytes.fromHexString(VALID_TRANSACTION)); + RlpTransactionProvider.readFrom(Bytes.fromHexString(VALID_TRANSACTION)); final TransactionWithMetadata transactionWithMetadata = new TransactionWithMetadata(transaction, 1, Optional.empty(), Hash.ZERO, 0); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java index 37bf10c208..32521ace6f 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3Test.java @@ -225,8 +225,7 @@ public class EngineNewPayloadV3Test extends EngineNewPayloadV2Test { public void shouldRejectTransactionsWithFullBlobs() { Bytes transactionWithBlobsBytes = - RlpPooledTransactionProvider.encodeOpaqueBytes( - createTransactionWithBlobs()); + RlpPooledTransactionProvider.encodeOpaqueBytes(createTransactionWithBlobs()); List transactions = List.of(transactionWithBlobsBytes.toString()); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java index 96facd06b3..9ecee08d9b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java @@ -66,8 +66,7 @@ public class DomainObjectDecodeUtilsTest { @Test public void testAccessList2718OpaqueSerDes() { - final Bytes encoded = - RlpPooledTransactionProvider.encodeOpaqueBytes(accessListTxn); + final Bytes encoded = RlpPooledTransactionProvider.encodeOpaqueBytes(accessListTxn); Transaction decoded = DomainObjectDecodeUtils.decodeRawTransaction(encoded.toString()); Assertions.assertThat(decoded.getAccessList().isPresent()).isTrue(); Assertions.assertThat(decoded.getAccessList().map(List::size).get()).isEqualTo(1); diff --git a/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/vm/TraceTransactionIntegrationTest.java b/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/vm/TraceTransactionIntegrationTest.java index 8fe3a974cf..d9da83dcf7 100644 --- a/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/vm/TraceTransactionIntegrationTest.java +++ b/ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/vm/TraceTransactionIntegrationTest.java @@ -171,7 +171,7 @@ public class TraceTransactionIntegrationTest { final DebugOperationTracer tracer = new DebugOperationTracer(new TraceOptions(true, true, true), false); final Transaction transaction = - RlpTransactionProvider.readFrom( + RlpTransactionProvider.readFrom( new BytesValueRLPInput(Bytes.fromHexString(CONTRACT_CREATION_TX), false)); final BlockHeader genesisBlockHeader = genesisBlock.getHeader(); transactionProcessor.processTransaction( 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 1062bf5c7d..8d80fd3665 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 @@ -40,7 +40,6 @@ import org.hyperledger.besu.ethereum.core.encoding.AccessListTransactionEncoder; import org.hyperledger.besu.ethereum.core.encoding.BlobTransactionEncoder; import org.hyperledger.besu.ethereum.core.encoding.CodeDelegationEncoder; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; - import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; @@ -541,8 +540,7 @@ public class Transaction final Bytes bytes = RlpTransactionProvider.encodeOpaqueBytes(this); hash = Hash.hash(bytes); if (transactionType.supportsBlob() && getBlobsWithCommitments().isPresent()) { - final Bytes pooledBytes = - RlpPooledTransactionProvider.encodeOpaqueBytes(this); + final Bytes pooledBytes = RlpPooledTransactionProvider.encodeOpaqueBytes(this); size = pooledBytes.size(); return; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionDecoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionDecoder.java index 567fc29a98..8f0386c50e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionDecoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionDecoder.java @@ -16,7 +16,6 @@ package org.hyperledger.besu.ethereum.core.encoding; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.annotations.VisibleForTesting; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.registry.TransactionDecoder; @@ -25,6 +24,7 @@ import org.hyperledger.besu.ethereum.rlp.RLPInput; import java.util.Optional; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import org.apache.tuweni.bytes.Bytes; @@ -53,8 +53,7 @@ public class MainnetTransactionDecoder implements TransactionDecoder { * @param rlpInput the RLP input * @return the decoded transaction */ - public Transaction readFrom( - final RLPInput rlpInput) { + public Transaction readFrom(final RLPInput rlpInput) { if (!rlpInput.nextIsList()) { return decodeTypedTransaction(rlpInput); } else { @@ -73,8 +72,7 @@ public class MainnetTransactionDecoder implements TransactionDecoder { * @param rlpInput the RLP input * @return the decoded transaction */ - private Transaction decodeTypedTransaction( - final RLPInput rlpInput) { + private Transaction decodeTypedTransaction(final RLPInput rlpInput) { // Read the typed transaction bytes from the RLP input final Bytes typedTransactionBytes = rlpInput.readBytes(); @@ -95,8 +93,7 @@ public class MainnetTransactionDecoder implements TransactionDecoder { * @return the decoded transaction */ private Transaction decodeTypedTransaction( - final Bytes transactionBytes, - final TransactionType transactionType) { + final Bytes transactionBytes, final TransactionType transactionType) { // Slice the transaction bytes to exclude the transaction type and prepare for decoding final RLPInput transactionInput = RLP.input(transactionBytes.slice(1)); // Use the appropriate decoder for the transaction type to decode the remaining bytes @@ -111,8 +108,7 @@ public class MainnetTransactionDecoder implements TransactionDecoder { * @param opaqueBytes the opaque bytes * @return the decoded transaction */ - public Transaction decodeOpaqueBytes( - final Bytes opaqueBytes) { + public Transaction decodeOpaqueBytes(final Bytes opaqueBytes) { var transactionType = getTransactionType(opaqueBytes); if (transactionType.isPresent()) { return decodeTypedTransaction(opaqueBytes, transactionType.get()); @@ -140,7 +136,6 @@ public class MainnetTransactionDecoder implements TransactionDecoder { } } - /** * Gets the decoder for a given transaction type * @@ -148,8 +143,7 @@ public class MainnetTransactionDecoder implements TransactionDecoder { * @return the decoder */ @VisibleForTesting - protected Decoder getDecoder( - final TransactionType transactionType) { + protected Decoder getDecoder(final TransactionType transactionType) { return checkNotNull( TYPED_TRANSACTION_DECODERS.get(transactionType), "Developer Error. A supported transaction type %s has no associated decoding logic", diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionEncoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionEncoder.java index e2f3805465..c02f431b93 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionEncoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/MainnetTransactionEncoder.java @@ -16,7 +16,6 @@ package org.hyperledger.besu.ethereum.core.encoding; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.annotations.VisibleForTesting; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.registry.TransactionEncoder; @@ -24,6 +23,7 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import org.apache.tuweni.bytes.Bytes; @@ -51,9 +51,7 @@ public class MainnetTransactionEncoder implements TransactionEncoder { * @param transaction the transaction to encode * @param rlpOutput the RLP output stream */ - public void writeTo( - final Transaction transaction, - final RLPOutput rlpOutput) { + public void writeTo(final Transaction transaction, final RLPOutput rlpOutput) { final TransactionType transactionType = getTransactionType(transaction); Bytes opaqueBytes = encodeOpaqueBytes(transaction); encodeRLP(transactionType, opaqueBytes, rlpOutput); @@ -83,8 +81,7 @@ public class MainnetTransactionEncoder implements TransactionEncoder { * @param transaction the transaction to encode * @return the encoded transaction as bytes */ - public Bytes encodeOpaqueBytes( - final Transaction transaction) { + public Bytes encodeOpaqueBytes(final Transaction transaction) { final TransactionType transactionType = getTransactionType(transaction); if (TransactionType.FRONTIER.equals(transactionType)) { return RLP.encode(rlpOutput -> FrontierTransactionEncoder.encode(transaction, rlpOutput)); @@ -97,15 +94,13 @@ public class MainnetTransactionEncoder implements TransactionEncoder { } } - private static TransactionType getTransactionType(final Transaction transaction) { return checkNotNull( transaction.getType(), "Transaction type for %s was not specified.", transaction); } @VisibleForTesting - protected Encoder getEncoder( - final TransactionType transactionType) { + protected Encoder getEncoder(final TransactionType transactionType) { return checkNotNull( TYPED_TRANSACTION_ENCODERS.get(transactionType), "Developer Error. A supported transaction type %s has no associated encoding logic", diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionDecoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionDecoder.java index 9f8f7cb10c..87c1bb7b23 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionDecoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionDecoder.java @@ -1,23 +1,39 @@ +/* + * Copyright contributors to Besu. + * + * 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.ethereum.core.encoding; import static com.google.common.base.Preconditions.checkNotNull; +import org.hyperledger.besu.datatypes.TransactionType; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; -import org.hyperledger.besu.datatypes.TransactionType; public class PooledMainnetTransactionDecoder extends MainnetTransactionDecoder { - private static final ImmutableMap POOLED_TRANSACTION_DECODERS = - ImmutableMap.of( - TransactionType.ACCESS_LIST, - AccessListTransactionDecoder::decode, - TransactionType.EIP1559, - EIP1559TransactionDecoder::decode, - TransactionType.BLOB, - BlobPooledTransactionDecoder::decode , - TransactionType.DELEGATE_CODE, - CodeDelegationTransactionDecoder::decode); + private static final ImmutableMap + POOLED_TRANSACTION_DECODERS = + ImmutableMap.of( + TransactionType.ACCESS_LIST, + AccessListTransactionDecoder::decode, + TransactionType.EIP1559, + EIP1559TransactionDecoder::decode, + TransactionType.BLOB, + BlobPooledTransactionDecoder::decode, + TransactionType.DELEGATE_CODE, + CodeDelegationTransactionDecoder::decode); /** * Gets the decoder for a given transaction type @@ -25,13 +41,12 @@ public class PooledMainnetTransactionDecoder extends MainnetTransactionDecoder { * @param transactionType the transaction type * @return the decoder */ -@VisibleForTesting -@Override - protected MainnetTransactionDecoder.Decoder getDecoder( - final TransactionType transactionType) { + @VisibleForTesting + @Override + protected MainnetTransactionDecoder.Decoder getDecoder(final TransactionType transactionType) { return checkNotNull( - POOLED_TRANSACTION_DECODERS.get(transactionType), - "Developer Error. A supported transaction type %s has no associated decoding logic", - transactionType); + POOLED_TRANSACTION_DECODERS.get(transactionType), + "Developer Error. A supported transaction type %s has no associated decoding logic", + transactionType); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionEncoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionEncoder.java index cfdc554796..8563003d8d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionEncoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/PooledMainnetTransactionEncoder.java @@ -16,10 +16,10 @@ package org.hyperledger.besu.ethereum.core.encoding; import static com.google.common.base.Preconditions.checkNotNull; +import org.hyperledger.besu.datatypes.TransactionType; + import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; public class PooledMainnetTransactionEncoder extends MainnetTransactionEncoder { @@ -35,10 +35,9 @@ public class PooledMainnetTransactionEncoder extends MainnetTransactionEncoder { CodeDelegationEncoder::encode); @VisibleForTesting - protected Encoder getEncoder( - final TransactionType transactionType) { + protected Encoder getEncoder(final TransactionType transactionType) { return checkNotNull( - POOLED_TRANSACTION_ENCODERS.get(transactionType), + POOLED_TRANSACTION_ENCODERS.get(transactionType), "Developer Error. A supported transaction type %s has no associated encoding logic", transactionType); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/SignatureEncoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/SignatureEncoder.java index 7496d6f15a..16be2cb858 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/SignatureEncoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/SignatureEncoder.java @@ -1,3 +1,17 @@ +/* + * Copyright contributors to Besu. + * + * 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.ethereum.core.encoding; import org.hyperledger.besu.ethereum.core.Transaction; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpDecoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpDecoder.java index e74548c10b..312409545c 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpDecoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpDecoder.java @@ -14,10 +14,11 @@ */ package org.hyperledger.besu.ethereum.core.encoding.registry; -import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; +import org.apache.tuweni.bytes.Bytes; + public interface RlpDecoder { T readFrom(final RLPInput input); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpEncoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpEncoder.java index 66b93fcda2..3d4a498a06 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpEncoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpEncoder.java @@ -14,7 +14,6 @@ */ package org.hyperledger.besu.ethereum.core.encoding.registry; - import org.hyperledger.besu.ethereum.rlp.RLPOutput; public interface RlpEncoder { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpPooledTransactionProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpPooledTransactionProvider.java index f6ae55c3e6..b5cdeffad9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpPooledTransactionProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpPooledTransactionProvider.java @@ -1,23 +1,38 @@ +/* + * Copyright contributors to Besu. + * + * 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.ethereum.core.encoding.registry; -import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.apache.tuweni.bytes.Bytes; + public class RlpPooledTransactionProvider { - private RlpPooledTransactionProvider(){} + private RlpPooledTransactionProvider() {} - public static Transaction readFrom(final RLPInput rlpInput){ - return getDecoder().readFrom(rlpInput); + public static Transaction readFrom(final RLPInput rlpInput) { + return getDecoder().readFrom(rlpInput); } - public static Transaction readFrom(final Bytes bytes){ + public static Transaction readFrom(final Bytes bytes) { return getDecoder().readFrom(bytes); } - public static Transaction decodeOpaqueBytes(final Bytes bytes){ + public static Transaction decodeOpaqueBytes(final Bytes bytes) { return getDecoder().decodeOpaqueBytes(bytes); } @@ -25,18 +40,15 @@ public class RlpPooledTransactionProvider { getEncoder().writeTo(transaction, output); } - public static Bytes encodeOpaqueBytes(Transaction transaction){ + public static Bytes encodeOpaqueBytes(Transaction transaction) { return getEncoder().encodeOpaqueBytes(transaction); } - private static - TransactionEncoder getEncoder(){ + private static TransactionEncoder getEncoder() { return RlpRegistry.getInstance().getPooledTransactionEncoder(); } - private static - TransactionDecoder getDecoder(){ + private static TransactionDecoder getDecoder() { return RlpRegistry.getInstance().getPooledTransactionDecoder(); } - } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpRegistry.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpRegistry.java index 8cd27c7cc3..80c42020cf 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpRegistry.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpRegistry.java @@ -25,13 +25,13 @@ public class RlpRegistry { private TransactionDecoder transactionDecoder; private TransactionDecoder pooledTransactionDecoder; - private TransactionEncoder transactionEncoder; + private TransactionEncoder transactionEncoder; private TransactionEncoder pooledTransactionEncoder; private RlpRegistry() { transactionDecoder = new MainnetTransactionDecoder(); pooledTransactionDecoder = new PooledMainnetTransactionDecoder(); - transactionEncoder =new MainnetTransactionEncoder(); + transactionEncoder = new MainnetTransactionEncoder(); pooledTransactionEncoder = new PooledMainnetTransactionEncoder(); } @@ -42,35 +42,35 @@ public class RlpRegistry { return INSTANCE; } - public void setTransactionDecoder(final TransactionDecoder decoder){ + public void setTransactionDecoder(final TransactionDecoder decoder) { this.transactionDecoder = decoder; } - - public TransactionDecoder getTransactionDecoder(){ + + public TransactionDecoder getTransactionDecoder() { return transactionDecoder; } - public void setPooledTransactionDecoder(final TransactionDecoder pooledTransactionDecoder){ + public void setPooledTransactionDecoder(final TransactionDecoder pooledTransactionDecoder) { this.pooledTransactionDecoder = pooledTransactionDecoder; } - public TransactionDecoder getPooledTransactionDecoder(){ + public TransactionDecoder getPooledTransactionDecoder() { return pooledTransactionDecoder; } - public void setTransactionEncoder(final TransactionEncoder encoder){ + public void setTransactionEncoder(final TransactionEncoder encoder) { this.transactionEncoder = encoder; } - public TransactionEncoder getTransactionEncoder(){ + public TransactionEncoder getTransactionEncoder() { return transactionEncoder; } - public void setPooledTransactionEncoder(final TransactionEncoder pooledTransactionEncoder){ + public void setPooledTransactionEncoder(final TransactionEncoder pooledTransactionEncoder) { this.pooledTransactionEncoder = pooledTransactionEncoder; } - public TransactionEncoder getPooledTransactionEncoder(){ + public TransactionEncoder getPooledTransactionEncoder() { return pooledTransactionEncoder; } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpTransactionProvider.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpTransactionProvider.java index c493af5611..c945bcf353 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpTransactionProvider.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/RlpTransactionProvider.java @@ -1,22 +1,37 @@ +/* + * Copyright contributors to Besu. + * + * 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.ethereum.core.encoding.registry; -import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.apache.tuweni.bytes.Bytes; + public class RlpTransactionProvider { - private RlpTransactionProvider(){} + private RlpTransactionProvider() {} - public static Transaction readFrom(final RLPInput rlpInput){ - return getDecoder().readFrom(rlpInput); + public static Transaction readFrom(final RLPInput rlpInput) { + return getDecoder().readFrom(rlpInput); } - public static Transaction readFrom(final Bytes bytes){ + public static Transaction readFrom(final Bytes bytes) { return getDecoder().readFrom(bytes); } - public static Transaction decodeOpaqueBytes(final Bytes bytes){ + public static Transaction decodeOpaqueBytes(final Bytes bytes) { return getDecoder().decodeOpaqueBytes(bytes); } @@ -24,17 +39,15 @@ public class RlpTransactionProvider { getEncoder().writeTo(transaction, output); } - public static Bytes encodeOpaqueBytes(Transaction transaction){ + public static Bytes encodeOpaqueBytes(Transaction transaction) { return getEncoder().encodeOpaqueBytes(transaction); } - private static - TransactionDecoder getDecoder(){ + private static TransactionDecoder getDecoder() { return RlpRegistry.getInstance().getTransactionDecoder(); } - private static - TransactionEncoder getEncoder(){ + private static TransactionEncoder getEncoder() { return RlpRegistry.getInstance().getTransactionEncoder(); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionDecoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionDecoder.java index 2d1a3caa14..f257671b77 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionDecoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionDecoder.java @@ -1,8 +1,23 @@ +/* + * Copyright contributors to Besu. + * + * 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.ethereum.core.encoding.registry; -import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.ethereum.core.Transaction; +import org.apache.tuweni.bytes.Bytes; + public interface TransactionDecoder extends RlpDecoder { Transaction decodeOpaqueBytes(Bytes bytes); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionEncoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionEncoder.java index 33ee022658..134dc0af70 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionEncoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/registry/TransactionEncoder.java @@ -1,10 +1,24 @@ +/* + * Copyright contributors to Besu. + * + * 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.ethereum.core.encoding.registry; -import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.ethereum.core.Transaction; +import org.apache.tuweni.bytes.Bytes; + public interface TransactionEncoder extends RlpEncoder { - Bytes encodeOpaqueBytes( - final Transaction transaction); + Bytes encodeOpaqueBytes(final Transaction transaction); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java index 1a2e104b66..ec0ecbe3eb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java @@ -23,8 +23,8 @@ import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.Withdrawal; -import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; import org.hyperledger.besu.ethereum.core.encoding.WithdrawalEncoder; +import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerkleTrie; import org.hyperledger.besu.ethereum.trie.patricia.SimpleMerklePatriciaTrie; @@ -65,9 +65,7 @@ public final class BodyValidation { .forEach( i -> trie.put( - indexKey(i), - RlpTransactionProvider.encodeOpaqueBytes( - transactions.get(i)))); + indexKey(i), RlpTransactionProvider.encodeOpaqueBytes(transactions.get(i)))); return Hash.wrap(trie.getRootHash()); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/SigningPrivateMarkerTransactionFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/SigningPrivateMarkerTransactionFactory.java index 058e9f11ee..0fb23c49d0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/SigningPrivateMarkerTransactionFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/SigningPrivateMarkerTransactionFactory.java @@ -18,7 +18,6 @@ import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.plugin.data.UnsignedPrivateMarkerTransaction; import org.apache.tuweni.bytes.Bytes; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/BlobTransactionEncodingTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/BlobTransactionEncodingTest.java index 39b9de23e0..6a23fddae5 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/BlobTransactionEncodingTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/BlobTransactionEncodingTest.java @@ -18,7 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; -import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; @@ -60,15 +59,13 @@ public class BlobTransactionEncodingTest { final TypedTransactionBytesArgument argument) { Bytes bytes = argument.bytes; // Decode the transaction from the wire using the TransactionDecoder. - final Transaction transaction = - RlpPooledTransactionProvider.decodeOpaqueBytes(bytes); + final Transaction transaction = RlpPooledTransactionProvider.decodeOpaqueBytes(bytes); final BytesValueRLPOutput output = new BytesValueRLPOutput(); new MainnetTransactionEncoder().encodeRLP(transaction.getType(), bytes, output); final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput(); - RlpPooledTransactionProvider.writeTo( - transaction, bytesValueRLPOutput); + RlpPooledTransactionProvider.writeTo(transaction, bytesValueRLPOutput); assertThat(transaction.getSize()).isEqualTo(bytes.size()); } @@ -77,8 +74,7 @@ public class BlobTransactionEncodingTest { public void blobTransactionEncodingDecodingTest(final TypedTransactionBytesArgument argument) { Bytes bytes = argument.bytes; // Decode the transaction from the wire using the TransactionDecoder. - final Transaction transaction = - RlpTransactionProvider.decodeOpaqueBytes(bytes); + final Transaction transaction = RlpTransactionProvider.decodeOpaqueBytes(bytes); // Encode the transaction for wire using the TransactionEncoder. Bytes encoded = RlpTransactionProvider.encodeOpaqueBytes(transaction); @@ -86,7 +82,7 @@ public class BlobTransactionEncodingTest { assertThat(encoded.toHexString()).isEqualTo(bytes.toHexString()); final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput(); - new MainnetTransactionEncoder().encodeRLP(transaction.getType(), bytes, rlpOutput); + new MainnetTransactionEncoder().encodeRLP(transaction.getType(), bytes, rlpOutput); assertThat(transaction.getSize()).isEqualTo(bytes.size()); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPDecoderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPDecoderTest.java index 4c8d3c5510..ba3203bd85 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPDecoderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPDecoderTest.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; -import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPException; @@ -71,9 +70,7 @@ class TransactionRLPDecoderTest { final String txWithBigFees = "0x02f84e0101a1648a5f8b2dcad5ea5ba6b720ff069c1d87c21a4a6a5b3766b39e2c2792367bb066a1ffa5ffaf5b0560d3a9fb186c2ede2ae6751bc0b4fef9107cf36389630b6196a38805800180c0010203"; assertThatThrownBy( - () -> - RlpTransactionProvider.decodeOpaqueBytes( - Bytes.fromHexString(txWithBigFees))) + () -> RlpTransactionProvider.decodeOpaqueBytes(Bytes.fromHexString(txWithBigFees))) .isInstanceOf(RLPException.class); } @@ -118,8 +115,7 @@ class TransactionRLPDecoderTest { final Bytes bytes = Bytes.fromHexString(rlp_tx); // Decode bytes into a transaction final Transaction transaction = decodeRLP(RLP.input(bytes)); - Bytes transactionBytes = - RlpPooledTransactionProvider.encodeOpaqueBytes(transaction); + Bytes transactionBytes = RlpPooledTransactionProvider.encodeOpaqueBytes(transaction); // Bytes size should be equal to transaction size assertThat(transaction.getSize()).isEqualTo(transactionBytes.size()); } @@ -147,13 +143,16 @@ class TransactionRLPDecoderTest { } @Test - void shouldHaveDecodersForAllTransactionTypes(){ + void shouldHaveDecodersForAllTransactionTypes() { Stream.of(TransactionType.values()) - .filter(v -> v != TransactionType.FRONTIER).forEach( v -> { - assertThatNoException().isThrownBy(() -> new MainnetTransactionDecoder().getDecoder(v)); - assertThatNoException().isThrownBy(() -> new PooledMainnetTransactionDecoder().getDecoder(v)); - } - ); + .filter(v -> v != TransactionType.FRONTIER) + .forEach( + v -> { + assertThatNoException() + .isThrownBy(() -> new MainnetTransactionDecoder().getDecoder(v)); + assertThatNoException() + .isThrownBy(() -> new PooledMainnetTransactionDecoder().getDecoder(v)); + }); } private Transaction decodeRLP(final RLPInput input) { diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPEncoderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPEncoderTest.java index 9484823a5e..73ddc67f7f 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPEncoderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/encoding/TransactionRLPEncoderTest.java @@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.core.encoding; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatNoException; -import java.util.stream.Stream; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; @@ -28,6 +27,8 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; +import java.util.stream.Stream; + import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; @@ -80,13 +81,16 @@ class TransactionRLPEncoderTest { } @Test - void shouldHaveEncodersForAllTransactionTypes(){ + void shouldHaveEncodersForAllTransactionTypes() { Stream.of(TransactionType.values()) - .filter(v -> v != TransactionType.FRONTIER).forEach( v -> { - assertThatNoException().isThrownBy(() -> new MainnetTransactionEncoder().getEncoder(v)); - assertThatNoException().isThrownBy(() -> new PooledMainnetTransactionEncoder().getEncoder(v)); - } - ); + .filter(v -> v != TransactionType.FRONTIER) + .forEach( + v -> { + assertThatNoException() + .isThrownBy(() -> new MainnetTransactionEncoder().getEncoder(v)); + assertThatNoException() + .isThrownBy(() -> new PooledMainnetTransactionEncoder().getEncoder(v)); + }); } private Transaction decodeRLP(final RLPInput input) { diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java index 1db6699811..6bd60dc18f 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactoryTest.java @@ -65,7 +65,8 @@ public class FixedKeySigningPrivateMarkerTransactionFactoryTest { .build(); final Transaction transaction = - RlpTransactionProvider.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + RlpTransactionProvider.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); assertThat(transaction.getNonce()).isEqualTo(providedNonce); assertThat(transaction.getGasLimit()).isEqualTo(gasLimit); @@ -77,7 +78,8 @@ public class FixedKeySigningPrivateMarkerTransactionFactoryTest { assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey)); final Transaction nextTransaction = - RlpTransactionProvider.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + RlpTransactionProvider.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); assertThat(nextTransaction.getSender()).isEqualTo(transaction.getSender()); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java index b5f758dfb7..072fb6af10 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactoryTest.java @@ -61,7 +61,8 @@ public class RandomSigningPrivateMarkerTransactionFactoryTest { new RandomSigningPrivateMarkerTransactionFactory(); final Transaction transaction = - RlpTransactionProvider.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + RlpTransactionProvider.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); assertThat(transaction.getNonce()).isEqualTo(0); assertThat(transaction.getGasLimit()).isEqualTo(gasLimit); @@ -71,7 +72,8 @@ public class RandomSigningPrivateMarkerTransactionFactoryTest { assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey)); final Transaction nextTransaction = - RlpTransactionProvider.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); + RlpTransactionProvider.readFrom( + factory.create(unsignedPrivateMarkerTransaction, privTransaction, "")); assertThat(nextTransaction.getSender()).isNotEqualTo(transaction.getSender()); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java index cdb7163193..8dbb2db75f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthServer.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; - import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.messages.BlockBodiesMessage; import org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java index 14a7e1ca0f..1f2ef39948 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/messages/PooledTransactionsMessage.java @@ -15,8 +15,6 @@ package org.hyperledger.besu.ethereum.eth.messages; import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; - import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.AbstractMessageData; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; @@ -43,9 +41,7 @@ public final class PooledTransactionsMessage extends AbstractMessageData { public static PooledTransactionsMessage create(final List transactions) { final BytesValueRLPOutput out = new BytesValueRLPOutput(); - out.writeList( - transactions, - RlpPooledTransactionProvider::writeTo); + out.writeList(transactions, RlpPooledTransactionProvider::writeTo); return new PooledTransactionsMessage(out.encoded()); } @@ -76,9 +72,7 @@ public final class PooledTransactionsMessage extends AbstractMessageData { public List transactions() { if (pooledTransactions == null) { final BytesValueRLPInput in = new BytesValueRLPInput(getData(), false); - pooledTransactions = - in.readList( - RlpPooledTransactionProvider::readFrom); + pooledTransactions = in.readList(RlpPooledTransactionProvider::readFrom); } return pooledTransactions; } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java index b7a82c2009..09124603c3 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java @@ -799,8 +799,9 @@ public class TransactionPool implements BlockAddedObserver { allTxs.parallelStream() .takeWhile(unused -> !isCancelled.get()) .map( - ptx -> (ptx.isReceivedFromLocalSource() ? "l" : "r") - + ptx.getTransaction().encoded().toBase64String()) + ptx -> + (ptx.isReceivedFromLocalSource() ? "l" : "r") + + ptx.getTransaction().encoded().toBase64String()) .mapToInt( line -> { synchronized (bw) { @@ -841,7 +842,8 @@ public class TransactionPool implements BlockAddedObserver { line -> { final boolean isLocal = line.charAt(0) == 'l'; final Transaction tx = - RlpTransactionProvider.readFrom(Bytes.fromBase64String(line.substring(1))); + RlpTransactionProvider.readFrom( + Bytes.fromBase64String(line.substring(1))); final ValidationResult result = addTransaction(tx, isLocal); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java index 7ad3713531..248edce5d3 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java @@ -234,8 +234,7 @@ public class LayeredPendingTransactions implements PendingTransactions { .addArgument(pendingTransaction.getNonce()) .addArgument(pendingTransaction.getTransaction().getType()) .addArgument(pendingTransaction::getHash) - .addArgument( - () -> pendingTransaction.getTransaction().encoded().toHexString()) + .addArgument(() -> pendingTransaction.getTransaction().encoded().toHexString()) .log(); } @@ -251,17 +250,14 @@ public class LayeredPendingTransactions implements PendingTransactions { .addArgument(pendingTransaction.getNonce()) .addArgument(pendingTransaction.getTransaction().getType()) .addArgument(pendingTransaction::getHash) - .addArgument( - () -> pendingTransaction.getTransaction().encoded().toHexString()) + .addArgument(() -> pendingTransaction.getTransaction().encoded().toHexString()) .log(); LOG.atInfo() .addMarker(INVALID_TX_REMOVED) .addKeyValue("txhash", pendingTransaction::getHash) .addKeyValue("txlog", pendingTransaction::toTraceLog) .addKeyValue("reason", result) - .addKeyValue( - "txrlp", - () -> pendingTransaction.getTransaction().encoded().toHexString()) + .addKeyValue("txrlp", () -> pendingTransaction.getTransaction().encoded().toHexString()) .log(); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java index c804ceb8b7..d026cdf0ac 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java @@ -36,7 +36,6 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionAddedResult; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolReplacementHandler; import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; -import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.metrics.BesuMetricCategory; @@ -276,9 +275,7 @@ public abstract class AbstractPendingTransactionsSorter implements PendingTransa .addKeyValue("txhash", pendingTransaction::getHash) .addKeyValue("txlog", pendingTransaction::toTraceLog) .addKeyValue("reason", result) - .addKeyValue( - "txrlp", - () -> pendingTransaction.getTransaction().encoded().toHexString()) + .addKeyValue("txrlp", () -> pendingTransaction.getTransaction().encoded().toHexString()) .log(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionEstimatedMemorySizeTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionEstimatedMemorySizeTest.java index a527995726..82f3682295 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionEstimatedMemorySizeTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionEstimatedMemorySizeTest.java @@ -25,9 +25,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; - import org.hyperledger.besu.ethereum.core.encoding.registry.RlpTransactionProvider; -import org.hyperledger.besu.ethereum.core.encoding.registry.RlpPooledTransactionProvider; import org.hyperledger.besu.ethereum.eth.transactions.layered.BaseTransactionPoolTest; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; @@ -76,7 +74,9 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo BytesValueRLPOutput rlpOut = new BytesValueRLPOutput(); RlpTransactionProvider.writeTo(txTo, rlpOut); - txTo = RlpTransactionProvider.readFrom(new BytesValueRLPInput(rlpOut.encoded(), false)).detachedCopy(); + txTo = + RlpTransactionProvider.readFrom(new BytesValueRLPInput(rlpOut.encoded(), false)) + .detachedCopy(); System.out.println(txTo.getSender()); System.out.println(txTo.getHash()); System.out.println(txTo.getSize()); @@ -120,7 +120,8 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo Transaction txPayload = preparedTx.createTransaction(KEYS1); txPayload = - RlpTransactionProvider.readFrom(new BytesValueRLPInput(txPayload.encoded(), false)).detachedCopy(); + RlpTransactionProvider.readFrom(new BytesValueRLPInput(txPayload.encoded(), false)) + .detachedCopy(); System.out.println(txPayload.getSender()); System.out.println(txPayload.getHash()); System.out.println(txPayload.getSize()); @@ -212,8 +213,7 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo RlpPooledTransactionProvider.writeTo(txBlob, rlpOut); txBlob = - RlpPooledTransactionProvider.readFrom( - new BytesValueRLPInput(rlpOut.encoded(), false)) + RlpPooledTransactionProvider.readFrom(new BytesValueRLPInput(rlpOut.encoded(), false)) .detachedCopy(); System.out.println(txBlob.getSender()); System.out.println(txBlob.getHash()); @@ -244,8 +244,7 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo RlpPooledTransactionProvider.writeTo(txBlob, rlpOut); txBlob = - RlpPooledTransactionProvider.readFrom( - new BytesValueRLPInput(rlpOut.encoded(), false)) + RlpPooledTransactionProvider.readFrom(new BytesValueRLPInput(rlpOut.encoded(), false)) .detachedCopy(); System.out.println(txBlob.getSender()); System.out.println(txBlob.getHash()); @@ -271,7 +270,8 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo Transaction txPayload = preparedTx.createTransaction(KEYS1); txPayload = - RlpTransactionProvider.readFrom(new BytesValueRLPInput(txPayload.encoded(), false)).detachedCopy(); + RlpTransactionProvider.readFrom(new BytesValueRLPInput(txPayload.encoded(), false)) + .detachedCopy(); System.out.println(txPayload.getSender()); System.out.println(txPayload.getHash()); System.out.println(txPayload.getSize()); @@ -301,7 +301,8 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo Transaction txAccessList = preparedTx.accessList(ales).createTransaction(KEYS1); txAccessList = - RlpTransactionProvider.readFrom(new BytesValueRLPInput(txAccessList.encoded(), false)).detachedCopy(); + RlpTransactionProvider.readFrom(new BytesValueRLPInput(txAccessList.encoded(), false)) + .detachedCopy(); System.out.println(txAccessList.getSender()); System.out.println(txAccessList.getHash()); System.out.println(txAccessList.getSize()); @@ -341,7 +342,8 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo Transaction txEip1559 = createEIP1559Transaction(1, KEYS1, 10); txEip1559 = - RlpTransactionProvider.readFrom(new BytesValueRLPInput(txEip1559.encoded(), false)).detachedCopy(); + RlpTransactionProvider.readFrom(new BytesValueRLPInput(txEip1559.encoded(), false)) + .detachedCopy(); System.out.println(txEip1559.getSender()); System.out.println(txEip1559.getHash()); System.out.println(txEip1559.getSize()); @@ -383,7 +385,8 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo Transaction txFrontier = createTransaction(TransactionType.FRONTIER, 1, Wei.of(500), 0, KEYS1); txFrontier = - RlpTransactionProvider.readFrom(new BytesValueRLPInput(txFrontier.encoded(), false)).detachedCopy(); + RlpTransactionProvider.readFrom(new BytesValueRLPInput(txFrontier.encoded(), false)) + .detachedCopy(); System.out.println(txFrontier.getSender()); System.out.println(txFrontier.getHash()); System.out.println(txFrontier.getSize()); diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java index b58fcbb247..ab986f5472 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/T8nExecutor.java @@ -147,7 +147,8 @@ public class T8nExecutor { } else if (txNode.isObject()) { if (txNode.has("txBytes")) { Transaction tx = - RlpTransactionProvider.readFrom(Bytes.fromHexString(txNode.get("txbytes").asText())); + RlpTransactionProvider.readFrom( + Bytes.fromHexString(txNode.get("txbytes").asText())); transactions.add(tx); } else { Transaction.Builder builder = Transaction.builder();