Skip to content

Commit

Permalink
chore: Add HistoryService schemas and stores (#17439)
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
Signed-off-by: Michael Tinker <[email protected]>
Co-authored-by: Neeharika-Sompalli <[email protected]>
Co-authored-by: Neeharika Sompalli <[email protected]>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent c5e7dc1 commit bbdc054
Show file tree
Hide file tree
Showing 32 changed files with 1,791 additions and 102 deletions.
50 changes: 48 additions & 2 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/history/history_types.proto";
import "state/entity/entity_counts.proto";

/**
Expand Down Expand Up @@ -409,12 +410,12 @@ enum StateIdentifier {
/**
* A state identifier for the active hinTS construction.
*/
STATE_ID_ACTIVE_CONSTRUCTION = 38;
STATE_ID_ACTIVE_HINTS_CONSTRUCTION = 38;

/**
* A state identifier for the next hinTS construction.
*/
STATE_ID_NEXT_CONSTRUCTION = 39;
STATE_ID_NEXT_HINTS_CONSTRUCTION = 39;

/**
* A state identifier for hinTS preprocessing output votes.
Expand All @@ -426,6 +427,36 @@ enum StateIdentifier {
*/
STATE_ID_ENTITY_COUNTS = 41;

/**
* A state identifier for the ledger id.
*/
STATE_ID_LEDGER_ID = 42;

/**
* A state identifier for history proof key sets.
*/
STATE_ID_PROOF_KEY_SETS = 43;

/**
* A state identifier for the active proof construction.
*/
STATE_ID_ACTIVE_PROOF_CONSTRUCTION = 44;

/**
* A state identifier for the next proof construction.
*/
STATE_ID_NEXT_PROOF_CONSTRUCTION = 45;

/**
* A state identifier for signatures on roster transition histories.
*/
STATE_ID_HISTORY_SIGNATURES = 46;

/**
* A state identifier for votes on history proofs.
*/
STATE_ID_PROOF_VOTES = 47;

/**
* A state identifier for the round receipts queue.
*/
Expand Down Expand Up @@ -645,6 +676,11 @@ message SingletonUpdateChange {
* A change to the Entity counts singleton.
*/
com.hedera.hapi.node.state.entity.EntityCounts entity_counts_value = 15;

/**
* A change to a hinTS construction singleton.
*/
com.hedera.hapi.node.state.history.HistoryProofConstruction history_proof_construction_value = 16;
}
}

Expand Down Expand Up @@ -809,6 +845,16 @@ message MapChangeKey {
* A hinTS preprocessing vote id key.
*/
com.hedera.hapi.node.state.hints.PreprocessingVoteId preprocessing_vote_id_key = 20;

/**
* An unscoped node id key.
*/
com.hedera.hapi.platform.state.NodeId node_id_key = 21;

/**
* A construction-scoped node id key.
*/
com.hedera.hapi.node.state.history.ConstructionNodeId construction_node_id_key = 22;
}
}

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

package com.hedera.hapi.node.state.history;

/*
* Copyright (C) 2024 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.
*/

import "timestamp.proto";

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

/**
* A set of proof keys for a node; that is, the key the node is
* currently using and the key it wants to use in assembling the
* next address book in the ledger id's chain of trust.
*/
message ProofKeySet {
/**
* The consensus time when the network adopted the active
* proof key in this set. An adoption time that is sufficiently
* tardy relative to the latest assembly start time may result
* in the node's key being omitted from the address book.
*/
proto.Timestamp adoption_time = 2;
/**
* The proof key the node is using.
*/
bytes key = 3;
/**
* If set, the proof key the node wants to start using in the
* address book.
*/
bytes next_key = 4;
}

/**
* A record of the proof key a node had in a particular address
* book. Necessary to keep at each point history so that nodes
* can verify the correct key was used to sign in transitions
* starting from the current address book; no matter how keys
* have been rotated from the time the address book was created.
*/
message ProofKey {
/**
* The node id.
*/
uint64 node_id = 1;
/**
* The key.
*/
bytes key = 2;
}

/**
* A piece of new history in the form of an address book hash and
* associated metadata.
*/
message History {
/**
* The address book hash of the new history.
*/
bytes address_book_hash = 1;
/**
* The metadata associated to the address book.
*/
bytes metadata = 2;
}

/**
* A proof that some address book history belongs to the ledger id's
* chain of trust.
*/
message HistoryProof {
/**
* The hash of the source address book.
*/
bytes source_address_book_hash = 1;
/**
* The proof keys for the source address book.
*/
repeated ProofKey proof_keys = 2;
/**
* The target history of the proof.
*/
History target_history = 3;
/**
* The proof of chain of trust from the ledger id.
*/
bytes proof = 4;
}

