mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 15:37:54 -05:00
renamed PayloadTuple and made a separate class (#5916)
* renamed PayloadTuple and made a separate class * made a record * refactor tests to use PayloadWrapper Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> --------- Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
This commit is contained in:
@@ -157,10 +157,9 @@ public interface MergeContext extends ConsensusContext {
|
||||
/**
|
||||
* Put payload by Identifier.
|
||||
*
|
||||
* @param payloadId the payload identifier
|
||||
* @param blockWithReceipts the block with receipts
|
||||
* @param payloadWrapper payload wrapper
|
||||
*/
|
||||
void putPayloadById(final PayloadIdentifier payloadId, final BlockWithReceipts blockWithReceipts);
|
||||
void putPayloadById(final PayloadWrapper payloadWrapper);
|
||||
|
||||
/**
|
||||
* Retrieve block by id.
|
||||
@@ -173,7 +172,7 @@ public interface MergeContext extends ConsensusContext {
|
||||
/**
|
||||
* 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) {}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 record PayloadWrapper(
|
||||
PayloadIdentifier payloadIdentifier, BlockWithReceipts blockWithReceipts) {}
|
||||
@@ -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
|
||||
@@ -232,27 +232,35 @@ public class PostMergeContext implements MergeContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putPayloadById(
|
||||
final PayloadIdentifier payloadId, final BlockWithReceipts newBlockWithReceipts) {
|
||||
public void putPayloadById(final PayloadWrapper payloadWrapper) {
|
||||
synchronized (blocksInProgress) {
|
||||
final Optional<BlockWithReceipts> maybeCurrBestBlock = retrieveBlockById(payloadId);
|
||||
final Optional<BlockWithReceipts> maybeCurrBestBlock =
|
||||
retrieveBlockById(payloadWrapper.payloadIdentifier());
|
||||
|
||||
maybeCurrBestBlock.ifPresentOrElse(
|
||||
currBestBlock -> {
|
||||
if (compareByGasUsedDesc.compare(newBlockWithReceipts, currBestBlock) < 0) {
|
||||
if (compareByGasUsedDesc.compare(payloadWrapper.blockWithReceipts(), currBestBlock)
|
||||
< 0) {
|
||||
LOG.atDebug()
|
||||
.setMessage("New proposal for payloadId {} {} is better than the previous one {}")
|
||||
.addArgument(payloadId)
|
||||
.addArgument(() -> logBlockProposal(newBlockWithReceipts.getBlock()))
|
||||
.addArgument(payloadWrapper.payloadIdentifier())
|
||||
.addArgument(
|
||||
() -> logBlockProposal(payloadWrapper.blockWithReceipts().getBlock()))
|
||||
.addArgument(() -> logBlockProposal(currBestBlock.getBlock()))
|
||||
.log();
|
||||
blocksInProgress.removeAll(
|
||||
retrieveTuplesById(payloadId).collect(Collectors.toUnmodifiableList()));
|
||||
blocksInProgress.add(new PayloadTuple(payloadId, newBlockWithReceipts));
|
||||
logCurrentBestBlock(newBlockWithReceipts);
|
||||
retrievePayloadsById(payloadWrapper.payloadIdentifier())
|
||||
.collect(Collectors.toUnmodifiableList()));
|
||||
blocksInProgress.add(
|
||||
new PayloadWrapper(
|
||||
payloadWrapper.payloadIdentifier(), payloadWrapper.blockWithReceipts()));
|
||||
logCurrentBestBlock(payloadWrapper.blockWithReceipts());
|
||||
}
|
||||
},
|
||||
() -> blocksInProgress.add(new PayloadTuple(payloadId, newBlockWithReceipts)));
|
||||
() ->
|
||||
blocksInProgress.add(
|
||||
new PayloadWrapper(
|
||||
payloadWrapper.payloadIdentifier(), payloadWrapper.blockWithReceipts())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,15 +284,15 @@ public class PostMergeContext implements MergeContext {
|
||||
@Override
|
||||
public Optional<BlockWithReceipts> retrieveBlockById(final PayloadIdentifier payloadId) {
|
||||
synchronized (blocksInProgress) {
|
||||
return retrieveTuplesById(payloadId)
|
||||
.map(tuple -> tuple.blockWithReceipts)
|
||||
return retrievePayloadsById(payloadId)
|
||||
.map(payloadWrapper -> payloadWrapper.blockWithReceipts())
|
||||
.sorted(compareByGasUsedDesc)
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
|
||||
private Stream<PayloadTuple> retrieveTuplesById(final PayloadIdentifier payloadId) {
|
||||
return blocksInProgress.stream().filter(z -> z.payloadIdentifier.equals(payloadId));
|
||||
private Stream<PayloadWrapper> retrievePayloadsById(final PayloadIdentifier payloadId) {
|
||||
return blocksInProgress.stream().filter(z -> z.payloadIdentifier().equals(payloadId));
|
||||
}
|
||||
|
||||
private String logBlockProposal(final Block block) {
|
||||
@@ -296,25 +304,6 @@ public class PostMergeContext implements MergeContext {
|
||||
+ 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;
|
||||
|
||||
@@ -140,9 +140,8 @@ public class TransitionContext implements MergeContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putPayloadById(
|
||||
final PayloadIdentifier payloadId, final BlockWithReceipts blockWithReceipts) {
|
||||
postMergeContext.putPayloadById(payloadId, blockWithReceipts);
|
||||
public void putPayloadById(final PayloadWrapper payloadWrapper) {
|
||||
postMergeContext.putPayloadById(payloadWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ import static java.util.stream.Collectors.joining;
|
||||
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;
|
||||
@@ -289,7 +290,8 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
|
||||
BlockProcessingResult result = validateProposedBlock(emptyBlock);
|
||||
if (result.isSuccessful()) {
|
||||
mergeContext.putPayloadById(
|
||||
payloadIdentifier, new BlockWithReceipts(emptyBlock, result.getReceipts()));
|
||||
new PayloadWrapper(
|
||||
payloadIdentifier, new BlockWithReceipts(emptyBlock, result.getReceipts())));
|
||||
LOG.info(
|
||||
"Start building proposals for block {} identified by {}",
|
||||
emptyBlock.getHeader().getNumber(),
|
||||
@@ -444,7 +446,8 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
|
||||
if (isBlockCreationCancelled(payloadIdentifier)) return;
|
||||
|
||||
mergeContext.putPayloadById(
|
||||
payloadIdentifier, new BlockWithReceipts(bestBlock, resultBest.getReceipts()));
|
||||
new PayloadWrapper(
|
||||
payloadIdentifier, new BlockWithReceipts(bestBlock, resultBest.getReceipts())));
|
||||
LOG.atDebug()
|
||||
.setMessage(
|
||||
"Successfully built block {} for proposal identified by {}, with {} transactions, in {}ms")
|
||||
|
||||
@@ -138,7 +138,7 @@ public class PostMergeContextTest {
|
||||
BlockWithReceipts mockBlockWithReceipts = createBlockWithReceipts(1, 21000, 1);
|
||||
|
||||
PayloadIdentifier firstPayloadId = new PayloadIdentifier(1L);
|
||||
postMergeContext.putPayloadById(firstPayloadId, mockBlockWithReceipts);
|
||||
postMergeContext.putPayloadById(new PayloadWrapper(firstPayloadId, mockBlockWithReceipts));
|
||||
|
||||
assertThat(postMergeContext.retrieveBlockById(firstPayloadId)).contains(mockBlockWithReceipts);
|
||||
}
|
||||
@@ -149,8 +149,8 @@ public class PostMergeContextTest {
|
||||
BlockWithReceipts betterBlockWithReceipts = createBlockWithReceipts(2, 11, 1);
|
||||
|
||||
PayloadIdentifier payloadId = new PayloadIdentifier(1L);
|
||||
postMergeContext.putPayloadById(payloadId, zeroTxBlockWithReceipts);
|
||||
postMergeContext.putPayloadById(payloadId, betterBlockWithReceipts);
|
||||
postMergeContext.putPayloadById(new PayloadWrapper(payloadId, zeroTxBlockWithReceipts));
|
||||
postMergeContext.putPayloadById(new PayloadWrapper(payloadId, betterBlockWithReceipts));
|
||||
|
||||
assertThat(postMergeContext.retrieveBlockById(payloadId)).contains(betterBlockWithReceipts);
|
||||
}
|
||||
@@ -162,9 +162,9 @@ public class PostMergeContextTest {
|
||||
BlockWithReceipts smallBlockWithReceipts = createBlockWithReceipts(3, 5, 1);
|
||||
|
||||
PayloadIdentifier payloadId = new PayloadIdentifier(1L);
|
||||
postMergeContext.putPayloadById(payloadId, zeroTxBlockWithReceipts);
|
||||
postMergeContext.putPayloadById(payloadId, betterBlockWithReceipts);
|
||||
postMergeContext.putPayloadById(payloadId, smallBlockWithReceipts);
|
||||
postMergeContext.putPayloadById(new PayloadWrapper(payloadId, zeroTxBlockWithReceipts));
|
||||
postMergeContext.putPayloadById(new PayloadWrapper(payloadId, betterBlockWithReceipts));
|
||||
postMergeContext.putPayloadById(new PayloadWrapper(payloadId, smallBlockWithReceipts));
|
||||
|
||||
assertThat(postMergeContext.retrieveBlockById(payloadId)).contains(betterBlockWithReceipts);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hyperledger.besu.config.MergeConfigOptions;
|
||||
import org.hyperledger.besu.consensus.merge.MergeContext;
|
||||
import org.hyperledger.besu.consensus.merge.PayloadWrapper;
|
||||
import org.hyperledger.besu.consensus.merge.blockcreation.MergeCoordinator.ProposalBuilderExecutor;
|
||||
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator.ForkchoiceResult;
|
||||
import org.hyperledger.besu.crypto.KeyPair;
|
||||
@@ -55,7 +56,6 @@ import org.hyperledger.besu.ethereum.core.Block;
|
||||
import org.hyperledger.besu.ethereum.core.BlockBody;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
|
||||
import org.hyperledger.besu.ethereum.core.Difficulty;
|
||||
import org.hyperledger.besu.ethereum.core.MiningParameters;
|
||||
import org.hyperledger.besu.ethereum.core.Transaction;
|
||||
@@ -242,11 +242,12 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void coinbaseShouldMatchSuggestedFeeRecipient() {
|
||||
doAnswer(
|
||||
invocation -> {
|
||||
coordinator.finalizeProposalById(invocation.getArgument(0, PayloadIdentifier.class));
|
||||
coordinator.finalizeProposalById(
|
||||
invocation.getArgument(0, PayloadWrapper.class).payloadIdentifier());
|
||||
return null;
|
||||
})
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
var payloadId =
|
||||
coordinator.preparePayload(
|
||||
@@ -257,12 +258,12 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
Optional.empty(),
|
||||
Optional.empty());
|
||||
|
||||
ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
|
||||
ArgumentCaptor.forClass(BlockWithReceipts.class);
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, atLeastOnce()).putPayloadById(eq(payloadId), blockWithReceipts.capture());
|
||||
verify(mergeContext, atLeastOnce()).putPayloadById(payloadWrapper.capture());
|
||||
|
||||
assertThat(blockWithReceipts.getValue().getHeader().getCoinbase())
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
assertThat(payloadWrapper.getValue().blockWithReceipts().getHeader().getCoinbase())
|
||||
.isEqualTo(suggestedFeeRecipient);
|
||||
}
|
||||
|
||||
@@ -317,12 +318,13 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
createTransaction(retries.get() - 1), Optional.empty());
|
||||
} else {
|
||||
// when we have 5 transactions finalize block creation
|
||||
willThrow.finalizeProposalById(invocation.getArgument(0, PayloadIdentifier.class));
|
||||
willThrow.finalizeProposalById(
|
||||
invocation.getArgument(0, PayloadWrapper.class).payloadIdentifier());
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
var payloadId =
|
||||
willThrow.preparePayload(
|
||||
@@ -336,12 +338,19 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
verify(willThrow, never()).addBadBlock(any(), any());
|
||||
blockCreationTask.get();
|
||||
|
||||
ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
|
||||
ArgumentCaptor.forClass(BlockWithReceipts.class);
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, times(txPerBlock + 1))
|
||||
.putPayloadById(eq(payloadId), blockWithReceipts.capture()); // +1 for the empty
|
||||
assertThat(blockWithReceipts.getValue().getBlock().getBody().getTransactions().size())
|
||||
.putPayloadById(payloadWrapper.capture()); // +1 for the empty
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
assertThat(
|
||||
payloadWrapper
|
||||
.getValue()
|
||||
.blockWithReceipts()
|
||||
.getBlock()
|
||||
.getBody()
|
||||
.getTransactions()
|
||||
.size())
|
||||
.isEqualTo(txPerBlock);
|
||||
// this only verifies that adding the bad block didn't happen through the mergeCoordinator, it
|
||||
// still may be called directly.
|
||||
@@ -383,12 +392,12 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
} else {
|
||||
// when we have 5 transactions finalize block creation
|
||||
coordinator.finalizeProposalById(
|
||||
invocation.getArgument(0, PayloadIdentifier.class));
|
||||
invocation.getArgument(0, PayloadWrapper.class).payloadIdentifier());
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
var payloadId =
|
||||
coordinator.preparePayload(
|
||||
@@ -401,15 +410,21 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
blockCreationTask.get();
|
||||
|
||||
ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
|
||||
ArgumentCaptor.forClass(BlockWithReceipts.class);
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, times(retries.intValue()))
|
||||
.putPayloadById(eq(payloadId), blockWithReceipts.capture());
|
||||
verify(mergeContext, times(retries.intValue())).putPayloadById(payloadWrapper.capture());
|
||||
|
||||
assertThat(blockWithReceipts.getAllValues().size()).isEqualTo(retries.intValue());
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
assertThat(payloadWrapper.getAllValues().size()).isEqualTo(retries.intValue());
|
||||
for (int i = 0; i < retries.intValue(); i++) {
|
||||
assertThat(blockWithReceipts.getAllValues().get(i).getBlock().getBody().getTransactions())
|
||||
assertThat(
|
||||
payloadWrapper
|
||||
.getAllValues()
|
||||
.get(i)
|
||||
.blockWithReceipts()
|
||||
.getBlock()
|
||||
.getBody()
|
||||
.getTransactions())
|
||||
.hasSize(i);
|
||||
}
|
||||
}
|
||||
@@ -435,12 +450,12 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
} else {
|
||||
// finalize after 5 repetitions
|
||||
coordinator.finalizeProposalById(
|
||||
invocation.getArgument(0, PayloadIdentifier.class));
|
||||
invocation.getArgument(0, PayloadWrapper.class).payloadIdentifier());
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
var payloadId =
|
||||
coordinator.preparePayload(
|
||||
@@ -453,7 +468,10 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
blockCreationTask.get();
|
||||
|
||||
verify(mergeContext, times(retries.intValue())).putPayloadById(eq(payloadId), any());
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, times(retries.intValue())).putPayloadById(payloadWrapper.capture());
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
|
||||
// check with a tolerance
|
||||
assertThat(repetitionDurations)
|
||||
@@ -466,7 +484,8 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
doAnswer(
|
||||
invocation -> {
|
||||
if (invocation
|
||||
.getArgument(1, BlockWithReceipts.class)
|
||||
.getArgument(0, PayloadWrapper.class)
|
||||
.blockWithReceipts()
|
||||
.getBlock()
|
||||
.getBody()
|
||||
.getTransactions()
|
||||
@@ -480,12 +499,12 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
} else {
|
||||
// stop block creation loop when we see a not empty block
|
||||
coordinator.finalizeProposalById(
|
||||
invocation.getArgument(0, PayloadIdentifier.class));
|
||||
invocation.getArgument(0, PayloadWrapper.class).payloadIdentifier());
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
transactions.addLocalTransaction(createTransaction(0), Optional.empty());
|
||||
|
||||
@@ -500,15 +519,29 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
blockCreationTask.get();
|
||||
|
||||
ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
|
||||
ArgumentCaptor.forClass(BlockWithReceipts.class);
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, times(2)).putPayloadById(eq(payloadId), blockWithReceipts.capture());
|
||||
verify(mergeContext, times(2)).putPayloadById(payloadWrapper.capture());
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
|
||||
assertThat(blockWithReceipts.getAllValues().size()).isEqualTo(2);
|
||||
assertThat(blockWithReceipts.getAllValues().get(0).getBlock().getBody().getTransactions())
|
||||
assertThat(payloadWrapper.getAllValues().size()).isEqualTo(2);
|
||||
assertThat(
|
||||
payloadWrapper
|
||||
.getAllValues()
|
||||
.get(0)
|
||||
.blockWithReceipts()
|
||||
.getBlock()
|
||||
.getBody()
|
||||
.getTransactions())
|
||||
.hasSize(0);
|
||||
assertThat(blockWithReceipts.getAllValues().get(1).getBlock().getBody().getTransactions())
|
||||
assertThat(
|
||||
payloadWrapper
|
||||
.getAllValues()
|
||||
.get(1)
|
||||
.blockWithReceipts()
|
||||
.getBlock()
|
||||
.getBody()
|
||||
.getTransactions())
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
@@ -522,7 +555,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
return null;
|
||||
})
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
var payloadId =
|
||||
coordinator.preparePayload(
|
||||
@@ -540,7 +573,10 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
assertThat(e).hasCauseInstanceOf(TimeoutException.class);
|
||||
}
|
||||
|
||||
verify(mergeContext, atLeast(retries.intValue())).putPayloadById(eq(payloadId), any());
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, atLeast(retries.intValue())).putPayloadById(payloadWrapper.capture());
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -565,7 +601,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
.when(blockchain)
|
||||
.getBlockHeader(any()))
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
var payloadId =
|
||||
coordinator.preparePayload(
|
||||
@@ -582,13 +618,20 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
blockCreationTask.get();
|
||||
|
||||
// check that we only the empty block has been built
|
||||
ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
|
||||
ArgumentCaptor.forClass(BlockWithReceipts.class);
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, times(1)).putPayloadById(eq(payloadId), blockWithReceipts.capture());
|
||||
verify(mergeContext, times(1)).putPayloadById(payloadWrapper.capture());
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
|
||||
assertThat(blockWithReceipts.getAllValues().size()).isEqualTo(1);
|
||||
assertThat(blockWithReceipts.getAllValues().get(0).getBlock().getBody().getTransactions())
|
||||
assertThat(payloadWrapper.getAllValues().size()).isEqualTo(1);
|
||||
assertThat(
|
||||
payloadWrapper
|
||||
.getAllValues()
|
||||
.get(0)
|
||||
.blockWithReceipts()
|
||||
.getBlock()
|
||||
.getBody()
|
||||
.getTransactions())
|
||||
.hasSize(0);
|
||||
}
|
||||
|
||||
@@ -605,12 +648,12 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
} else {
|
||||
// when we have 5 transactions finalize block creation
|
||||
coordinator.finalizeProposalById(
|
||||
invocation.getArgument(0, PayloadIdentifier.class));
|
||||
invocation.getArgument(0, PayloadWrapper.class).payloadIdentifier());
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.when(mergeContext)
|
||||
.putPayloadById(any(), any());
|
||||
.putPayloadById(any());
|
||||
|
||||
final long timestamp = System.currentTimeMillis() / 1000;
|
||||
|
||||
@@ -642,17 +685,22 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
blockCreationTask.get();
|
||||
|
||||
ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
|
||||
ArgumentCaptor.forClass(BlockWithReceipts.class);
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, times(retries.intValue()))
|
||||
.putPayloadById(eq(payloadId1), blockWithReceipts.capture());
|
||||
verify(mergeContext, times(retries.intValue())).putPayloadById(payloadWrapper.capture());
|
||||
|
||||
assertThat(blockWithReceipts.getAllValues().size()).isEqualTo(retries.intValue());
|
||||
assertThat(payloadWrapper.getAllValues().size()).isEqualTo(retries.intValue());
|
||||
for (int i = 0; i < retries.intValue(); i++) {
|
||||
assertThat(blockWithReceipts.getAllValues().get(i).getBlock().getBody().getTransactions())
|
||||
assertThat(
|
||||
payloadWrapper
|
||||
.getAllValues()
|
||||
.get(i)
|
||||
.blockWithReceipts()
|
||||
.getBlock()
|
||||
.getBody()
|
||||
.getTransactions())
|
||||
.hasSize(i);
|
||||
assertThat(blockWithReceipts.getAllValues().get(i).getReceipts()).hasSize(i);
|
||||
assertThat(payloadWrapper.getAllValues().get(i).blockWithReceipts().getReceipts()).hasSize(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -711,12 +759,13 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
Optional.empty(),
|
||||
Optional.empty());
|
||||
|
||||
ArgumentCaptor<BlockWithReceipts> blockWithReceipts =
|
||||
ArgumentCaptor.forClass(BlockWithReceipts.class);
|
||||
ArgumentCaptor<PayloadWrapper> payloadWrapper = ArgumentCaptor.forClass(PayloadWrapper.class);
|
||||
|
||||
verify(mergeContext, atLeastOnce()).putPayloadById(eq(payloadId), blockWithReceipts.capture());
|
||||
verify(mergeContext, atLeastOnce()).putPayloadById(payloadWrapper.capture());
|
||||
|
||||
assertThat(blockWithReceipts.getValue().getHeader().getExtraData()).isEqualTo(extraData);
|
||||
assertThat(payloadWrapper.getValue().payloadIdentifier()).isEqualTo(payloadId);
|
||||
assertThat(payloadWrapper.getValue().blockWithReceipts().getHeader().getExtraData())
|
||||
.isEqualTo(extraData);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -264,7 +264,7 @@ public class 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()
|
||||
@@ -280,7 +280,7 @@ public class BlockTransactionSelector {
|
||||
return res;
|
||||
});
|
||||
LOG.atTrace()
|
||||
.setMessage("Transaction selection result result {}")
|
||||
.setMessage("Transaction selection result {}")
|
||||
.addArgument(transactionSelectionResults::toTraceLog)
|
||||
.log();
|
||||
return transactionSelectionResults;
|
||||
|
||||
Reference in New Issue
Block a user