Skip to content

Commit 03dd7f1

Browse files
authored
QBFT + shanghai support (#6353)
* Refactored version of QBFT/shanghai Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * More refactoring Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Add equivalent IBFT fixes. Update QBFT and IBFT round tests Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Update the change log Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Remove old comments Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Add shanghai contract validator test Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Add shanghai acceptance test Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Add Shanghai to the combined protocol schedule test, update IBFT message validator creation Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Fix merge Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Update tests to use shanghai time > 0 Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Address PR comments Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Refactor unit tests Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Refactor unit tests Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * IbftRoundTests update Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Address PR comments Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * Remove unnecessary class type check Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> --------- Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> Signed-off-by: Matt Whitehead <matthew1001@gmail.com> Signed-off-by: Matt Whitehead <matthew.whitehead@kaleido.io>
1 parent dbea838 commit 03dd7f1

File tree

30 files changed

+476
-202
lines changed

30 files changed

+476
-202
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Introduce caching mechanism to optimize Keccak hash calculations for account storage slots during block processing [#6452](https://github.com/hyperledger/besu/pull/6452)
2929
- Added configuration options for `pragueTime` to genesis file for Prague fork development [#6473](https://github.com/hyperledger/besu/pull/6473)
3030
- Moving trielog storage to RocksDB's blobdb to improve write amplications [#6289](https://github.com/hyperledger/besu/pull/6289)
31+
- Support for `shanghaiTime` fork and Shanghai EVM smart contracts in QBFT/IBFT chains [#6353](https://github.com/hyperledger/besu/pull/6353)
3132

3233
### Bug fixes
3334
- Fix the way an advertised host configured with `--p2p-host` is treated when communicating with the originator of a PING packet [#6225](https://github.com/hyperledger/besu/pull/6225)

acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/bft/BftMiningAcceptanceTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,36 @@ public void shouldMineOnSingleNodeWithFreeGas_London(
150150
cluster.verify(receiver.balanceEquals(3));
151151
}
152152

153+
@ParameterizedTest(name = "{index}: {0}")
154+
@MethodSource("factoryFunctions")
155+
public void shouldMineOnSingleNodeWithFreeGas_Shanghai(
156+
final String testName, final BftAcceptanceTestParameterization nodeFactory) throws Exception {
157+
setUp(testName, nodeFactory);
158+
final BesuNode minerNode = nodeFactory.createNode(besu, "miner1");
159+
updateGenesisConfigToShanghai(minerNode, true);
160+
161+
cluster.start(minerNode);
162+
163+
cluster.verify(blockchain.reachesHeight(minerNode, 1));
164+
165+
final Account sender = accounts.createAccount("account1");
166+
final Account receiver = accounts.createAccount("account2");
167+
168+
minerNode.execute(accountTransactions.createTransfer(sender, 50, Amount.ZERO));
169+
cluster.verify(sender.balanceEquals(50));
170+
171+
minerNode.execute(accountTransactions.create1559Transfer(sender, 50, 4, Amount.ZERO));
172+
cluster.verify(sender.balanceEquals(100));
173+
174+
minerNode.execute(
175+
accountTransactions.createIncrementalTransfers(sender, receiver, 1, Amount.ZERO));
176+
cluster.verify(receiver.balanceEquals(1));
177+
178+
minerNode.execute(
179+
accountTransactions.create1559IncrementalTransfers(sender, receiver, 2, 4, Amount.ZERO));
180+
cluster.verify(receiver.balanceEquals(3));
181+
}
182+
153183
@ParameterizedTest(name = "{index}: {0}")
154184
@MethodSource("factoryFunctions")
155185
public void shouldMineOnMultipleNodes(
@@ -245,4 +275,16 @@ private static void updateGenesisConfigToLondon(
245275
config.put("zeroBaseFee", zeroBaseFeeEnabled);
246276
minerNode.setGenesisConfig(genesisConfigNode.toString());
247277
}
278+
279+
private static void updateGenesisConfigToShanghai(
280+
final BesuNode minerNode, final boolean zeroBaseFeeEnabled) {
281+
final Optional<String> genesisConfig =
282+
minerNode.getGenesisConfigProvider().create(List.of(minerNode));
283+
final ObjectNode genesisConfigNode = JsonUtil.objectNodeFromString(genesisConfig.orElseThrow());
284+
final ObjectNode config = (ObjectNode) genesisConfigNode.get("config");
285+
config.remove("berlinBlock");
286+
config.put("shanghaiTime", 100);
287+
config.put("zeroBaseFee", zeroBaseFeeEnabled);
288+
minerNode.setGenesisConfig(genesisConfigNode.toString());
289+
}
248290
}

consensus/common/src/main/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactory.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,22 @@ public BftProtocolSchedule create(
5353
protocolSchedule.getScheduledProtocolSpecs().stream()
5454
.filter(protocolSpecMatchesConsensusBlockRange(spec.getBlock(), endBlock))
5555
.forEach(
56-
s ->
57-
combinedProtocolSchedule.putBlockNumberMilestone(s.fork().milestone(), s.spec()));
56+
s -> {
57+
if (s instanceof ScheduledProtocolSpec.TimestampProtocolSpec) {
58+
combinedProtocolSchedule.putTimestampMilestone(s.fork().milestone(), s.spec());
59+
} else if (s instanceof ScheduledProtocolSpec.BlockNumberProtocolSpec) {
60+
combinedProtocolSchedule.putBlockNumberMilestone(s.fork().milestone(), s.spec());
61+
} else {
62+
throw new IllegalStateException(
63+
"Unexpected milestone: " + s + " for milestone: " + s.fork().milestone());
64+
}
65+
});
5866

5967
// When moving to a new consensus mechanism we want to use the last milestone but created by
6068
// our consensus mechanism's BesuControllerBuilder so any additional rules are applied
6169
if (spec.getBlock() > 0) {
6270
combinedProtocolSchedule.putBlockNumberMilestone(
63-
spec.getBlock(), protocolSchedule.getByBlockNumber(spec.getBlock()));
71+
spec.getBlock(), protocolSchedule.getByBlockNumberOrTimestamp(spec.getBlock(), 0L));
6472
}
6573
}
6674
return combinedProtocolSchedule;

consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
2929
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
3030
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;
31+
import org.hyperledger.besu.ethereum.mainnet.WithdrawalsValidator;
3132
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
3233
import org.hyperledger.besu.evm.internal.EvmConfiguration;
3334

@@ -116,6 +117,9 @@ private ProtocolSpecBuilder applyBftChanges(
116117
.skipZeroBlockRewards(true)
117118
.blockHeaderFunctions(BftBlockHeaderFunctions.forOnchainBlock(bftExtraDataCodec))
118119
.blockReward(Wei.of(configOptions.getBlockRewardWei()))
120+
.withdrawalsValidator(
121+
new WithdrawalsValidator
122+
.ProhibitedWithdrawals()) // QBFT/IBFT doesn't support withdrawals
119123
.miningBeneficiaryCalculator(
120124
header -> configOptions.getMiningBeneficiary().orElseGet(header::getCoinbase));
121125
}

consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ public BftProtocolSchedule(final DefaultProtocolSchedule protocolSchedule) {
3939
}
4040

4141
/**
42-
* Look up ProtocolSpec by block number
42+
* Look up ProtocolSpec by block number or timestamp
4343
*
4444
* @param number block number
45-
* @return the protocol spec for that block number
45+
* @param timestamp block timestamp
46+
* @return the protocol spec for that block number or timestamp
4647
*/
47-
public ProtocolSpec getByBlockNumber(final long number) {
48+
public ProtocolSpec getByBlockNumberOrTimestamp(final long number, final long timestamp) {
4849
checkArgument(number >= 0, "number must be non-negative");
4950
checkArgument(
5051
!protocolSpecs.isEmpty(), "At least 1 milestone must be provided to the protocol schedule");
@@ -53,12 +54,19 @@ public ProtocolSpec getByBlockNumber(final long number) {
5354
"There must be a milestone starting from block 0");
5455
// protocolSpecs is sorted in descending block order, so the first one we find that's lower than
5556
// the requested level will be the most appropriate spec
57+
ProtocolSpec theSpec = null;
5658
for (final ScheduledProtocolSpec s : protocolSpecs) {
57-
if (number >= s.fork().milestone()) {
58-
return s.spec();
59+
if ((s instanceof ScheduledProtocolSpec.BlockNumberProtocolSpec)
60+
&& (number >= s.fork().milestone())) {
61+
theSpec = s.spec();
62+
break;
63+
} else if ((s instanceof ScheduledProtocolSpec.TimestampProtocolSpec)
64+
&& (timestamp >= s.fork().milestone())) {
65+
theSpec = s.spec();
66+
break;
5967
}
6068
}
61-
return null;
69+
return theSpec;
6270
}
6371

6472
/**

consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,20 @@ public void createsCombinedProtocolScheduleWithMilestonesFromSingleProtocolSched
6060
final BftProtocolSchedule combinedProtocolSchedule =
6161
combinedProtocolScheduleFactory.create(consensusSchedule, Optional.of(BigInteger.TEN));
6262

63-
assertThat(combinedProtocolSchedule.getByBlockNumber(0L).getName()).isEqualTo("Frontier");
64-
assertThat(combinedProtocolSchedule.getByBlockNumber(0L))
65-
.isSameAs(protocolSchedule.getByBlockNumber(0L));
63+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(0L, 0L).getName())
64+
.isEqualTo("Frontier");
65+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(0L, 0L))
66+
.isSameAs(protocolSchedule.getByBlockNumberOrTimestamp(0L, 0L));
6667

67-
assertThat(combinedProtocolSchedule.getByBlockNumber(5L).getName()).isEqualTo("Homestead");
68-
assertThat(combinedProtocolSchedule.getByBlockNumber(5L))
69-
.isSameAs(protocolSchedule.getByBlockNumber(5L));
68+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(5L, 0L).getName())
69+
.isEqualTo("Homestead");
70+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(5L, 0L))
71+
.isSameAs(protocolSchedule.getByBlockNumberOrTimestamp(5L, 0L));
7072

71-
assertThat(combinedProtocolSchedule.getByBlockNumber(10L).getName())
73+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(10L, 0L).getName())
7274
.isEqualTo("Constantinople");
73-
assertThat(combinedProtocolSchedule.getByBlockNumber(10L))
74-
.isSameAs(protocolSchedule.getByBlockNumber(10L));
75+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(10L, 0L))
76+
.isSameAs(protocolSchedule.getByBlockNumberOrTimestamp(10L, 0L));
7577

7678
assertThat(
7779
new MilestoneStreamingProtocolSchedule(combinedProtocolSchedule)
@@ -88,63 +90,78 @@ public void createsCombinedProtocolScheduleWithMilestonesFromMultipleSchedules()
8890
genesisConfigOptions.byzantiumBlock(105L);
8991
genesisConfigOptions.berlinBlock(110L);
9092
genesisConfigOptions.londonBlock(220L);
93+
genesisConfigOptions.shanghaiTime(1000000050L);
9194
genesisConfigOptions.chainId(BigInteger.TEN);
9295

9396
final BftProtocolSchedule protocolSchedule1 = createProtocolSchedule(genesisConfigOptions);
9497
final BftProtocolSchedule protocolSchedule2 = createProtocolSchedule(genesisConfigOptions);
9598
final BftProtocolSchedule protocolSchedule3 = createProtocolSchedule(genesisConfigOptions);
99+
final BftProtocolSchedule protocolSchedule4 = createProtocolSchedule(genesisConfigOptions);
96100

97101
final NavigableSet<ForkSpec<ProtocolSchedule>> consensusSchedule =
98102
new TreeSet<>(ForkSpec.COMPARATOR);
99103
consensusSchedule.add(new ForkSpec<>(0, protocolSchedule1));
100104
consensusSchedule.add(new ForkSpec<>(100L, protocolSchedule2));
101105
consensusSchedule.add(new ForkSpec<>(200L, protocolSchedule3));
106+
consensusSchedule.add(new ForkSpec<>(1000000000L, protocolSchedule4));
102107

103108
final BftProtocolSchedule combinedProtocolSchedule =
104109
combinedProtocolScheduleFactory.create(consensusSchedule, Optional.of(BigInteger.TEN));
105110

106111
// consensus schedule 1
107-
assertThat(combinedProtocolSchedule.getByBlockNumber(0L).getName()).isEqualTo("Frontier");
108-
assertThat(combinedProtocolSchedule.getByBlockNumber(0L))
109-
.isSameAs(protocolSchedule1.getByBlockNumber(0L));
110-
111-
assertThat(combinedProtocolSchedule.getByBlockNumber(5L).getName()).isEqualTo("Homestead");
112-
assertThat(combinedProtocolSchedule.getByBlockNumber(5L))
113-
.isSameAs(protocolSchedule1.getByBlockNumber(5L));
114-
assertThat(combinedProtocolSchedule.getByBlockNumber(10L).getName())
112+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(0L, 0L).getName())
113+
.isEqualTo("Frontier");
114+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(0L, 0L))
115+
.isSameAs(protocolSchedule1.getByBlockNumberOrTimestamp(0L, 0L));
116+
117+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(5L, 0L).getName())
118+
.isEqualTo("Homestead");
119+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(5L, 0L))
120+
.isSameAs(protocolSchedule1.getByBlockNumberOrTimestamp(5L, 0L));
121+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(10L, 0L).getName())
115122
.isEqualTo("Constantinople");
116-
assertThat(combinedProtocolSchedule.getByBlockNumber(10L))
117-
.isSameAs(protocolSchedule1.getByBlockNumber(10L));
123+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(10L, 0L))
124+
.isSameAs(protocolSchedule1.getByBlockNumberOrTimestamp(10L, 0L));
118125

119126
// consensus schedule 2 migration block
120-
assertThat(combinedProtocolSchedule.getByBlockNumber(100L).getName())
127+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(100L, 0L).getName())
121128
.isEqualTo("Constantinople");
122-
assertThat(combinedProtocolSchedule.getByBlockNumber(100L))
123-
.isSameAs(protocolSchedule2.getByBlockNumber(10L));
129+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(100L, 0L))
130+
.isSameAs(protocolSchedule2.getByBlockNumberOrTimestamp(10L, 0L));
124131

125132
// consensus schedule 2
126-
assertThat(combinedProtocolSchedule.getByBlockNumber(105L).getName()).isEqualTo("Byzantium");
127-
assertThat(combinedProtocolSchedule.getByBlockNumber(105L))
128-
.isSameAs(protocolSchedule2.getByBlockNumber(105L));
129-
assertThat(combinedProtocolSchedule.getByBlockNumber(110L).getName()).isEqualTo("Berlin");
130-
assertThat(combinedProtocolSchedule.getByBlockNumber(110L))
131-
.isSameAs(protocolSchedule2.getByBlockNumber(110L));
133+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(105L, 0L).getName())
134+
.isEqualTo("Byzantium");
135+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(105L, 0L))
136+
.isSameAs(protocolSchedule2.getByBlockNumberOrTimestamp(105L, 0L));
137+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(110L, 0L).getName())
138+
.isEqualTo("Berlin");
139+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(110L, 0L))
140+
.isSameAs(protocolSchedule2.getByBlockNumberOrTimestamp(110L, 0L));
132141

133142
// consensus schedule 3 migration block
134-
assertThat(combinedProtocolSchedule.getByBlockNumber(200L).getName()).isEqualTo("Berlin");
135-
assertThat(combinedProtocolSchedule.getByBlockNumber(200L))
136-
.isSameAs(protocolSchedule3.getByBlockNumber(110L));
143+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(200L, 0L).getName())
144+
.isEqualTo("Berlin");
145+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(200L, 0L))
146+
.isSameAs(protocolSchedule3.getByBlockNumberOrTimestamp(110L, 0L));
137147

138148
// consensus schedule 3
139-
assertThat(combinedProtocolSchedule.getByBlockNumber(220L).getName()).isEqualTo("London");
140-
assertThat(combinedProtocolSchedule.getByBlockNumber(220L))
141-
.isSameAs(protocolSchedule3.getByBlockNumber(220L));
149+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(220L, 0L).getName())
150+
.isEqualTo("London");
151+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(220L, 0L))
152+
.isSameAs(protocolSchedule3.getByBlockNumberOrTimestamp(220L, 0L));
153+
154+
// consensus schedule 4
155+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(0L, 1000000050L).getName())
156+
.isEqualTo("Shanghai");
157+
assertThat(combinedProtocolSchedule.getByBlockNumberOrTimestamp(220L, 1000000050L))
158+
.isSameAs(protocolSchedule4.getByBlockNumberOrTimestamp(220L, 1000000050L));
142159

143160
assertThat(
144161
new MilestoneStreamingProtocolSchedule(combinedProtocolSchedule)
145162
.streamMilestoneBlocks()
146163
.collect(Collectors.toList()))
147-
.isEqualTo(List.of(0L, 5L, 10L, 100L, 105L, 110L, 200L, 220L));
164+
.isEqualTo(List.of(0L, 5L, 10L, 100L, 105L, 110L, 200L, 220L, 1000000000L, 1000000050L));
148165
}
149166

150167
private BftProtocolSchedule createProtocolSchedule(

consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.mockito.Mockito.when;
2525

2626
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
27+
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
2728
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
2829
import org.hyperledger.besu.consensus.common.bft.RoundTimer;
2930
import org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreator;
@@ -48,6 +49,7 @@
4849
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
4950
import org.hyperledger.besu.ethereum.core.BlockImporter;
5051
import org.hyperledger.besu.ethereum.mainnet.BlockImportResult;
52+
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
5153
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
5254
import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException;
5355
import org.hyperledger.besu.util.Subscribers;
@@ -74,6 +76,8 @@ public class IbftRoundIntegrationTest {
7476
private final Subscribers<MinedBlockObserver> subscribers = Subscribers.create();
7577
private ProtocolContext protocolContext;
7678

79+
@Mock private BftProtocolSchedule protocolSchedule;
80+
@Mock private ProtocolSpec protocolSpec;
7781
@Mock private MutableBlockchain blockChain;
7882
@Mock private WorldStateArchive worldStateArchive;
7983
@Mock private BlockImporter blockImporter;
@@ -112,6 +116,9 @@ public void setup() {
112116
final BlockHeader header = headerTestFixture.buildHeader();
113117
proposedBlock = new Block(header, new BlockBody(emptyList(), emptyList()));
114118

119+
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
120+
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
121+
115122
when(blockImporter.importBlock(any(), any(), any())).thenReturn(new BlockImportResult(true));
116123

117124
protocolContext =
@@ -131,7 +138,7 @@ public void signingFailsOnReceiptOfProposalUpdatesRoundButTransmitsNothing() {
131138
roundState,
132139
blockCreator,
133140
protocolContext,
134-
blockImporter,
141+
protocolSchedule,
135142
subscribers,
136143
nodeKey,
137144
throwingMessageFactory,
@@ -158,7 +165,7 @@ public void failuresToSignStillAllowBlockToBeImported() {
158165
roundState,
159166
blockCreator,
160167
protocolContext,
161-
blockImporter,
168+
protocolSchedule,
162169
subscribers,
163170
nodeKey,
164171
throwingMessageFactory,

consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRound.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.hyperledger.besu.ethereum.core.BlockImporter;
4141
import org.hyperledger.besu.ethereum.mainnet.BlockImportResult;
4242
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
43+
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
4344
import org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException;
4445
import org.hyperledger.besu.util.Subscribers;
4546

@@ -57,7 +58,7 @@ public class IbftRound {
5758
private final RoundState roundState;
5859
private final BlockCreator blockCreator;
5960
private final ProtocolContext protocolContext;
60-
private final BlockImporter blockImporter;
61+
private final ProtocolSchedule protocolSchedule;
6162
private final NodeKey nodeKey;
6263
private final MessageFactory messageFactory; // used only to create stored local msgs
6364
private final IbftMessageTransmitter transmitter;
@@ -69,7 +70,7 @@ public class IbftRound {
6970
* @param roundState the round state
7071
* @param blockCreator the block creator
7172
* @param protocolContext the protocol context
72-
* @param blockImporter the block importer
73+
* @param protocolSchedule the protocol schedule
7374
* @param observers the observers
7475
* @param nodeKey the node key
7576
* @param messageFactory the message factory
@@ -81,7 +82,7 @@ public IbftRound(
8182
final RoundState roundState,
8283
final BlockCreator blockCreator,
8384
final ProtocolContext protocolContext,
84-
final BlockImporter blockImporter,
85+
final ProtocolSchedule protocolSchedule,
8586
final Subscribers<MinedBlockObserver> observers,
8687
final NodeKey nodeKey,
8788
final MessageFactory messageFactory,
@@ -91,7 +92,7 @@ public IbftRound(
9192
this.roundState = roundState;
9293
this.blockCreator = blockCreator;
9394
this.protocolContext = protocolContext;
94-
this.blockImporter = blockImporter;
95+
this.protocolSchedule = protocolSchedule;
9596
this.observers = observers;
9697
this.nodeKey = nodeKey;
9798
this.messageFactory = messageFactory;
@@ -312,6 +313,8 @@ private void importBlockToChain() {
312313
blockToImport.getHash());
313314
}
314315
LOG.trace("Importing block with extraData={}", extraData);
316+
final BlockImporter blockImporter =
317+
protocolSchedule.getByBlockHeader(blockToImport.getHeader()).getBlockImporter();
315318
final BlockImportResult result =
316319
blockImporter.importBlock(protocolContext, blockToImport, HeaderValidationMode.FULL);
317320
if (!result.isImported()) {

0 commit comments

Comments
 (0)