Skip to content

Commit

Permalink
Merge branch 'main' into update-gradle-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
fab-10 committed Dec 13, 2023
2 parents f4d3760 + 0f89356 commit 3e4dc7c
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 65 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
Original file line number Diff line number Diff line change
Expand Up @@ -3246,7 +3246,7 @@ private List<EnodeURL> buildEnodes(
}

/**
* Besu CLI Paramaters exception handler used by VertX. Visible for testing.
* Besu CLI Parameters exception handler used by VertX. Visible for testing.
*
* @return instance of BesuParameterExceptionHandler
*/
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ public void nodeAllowlistCheckShouldNotWorkWithUnknownHostnameWhenOnlyDnsEnabled
true,
toml.toAbsolutePath().toString()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false.");
.hasMessageContaining("Invalid IP address");
}
}
2 changes: 1 addition & 1 deletion besu/src/test/resources/everything_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ tx-pool-save-file="txpool.dump"
tx-pool-layer-max-capacity=12345678
tx-pool-max-prioritized=9876
tx-pool-max-future-by-sender=321
## Legacy
## Legacy/Sequenced
tx-pool-retention-hours=999
tx-pool-max-size=1234
tx-pool-limit-by-account-percentage=0.017
Expand Down
2 changes: 2 additions & 0 deletions config/src/main/resources/classic.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"thanosBlock": 11700000,
"magnetoBlock": 13189133,
"mystiqueBlock": 14525000,
"spiralBlock": 19250000,
"ethash": {

},
"discovery" : {
"dns": "enrtree://AJE62Q4DUX4QMMXEHCSSCSC65TDHZYSMONSD64P3WULVLSF6MRQ3K@all.classic.blockd.info",
"bootnodes" : [
"enode://8e73168affd8d445edda09c561d607081ca5d7963317caae2702f701eb6546b06948b7f8687a795de576f6a5f33c44828e25a90aa63de18db380a11e660dd06f@159.203.37.80:30303",
"enode://2b1ef75e8b7119b6e0294f2e51ead2cf1a5400472452c199e9587727ada99e7e2b1199e36adcad6cbae65dce2410559546e4d83d8c93d45a559e723e56444c03@67.207.93.100:30303",
Expand Down
3 changes: 0 additions & 3 deletions crypto/services/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ dependencies {
api project(':crypto:algorithms')
api project(':plugin-api')

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

artifacts { testSupportArtifacts testSupportJar }
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,22 @@
import org.hyperledger.besu.crypto.SECPPublicKey;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.security.spec.ECPoint;

import org.apache.tuweni.bytes.Bytes;
import org.assertj.core.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class KeyPairSecurityModuleTest {

@Rule public final TemporaryFolder temp = new TemporaryFolder();
@TempDir public Path keyFile;

@Test
public void validatePublicKeyFromECPointCanBeConstructed() throws IOException {
final File keyDirectory = temp.newFolder();
final File keyFile = new File(keyDirectory, "key");

final KeyPair keyPair = KeyPairUtil.loadKeyPair(keyFile);
final KeyPair keyPair = KeyPairUtil.loadKeyPair(keyFile.resolve("key"));

final KeyPairSecurityModule keyPairSecurityModule = new KeyPairSecurityModule(keyPair);
final ECPoint ecPoint = keyPairSecurityModule.getPublicKey().getW();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class NodeKeyTest {

@Before
@BeforeEach
public void resetInstance() {
SignatureAlgorithmFactory.resetInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Optional;

import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
Expand All @@ -46,6 +47,10 @@

public class WebSocketMessageHandler {

private static final ObjectMapper jsonObjectMapper =
new ObjectMapper()
.registerModule(new Jdk8Module()); // Handle JDK8 Optionals (de)serialization

private static final Logger LOG = LoggerFactory.getLogger(WebSocketMessageHandler.class);
private static final ObjectWriter JSON_OBJECT_WRITER =
new ObjectMapper()
Expand Down Expand Up @@ -161,6 +166,7 @@ public void handle(
}

private void replyToClient(final ServerWebSocket websocket, final Object result) {
traceResponse(result);
try {
// underlying output stream lifecycle is managed by the json object writer
JSON_OBJECT_WRITER.writeValue(new JsonResponseStreamer(websocket), result);
Expand All @@ -172,4 +178,12 @@ private void replyToClient(final ServerWebSocket websocket, final Object result)
private JsonRpcResponse errorResponse(final Object id, final RpcErrorType error) {
return new JsonRpcErrorResponse(id, error);
}

private void traceResponse(final Object response) {
try {
LOG.trace(jsonObjectMapper.writeValueAsString(response));
} catch (JsonProcessingException e) {
LOG.error("Error tracing JSON-RPC response", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ private void updateAccountStorageState(
worldStateUpdater.getAccountsToUpdate().get(updatedAddress);
final BonsaiAccount accountOriginal = accountValue.getPrior();
final Hash storageRoot =
(accountOriginal == null) ? Hash.EMPTY_TRIE_HASH : accountOriginal.getStorageRoot();
(accountOriginal == null
|| worldStateUpdater.getStorageToClear().contains(updatedAddress))
? Hash.EMPTY_TRIE_HASH
: accountOriginal.getStorageRoot();
final StoredMerklePatriciaTrie<Bytes, Bytes> storageTrie =
createTrie(
(location, key) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,6 @@ public void commit() {
}
if (tracked.getStorageWasCleared()) {
updatedAccount.clearStorage();
wrappedWorldView()
.getAllAccountStorage(updatedAddress, updatedAccount.getStorageRoot())
.forEach(
(keyHash, entryValue) -> {
final StorageSlotKey storageSlotKey =
new StorageSlotKey(Hash.wrap(keyHash), Optional.empty());
final UInt256 value = UInt256.fromBytes(RLP.decodeOne(entryValue));
pendingStorageUpdates.put(
storageSlotKey, new BonsaiValue<>(value, null, true));
});
updatedAccount.setStorageRoot(Hash.EMPTY_TRIE_HASH);
}
tracked.getUpdatedStorage().forEach(updatedAccount::setStorageValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ default int getTxMessageKeepAliveSeconds() {
}

enum Implementation {
LEGACY,
LAYERED;
LEGACY, // Remove in future version
LAYERED,
SEQUENCED; // Synonym for LEGACY
}

String DEFAULT_SAVE_FILE_NAME = "txpool.dump";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public static EnodeURL fromString(
String message = "";
if (enodeDnsConfiguration.dnsEnabled() && !enodeDnsConfiguration.updateEnabled()) {
message =
"Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false.";
String.format(
"Invalid IP address '%s' (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false.",
value);
} else {
message =
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static class NonDeterministicOperationException extends RuntimeException
public Comparator<BlockHeader> getBlockChoiceRule() {
return (a, b) -> {
throw new NonDeterministicOperationException(
"ReferenceTestBlockchian for VMTest Chains do not support fork choice rules");
"ReferenceTestBlockchain for VMTest Chains do not support fork choice rules");
};
}

Expand Down
Loading

0 comments on commit 3e4dc7c

Please sign in to comment.