Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ void fireNewUnverifiedForkchoiceEvent(
*/
boolean validateCandidateHead(final BlockHeader candidateHeader);

/**
* Put payloadWrapper containing Identifier.
*
* @param payload the payload
*/
default void putPayload(final PayloadWrapper payload) {
putPayloadById(payload.payloadIdentifier, payload.blockWithReceipts);
}

/**
* Put payload by Identifier.
*
Expand All @@ -173,7 +182,7 @@ void fireNewUnverifiedForkchoiceEvent(
/**
* Sets is chain pruning enabled.
*
* @param isChainPruningEnabled the is chain pruning enabled
* @param isChainPruningEnabled whether chain pruning is enabled
*/
default void setIsChainPruningEnabled(final boolean isChainPruningEnabled) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.consensus.merge;

import org.hyperledger.besu.consensus.merge.blockcreation.PayloadIdentifier;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;

/** Wrapper for payload plus extra info. */
public class PayloadWrapper {
Comment thread
macfarla marked this conversation as resolved.
Outdated
/** The Payload identifier. */
final PayloadIdentifier payloadIdentifier;
/** The Block with receipts. */
final BlockWithReceipts blockWithReceipts;

/**
* Instantiates a new PayloadWrapper.
*
* @param payloadIdentifier the payload identifier
* @param blockWithReceipts the block with receipts
*/
public PayloadWrapper(
final PayloadIdentifier payloadIdentifier, final BlockWithReceipts blockWithReceipts) {
this.payloadIdentifier = payloadIdentifier;
this.blockWithReceipts = blockWithReceipts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class PostMergeContext implements MergeContext {
private final Subscribers<UnverifiedForkchoiceListener>
newUnverifiedForkchoiceCallbackSubscribers = Subscribers.create();

private final EvictingQueue<PayloadTuple> blocksInProgress =
private final EvictingQueue<PayloadWrapper> blocksInProgress =
EvictingQueue.create(MAX_BLOCKS_IN_PROGRESS);

// latest finalized block
Expand Down Expand Up @@ -247,12 +247,12 @@ public void putPayloadById(
.addArgument(() -> logBlockProposal(currBestBlock.getBlock()))
.log();
blocksInProgress.removeAll(
retrieveTuplesById(payloadId).collect(Collectors.toUnmodifiableList()));
blocksInProgress.add(new PayloadTuple(payloadId, newBlockWithReceipts));
retrievePayloadsById(payloadId).collect(Collectors.toUnmodifiableList()));
blocksInProgress.add(new PayloadWrapper(payloadId, newBlockWithReceipts));
logCurrentBestBlock(newBlockWithReceipts);
}
},
() -> blocksInProgress.add(new PayloadTuple(payloadId, newBlockWithReceipts)));
() -> blocksInProgress.add(new PayloadWrapper(payloadId, newBlockWithReceipts)));
}
}

Expand All @@ -276,14 +276,14 @@ private void logCurrentBestBlock(final BlockWithReceipts blockWithReceipts) {
@Override
public Optional<BlockWithReceipts> retrieveBlockById(final PayloadIdentifier payloadId) {
synchronized (blocksInProgress) {
return retrieveTuplesById(payloadId)
return retrievePayloadsById(payloadId)
.map(tuple -> tuple.blockWithReceipts)
.sorted(compareByGasUsedDesc)
.findFirst();
}
}

private Stream<PayloadTuple> retrieveTuplesById(final PayloadIdentifier payloadId) {
private Stream<PayloadWrapper> retrievePayloadsById(final PayloadIdentifier payloadId) {
return blocksInProgress.stream().filter(z -> z.payloadIdentifier.equals(payloadId));
}

Expand All @@ -296,25 +296,6 @@ private String logBlockProposal(final Block block) {
+ block.getBody().getTransactions().size();
}

private static class PayloadTuple {
/** The Payload identifier. */
final PayloadIdentifier payloadIdentifier;
/** The Block with receipts. */
final BlockWithReceipts blockWithReceipts;

/**
* Instantiates a new Payload tuple.
*
* @param payloadIdentifier the payload identifier
* @param blockWithReceipts the block with receipts
*/
PayloadTuple(
final PayloadIdentifier payloadIdentifier, final BlockWithReceipts blockWithReceipts) {
this.payloadIdentifier = payloadIdentifier;
this.blockWithReceipts = blockWithReceipts;
}
}

@Override
public void setIsChainPruningEnabled(final boolean isChainPruningEnabled) {
this.isChainPruningEnabled = isChainPruningEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator.ForkchoiceResult.Status.INVALID;

import org.hyperledger.besu.consensus.merge.MergeContext;
import org.hyperledger.besu.consensus.merge.PayloadWrapper;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
Expand Down Expand Up @@ -288,8 +289,9 @@ public PayloadIdentifier preparePayload(

BlockProcessingResult result = validateProposedBlock(emptyBlock);
if (result.isSuccessful()) {
mergeContext.putPayloadById(
payloadIdentifier, new BlockWithReceipts(emptyBlock, result.getReceipts()));
mergeContext.putPayload(
new PayloadWrapper(
payloadIdentifier, new BlockWithReceipts(emptyBlock, result.getReceipts())));
LOG.info(
"Start building proposals for block {} identified by {}",
emptyBlock.getHeader().getNumber(),
Expand Down Expand Up @@ -443,8 +445,9 @@ private void evaluateNewBlock(

if (isBlockCreationCancelled(payloadIdentifier)) return;

mergeContext.putPayloadById(
payloadIdentifier, new BlockWithReceipts(bestBlock, resultBest.getReceipts()));
mergeContext.putPayload(
new PayloadWrapper(
payloadIdentifier, new BlockWithReceipts(bestBlock, resultBest.getReceipts())));
LOG.atDebug()
.setMessage(
"Successfully built block {} for proposal identified by {}, with {} transactions, in {}ms")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public BlockTransactionSelector(
/*
This function iterates over (potentially) all transactions in the PendingTransactions, this is a
long-running process. If running in a thread, it can be cancelled via the isCancelled supplier (which will result
in this throwing an CancellationException).
in this throwing a CancellationException).
*/
public TransactionSelectionResults buildTransactionListForBlock() {
LOG.atDebug()
Expand All @@ -280,7 +280,7 @@ public TransactionSelectionResults buildTransactionListForBlock() {
return res;
});
LOG.atTrace()
.setMessage("Transaction selection result result {}")
.setMessage("Transaction selection result {}")
.addArgument(transactionSelectionResults::toTraceLog)
.log();
return transactionSelectionResults;
Expand Down