Skip to content

Commit

Permalink
Merge branch 'main' into fix_javadoc_java21_7
Browse files Browse the repository at this point in the history
  • Loading branch information
usmansaleem authored May 8, 2024
2 parents 4dba8f9 + 42e9139 commit 074214d
Show file tree
Hide file tree
Showing 46 changed files with 194 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void recordRequestTimeout(final int requestCode) {
.addArgument(this::getLoggableId)
.log();
LOG.trace("Timed out while waiting for response from peer {}", this);
reputation.recordRequestTimeout(requestCode).ifPresent(this::disconnect);
reputation.recordRequestTimeout(requestCode, this).ifPresent(this::disconnect);
}

public void recordUselessResponse(final String requestType) {
Expand All @@ -224,7 +224,7 @@ public void recordUselessResponse(final String requestType) {
.addArgument(requestType)
.addArgument(this::getLoggableId)
.log();
reputation.recordUselessResponse(System.currentTimeMillis()).ifPresent(this::disconnect);
reputation.recordUselessResponse(System.currentTimeMillis(), this).ifPresent(this::disconnect);
}

public void recordUsefulResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ public PeerReputation(final int initialScore, final int maxScore) {
this.score = initialScore;
}

public Optional<DisconnectReason> recordRequestTimeout(final int requestCode) {
public Optional<DisconnectReason> recordRequestTimeout(
final int requestCode, final EthPeer peer) {
final int newTimeoutCount = getOrCreateTimeoutCount(requestCode).incrementAndGet();
if (newTimeoutCount >= TIMEOUT_THRESHOLD) {
LOG.debug(
"Disconnection triggered by {} repeated timeouts for requestCode {}",
"Disconnection triggered by {} repeated timeouts for requestCode {} for peer {}",
newTimeoutCount,
requestCode);
requestCode,
peer.getLoggableId());
score -= LARGE_ADJUSTMENT;
return Optional.of(DisconnectReason.TIMEOUT);
} else {
Expand All @@ -89,14 +91,17 @@ public Map<Integer, AtomicInteger> timeoutCounts() {
return timeoutCountByRequestType;
}

public Optional<DisconnectReason> recordUselessResponse(final long timestamp) {
public Optional<DisconnectReason> recordUselessResponse(
final long timestamp, final EthPeer peer) {
uselessResponseTimes.add(timestamp);
while (shouldRemove(uselessResponseTimes.peek(), timestamp)) {
uselessResponseTimes.poll();
}
if (uselessResponseTimes.size() >= USELESS_RESPONSE_THRESHOLD) {
score -= LARGE_ADJUSTMENT;
LOG.debug("Disconnection triggered by exceeding useless response threshold");
LOG.debug(
"Disconnection triggered by exceeding useless response threshold for peer {}",
peer.getLoggableId());
return Optional.of(DisconnectReason.USELESS_PEER_USELESS_RESPONSES);
} else {
score -= SMALL_ADJUSTMENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public CompletableFuture<Task<SnapDataRequest>> requestAccount(
accountDataRequest.addResponse(
worldStateProofProvider, response.accounts(), response.proofs());
}
if (error != null) {
LOG.atDebug()
.setMessage("Error handling account download accounts ({} - {}) task: {}")
.addArgument(accountDataRequest.getStartKeyHash())
.addArgument(accountDataRequest.getEndKeyHash())
.addArgument(error)
.log();
}
return requestTask;
});
}
Expand Down Expand Up @@ -167,6 +175,12 @@ public CompletableFuture<List<Task<SnapDataRequest>>> requestStorage(
LOG.error("Error while processing storage range response", e);
}
}
if (error != null) {
LOG.atDebug()
.setMessage("Error handling storage range request task: {}")
.addArgument(error)
.log();
}
return requestTasks;
});
}
Expand Down Expand Up @@ -200,6 +214,12 @@ public CompletableFuture<List<Task<SnapDataRequest>>> requestCode(
}
}
}
if (error != null) {
LOG.atDebug()
.setMessage("Error handling code request task: {}")
.addArgument(error)
.log();
}
return requestTasks;
});
}
Expand Down Expand Up @@ -240,6 +260,12 @@ public CompletableFuture<List<Task<SnapDataRequest>>> requestTrieNodeByPath(
}
}
}
if (error != null) {
LOG.atDebug()
.setMessage("Error handling trie node request task: {}")
.addArgument(error)
.log();
}
return requestTasks;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ void sendTransactionsToPeer(final EthPeer peer) {
LOG.atTrace()
.setMessage(
"Sending transactions to peer {} all transactions count {}, "
+ "single message transactions {}, single message list {}")
+ "single message transactions {}, single message list {}, transactions {}, AgreedCapabilities {}")
.addArgument(peer)
.addArgument(allTxToSend::size)
.addArgument(includedTransactions::size)
.addArgument(() -> toHashList(includedTransactions))
.addArgument(() -> includedTransactions)
.addArgument(peer::getAgreedCapabilities)
.log();
allTxToSend.removeAll(limitedTransactionsMessages.getIncludedTransactions());
try {
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.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason.TIMEOUT;
import static org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason.USELESS_PEER_USELESS_RESPONSES;
import static org.mockito.Mockito.mock;

import org.hyperledger.besu.ethereum.eth.messages.EthPV62;

Expand All @@ -28,6 +29,7 @@ public class PeerReputationTest {
private static final int INITIAL_SCORE = 25;
private static final int MAX_SCORE = 50;
private final PeerReputation reputation = new PeerReputation(INITIAL_SCORE, MAX_SCORE);
private final EthPeer mockEthPeer = mock(EthPeer.class);

@Test
public void shouldThrowOnInvalidInitialScore() {
Expand All @@ -37,16 +39,19 @@ public void shouldThrowOnInvalidInitialScore() {
@Test
public void shouldOnlyDisconnectWhenTimeoutLimitReached() {
sendRequestTimeouts(EthPV62.GET_BLOCK_HEADERS, PeerReputation.TIMEOUT_THRESHOLD - 1);
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).contains(TIMEOUT);
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS, mockEthPeer))
.contains(TIMEOUT);
}

@Test
public void shouldTrackTimeoutsSeparatelyForDifferentRequestTypes() {
sendRequestTimeouts(EthPV62.GET_BLOCK_HEADERS, PeerReputation.TIMEOUT_THRESHOLD - 1);
sendRequestTimeouts(EthPV62.GET_BLOCK_BODIES, PeerReputation.TIMEOUT_THRESHOLD - 1);

assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).contains(TIMEOUT);
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).contains(TIMEOUT);
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS, mockEthPeer))
.contains(TIMEOUT);
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES, mockEthPeer))
.contains(TIMEOUT);
}

