Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
fab-10 committed Aug 25, 2023
2 parents 295f7c8 + d0391ed commit 21e623a
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 54 deletions.
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ task manifestDockerRelease {
}
}

def sc = Pattern.quote(File.separator)
def sep = Pattern.quote(File.separator)

task checkSpdxHeader(type: CheckSpdxHeader) {
apply plugin: 'groovy'
Expand All @@ -910,16 +910,16 @@ task checkSpdxHeader(type: CheckSpdxHeader) {
spdxHeader = "* SPDX-License-Identifier: Apache-2.0"
filesRegex = "(.*.java)|(.*.groovy)"
excludeRegex = [
"(.*${sc}generalstate${sc}GeneralStateRegressionReferenceTest.*)",
"(.*${sc}generalstate${sc}GeneralStateReferenceTest.*)",
"(.*${sc}generalstate${sc}LegacyGeneralStateReferenceTest.*)",
"(.*${sc}blockchain${sc}BlockchainReferenceTest.*)",
"(.*${sc}blockchain${sc}LegacyBlockchainReferenceTest.*)",
"(.*${sc}.gradle${sc}.*)",
"(.*${sc}.idea${sc}.*)",
"(.*${sc}out${sc}.*)",
"(.*${sc}build${sc}.*)",
"(.*${sc}src${sc}[^${sc}]+${sc}generated${sc}.*)"
"(.*${sep}generalstate${sep}GeneralStateRegressionReferenceTest.*)",
"(.*${sep}generalstate${sep}GeneralStateReferenceTest.*)",
"(.*${sep}generalstate${sep}LegacyGeneralStateReferenceTest.*)",
"(.*${sep}blockchain${sep}BlockchainReferenceTest.*)",
"(.*${sep}blockchain${sep}LegacyBlockchainReferenceTest.*)",
"(.*${sep}.gradle${sep}.*)",
"(.*${sep}.idea${sep}.*)",
"(.*${sep}out${sep}.*)",
"(.*${sep}build${sep}.*)",
"(.*${sep}src${sep}[^${sep}]+${sep}generated${sep}.*)"
].join("|")

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
"Computed block hash %s does not match block hash parameter %s",
newBlockHeader.getBlockHash(), blockParam.getBlockHash());
LOG.debug(errorMessage);
return respondWithInvalid(
reqId,
blockParam,
mergeCoordinator.getLatestValidAncestor(blockParam.getParentHash()).orElse(null),
getInvalidBlockHashStatus(),
errorMessage);
return respondWithInvalid(reqId, blockParam, null, getInvalidBlockHashStatus(), errorMessage);
}

ValidationResult<RpcErrorType> blobValidationResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.tuweni.bytes.Bytes32;

