Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Fast Sync

### Additions and Improvements
- Expose new method to query hardfork by block number Plugin API [#9115](https://github.com/hyperledger/besu/pull/9115)

#### Fusaka devnets

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ public void start() {
private HardforkSeen queryHardfork(
final BlockchainService blockchainService, final BlockHeader header) {
final var currentHardfork = blockchainService.getHardforkId(header);
final var currentHardforkByNumber = blockchainService.getHardforkId(header.getNumber());
final var nextHardfork =
blockchainService.getNextBlockHardforkId(header, header.getTimestamp() + 1);

return new HardforkSeen(header.getNumber(), currentHardfork, nextHardfork);
return new HardforkSeen(
header.getNumber(), currentHardfork, currentHardforkByNumber, nextHardfork);
}

@Override
Expand All @@ -97,7 +99,11 @@ private void writeSeenHardforks() {
.map(
r ->
String.join(
",", String.valueOf(r.blockNumber), r.current.name(), r.next.name()))
",",
String.valueOf(r.blockNumber),
r.current.name(),
r.currentByNumber().name(),
r.next.name()))
.collect(Collectors.joining("\n"));

Files.write(callbackFile.toPath(), content.getBytes(UTF_8));
Expand All @@ -107,5 +113,6 @@ private void writeSeenHardforks() {
}
}

private record HardforkSeen(long blockNumber, HardforkId current, HardforkId next) {}
private record HardforkSeen(
long blockNumber, HardforkId current, HardforkId currentByNumber, HardforkId next) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationFactory;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -30,25 +29,18 @@
import org.junit.jupiter.api.Test;

public class BlockchainServicePluginTest extends AcceptanceTestBase {
private BesuNode minerNode;
private BesuNode pluginNode;

@BeforeEach
public void setUp() throws Exception {
minerNode =
besu.createQbftNode(
"minerNode",
besuNodeConfigurationBuilder ->
besuNodeConfigurationBuilder.genesisConfigProvider(
GenesisConfigurationFactory::createQbftLondonGenesisConfig));
pluginNode =
besu.createQbftPluginsNode(
"pluginNode",
Collections.singletonList("testPlugins"),
Collections.singletonList("--plugin-tx-validator-test-enabled=true"),
"DEBUG");

cluster.start(pluginNode, minerNode);
cluster.start(pluginNode);
}

@Test
Expand All @@ -57,7 +49,8 @@ public void hardforkListIsCorrect() throws IOException {
waitForFile(hardforkListFile);
final var fileContents = Files.readAllLines(hardforkListFile);

final var expectedLines = List.of("0,BERLIN,BERLIN", "1,BERLIN,LONDON", "2,LONDON,LONDON");
final var expectedLines =
List.of("0,BERLIN,BERLIN,BERLIN", "1,BERLIN,BERLIN,LONDON", "2,LONDON,LONDON,LONDON");

for (int i = 0; i < expectedLines.size(); i++) {
assertThat(fileContents.get(i)).isEqualTo(expectedLines.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ public HardforkId getHardforkId(final BlockHeader blockHeader) {
return protocolSchedule.getByBlockHeader(blockHeader).getHardforkId();
}

@Override
public HardforkId getHardforkId(final long blockNumber) {
return blockchain
.getBlockHeader(blockNumber)
.map(this::getHardforkId)
.orElseThrow(
() -> new IllegalArgumentException("Block not found for number: " + blockNumber));
}

@Override
public HardforkId getNextBlockHardforkId(
final BlockHeader parentBlockHeader, final long timestampForNextBlock) {
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = '5BI+4JAKgBsTClKWIeF86C3kS/RVT3Cdwyju/HydR9o='
knownHash = 'fhbRRCXyfMDwSkyEe+YhgUhzIu2/OWSMhttKCnmTqlc='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ void setFinalizedBlock(Hash blockHash)
@Unstable
HardforkId getHardforkId(BlockHeader blockHeader);

/**
* Get the hardfork identifier for the given block number
*
* @param blockNumber the block number to determine the hardfork for
* @return the hardfork identifier applicable to the given block number
* @throws IllegalArgumentException if no block with that number exists
*/
@Unstable
HardforkId getHardforkId(long blockNumber);

/**
* Get the hardfork identifier for the next block based on the parent block and timestamp
*
Expand Down