Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
  • Loading branch information
Neeharika-Sompalli committed Jan 16, 2025
1 parent 125196a commit 387fb22
Show file tree
Hide file tree
Showing 76 changed files with 409 additions and 477 deletions.
11 changes: 11 additions & 0 deletions hapi/hedera-protobufs/block/stream/output/state_changes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import "auxiliary/tss/tss_vote.proto";
import "state/tss/tss_encryption_keys.proto";
import "state/tss/tss_message_map_key.proto";
import "state/tss/tss_vote_map_key.proto";
import "state/entity/entity_counts.proto";

/**
* A set of state changes.
Expand Down Expand Up @@ -399,6 +400,11 @@ enum StateIdentifier {
*/
STATE_ID_TSS_STATUS = 36;

/**
* A state identifier for the entity counts.
*/
STATE_ID_ENTITY_COUNTS = 37;

/**
* A state identifier for the round receipts queue.
*/
Expand Down Expand Up @@ -608,6 +614,11 @@ message SingletonUpdateChange {
* A change to the roster state singleton.
*/
com.hedera.hapi.node.state.roster.RosterState roster_state_value = 13;

/**
* A change to the Entity counts singleton.
*/
com.hedera.hapi.node.state.entity.EntityCounts entity_counts_value = 14;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package proto;
package com.hedera.hapi.node.state.entity;
/*
* Copyright (C) 2025 Hedera Hashgraph, LLC
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

import com.hedera.hapi.node.state.addressbook.Node;
import com.hedera.hapi.node.state.common.EntityNumber;
import com.hedera.node.app.spi.metrics.StoreMetricsService;
import com.hedera.node.app.spi.metrics.StoreMetricsService.StoreType;
import com.hedera.node.config.data.NodesConfig;
import com.swirlds.config.api.Configuration;
import com.swirlds.state.spi.WritableKVState;
import com.swirlds.state.spi.WritableStates;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand All @@ -41,18 +37,9 @@ public class WritableNodeStore extends ReadableNodeStoreImpl {
* Create a new {@link WritableNodeStore} instance.
*
* @param states The state to use.
* @param configuration The configuration used to read the maximum capacity.
* @param storeMetricsService Service that provides utilization metrics.
*/
public WritableNodeStore(
@NonNull final WritableStates states,
@NonNull final Configuration configuration,
@NonNull final StoreMetricsService storeMetricsService) {
public WritableNodeStore(@NonNull final WritableStates states) {
super(states);

final long maxCapacity = configuration.getConfigData(NodesConfig.class).maxNumber();
final var storeMetrics = storeMetricsService.get(StoreType.NODE, maxCapacity);
nodesState().setMetrics(storeMetrics);
}

@Override
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 @@ -45,16 +45,15 @@ class WritableNodeStoreTest extends AddressBookTestBase {

@Test
void throwsIfNullValuesAsArgs() {
assertThrows(NullPointerException.class, () -> new WritableNodeStore(null, CONFIGURATION, storeMetricsService));
assertThrows(
NullPointerException.class, () -> new WritableNodeStore(writableStates, null, storeMetricsService));
assertThrows(NullPointerException.class, () -> new WritableNodeStore(writableStates, CONFIGURATION, null));
assertThrows(NullPointerException.class, () -> new WritableNodeStore(null));
assertThrows(NullPointerException.class, () -> new WritableNodeStore(writableStates));
assertThrows(NullPointerException.class, () -> new WritableNodeStore(writableStates));
assertThrows(NullPointerException.class, () -> writableStore.put(null));
}

@Test
void constructorCreatesNodeState() {
final var store = new WritableNodeStore(writableStates, CONFIGURATION, storeMetricsService);
final var store = new WritableNodeStore(writableStates);
assertNotNull(store);
}

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,7 +178,7 @@ protected void refreshStoresWithCurrentNodeInReadable() {
given(readableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(readableNodeState);
given(writableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(writableNodeState);
readableStore = new ReadableNodeStoreImpl(readableStates);
writableStore = new WritableNodeStore(writableStates, DEFAULT_CONFIG, storeMetricsService);
writableStore = new WritableNodeStore(writableStates);
}

protected void refreshStoresWithCurrentNodeInBothReadableAndWritable() {
Expand All @@ -188,21 +188,21 @@ protected void refreshStoresWithCurrentNodeInBothReadableAndWritable() {
given(writableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(writableNodeState);
readableStore = new ReadableNodeStoreImpl(readableStates);
final var configuration = HederaTestConfigBuilder.createConfig();
writableStore = new WritableNodeStore(writableStates, configuration, storeMetricsService);
writableStore = new WritableNodeStore(writableStates);
}

protected void refreshStoresWithCurrentNodeInWritable() {
writableNodeState = writableNodeStateWithOneKey();
given(writableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(writableNodeState);
final var configuration = HederaTestConfigBuilder.createConfig();
writableStore = new WritableNodeStore(writableStates, configuration, storeMetricsService);
writableStore = new WritableNodeStore(writableStates);
}

protected void refreshStoresWithMoreNodeInWritable() {
writableNodeState = writableNodeStateWithMoreKeys();
given(writableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(writableNodeState);
final var configuration = HederaTestConfigBuilder.createConfig();
writableStore = new WritableNodeStore(writableStates, configuration, storeMetricsService);
writableStore = new WritableNodeStore(writableStates);
}

@NonNull
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 @@ -97,7 +97,7 @@ void setUp() {
writableNodeState = writableNodeStateWithOneKey();
given(writableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(writableNodeState);
testConfig = HederaTestConfigBuilder.createConfig();
writableStore = new WritableNodeStore(writableStates, testConfig, storeMetricsService);
writableStore = new WritableNodeStore(writableStates);
lenient().when(handleContext.configuration()).thenReturn(testConfig);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ void fileDoesntExist() {
given(handleContext.storeFactory()).willReturn(storeFactory);
writableNodeState = emptyWritableNodeState();
given(writableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(writableNodeState);
writableStore = new WritableNodeStore(writableStates, testConfig, storeMetricsService);
writableStore = new WritableNodeStore(writableStates);
given(storeFactory.writableStore(WritableNodeStore.class)).willReturn(writableStore);

given(handleContext.body())
Expand All @@ -171,7 +171,7 @@ void NodeIsNull() {
given(handleContext.storeFactory()).willReturn(storeFactory);
writableNodeState = writableNodeStateWithOneKey();
given(writableStates.<EntityNumber, Node>get(NODES_KEY)).willReturn(writableNodeState);
writableStore = new WritableNodeStore(writableStates, testConfig, storeMetricsService);
writableStore = new WritableNodeStore(writableStates);
given(storeFactory.writableStore(WritableNodeStore.class)).willReturn(writableStore);

given(handleContext.body())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.hedera.node.app.info.CurrentPlatformStatusImpl;
import com.hedera.node.app.info.GenesisNetworkInfo;
import com.hedera.node.app.info.StateNetworkInfo;
import com.hedera.node.app.metrics.StoreMetricsServiceImpl;
import com.hedera.node.app.records.BlockRecordService;
import com.hedera.node.app.roster.RosterService;
import com.hedera.node.app.service.addressbook.impl.AddressBookServiceImpl;
Expand Down Expand Up @@ -325,7 +326,7 @@ public final class Hedera implements SwirldMain, PlatformStatusChangeListener, A
* current system, these are the singleton and queue updates. Every {@link MerkleStateRoot} will have this
* listener registered.
*/
private final BoundaryStateChangeListener boundaryStateChangeListener = new BoundaryStateChangeListener();
private final BoundaryStateChangeListener boundaryStateChangeListener;

/**
* A {@link StateChangeListener} that accumulates state changes that must be immediately reported as they occur,
Expand Down Expand Up @@ -356,6 +357,9 @@ public final class Hedera implements SwirldMain, PlatformStatusChangeListener, A
@Nullable
private StartupNetworks startupNetworks;

@NonNull
private StoreMetricsServiceImpl storeMetricsService;

@FunctionalInterface
public interface StartupNetworksFactory {
@NonNull
Expand All @@ -381,21 +385,24 @@ public interface BlockHashSignerFactory {
* <p>This registration is a critical side effect that must happen called before any Platform initialization
* steps that try to create or deserialize a {@link MerkleStateRoot}.
*
* @param constructableRegistry the registry to register {@link RuntimeConstructable} factories with
* @param registryFactory the factory to use for creating the services registry
* @param migrator the migrator to use with the services
* @param constructableRegistry the registry to register {@link RuntimeConstructable} factories with
* @param registryFactory the factory to use for creating the services registry
* @param migrator the migrator to use with the services
* @param startupNetworksFactory the factory for the startup networks
* @param blockHashSignerFactory the factory for the block hash signer
* @param storeMetricsService the metrics service to use
*/
public Hedera(
@NonNull final ConstructableRegistry constructableRegistry,
@NonNull final ServicesRegistry.Factory registryFactory,
@NonNull final ServiceMigrator migrator,
@NonNull final InstantSource instantSource,
@NonNull final StartupNetworksFactory startupNetworksFactory,
@NonNull final BlockHashSignerFactory blockHashSignerFactory) {
@NonNull final BlockHashSignerFactory blockHashSignerFactory,
@NonNull final StoreMetricsServiceImpl storeMetricsService) {
requireNonNull(registryFactory);
requireNonNull(constructableRegistry);
this.storeMetricsService = requireNonNull(storeMetricsService);
this.serviceMigrator = requireNonNull(migrator);
this.startupNetworksFactory = requireNonNull(startupNetworksFactory);
this.blockHashSignerFactory = requireNonNull(blockHashSignerFactory);
Expand Down Expand Up @@ -437,6 +444,7 @@ public Hedera(
() -> daggerApp.workingStateAccessor().getState(),
() -> daggerApp.throttleServiceManager().activeThrottleDefinitionsOrThrow(),
ThrottleAccumulator::new));
boundaryStateChangeListener = new BoundaryStateChangeListener(storeMetricsService, configProvider);
contractServiceImpl = new ContractServiceImpl(appContext);
scheduleServiceImpl = new ScheduleServiceImpl();
blockStreamService = new BlockStreamService();
Expand Down Expand Up @@ -669,7 +677,9 @@ private void migrateSchemas(
platformConfig,
genesisNetworkInfo,
metrics,
startupNetworks);
startupNetworks,
storeMetricsService,
configProvider);
this.initState = null;
PLATFORM_STATE_SERVICE.clearDiskAddressBook();
migrationStateChanges = new ArrayList<>(migrationChanges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.hedera.node.app.info.DiskStartupNetworks;
import com.hedera.node.app.metrics.StoreMetricsServiceImpl;
import com.hedera.node.app.service.addressbook.AddressBookService;
import com.hedera.node.app.service.addressbook.impl.ReadableNodeStoreImpl;
import com.hedera.node.app.services.OrderedServiceMigrator;
Expand Down Expand Up @@ -376,7 +377,8 @@ public static Hedera newHedera(@NonNull final NodeId selfNodeId, @NonNull final
new OrderedServiceMigrator(),
InstantSource.system(),
DiskStartupNetworks::new,
TssBlockHashSigner::new);
TssBlockHashSigner::new,
new StoreMetricsServiceImpl(metrics));
}

/**
Expand Down
Loading

0 comments on commit 387fb22

Please sign in to comment.