Skip to content

Commit

Permalink
feat: Add ENTITY_COUNTS state in EntityIdService (#17421)
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
  • Loading branch information
Neeharika-Sompalli authored Jan 21, 2025
1 parent a6768cf commit c5e7dc1
Show file tree
Hide file tree
Showing 51 changed files with 957 additions and 106 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 @@ -70,6 +70,7 @@ 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/hints/hints_types.proto";
import "state/entity/entity_counts.proto";

/**
* A set of state changes.
Expand Down Expand Up @@ -420,6 +421,11 @@ enum StateIdentifier {
*/
STATE_ID_PREPROCESSING_VOTES = 40;

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

/**
* A state identifier for the round receipts queue.
*/
Expand Down Expand Up @@ -634,6 +640,11 @@ message SingletonUpdateChange {
* A change to a hinTS construction singleton.
*/
com.hedera.hapi.node.state.hints.HintsConstruction hints_construction_value = 14;

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

Expand Down
89 changes: 89 additions & 0 deletions hapi/hedera-protobufs/services/state/entity/entity_counts.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
syntax = "proto3";

package com.hedera.hapi.node.state.entity;
/*
* Copyright (C) 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* This proto file contains primitive value messages.
* These are intended only for situations where the entire value to be stored in state is a single
* primitive. These should never be used as components of another message; use the protobuf
* type instead.
*/

option java_package = "com.hederahashgraph.api.proto.java";
// <<<pbj.java_package = "com.hedera.hapi.node.state.entity">>> This comment is special code for setting PBJ Compiler java package
option java_multiple_files = true;

/**
* Representation of a Hedera Entity Service entity counts in the network Merkle tree.
*
* This message is used to store the counts of various entities in the network.
*/
message EntityCounts {
/**
* The number of accounts in the network.
*/
uint64 num_accounts = 1;
/**
* The number of aliases in the network.
*/
uint64 num_aliases = 2;
/**
* The number of tokens in the network.
*/
uint64 num_tokens = 3;
/**
* The number of token relationships in the network.
*/
uint64 num_token_relations = 4;
/**
* The number of NFTs in the network.
*/
uint64 num_nfts = 5;
/**
* The number of airdrops in the network.
*/
uint64 num_airdrops = 6;
/**
* The number of staking infos in the network.
*/
uint64 num_staking_infos = 7;
/**
* The number of topics in the network.
*/
uint64 num_topics = 8;
/**
* The number of files in the network.
*/
uint64 num_files = 9;
/**
* The number of nodes in the network.
*/
uint64 num_nodes = 10;
/**
* The number of schedules in the network.
*/
uint64 num_schedules = 11;
/**
* The number of contract storage slots in the network.
*/
uint64 num_contract_storage_slots = 12;
/**
* The number of contract bytecodes in the network.
*/
uint64 num_contract_bytecodes = 13;
}
1 change: 1 addition & 0 deletions hapi/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
exports com.hedera.hapi.services.auxiliary.tss.legacy;
exports com.hedera.hapi.platform.event.legacy;
exports com.hedera.hapi.node.state.hints;
exports com.hedera.hapi.node.state.entity;

requires transitive com.hedera.pbj.runtime;
requires transitive com.google.common;
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 @@ -16,6 +16,8 @@

package com.hedera.node.app.spi.ids;

import com.hedera.node.app.spi.validation.EntityType;

/**
* Provides a way to generate entity numbers.
*/
Expand All @@ -28,9 +30,10 @@ public interface EntityNumGenerator {
* the counter will be rolled back, too. Consequently, the provided number must not be used anymore in this case,
* because it will be reused.
*
* @param entityType the type of entity for which to generate a number
* @return the next entity number
*/
long newEntityNum();
long newEntityNum(EntityType entityType);

/**
* Peeks at the next entity number, for use by handlers that create entities.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.spi.ids;

public interface ReadableEntityIdStore {
/**
* Returns the next entity number that will be used.
*
* @return the next entity number that will be used
*/
long peekAtNextNumber();

/**
* Returns the number of accounts in the store.
*
* @return the number of accounts in the store
*/
long numAccounts();

/**
* Returns the number of tokens in the store.
*
* @return the number of tokens in the store
*/
long numTokens();

/**
* Returns the number of files in the store.
*
* @return the number of files in the store
*/
long numFiles();

/**
* Returns the number of topics in the store.
*
* @return the number of topics in the store
*/
long numTopics();

/**
* Returns the number of contracts in the store.
*
* @return the number of contracts in the store
*/
long numContractBytecodes();

/**
* Returns the number of contract storage slots in the store.
*
* @return the number of contract storage slots in the store
*/
long numContractStorageSlots();

/**
* Returns the number of NFTs in the store.
*
* @return the number of NFTs in the store
*/
long numNfts();

/**
* Returns the number of token relations in the store.
*
* @return the number of token relations in the store
*/
long numTokenRelations();

/**
* Returns the number of aliases in the store.
*
* @return the number of aliases in the store
*/
long numAliases();

/**
* Returns the number of schedules in the store.
*
* @return the number of schedules in the store
*/
long numSchedules();

/**
* Returns the number of airdrops in the store.
*
* @return the number of airdrops in the store
*/
long numAirdrops();

/**
* Returns the number of nodes in the store.
*
* @return the number of nodes in the store
*/
long numNodes();
}
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 All @@ -21,11 +21,16 @@
*/
public enum EntityType {
ACCOUNT,
CONTRACT,
FILE,
NFT,
SCHEDULE,
ALIAS,
TOKEN,
TOKEN_ASSOCIATION,
TOPIC
NFT,
AIRDROP,
TOPIC,
NODE,
FILE,
SCHEDULE,
CONTRACT_BYTECODE,
CONTRACT_STORAGE,
STAKING_INFO
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static com.hedera.hapi.block.stream.output.StateIdentifier.STATE_ID_CONGESTION_STARTS;
import static com.hedera.hapi.block.stream.output.StateIdentifier.STATE_ID_CONTRACT_BYTECODE;
import static com.hedera.hapi.block.stream.output.StateIdentifier.STATE_ID_CONTRACT_STORAGE;
import static com.hedera.hapi.block.stream.output.StateIdentifier.STATE_ID_ENTITY_COUNTS;
import static com.hedera.hapi.block.stream.output.StateIdentifier.STATE_ID_ENTITY_ID;
import static com.hedera.hapi.block.stream.output.StateIdentifier.STATE_ID_FILES;
import static com.hedera.hapi.block.stream.output.StateIdentifier.STATE_ID_FREEZE_TIME;
Expand Down Expand Up @@ -128,6 +129,7 @@ public static int stateIdFor(@NonNull final String serviceName, @NonNull final S
};
case "EntityIdService" -> switch (stateKey) {
case "ENTITY_ID" -> STATE_ID_ENTITY_ID.protoOrdinal();
case "ENTITY_COUNTS" -> STATE_ID_ENTITY_COUNTS.protoOrdinal();
default -> UNKNOWN_STATE_ID;
};
case "FeeService" -> switch (stateKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.hedera.hapi.node.state.blockstream.BlockStreamInfo;
import com.hedera.hapi.node.state.common.EntityNumber;
import com.hedera.hapi.node.state.congestion.CongestionLevelStarts;
import com.hedera.hapi.node.state.entity.EntityCounts;
import com.hedera.hapi.node.state.hints.HintsConstruction;
import com.hedera.hapi.node.state.primitives.ProtoBytes;
import com.hedera.hapi.node.state.primitives.ProtoString;
Expand Down Expand Up @@ -235,6 +236,9 @@ private static <V> OneOf<QueuePushChange.ValueOneOfType> queuePushChangeValueFor
case HintsConstruction hintsConstruction -> {
return new OneOf<>(SingletonUpdateChange.NewValueOneOfType.HINTS_CONSTRUCTION_VALUE, hintsConstruction);
}
case EntityCounts entityCounts -> {
return new OneOf<>(SingletonUpdateChange.NewValueOneOfType.ENTITY_COUNTS_VALUE, entityCounts);
}
default -> throw new IllegalArgumentException(
"Unknown value type " + value.getClass().getName());
}
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 All @@ -17,6 +17,7 @@
package com.hedera.node.app.ids;

import com.hedera.node.app.ids.schemas.V0490EntityIdSchema;
import com.hedera.node.app.ids.schemas.V0590EntityIdSchema;
import com.swirlds.state.lifecycle.SchemaRegistry;
import com.swirlds.state.lifecycle.Service;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand All @@ -38,5 +39,6 @@ public String getServiceName() {
@Override
public void registerSchemas(@NonNull final SchemaRegistry registry) {
registry.register(new V0490EntityIdSchema());
registry.register(new V0590EntityIdSchema());
}
}
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 @@ -19,6 +19,7 @@
import static java.util.Objects.requireNonNull;

import com.hedera.node.app.spi.ids.EntityNumGenerator;
import com.hedera.node.app.spi.validation.EntityType;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.inject.Inject;

Expand All @@ -35,8 +36,8 @@ public EntityNumGeneratorImpl(@NonNull final WritableEntityIdStore entityIdStore
}

@Override
public long newEntityNum() {
return entityIdStore.incrementAndGet();
public long newEntityNum(EntityType entityType) {
return entityIdStore.incrementAndGet(entityType);
}

@Override
Expand Down
Loading

0 comments on commit c5e7dc1

Please sign in to comment.