@Test
Expand All @@ -55,14 +60,16 @@ public void shouldResetTimeoutCountForRequestType() {
sendRequestTimeouts(EthPV62.GET_BLOCK_BODIES, PeerReputation.TIMEOUT_THRESHOLD - 1);

reputation.resetTimeoutCount(EthPV62.GET_BLOCK_HEADERS);
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS)).isEmpty();
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES)).contains(TIMEOUT);
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_HEADERS, mockEthPeer)).isEmpty();
assertThat(reputation.recordRequestTimeout(EthPV62.GET_BLOCK_BODIES, mockEthPeer))
.contains(TIMEOUT);
}

@Test
public void shouldOnlyDisconnectWhenEmptyResponseThresholdReached() {
sendUselessResponses(1001, PeerReputation.USELESS_RESPONSE_THRESHOLD - 1);
assertThat(reputation.recordUselessResponse(1005)).contains(USELESS_PEER_USELESS_RESPONSES);
assertThat(reputation.recordUselessResponse(1005, mockEthPeer))
.contains(USELESS_PEER_USELESS_RESPONSES);
}

@Test
Expand All @@ -73,7 +80,7 @@ public void shouldDiscardEmptyResponseRecordsAfterTimeWindowElapses() {
// But then the next empty response doesn't come in until after the window expires on the first
assertThat(
reputation.recordUselessResponse(
1001 + PeerReputation.USELESS_RESPONSE_WINDOW_IN_MILLIS + 1))
1001 + PeerReputation.USELESS_RESPONSE_WINDOW_IN_MILLIS + 1, mockEthPeer))
.isEmpty();
}

