Improve get protocol schedule (only get header and not the entire block) (#4938)

There is a performance regression in the RC version 23.1.0-RC1 compared to 22.10.3 in both engine_getPayloadV1 and engine_forkchoiceUpdatedV1 calls. This regression is related to recent changes in the way we get the protocol specifications. We get the whole block by decoding each single transaction to use only the block header.

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
This commit is contained in:
matkt
2023-01-17 11:18:45 +01:00
committed by GitHub
parent dd41abe01d
commit b2ff02d950
2 changed files with 4 additions and 11 deletions

View File

@@ -17,7 +17,6 @@ package org.hyperledger.besu.consensus.merge;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.core.TransactionFilter;
@@ -117,8 +116,7 @@ public class TransitionProtocolSchedule implements ProtocolSchedule {
return Optional.ofNullable(protocolContext)
.map(ProtocolContext::getBlockchain)
.flatMap(blockchain -> blockchain.getBlockByNumber(number))
.map(Block::getHeader)
.flatMap(blockchain -> blockchain.getBlockHeader(number))
.map(timestampSchedule::getByBlockHeader)
.orElseGet(
() ->

View File

@@ -23,8 +23,6 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
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.Difficulty;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@@ -162,8 +160,7 @@ public class TransitionProtocolScheduleTest {
@Test
public void getByBlockNumber_returnsTimestampScheduleIfPresent() {
final Block block = new Block(blockHeader, BlockBody.empty());
when(blockchain.getBlockByNumber(BLOCK_NUMBER)).thenReturn(Optional.of(block));
when(blockchain.getBlockHeader(BLOCK_NUMBER)).thenReturn(Optional.of(blockHeader));
when(timestampSchedule.getByBlockHeader(blockHeader)).thenReturn(mock(ProtocolSpec.class));
assertThat(transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER)).isNotNull();
@@ -174,7 +171,7 @@ public class TransitionProtocolScheduleTest {
@Test
public void getByBlockNumber_delegatesToPreMergeScheduleWhenBlockNotFound() {
when(blockchain.getBlockByNumber(BLOCK_NUMBER)).thenReturn(Optional.empty());
when(blockchain.getBlockHeader(BLOCK_NUMBER)).thenReturn(Optional.empty());
when(mergeContext.isPostMerge()).thenReturn(false);
transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER);
@@ -184,7 +181,7 @@ public class TransitionProtocolScheduleTest {
@Test
public void getByBlockNumber_delegatesToPostMergeScheduleWhenBlockNotFound() {
when(blockchain.getBlockByNumber(BLOCK_NUMBER)).thenReturn(Optional.empty());
when(blockchain.getBlockHeader(BLOCK_NUMBER)).thenReturn(Optional.empty());
when(mergeContext.isPostMerge()).thenReturn(true);
transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER);
@@ -194,8 +191,6 @@ public class TransitionProtocolScheduleTest {
@Test
public void getByBlockNumber_delegatesToPostMergeScheduleWhenTimestampScheduleDoesNotExist() {
final Block block = new Block(blockHeader, BlockBody.empty());
when(blockchain.getBlockByNumber(BLOCK_NUMBER)).thenReturn(Optional.of(block));
when(mergeContext.isPostMerge()).thenReturn(true);
transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER);