Skip to content

Commit

Permalink
chore: do not update file 102 during the first transaction after a fr…
Browse files Browse the repository at this point in the history
…eeze upgrade when DAB is disabled (#15467)

Signed-off-by: Iris Simon <[email protected]>
  • Loading branch information
iwsimon authored Sep 13, 2024
1 parent 49cee4f commit 5bc907e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.hedera.node.config.data.FilesConfig;
import com.hedera.node.config.data.HederaConfig;
import com.hedera.node.config.data.NetworkAdminConfig;
import com.hedera.node.config.data.NodesConfig;
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.swirlds.config.api.Configuration;
import com.swirlds.platform.system.InitTrigger;
Expand Down Expand Up @@ -133,15 +134,18 @@ public void doGenesisSetup(@NonNull final Dispatch dispatch) {
*/
public void doPostUpgradeSetup(@NonNull final Dispatch dispatch) {
final var systemContext = systemContextFor(dispatch);
final var config = dispatch.config();

// We update the node details file from the address book that resulted from all pre-upgrade HAPI node changes
final var nodeStore = dispatch.handleContext().storeFactory().readableStore(ReadableNodeStore.class);
fileService.updateNodeDetailsAfterFreeze(systemContext, nodeStore);
dispatch.stack().commitFullStack();
final var nodesConfig = config.getConfigData(NodesConfig.class);
if (nodesConfig.enableDAB()) {
final var nodeStore = dispatch.handleContext().storeFactory().readableStore(ReadableNodeStore.class);
fileService.updateNodeDetailsAfterFreeze(systemContext, nodeStore);
dispatch.stack().commitFullStack();
}

// And then we update the system files for fees schedules, throttles, override properties, and override
// permissions from any upgrade files that are present in the configured directory
final var config = dispatch.config();
final var filesConfig = config.getConfigData(FilesConfig.class);
final var adminConfig = config.getConfigData(NetworkAdminConfig.class);
final List<AutoSysFileUpdate> autoUpdates = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import com.hedera.node.app.spi.fixtures.util.LoggingTarget;
import com.hedera.node.app.spi.store.StoreFactory;
import com.hedera.node.app.spi.workflows.HandleContext;
import com.hedera.node.app.spi.workflows.SystemContext;
import com.hedera.node.app.spi.workflows.record.StreamBuilder;
import com.hedera.node.app.workflows.handle.Dispatch;
import com.hedera.node.app.workflows.handle.record.SystemSetup;
Expand Down Expand Up @@ -169,37 +168,29 @@ void successfulAutoUpdatesAreDispatchedWithFilesAvailable() throws IOException {
given(dispatch.config()).willReturn(config);
given(dispatch.consensusNow()).willReturn(CONSENSUS_NOW);
given(dispatch.handleContext()).willReturn(handleContext);
given(handleContext.storeFactory()).willReturn(storeFactory);
given(storeFactory.readableStore(ReadableNodeStore.class)).willReturn(readableNodeStore);
given(handleContext.dispatchPrecedingTransaction(any(), any(), any(), any()))
.willReturn(streamBuilder);

subject.doPostUpgradeSetup(dispatch);

final var filesConfig = config.getConfigData(FilesConfig.class);
verify(fileService).updateNodeDetailsAfterFreeze(any(SystemContext.class), eq(readableNodeStore));
verifyUpdateDispatch(filesConfig.networkProperties(), serializedPropertyOverrides());
verifyUpdateDispatch(filesConfig.hapiPermissions(), serializedPermissionOverrides());
verifyUpdateDispatch(filesConfig.throttleDefinitions(), serializedThrottleOverrides());
verifyUpdateDispatch(filesConfig.feeSchedules(), serializedFeeSchedules());
verify(stack, times(5)).commitFullStack();
verify(stack, times(4)).commitFullStack();
}

@Test
void onlyNodeDetailsAutoUpdateIsDispatchedWithNoFilesAvailable() {
final var config = HederaTestConfigBuilder.create()
.withValue("networkAdmin.upgradeSysFilesLoc", tempDir.toString())
.getOrCreateConfig();
given(dispatch.stack()).willReturn(stack);
given(dispatch.config()).willReturn(config);
given(dispatch.handleContext()).willReturn(handleContext);
given(handleContext.storeFactory()).willReturn(storeFactory);
given(storeFactory.readableStore(ReadableNodeStore.class)).willReturn(readableNodeStore);

subject.doPostUpgradeSetup(dispatch);

verify(fileService).updateNodeDetailsAfterFreeze(any(SystemContext.class), eq(readableNodeStore));
verify(stack, times(1)).commitFullStack();
verify(stack, times(0)).commitFullStack();

final var infoLogs = logCaptor.infoLogs();
assertThat(infoLogs.size()).isEqualTo(4);
Expand All @@ -209,36 +200,6 @@ void onlyNodeDetailsAutoUpdateIsDispatchedWithNoFilesAvailable() {
assertThat(infoLogs.getLast()).startsWith("No post-upgrade file for api-permission-override.properties");
}

@Test
void onlyNodeDetailsAutoUpdateIsDispatchedWithInvalidFilesAvailable() throws IOException {
final var config = HederaTestConfigBuilder.create()
.withValue("networkAdmin.upgradeSysFilesLoc", tempDir.toString())
.getOrCreateConfig();
final var adminConfig = config.getConfigData(NetworkAdminConfig.class);
Files.writeString(tempDir.resolve(adminConfig.upgradePropertyOverridesFile()), invalidPropertyOverrides());
Files.writeString(tempDir.resolve(adminConfig.upgradePermissionOverridesFile()), invalidPermissionOverrides());
Files.writeString(tempDir.resolve(adminConfig.upgradeThrottlesFile()), invalidThrottleOverrides());
Files.writeString(tempDir.resolve(adminConfig.upgradeFeeSchedulesFile()), invalidFeeScheduleOverrides());
given(dispatch.stack()).willReturn(stack);
given(dispatch.config()).willReturn(config);
given(dispatch.handleContext()).willReturn(handleContext);
given(handleContext.storeFactory()).willReturn(storeFactory);
given(storeFactory.readableStore(ReadableNodeStore.class)).willReturn(readableNodeStore);

subject.doPostUpgradeSetup(dispatch);

verify(fileService).updateNodeDetailsAfterFreeze(any(SystemContext.class), eq(readableNodeStore));
verify(stack, times(1)).commitFullStack();

final var errorLogs = logCaptor.errorLogs();
assertThat(errorLogs.size()).isEqualTo(4);
assertThat(errorLogs.getFirst()).startsWith("Failed to parse upgrade file for feeSchedules.json");
assertThat(errorLogs.get(1)).startsWith("Failed to parse upgrade file for throttles.json");
assertThat(errorLogs.get(2)).startsWith("Failed to parse upgrade file for application-override.properties");
assertThat(errorLogs.getLast())
.startsWith("Failed to parse upgrade file for api-permission-override.properties");
}

@Test
@SuppressWarnings("unchecked")
void externalizeInitSideEffectsCreatesAllRecords() {
Expand Down

0 comments on commit 5bc907e

Please sign in to comment.