Expand All @@ -93,13 +100,13 @@ public void shouldNotIncreaseScoreOverMax() {

private void sendRequestTimeouts(final int requestType, final int repeatCount) {
for (int i = 0; i < repeatCount; i++) {
assertThat(reputation.recordRequestTimeout(requestType)).isEmpty();
assertThat(reputation.recordRequestTimeout(requestType, mockEthPeer)).isEmpty();
}
}

private void sendUselessResponses(final long timestamp, final int repeatCount) {
for (int i = 0; i < repeatCount; i++) {
assertThat(reputation.recordUselessResponse(timestamp + i)).isEmpty();
assertThat(reputation.recordUselessResponse(timestamp + i, mockEthPeer)).isEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
* increases the global mark, so a mark set in once collection is usable across all
* UndoableCollection instances.
*
* @param <V> The type of the collection.
* @param <K> The type of the keys maintained by this map.
* @param <V> The type of mapped values.
*/
public class UndoMap<K, V> implements Map<K, V>, Undoable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* increases the global mark, so a mark set in once collection is usable across all
* UndoableCollection instances.
*
* @param <V> The type of the collection.
* @param <K> The type of the keys maintained by this map.
* @param <V> The type of mapped values.
*/
public class UndoNavigableMap<K, V> extends UndoMap<K, V> implements NavigableMap<K, V> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
* increases the global mark, so a mark set in once collection is usable across all
* UndoableCollection instances.
*
* @param <V> The type of the collection.
* @param <R> the type of the table row keys
* @param <C> the type of the table column keys
* @param <V> the type of the mapped values
*/
public class UndoTable<R, C, V> implements Table<R, C, V>, Undoable {

Expand Down
2 changes: 2 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/ClassicEVMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

/** Provides EVMs supporting the appropriate operations for ETC network upgrades. */
public class ClassicEVMs {
/** Default constructor. */
private ClassicEVMs() {}

/**
* spiral evm.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class PrefixCodeRule implements ContractValidationRule {

private static final byte FORMAT_RESERVED = (byte) 0xEF;

/** Default constructor. */
public PrefixCodeRule() {}

@Override
// As per https://eips.ethereum.org/EIPS/eip-3541
public Optional<ExceptionalHaltReason> validate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class SimpleBlockValues implements BlockValues {
long timestamp = 1;
long gasLimit = Long.MAX_VALUE;

/** Default constructor. */
public SimpleBlockValues() {}

@Override
public Bytes getDifficultyBytes() {
return difficultyBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,9 @@ public static class Builder {

private Optional<List<VersionedHash>> versionedHashes = Optional.empty();

/** Instantiates a new Builder. */
public Builder() {}

/**
* The "parent" message frame. When present some fields will be populated from the parent and
* ignored if passed in via builder
Expand Down
16 changes: 16 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/frame/TxValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
* Transaction Values used by various EVM Opcodes. These are the values that either do not change or
* the backing stores whose changes transcend message frames and are not part of state, such as
* transient storage and address warming.
*
* @param blockHashLookup The block hash lookup function
* @param maxStackSize The maximum stack size
* @param warmedUpAddresses The warmed up addresses
* @param warmedUpStorage The warmed up storage
* @param originator The originator address
* @param gasPrice The gas price
* @param blobGasPrice The blob gas price
* @param blockValues The block values
* @param messageFrameStack The message frame stack
* @param miningBeneficiary The mining beneficiary address
* @param versionedHashes The optional list of versioned hashes
* @param transientStorage The transient storage
* @param creates The set of addresses that creates
* @param selfDestructs The set of addresses that self-destructs
* @param gasRefunds The gas refunds
*/
public record TxValues(
Function<Long, Hash> blockHashLookup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class ByzantiumGasCalculator extends SpuriousDragonGasCalculator {
/** The constant MAX_FIRST_EXPONENT_BYTES. */
public static final int MAX_FIRST_EXPONENT_BYTES = 32;

/** Default constructor. */
public ByzantiumGasCalculator() {}

@Override
public long modExpGasCost(final Bytes input) {
final long baseLength = BigIntegerModularExponentiationPrecompiledContract.baseLength(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class ConstantinopleGasCalculator extends ByzantiumGasCalculator {

private static final long EXTCODE_HASH_COST = 400L;

/** Default constructor. */
public ConstantinopleGasCalculator() {}

/**
* Returns the amount of gas the CREATE2 operation will consume.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
public class DieHardGasCalculator extends TangerineWhistleGasCalculator {
private static final long EXP_OPERATION_BYTE_GAS_COST = 50L;

/** Default constructor. */
public DieHardGasCalculator() {}

@Override
protected long expOperationByteGasCost() {
return EXP_OPERATION_BYTE_GAS_COST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public class FrontierGasCalculator implements GasCalculator {

private static final long SELF_DESTRUCT_REFUND_AMOUNT = 24_000L;

/** Default constructor. */
public FrontierGasCalculator() {}

@Override
public long transactionIntrinsicGasCost(final Bytes payload, final boolean isContractCreate) {
int zeros = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class HomesteadGasCalculator extends FrontierGasCalculator {

private static final long TX_CREATE_EXTRA = 32_000L;

/** Default constructor. */
public HomesteadGasCalculator() {}

@Override
protected long txCreateExtraGasCost() {
return TX_CREATE_EXTRA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class IstanbulGasCalculator extends PetersburgGasCalculator {
private static final long SSTORE_RESET_GAS_LESS_SLOAD_GAS = SSTORE_RESET_GAS - SLOAD_GAS;
private static final long NEGATIVE_SSTORE_CLEARS_SCHEDULE = -SSTORE_CLEARS_SCHEDULE;

/** Default constructor. */
public IstanbulGasCalculator() {}

@Override
public long transactionIntrinsicGasCost(final Bytes payload, final boolean isContractCreation) {
int zeros = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class PetersburgGasCalculator extends ConstantinopleGasCalculator {
/** Same as {#link {@link FrontierGasCalculator#STORAGE_RESET_REFUND_AMOUNT} */
private static final long STORAGE_RESET_REFUND_AMOUNT = 15_000L;

/** Default constructor. */
public PetersburgGasCalculator() {}

/**
* Same as {#link {@link FrontierGasCalculator#calculateStorageCost(UInt256, Supplier, Supplier)}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SpuriousDragonGasCalculator extends TangerineWhistleGasCalculator {

private static final long EXP_OPERATION_BYTE_GAS_COST = 50L;

/** Default constructor. */
public SpuriousDragonGasCalculator() {}

@Override
public long callOperationGasCost(
final MessageFrame frame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class TangerineWhistleGasCalculator extends HomesteadGasCalculator {

private static final long SLOAD_OPERATION_GAS_COST = 200L;

/** Default constructor. */
public TangerineWhistleGasCalculator() {}

@Override
public long getBalanceOperationGasCost() {
return BALANCE_OPERATION_GAS_COST;
Expand Down
Loading

0 comments on commit 074214d

Please sign in to comment.