Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retain override values on ConfigProviderImpl.update() (#17424) #17430

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@
if (hasHandledGenesisTxn(state)) {
initializeExchangeRateManager(state, configProvider, exchangeRateManager);
initializeFeeManager(state, configProvider, feeManager);
observePropertiesAndPermissions(state, configProvider.getConfiguration(), configProvider::update);
observePropertiesAndPermissions(state, configProvider.getConfiguration(), (properties, permissions) -> {

Check warning on line 91 in hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/FacilityInitModule.java

View check run for this annotation

Codecov / codecov/patch

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/FacilityInitModule.java#L91

Added line #L91 was not covered by tests
if (!Bytes.EMPTY.equals(properties) || !Bytes.EMPTY.equals(permissions)) {
configProvider.update(properties, permissions);

Check warning on line 93 in hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/FacilityInitModule.java

View check run for this annotation

Codecov / codecov/patch

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/FacilityInitModule.java#L93

Added line #L93 was not covered by tests
}
});

Check warning on line 95 in hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/FacilityInitModule.java

View check run for this annotation

Codecov / codecov/patch

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/FacilityInitModule.java#L95

Added line #L95 was not covered by tests
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
Loading