Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into code_storage_by_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
jframe committed Dec 13, 2023
2 parents 9a61020 + 7770f96 commit b5b4601
Show file tree
Hide file tree
Showing 19 changed files with 337 additions and 60 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

### Additions and Improvements
- Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212)
- New `Sequenced` transaction pool. The pool is an evolution of the `legacy` pool and is likely to be more suitable to enterprise or permissioned chains than the `layered` transaction pool. Select to use this pool with `--tx-pool=sequenced`. Supports the same options as the `legacy` pool [#6211](https://github.com/hyperledger/besu/issues/6211)
- Set Ethereum Classic mainnet activation block for Spiral network upgrade [#6267](https://github.com/hyperledger/besu/pull/6267)

### Bug fixes

Expand Down
3 changes: 3 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.hyperledger.besu.cli.subcommands.PasswordSubCommand;
import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand;
import org.hyperledger.besu.cli.subcommands.RetestethSubCommand;
import org.hyperledger.besu.cli.subcommands.TxParseSubCommand;
import org.hyperledger.besu.cli.subcommands.ValidateConfigSubCommand;
import org.hyperledger.besu.cli.subcommands.blocks.BlocksSubCommand;
import org.hyperledger.besu.cli.subcommands.operator.OperatorSubCommand;
Expand Down Expand Up @@ -1493,6 +1494,8 @@ private void addSubCommands(final InputStream in) {
jsonBlockImporterFactory,
rlpBlockExporterFactory,
commandLine.getOut()));
commandLine.addSubcommand(
TxParseSubCommand.COMMAND_NAME, new TxParseSubCommand(commandLine.getOut()));
commandLine.addSubcommand(
PublicKeySubCommand.COMMAND_NAME, new PublicKeySubCommand(commandLine.getOut()));
commandLine.addSubcommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_LONG_FORMAT_HELP;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED;

import org.hyperledger.besu.cli.converter.DurationMillisConverter;
import org.hyperledger.besu.cli.converter.FractionConverter;
Expand Down Expand Up @@ -171,10 +172,10 @@ static class Layered {

@CommandLine.ArgGroup(
validate = false,
heading = "@|bold Tx Pool Legacy Implementation Options|@%n")
private final Legacy legacyOptions = new Legacy();
heading = "@|bold Tx Pool Sequenced Implementation Options|@%n")
private final Sequenced sequencedOptions = new Sequenced();

static class Legacy {
static class Sequenced {
private static final String TX_POOL_RETENTION_HOURS = "--tx-pool-retention-hours";
private static final String TX_POOL_LIMIT_BY_ACCOUNT_PERCENTAGE =
"--tx-pool-limit-by-account-percentage";
Expand Down Expand Up @@ -272,10 +273,10 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati
config.getPendingTransactionsLayerMaxCapacityBytes();
options.layeredOptions.txPoolMaxPrioritized = config.getMaxPrioritizedTransactions();
options.layeredOptions.txPoolMaxFutureBySender = config.getMaxFutureBySender();
options.legacyOptions.txPoolLimitByAccountPercentage =
options.sequencedOptions.txPoolLimitByAccountPercentage =
config.getTxPoolLimitByAccountPercentage();
options.legacyOptions.txPoolMaxSize = config.getTxPoolMaxSize();
options.legacyOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod();
options.sequencedOptions.txPoolMaxSize = config.getTxPoolMaxSize();
options.sequencedOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod();
options.unstableOptions.txMessageKeepAliveSeconds =
config.getUnstable().getTxMessageKeepAliveSeconds();
options.unstableOptions.eth65TrxAnnouncedBufferingPeriod =
Expand All @@ -295,14 +296,14 @@ public void validate(
final CommandLine commandLine, final GenesisConfigOptions genesisConfigOptions) {
CommandLineUtils.failIfOptionDoesntMeetRequirement(
commandLine,
"Could not use legacy transaction pool options with layered implementation",
"Could not use legacy or sequenced transaction pool options with layered implementation",
!txPoolImplementation.equals(LAYERED),
CommandLineUtils.getCLIOptionNames(Legacy.class));
CommandLineUtils.getCLIOptionNames(Sequenced.class));

CommandLineUtils.failIfOptionDoesntMeetRequirement(
commandLine,
"Could not use layered transaction pool options with legacy implementation",
!txPoolImplementation.equals(LEGACY),
"Could not use layered transaction pool options with legacy or sequenced implementation",
!txPoolImplementation.equals(LEGACY) && !txPoolImplementation.equals(SEQUENCED),
CommandLineUtils.getCLIOptionNames(Layered.class));

CommandLineUtils.failIfOptionDoesntMeetRequirement(
Expand All @@ -327,9 +328,9 @@ public TransactionPoolConfiguration toDomainObject() {
.pendingTransactionsLayerMaxCapacityBytes(layeredOptions.txPoolLayerMaxCapacity)
.maxPrioritizedTransactions(layeredOptions.txPoolMaxPrioritized)
.maxFutureBySender(layeredOptions.txPoolMaxFutureBySender)
.txPoolLimitByAccountPercentage(legacyOptions.txPoolLimitByAccountPercentage)
.txPoolMaxSize(legacyOptions.txPoolMaxSize)
.pendingTxRetentionPeriod(legacyOptions.pendingTxRetentionPeriod)
.txPoolLimitByAccountPercentage(sequencedOptions.txPoolLimitByAccountPercentage)
.txPoolMaxSize(sequencedOptions.txPoolMaxSize)
.pendingTxRetentionPeriod(sequencedOptions.pendingTxRetentionPeriod)
.unstable(
ImmutableTransactionPoolConfiguration.Unstable.builder()
.txMessageKeepAliveSeconds(unstableOptions.txMessageKeepAliveSeconds)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* 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.cli.subcommands;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hyperledger.besu.cli.subcommands.TxParseSubCommand.COMMAND_NAME;

import org.hyperledger.besu.cli.util.VersionProvider;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.ethereum.core.encoding.EncodingContext;
import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

import org.apache.tuweni.bytes.Bytes;
import picocli.CommandLine;

/**
* txparse sub command implementing txparse spec from
* https://github.com/holiman/txparse/tree/main/cmd/txparse
*/
@CommandLine.Command(
name = COMMAND_NAME,
description = "Parse input transactions and return the sender, or an error.",
mixinStandardHelpOptions = true,
versionProvider = VersionProvider.class)
public class TxParseSubCommand implements Runnable {

/** The constant COMMAND_NAME. */
public static final String COMMAND_NAME = "txparse";

@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
@CommandLine.Option(
names = "--corpus-file",
arity = "1..1",
description = "file to read transaction data lines from, otherwise defaults to stdin")
private String corpusFile = null;

static final BigInteger halfCurveOrder =
SignatureAlgorithmFactory.getInstance().getHalfCurveOrder();
static final BigInteger chainId = new BigInteger("1", 10);

private final PrintWriter out;

/**
* Instantiates a new TxParse sub command.
*
* @param out the PrintWriter where validation results will be reported.
*/
public TxParseSubCommand(final PrintWriter out) {
this.out = out;
}

@SuppressWarnings("StreamResourceLeak")
Stream<String> fileStreamReader(final String filePath) {
try {
return Files.lines(Paths.get(filePath))
// skip comments
.filter(line -> !line.startsWith("#"))
// strip out non-alphanumeric characters
.map(line -> line.replaceAll("[^a-zA-Z0-9]", ""));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}

@Override
public void run() {

Stream<String> txStream;
if (corpusFile != null) {
txStream = fileStreamReader(corpusFile);
} else {
txStream = new BufferedReader(new InputStreamReader(System.in, UTF_8)).lines();
}

txStream.forEach(
line -> {
try {
Bytes bytes = Bytes.fromHexStringLenient(line);
dump(bytes);
} catch (Exception ex) {
err(ex.getMessage());
}
});
}

void dump(final Bytes tx) {
try {
var transaction = TransactionDecoder.decodeOpaqueBytes(tx, EncodingContext.BLOCK_BODY);

// https://github.com/hyperledger/besu/blob/5fe49c60b30fe2954c7967e8475c3b3e9afecf35/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java#L252
if (transaction.getChainId().isPresent() && !transaction.getChainId().get().equals(chainId)) {
throw new Exception("wrong chain id");
}

// https://github.com/hyperledger/besu/blob/5fe49c60b30fe2954c7967e8475c3b3e9afecf35/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java#L270
if (transaction.getS().compareTo(halfCurveOrder) > 0) {
throw new Exception("signature s out of range");
}
out.println(transaction.getSender());

} catch (Exception ex) {
err(ex.getMessage());
}
}

void err(final String message) {
out.println("err: " + message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ public static Collection<Object[]> parameters() {
new ForkId(Bytes.ofUnsignedInt(0x9007bfccL), 11700000L),
new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 13189133),
new ForkId(Bytes.ofUnsignedInt(0x0f6bf187L), 14525000L),
new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 0L),
new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 0L))
new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 19250000L),
new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L),
new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L))
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED;
import static org.mockito.Mockito.mock;

import org.hyperledger.besu.evm.internal.EvmConfiguration;
Expand Down Expand Up @@ -180,6 +181,13 @@ void setTxPoolImplementationLegacy() {
assertThat(legacyTxPoolSelected).contains("Using LEGACY transaction pool implementation");
}

@Test
void setTxPoolImplementationSequenced() {
builder.setTxPoolImplementation(SEQUENCED);
final String sequencedTxPoolSelected = builder.build();
assertThat(sequencedTxPoolSelected).contains("Using SEQUENCED transaction pool implementation");
}

@Test
void setWorldStateUpdateModeDefault() {
builder.setWorldStateUpdateMode(EvmConfiguration.DEFAULT.worldUpdaterMode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED;

import org.hyperledger.besu.cli.converter.DurationMillisConverter;
import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -63,7 +64,7 @@ public void strictTxReplayProtection_default() {
}

@Test
public void pendingTransactionRetentionPeriod() {
public void pendingTransactionRetentionPeriodLegacy() {
final int pendingTxRetentionHours = 999;
internalTestSuccess(
config ->
Expand All @@ -73,6 +74,17 @@ public void pendingTransactionRetentionPeriod() {
"--tx-pool=legacy");
}

@Test
public void pendingTransactionRetentionPeriodSequenced() {
final int pendingTxRetentionHours = 999;
internalTestSuccess(
config ->
assertThat(config.getPendingTxRetentionPeriod()).isEqualTo(pendingTxRetentionHours),
"--tx-pool-retention-hours",
String.valueOf(pendingTxRetentionHours),
"--tx-pool=sequenced");
}

@Test
public void disableLocalsDefault() {
internalTestSuccess(config -> assertThat(config.getNoLocalPriority()).isFalse());
Expand Down Expand Up @@ -193,29 +205,44 @@ public void selectLegacyImplementationByArg() {
"--tx-pool=legacy");
}

@Test
public void selectSequencedImplementationByArg() {
internalTestSuccess(
config -> assertThat(config.getTxPoolImplementation()).isEqualTo(SEQUENCED),
"--tx-pool=sequenced");
}

@Test
public void failIfLegacyOptionsWhenLayeredSelectedByDefault() {
internalTestFailure(
"Could not use legacy transaction pool options with layered implementation",
"Could not use legacy or sequenced transaction pool options with layered implementation",
"--tx-pool-max-size=1000");
}

@Test
public void failIfLegacyOptionsWhenLayeredSelectedByArg() {
internalTestFailure(
"Could not use legacy transaction pool options with layered implementation",
"Could not use legacy or sequenced transaction pool options with layered implementation",
"--tx-pool=layered",
"--tx-pool-max-size=1000");
}

@Test
public void failIfLayeredOptionsWhenLegacySelectedByArg() {
internalTestFailure(
"Could not use layered transaction pool options with legacy implementation",
"Could not use layered transaction pool options with legacy or sequenced implementation",
"--tx-pool=legacy",
"--tx-pool-max-prioritized=1000");
}

@Test
public void failIfLayeredOptionsWhenSequencedSelectedByArg() {
internalTestFailure(
"Could not use layered transaction pool options with legacy or sequenced implementation",
"--tx-pool=sequenced",
"--tx-pool-max-prioritized=1000");
}

@Test
public void byDefaultNoPrioritySenders() {
internalTestSuccess(config -> assertThat(config.getPrioritySenders()).isEmpty());
Expand Down
Loading

0 comments on commit b5b4601

Please sign in to comment.