Skip to content

Commit

Permalink
feat: nullify PlatformState.addressBooks
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
  • Loading branch information
anthony-swirldslabs committed Jan 9, 2025
1 parent c7ce308 commit e43ca88
Show file tree
Hide file tree
Showing 31 changed files with 463 additions and 604 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.swirlds.common.crypto.Hash;
import com.swirlds.platform.state.service.PlatformStateService;
import com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema;
import com.swirlds.platform.state.service.schemas.V0590PlatformStateSchema;
import com.swirlds.platform.system.Round;
import com.swirlds.platform.system.events.ConsensusEvent;
import com.swirlds.platform.system.state.notifications.StateHashedNotification;
Expand Down Expand Up @@ -138,7 +138,7 @@ public void setup() throws IOException, ParseException {
loadSampleItems();
state = new FakeState();
addServiceSingleton(new V0560BlockStreamSchema(ignore -> {}), BlockStreamService.NAME, BlockStreamInfo.DEFAULT);
addServiceSingleton(new V0540PlatformStateSchema(), PlatformStateService.NAME, platformState);
addServiceSingleton(new V0590PlatformStateSchema(), PlatformStateService.NAME, platformState);
subject.initLastBlockHash(ZERO_BLOCK_HASH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.swirlds.common.crypto.Hash;
import com.swirlds.platform.state.service.PlatformStateService;
import com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema;
import com.swirlds.platform.state.service.schemas.V0590PlatformStateSchema;
import com.swirlds.platform.system.Round;
import com.swirlds.platform.system.events.ConsensusEvent;
import com.swirlds.platform.system.state.notifications.StateHashedNotification;
Expand Down Expand Up @@ -114,7 +114,7 @@ public void setup() throws IOException, ParseException {
loadSampleItems();
state = new FakeState();
addServiceSingleton(new V0560BlockStreamSchema(ignore -> {}), BlockStreamService.NAME, BlockStreamInfo.DEFAULT);
addServiceSingleton(new V0540PlatformStateSchema(), PlatformStateService.NAME, platformState);
addServiceSingleton(new V0590PlatformStateSchema(), PlatformStateService.NAME, platformState);
subject.initLastBlockHash(ZERO_BLOCK_HASH);
System.out.println("serializationBatchSize = "
+ configProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static com.hedera.node.config.types.StreamMode.BLOCKS;
import static com.hedera.node.config.types.StreamMode.RECORDS;
import static com.swirlds.platform.state.service.PlatformStateService.PLATFORM_STATE_SERVICE;
import static com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema.PLATFORM_STATE_KEY;
import static com.swirlds.platform.state.service.schemas.V0590PlatformStateSchema.PLATFORM_STATE_KEY;
import static com.swirlds.platform.system.InitTrigger.EVENT_STREAM_RECOVERY;
import static com.swirlds.platform.system.InitTrigger.GENESIS;
import static com.swirlds.platform.system.InitTrigger.RECONNECT;
Expand Down Expand Up @@ -649,9 +649,9 @@ private void migrateSchemas(
startupNetworks = startupNetworksFactory.apply(configProvider);
PLATFORM_STATE_SERVICE.setAppVersionFn(ServicesSoftwareVersion::from);
// If the client code did not provide a disk address book, we are reconnecting; and
// PlatformState schemas must not try to update the current address book anyway
// RosterService schemas must not try to update the current address book anyway
if (diskAddressBook != null) {
PLATFORM_STATE_SERVICE.setDiskAddressBook(diskAddressBook);
RosterService.setDiskAddressBook(diskAddressBook);
}
this.initState = state;
final var migrationChanges = serviceMigrator.doMigrations(
Expand All @@ -667,7 +667,7 @@ private void migrateSchemas(
metrics,
startupNetworks);
this.initState = null;
PLATFORM_STATE_SERVICE.clearDiskAddressBook();
RosterService.clearDiskAddressBook();
migrationStateChanges = new ArrayList<>(migrationChanges);
kvStateChangeListener.reset();
boundaryStateChangeListener.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.swirlds.config.api.Configuration;
import com.swirlds.platform.state.service.PlatformStateService;
import com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema;
import com.swirlds.platform.state.service.schemas.V0590PlatformStateSchema;
import com.swirlds.platform.system.Round;
import com.swirlds.platform.system.events.ConsensusEvent;
import com.swirlds.platform.system.state.notifications.StateHashedNotification;
Expand Down Expand Up @@ -220,7 +220,7 @@ public void startRound(@NonNull final Round round, @NonNull final State state) {
endRoundStateHashes.put(round.getRoundNum(), new CompletableFuture<>());

final var platformState = state.getReadableStates(PlatformStateService.NAME)
.<PlatformState>getSingleton(V0540PlatformStateSchema.PLATFORM_STATE_KEY)
.<PlatformState>getSingleton(V0590PlatformStateSchema.PLATFORM_STATE_KEY)
.get();
requireNonNull(platformState);
if (isFreezeRound(platformState, round)) {
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 @@ -38,7 +38,7 @@
import com.swirlds.common.stream.LinkedObjectStreamUtilities;
import com.swirlds.platform.state.service.PlatformStateService;
import com.swirlds.platform.state.service.WritablePlatformStateStore;
import com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema;
import com.swirlds.platform.state.service.schemas.V0590PlatformStateSchema;
import com.swirlds.state.State;
import com.swirlds.state.spi.WritableSingletonStateBase;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down Expand Up @@ -177,7 +177,7 @@ public boolean startUserTransaction(@NonNull final Instant consensusTime, @NonNu
final var newBlockPeriod = getBlockPeriod(consensusTime);

final var platformState = state.getReadableStates(PlatformStateService.NAME)
.<PlatformState>getSingleton(V0540PlatformStateSchema.PLATFORM_STATE_KEY)
.<PlatformState>getSingleton(V0590PlatformStateSchema.PLATFORM_STATE_KEY)
.get();
requireNonNull(platformState);
// Also check to see if this is the first transaction we're handling after a freeze restart. If so, we also
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 All @@ -20,12 +20,14 @@
import static java.util.Objects.requireNonNull;

import com.hedera.hapi.node.state.roster.Roster;
import com.hedera.node.app.roster.schemas.V0540RosterSchema;
import com.hedera.node.app.roster.schemas.V0590RosterSchema;
import com.swirlds.platform.state.service.WritableRosterStore;
import com.swirlds.platform.system.address.AddressBook;
import com.swirlds.state.State;
import com.swirlds.state.lifecycle.SchemaRegistry;
import com.swirlds.state.lifecycle.Service;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.function.Supplier;

Expand All @@ -44,6 +46,13 @@ public class RosterService implements Service {

public static final String NAME = "RosterService";

/**
* Temporary access to the disk address book used in upgrade or network transplant
* scenarios before the roster lifecycle is enabled.
*/
@Deprecated
private static final AtomicReference<AddressBook> DISK_ADDRESS_BOOK = new AtomicReference<>();

/**
* The test to use to determine if a candidate roster may be
* adopted at an upgrade boundary.
Expand Down Expand Up @@ -75,6 +84,21 @@ public int migrationOrder() {
@Override
public void registerSchemas(@NonNull final SchemaRegistry registry) {
requireNonNull(registry);
registry.register(new V0540RosterSchema(canAdopt, WritableRosterStore::new, stateSupplier));
registry.register(
new V0590RosterSchema(canAdopt, WritableRosterStore::new, stateSupplier, DISK_ADDRESS_BOOK::get));
}

/**
* Sets the disk address book to the given address book.
*/
public static void setDiskAddressBook(@NonNull final AddressBook addressBook) {
DISK_ADDRESS_BOOK.set(requireNonNull(addressBook));
}

/**
* Clears the disk address book.
*/
public static void clearDiskAddressBook() {
DISK_ADDRESS_BOOK.set(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface RosterTransplantSchema {
* Restart the {@link RosterService} by copying any roster overrides from the startup assets into the state.
* @param ctx the migration context
* @param rosterStoreFactory the factory to use to create the writable roster store
* @return true if the override network configuration is present and thus has been applied to the state
*/
default boolean restart(
@NonNull final MigrationContext ctx,
Expand Down

This file was deleted.

Loading

0 comments on commit e43ca88

Please sign in to comment.