/**
* Summary of the status of constructing a metadata proof, necessary to
* ensure deterministic construction ending in a roster with sufficient
* weight to enact its own constructions.
*/
message HistoryProofConstruction {
/**
* The construction id.
*/
uint64 construction_id = 1;
/**
* The hash of the roster whose weights are used to determine when
* certain thresholds are during construction.
*/
bytes source_roster_hash = 2;
/**
* If set, the proof that the address book of the source roster belongs
* to the the ledger id's chain of trust; if not set, the source roster's
* address book must *be* the ledger id.
*/
HistoryProof source_proof = 3;
/**
* The hash of the roster whose weights are used to assess progress
* toward obtaining proof keys for parties that hold at least a
* strong minority of the stake in that roster.
*/
bytes target_roster_hash = 4;

oneof proof_state {
/**
* If the network is still gathering proof keys for this
* construction, the next time at which nodes should stop waiting
* for tardy proof keys and assembly the history to be proven as
* soon as it has the associated metadata and proof keys for nodes
* with >2/3 weight in the target roster.
*/
proto.Timestamp grace_period_end_time = 5;
/**
* If the network has gathered enough proof keys to assemble the
* history for this construction, the cutoff time at which those
* keys must have been adopted to be included in the final history.
*/
proto.Timestamp assembly_start_time = 6;
/**
* When this construction is complete, the recursive proof that
* the target roster's address book and associated metadata belong
* to the ledger id's chain of trust.
*/
HistoryProof target_proof = 7;
}
}

/**
* A construction-scoped node id.
*/
message ConstructionNodeId {
/**
* The unique id of a history proof construction.
*/
uint64 construction_id = 1;
/**
* The unique id of a node.
*/
uint64 node_id = 2;
}

/**
* A node's vote for a particular history proof; either by explicitly
* giving the proof, or by identifying a node that already voted for it.
*/
message HistoryProofVote {
oneof vote {
/**
* The history proof the submitting node is voting for.
*/
HistoryProof proof = 1;
/**
* The id of another node that already voted for the exact proof
* the submitting node is voting for.
*/
uint64 congruent_node_id = 2;
}
}

/**
* A node's signature blessing some new history.
*/
message HistorySignature {
/**
* The new history the node is signing.
*/
History history = 1;
/**
* The node's signature on the canonical serialization of
* the new history.
*/
bytes signature = 2;
}

/**
* A signature on some new history recorded at a certain time.
*/
message RecordedHistorySignature {
/**
* The time at which the signature was recorded.
*/
proto.Timestamp signing_time = 1;

/**
* The signature on some new history.
*/
HistorySignature history_signature = 2;
}

3 changes: 2 additions & 1 deletion hapi/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
exports com.hedera.hapi.node.state.common;
exports com.hedera.hapi.node.state.contract;
exports com.hedera.hapi.node.state.file;
exports com.hedera.hapi.node.state.hints;
exports com.hedera.hapi.node.state.history;
exports com.hedera.hapi.node.state.recordcache;
exports com.hedera.hapi.node.state.recordcache.codec;
exports com.hedera.hapi.node.state.blockrecords;
Expand Down Expand Up @@ -86,7 +88,6 @@
exports com.hedera.hapi.block;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hedera.node.app;

import static com.hedera.node.app.history.impl.HistoryLibraryCodecImpl.HISTORY_LIBRARY_CODEC;
import static com.swirlds.common.io.utility.FileUtils.getAbsolutePath;
import static com.swirlds.common.io.utility.FileUtils.rethrowIO;
import static com.swirlds.common.threading.manager.AdHocThreadManager.getStaticThreadManager;
Expand Down Expand Up @@ -43,6 +44,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.hedera.node.app.hints.impl.FakeHintsLibrary;
import com.hedera.node.app.hints.impl.HintsServiceImpl;
import com.hedera.node.app.history.impl.HistoryLibraryImpl;
import com.hedera.node.app.history.impl.HistoryServiceImpl;
import com.hedera.node.app.info.DiskStartupNetworks;
import com.hedera.node.app.roster.RosterService;
Expand Down Expand Up @@ -416,7 +418,12 @@ public static Hedera newHedera(@NonNull final Metrics metrics) {
TssBlockHashSigner::new,
appContext ->
new HintsServiceImpl(metrics, ForkJoinPool.commonPool(), appContext, new FakeHintsLibrary()),
HistoryServiceImpl::new,
appContext -> new HistoryServiceImpl(
metrics,
ForkJoinPool.commonPool(),
appContext,
new HistoryLibraryImpl(),
HISTORY_LIBRARY_CODEC),
metrics);
}

Expand Down
Loading

0 comments on commit bbdc054

Please sign in to comment.