/**
* parentHash: DATA, 32 Bytes feeRecipient: DATA, 20 Bytes stateRoot: DATA, 32 Bytes receiptsRoot:
* DATA, 32 Bytes logsBloom: DATA, 256 Bytes prevRandao: DATA, 32 Bytes blockNumber: QUANTITY
* gasLimit: QUANTITY gasUsed: QUANTITY timestamp: QUANTITY baseFeePerGas: QUANTITY blockHash: DATA,
* 32 Bytes transactions: Array of TypedTransaction
*/
public class EnginePayloadParameter {
private final Hash blockHash;
private final Hash parentHash;
Expand All @@ -49,9 +43,30 @@ public class EnginePayloadParameter {
private final List<WithdrawalParameter> withdrawals;
private final Long blobGasUsed;
private final String excessBlobGas;
private final List<Bytes32> versionedHashes;
private final List<DepositParameter> deposits;

/**
* Creates an instance of EnginePayloadParameter.
*
* @param blockHash DATA, 32 Bytes
* @param parentHash DATA, 32 Bytes
* @param feeRecipient DATA, 20 Bytes
* @param stateRoot DATA, 32 Bytes
* @param blockNumber QUANTITY, 64 Bits
* @param baseFeePerGas QUANTITY, 256 Bits
* @param gasLimit QUANTITY, 64 Bits
* @param gasUsed QUANTITY, 64 Bits
* @param timestamp QUANTITY, 64 Bits
* @param extraData DATA, 0 to 32 Bytes
* @param receiptsRoot DATA, 32 Bytes
* @param logsBloom DATA, 256 Bytes
* @param prevRandao DATA, 32 Bytes
* @param transactions Array of DATA
* @param withdrawals Array of Withdrawal
* @param blobGasUsed QUANTITY, 64 Bits
* @param excessBlobGas QUANTITY, 64 Bits
* @param deposits List of deposit parameters.
*/
@JsonCreator
public EnginePayloadParameter(
@JsonProperty("blockHash") final Hash blockHash,
Expand All @@ -71,7 +86,6 @@ public EnginePayloadParameter(
@JsonProperty("withdrawals") final List<WithdrawalParameter> withdrawals,
@JsonProperty("blobGasUsed") final UnsignedLongParameter blobGasUsed,
@JsonProperty("excessBlobGas") final String excessBlobGas,
@JsonProperty("versionedHashes") final List<Bytes32> versionedHashes,
@JsonProperty("deposits") final List<DepositParameter> deposits) {
this.blockHash = blockHash;
this.parentHash = parentHash;
Expand All @@ -90,7 +104,6 @@ public EnginePayloadParameter(
this.withdrawals = withdrawals;
this.blobGasUsed = blobGasUsed == null ? null : blobGasUsed.getValue();
this.excessBlobGas = excessBlobGas;
this.versionedHashes = versionedHashes;
this.deposits = deposits;
}

Expand Down Expand Up @@ -165,8 +178,4 @@ public String getExcessBlobGas() {
public List<DepositParameter> getDeposits() {
return deposits;
}

public List<Bytes32> getVersionedHashes() {
return versionedHashes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.VersionedHash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.BlockProcessingOutputs;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
Expand Down Expand Up @@ -401,28 +400,14 @@ protected JsonRpcResponse resp(final EnginePayloadParameter payload) {

protected EnginePayloadParameter mockEnginePayload(
final BlockHeader header, final List<String> txs) {
return mockEnginePayload(header, txs, null, null, null);
return mockEnginePayload(header, txs, null, null);
}

protected EnginePayloadParameter mockEnginePayload(
final BlockHeader header,
final List<String> txs,
final List<WithdrawalParameter> withdrawals,
final List<DepositParameter> deposits) {
return mockEnginePayload(
header,
txs,
withdrawals,
deposits,
List.of(VersionedHash.DEFAULT_VERSIONED_HASH.toBytes()));
}

protected EnginePayloadParameter mockEnginePayload(
final BlockHeader header,
final List<String> txs,
final List<WithdrawalParameter> withdrawals,
final List<DepositParameter> deposits,
final List<Bytes32> versionedHashes) {
return new EnginePayloadParameter(
header.getHash(),
header.getParentHash(),
Expand All @@ -441,7 +426,6 @@ protected EnginePayloadParameter mockEnginePayload(
withdrawals,
header.getBlobGasUsed().map(UnsignedLongParameter::new).orElse(null),
header.getExcessBlobGas().map(BlobGas::toHexString).orElse(null),
versionedHashes,
deposits);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void shouldReturnValidIfDepositsIsNull_WhenDepositsProhibited() {
when(mergeCoordinator.getLatestValidAncestor(mockHeader))
.thenReturn(Optional.of(mockHeader.getHash()));

var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList(), null, deposits, null));
var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList(), null, deposits));

assertValidResponse(mockHeader, resp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public void shouldReturnValidIfWithdrawalsIsNull_WhenWithdrawalsProhibited() {
lenient()
.when(blockchain.getBlockHeader(mockHeader.getParentHash()))
.thenReturn(Optional.of(mock(BlockHeader.class)));
var resp =
resp(mockEnginePayload(mockHeader, Collections.emptyList(), withdrawals, null, null));
var resp = resp(mockEnginePayload(mockHeader, Collections.emptyList(), withdrawals, null));

assertValidResponse(mockHeader, resp);
}
Expand All @@ -121,7 +120,6 @@ public void shouldReturnInvalidIfWithdrawalsIsNotNull_WhenWithdrawalsProhibited(
createBlockHeader(Optional.of(Collections.emptyList()), Optional.empty()),
Collections.emptyList(),
withdrawals,
null,
null));

final JsonRpcError jsonRpcError = fromErrorResp(resp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hyperledger.besu.datatypes.KZGCommitment;
import org.hyperledger.besu.datatypes.KZGProof;
import org.hyperledger.besu.datatypes.VersionedHash;
import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -33,7 +34,6 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract;

public class BlobTestFixture {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import static java.util.concurrent.CompletableFuture.completedFuture;

import org.hyperledger.besu.services.pipeline.exception.AsyncOperationException;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -83,7 +85,7 @@ private void outputNextCompletedTask(final WritePipe<O> outputPipe) {
} catch (final InterruptedException e) {
LOG.trace("Interrupted while waiting for processing to complete", e);
} catch (final ExecutionException e) {
throw new RuntimeException("Async operation failed. " + e.getMessage(), e);
throw new AsyncOperationException("Async operation failed. " + e.getMessage(), e);
} catch (final TimeoutException e) {
// Ignore and go back around the loop.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

import static java.util.stream.Collectors.toList;

import org.hyperledger.besu.services.pipeline.exception.AsyncOperationException;
import org.hyperledger.besu.util.ExceptionUtils;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -169,7 +171,13 @@ private Future<?> runWithErrorHandling(final ExecutorService executorService, fi
if (tracingEnabled) {
taskSpan.setStatus(StatusCode.ERROR);
}
LOG.debug("Unhandled exception in pipeline. Aborting.", t);
if (t instanceof CompletionException
|| t instanceof CancellationException
|| t instanceof AsyncOperationException) {
LOG.debug("Unhandled exception in pipeline. Aborting.", t);
} else {
LOG.info("Unexpected exception in pipeline. Aborting.", t);
}
try {
abort(t);
} catch (final Throwable t2) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.services.pipeline.exception;

/** This class allows throwing an exception in case of failure of an async task in the pipeline */
public class AsyncOperationException extends RuntimeException {

/**
* Constructor of the exception that takes the message and the cause of it.
*
* @param message of the exception
* @param cause of the exception
*/
public AsyncOperationException(final String message, final Throwable cause) {
super(message, cause);
}
}

0 comments on commit 21e623a

Please sign in to comment.