Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into print-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfyone committed Jan 27, 2025
2 parents 53a0b0f + e44a47c commit b6d50e7
Show file tree
Hide file tree
Showing 18 changed files with 453 additions and 28 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import com.github.jk1.license.filter.LicenseBundleNormalizer
import groovy.json.JsonSlurper
import tech.pegasys.internal.license.reporter.GroupedLicenseHtmlRenderer
import tech.pegasys.teku.depcheck.DepCheckPlugin

import java.text.SimpleDateFormat

import groovy.json.JsonSlurper

import static tech.pegasys.teku.repackage.Repackage.repackage

buildscript {
Expand Down Expand Up @@ -325,7 +324,7 @@ allprojects {
}

def nightly = System.getenv("NIGHTLY") != null
def refTestVersion = nightly ? "nightly" : "v1.5.0-alpha.10"
def refTestVersion = nightly ? "nightly" : "v1.5.0-beta.0"
def blsRefTestVersion = 'v0.1.2'
def slashingProtectionInterchangeRefTestVersion = 'v5.3.0'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void verifyBlocksWithReferenceState(
block.getParentRoot().equals(previousArchiveLastBlock.getRoot()),
"First block in archive does not match last block of previous archive.");
}
// TODO should verify signature
// when fully implemented, we would check signature also
++populatedSlots;
}
System.out.println(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public abstract class Eth2ReferenceTestCase {
.put("light_client/single_merkle_proof", TestExecutor.IGNORE_TESTS)
.put("light_client/sync", TestExecutor.IGNORE_TESTS)
.put("light_client/update_ranking", TestExecutor.IGNORE_TESTS)
.put("light_client/data_collection", TestExecutor.IGNORE_TESTS)
.build();

private static final ImmutableMap<String, TestExecutor> PHASE_0_TEST_TYPES =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void changeSpecConfigTest() {

@Test
void roundTripViaSsz() {
// TODO - generate random version-specific state
BeaconState beaconState = randomState();
Bytes bytes = beaconState.sszSerialize();
BeaconState state = schema.sszDeserialize(bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ public void finishInitializingChainData() {
log.info("Storage initialization complete");
}

public void emptyChainData() {
log.info("Empty storage. Initialization complete.");
}

public void recordedFinalizedBlocks(final int numberRecorded, final int totalToRecord) {
log.info("Recorded {} of {} finalized blocks", numberRecorded, totalToRecord);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ default SszCollectionT createFromElements(final List<? extends SszElementT> elem
}

default TreeNode createTreeFromElements(final List<? extends SszElementT> elements) {
// TODO: probably suboptimal method implementation:
// https://github.com/Consensys/teku/issues/9035
// This is a generic implementation which works for both Vector and List but it potentially
// could do better if construct the tree directly in List/Vector subclasses
checkArgument(elements.size() <= getMaxLength(), "Too many elements for this collection type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class ScoringConfig {

private ScoringConfig(final Spec spec, final int d) {
this.spec = spec;
// TODO(#3356) Use spec provider through-out rather than relying only on genesis constants and
// genesis spec
this.genesisConfig = spec.getGenesisSpecConfig();
this.genesisSpec = spec.getGenesisSpec();
this.d = d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ protected Host createHost(final PrivKey privKey, final List<Multiaddr> advertise
b.getTransports().add(TcpTransport::new);
b.getSecureChannels().add(NoiseXXSecureChannel::new);

// yamux MUST take precedence during negotiation
// Yamux must take precedence during negotiation
if (config.isYamuxEnabled()) {
// TODO: https://github.com/Consensys/teku/issues/7532
// https://github.com/Consensys/teku/issues/7532
final int maxBufferedConnectionWrites = 150 * 1024 * 1024;
b.getMuxers().add(StreamMuxerProtocol.getYamux(maxBufferedConnectionWrites));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private SafeFuture<RecentChainData> processStoreFuture(
return storeFuture.thenApply(
maybeData -> {
if (maybeData.isEmpty()) {
STATUS_LOG.finishInitializingChainData();
STATUS_LOG.emptyChainData();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.
*/

package tech.pegasys.teku.storage.server.leveldb;

import org.iq80.leveldb.DBIterator;

/**
* This interface extends the DBIterator interface to provide additional methods for peeking at the
* next key which are used to avoid unnecessary value allocations
*/
public interface CustomDBIterator extends DBIterator {

byte[] peekNextKey();

byte[] nextKey();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.
*/

package tech.pegasys.teku.storage.server.leveldb;

import org.fusesource.leveldbjni.internal.JniDB;
import org.fusesource.leveldbjni.internal.NativeCache;
import org.fusesource.leveldbjni.internal.NativeComparator;
import org.fusesource.leveldbjni.internal.NativeDB;
import org.fusesource.leveldbjni.internal.NativeLogger;
import org.fusesource.leveldbjni.internal.NativeReadOptions;
import org.iq80.leveldb.DBException;
import org.iq80.leveldb.DBIterator;
import org.iq80.leveldb.ReadOptions;

/** This class extends the JniDB class to provide a custom DBIterator. */
public class CustomJniDB extends JniDB {
private final NativeDB db;

public CustomJniDB(
final NativeDB db,
final NativeCache cache,
final NativeComparator comparator,
final NativeLogger logger) {
super(db, cache, comparator, logger);
this.db = db;
}

@Override
public DBIterator iterator(final ReadOptions options) {
if (this.db == null) {
throw new DBException("Closed");
} else {
return new CustomJniDBIterator(this.db.iterator(this.convert(options)));
}
}

// this method is private in the super class, so has been copied here
private NativeReadOptions convert(final ReadOptions options) {
if (options == null) {
return null;
} else {
NativeReadOptions rc = new NativeReadOptions();
rc.fillCache(options.fillCache());
rc.verifyChecksums(options.verifyChecksums());
if (options.snapshot() != null) {
throw new UnsupportedOperationException("Snapshots are not supported");
}

return rc;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.
*/

package tech.pegasys.teku.storage.server.leveldb;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import org.fusesource.leveldbjni.JniDBFactory;
import org.fusesource.leveldbjni.internal.NativeCache;
import org.fusesource.leveldbjni.internal.NativeComparator;
import org.fusesource.leveldbjni.internal.NativeCompressionType;
import org.fusesource.leveldbjni.internal.NativeDB;
import org.fusesource.leveldbjni.internal.NativeLogger;
import org.fusesource.leveldbjni.internal.NativeOptions;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBComparator;
import org.iq80.leveldb.Logger;
import org.iq80.leveldb.Options;

/**
* This class extends the JniDBFactory class to provide a custom DBIterator. Only {@link
* CustomJniDBFactory#open} has been changed from the original class
*/
@SuppressWarnings("EmptyCatch")
public class CustomJniDBFactory extends JniDBFactory {
public static final CustomJniDBFactory FACTORY = new CustomJniDBFactory();
public static final String VERSION;

@Override
public DB open(final File path, final Options options) throws IOException {
final OptionsResourceHolder holder = new OptionsResourceHolder();

NativeDB db = null;
try {
holder.init(options);
db = NativeDB.open(holder.options, path);
} finally {
if (db == null) {
holder.close();
}
}

// this is the only line that has been functionally changed from the original class
return new CustomJniDB(db, holder.cache, holder.comparator, holder.logger);
}

static {
NativeDB.LIBRARY.load();
String v = "unknown";

try (final InputStream is = JniDBFactory.class.getResourceAsStream("version.txt")) {
if (is != null) {
try (final BufferedReader reader =
new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
v = reader.readLine();
}
}
} catch (final Throwable ignored) {
}

VERSION = v;
}

private static class OptionsResourceHolder {
NativeCache cache;
NativeComparator comparator;
NativeLogger logger;
NativeOptions options;

private OptionsResourceHolder() {
this.cache = null;
this.comparator = null;
this.logger = null;
}

private void init(final Options value) {
this.options = new NativeOptions();
this.options.blockRestartInterval(value.blockRestartInterval());
this.options.blockSize((long) value.blockSize());
this.options.createIfMissing(value.createIfMissing());
this.options.errorIfExists(value.errorIfExists());
this.options.maxOpenFiles(value.maxOpenFiles());
this.options.paranoidChecks(value.paranoidChecks());
this.options.writeBufferSize((long) value.writeBufferSize());
switch (value.compressionType()) {
case NONE:
this.options.compression(NativeCompressionType.kNoCompression);
break;
case SNAPPY:
this.options.compression(NativeCompressionType.kSnappyCompression);
}

if (value.cacheSize() > 0L) {
this.cache = new NativeCache(value.cacheSize());
this.options.cache(this.cache);
}

final DBComparator userComparator = value.comparator();
if (userComparator != null) {
this.comparator =
new NativeComparator() {
@Override
public int compare(final byte[] key1, final byte[] key2) {
return userComparator.compare(key1, key2);
}

@Override
public String name() {
return userComparator.name();
}
};
this.options.comparator(this.comparator);
}

final Logger userLogger = value.logger();
if (userLogger != null) {
this.logger =
new NativeLogger() {
@Override
public void log(final String message) {
userLogger.log(message);
}
};
this.options.infoLog(this.logger);
}
}

private void close() {
if (this.cache != null) {
this.cache.delete();
}

if (this.comparator != null) {
this.comparator.delete();
}

if (this.logger != null) {
this.logger.delete();
}
}
}
}
Loading

0 comments on commit b6d50e7

Please sign in to comment.