Skip to content

Commit

Permalink
fix: retain override values on ConfigProviderImpl.update() (#17424) (
Browse files Browse the repository at this point in the history
…#17430)

Signed-off-by: Michael Tinker <[email protected]>
  • Loading branch information
tinker-michaelj authored Jan 21, 2025
1 parent ad53b0c commit d8a0c10
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,6 +59,8 @@ public class ConfigProviderImpl extends ConfigProviderBase {

private final ConfigMetrics configMetrics;

private final Map<String, String> overrideValues;

/**
* Create a new instance, particularly from dependency injection.
*/
Expand Down Expand Up @@ -92,6 +94,9 @@ public ConfigProviderImpl(
addFileSources(builder, useGenesisSource);
if (overrideValues != null) {
overrideValues.forEach(builder::withValue);
this.overrideValues = Map.copyOf(overrideValues);
} else {
this.overrideValues = Map.of();
}
final Configuration config = builder.build();
configuration = new AtomicReference<>(new VersionedConfigImpl(config, 0));
Expand Down Expand Up @@ -124,6 +129,7 @@ public void update(@NonNull final Bytes networkProperties, @NonNull final Bytes
addFileSources(builder, false);
addByteSource(builder, networkProperties);
addByteSource(builder, permissions);
overrideValues.forEach(builder::withValue);
final Configuration config = builder.build();
configuration.set(
new VersionedConfigImpl(config, this.configuration.get().getVersion() + 1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,6 +46,7 @@ public static Bytes getFileContent(@NonNull final State state, @NonNull final Fi
/**
* Observes the properties and permissions of the network from a saved state.
*/
@FunctionalInterface
public interface SpecialFilesObserver {
/**
* Accepts the properties and permissions of the network from a saved state.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
* Copyright (C) 2024-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -88,7 +88,11 @@ static Consumer<State> initFacilities(
if (hasHandledGenesisTxn(state)) {
initializeExchangeRateManager(state, configProvider, exchangeRateManager);
initializeFeeManager(state, configProvider, feeManager);
observePropertiesAndPermissions(state, configProvider.getConfiguration(), configProvider::update);
observePropertiesAndPermissions(state, configProvider.getConfiguration(), (properties, permissions) -> {
if (!Bytes.EMPTY.equals(properties) || !Bytes.EMPTY.equals(permissions)) {
configProvider.update(properties, permissions);
}
});
throttleServiceManager.init(state, throttleDefinitionsFrom(state, configProvider));
} else {
final var schema = fileService.fileSchema();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -178,10 +178,14 @@ void testUpdateDoesNotUseGenesisProperties() {
}

@Test
void incorporatesOverrideProperties() {
void incorporatesOverridePropertiesEvenAfterUpdate() {
final var subject = new ConfigProviderImpl(false, null, Map.of("baz.test", "789"));
final var config = subject.getConfiguration();
assertThat(config.getValue("baz.test")).isEqualTo("789");

subject.update(Bytes.EMPTY, Bytes.EMPTY);
final var postUpdateConfig = subject.getConfiguration();
assertThat(postUpdateConfig.getValue("baz.test")).isEqualTo("789");
}

@Test
Expand Down

0 comments on commit d8a0c10

Please sign in to comment.