diff --git a/app/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java b/app/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java index e4387303042..019d37ea266 100644 --- a/app/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java +++ b/app/src/main/java/org/hyperledger/besu/services/BesuConfigurationImpl.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.plugin.services.BesuConfiguration; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.util.BesuVersionUtils; import java.nio.file.Path; import java.util.Optional; @@ -135,6 +136,16 @@ public Wei getMinGasPrice() { return new DataStoreConfigurationImpl(dataStorageConfiguration); } + @Override + public String getBesuVersion() { + return BesuVersionUtils.shortVersion(); + } + + @Override + public String getBesuCommitHash() { + return BesuVersionUtils.commit(); + } + /** * A concrete implementation of DataStorageConfiguration which is used in Besu plugin framework. */ diff --git a/app/src/test/java/org/hyperledger/besu/services/BesuConfigurationImplTest.java b/app/src/test/java/org/hyperledger/besu/services/BesuConfigurationImplTest.java new file mode 100644 index 00000000000..a5787e508bf --- /dev/null +++ b/app/src/test/java/org/hyperledger/besu/services/BesuConfigurationImplTest.java @@ -0,0 +1,36 @@ +/* + * Copyright contributors to Besu. + * + * 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.services; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.util.BesuVersionUtils; + +import org.junit.jupiter.api.Test; + +class BesuConfigurationImplTest { + + @Test + void getBesuVersion_delegatesToBesuVersionUtils() { + BesuConfigurationImpl config = new BesuConfigurationImpl(); + assertThat(config.getBesuVersion()).isEqualTo(BesuVersionUtils.shortVersion()); + } + + @Test + void getBesuCommitHash_delegatesToBesuVersionUtils() { + BesuConfigurationImpl config = new BesuConfigurationImpl(); + assertThat(config.getBesuCommitHash()).isEqualTo(BesuVersionUtils.commit()); + } +} diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 06dde1b1189..74b833b0e63 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -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 = 'fDkUshUOXLQDBHsugUujwwJkJtYVYnqipuScb8CIof0=' + knownHash = '4vItngNeppIRII2rFbvadnol4Whng6fPz4+Iytl2+sg=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java index 375843773a1..a529b70aa64 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/BesuConfiguration.java @@ -100,4 +100,26 @@ public interface BesuConfiguration extends BesuService { */ @Unstable DataStorageConfiguration getDataStorageConfiguration(); + + /** + * Returns the version of the running Besu node. + * + *

This is a human-readable version string. For release builds, it is typically a semantic + * version such as {@code "25.3.0"}. Development builds may include a qualifier, e.g. {@code + * "25.3.1-dev-ac23d311"}. + * + *

Available during all plugin lifecycle phases ({@code register} through {@code stop}). + * + * @return the Besu node version string + */ + String getBesuVersion(); + + /** + * Returns the git commit hash of the running Besu build. + * + *

Available during all plugin lifecycle phases ({@code register} through {@code stop}). + * + * @return the git commit hash + */ + String getBesuCommitHash(); }