-
Notifications
You must be signed in to change notification settings - Fork 195
feat: Highest node id in state #21861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
derektriley
wants to merge
87
commits into
main
Choose a base branch
from
18855-highest-nodeId
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 80 commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
e88d62a
initial highest node id changes
derektriley e12a1b2
unit tests
derektriley a67c57a
updates
derektriley 387ed61
Update proto
derektriley 1c6f23a
move schmema migration
derektriley 35f386d
wip
derektriley bb69099
wip
derektriley cc9539a
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev f7d8124
extract migration logic to v69 schema classes
JivkoKelchev fe97d3b
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 9f5986d
fix tests
JivkoKelchev a23c8c0
Replace deprecated EntityNumber with NodeId. Fix state changes valida…
JivkoKelchev 5dd1be7
Fix tests
JivkoKelchev 7740ca8
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 5b6179d
Fix unit tests
JivkoKelchev 3b6757e
Fix more unit tests
JivkoKelchev 89d0f8d
Update migration logic
JivkoKelchev 4a563c5
fix module info
JivkoKelchev a4aeadf
fix module info
JivkoKelchev 9b963a7
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 63aa4d8
Fix restart and iss tests. Remove V069AddressBookSchema.java
JivkoKelchev 500749a
Spotless
JivkoKelchev 8bdbed4
Fix test
JivkoKelchev 072b575
Remove deleted nodes on upgrade
JivkoKelchev ea6dc7d
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev ebcddaf
Revert test
JivkoKelchev 4b7a1f7
Fix SystemTransactions node create
JivkoKelchev f7b3458
Fix SystemTransactions node create
JivkoKelchev 4864c8b
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 8787c0c
Fix unit tests
JivkoKelchev 9911c89
revert unwanted changes
JivkoKelchev e14b984
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 15e2b1b
add java doc
JivkoKelchev 249301e
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 1e35c36
Rename the state
JivkoKelchev 581ba93
Remove redundant ISS exclusion in subProcess task
JivkoKelchev f59b08b
Remove duplicate code
JivkoKelchev e41faf5
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev a7a57e3
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev c130f79
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 6ca2a70
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev f3d1c43
Fix unit test
JivkoKelchev cc862b6
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 210bf0d
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 3a9e90d
Fix
JivkoKelchev 1261983
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 477a123
Fix
JivkoKelchev bffa0f9
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev bc4ff3c
Update staking info store to use the highest node id
JivkoKelchev c62071c
Fix unit test
JivkoKelchev e68784c
Fix unit tests
JivkoKelchev dee6150
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 25f71bf
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 21cb8f6
Set the schema version to 70
JivkoKelchev 542ce5c
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 8f40855
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev f830ef7
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 2715819
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 67ea14c
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 3a125f8
Fix unit tests
JivkoKelchev d499abe
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev f8cfcce
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 3a01ea2
Fix Merge conflicts. Update schema version.
JivkoKelchev 2ddf2fa
Fix StandaloneFeeCalculatorTest unit tests
JivkoKelchev 6a8fa1a
rename the state id
JivkoKelchev ae5a6fd
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 92e9479
fix: Wrong start of block state hash
JivkoKelchev 98eb6b8
init highest node id state with -1
JivkoKelchev 01c5c95
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 30d5869
Fix merge conflicts
JivkoKelchev 79dad8a
fix: Wrong start of block state hash
JivkoKelchev 95878a4
update protobufs
JivkoKelchev b552a8c
update protobufs
JivkoKelchev 98f4584
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 28186dd
Add unit tests
JivkoKelchev 113e71e
Add unit tests
JivkoKelchev 9c83ec3
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 11aaba1
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev e695c2e
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 96fbeb0
Address comments
JivkoKelchev 17b2217
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev 70252b5
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev d9fcf64
Update the schema version
JivkoKelchev 9a913c3
Add schema unit tests
JivkoKelchev df321c0
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev d0a255a
Update to NodeCreateHandler logic
derektriley b646f90
Merge branch 'main' into 18855-highest-nodeId
JivkoKelchev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| import static com.hedera.hapi.node.base.ResponseCodeEnum.MAX_NODES_CREATED; | ||
| import static com.hedera.node.app.service.addressbook.AddressBookHelper.checkDABEnabled; | ||
| import static com.hedera.node.app.service.addressbook.impl.validators.AddressBookValidator.validateX509Certificate; | ||
| import static com.hedera.node.app.spi.workflows.HandleException.validateFalse; | ||
| import static com.hedera.node.app.spi.workflows.HandleContext.DispatchMetadata.Type.SYSTEM_TXN_CREATION_ENTITY_NUM; | ||
| import static com.hedera.node.app.spi.workflows.HandleException.validateTrue; | ||
| import static com.hedera.node.app.spi.workflows.PreCheckException.validateFalsePreCheck; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
@@ -18,10 +18,12 @@ | |
| import com.hedera.hapi.node.base.HederaFunctionality; | ||
| import com.hedera.hapi.node.base.SubType; | ||
| import com.hedera.hapi.node.state.addressbook.Node; | ||
| import com.hedera.node.app.service.addressbook.ReadableNodeStore; | ||
| import com.hedera.node.app.service.addressbook.impl.WritableAccountNodeRelStore; | ||
| import com.hedera.node.app.service.addressbook.impl.WritableNodeStore; | ||
| import com.hedera.node.app.service.addressbook.impl.records.NodeCreateStreamBuilder; | ||
| import com.hedera.node.app.service.addressbook.impl.validators.AddressBookValidator; | ||
| import com.hedera.node.app.service.entityid.NodeIdGenerator; | ||
| import com.hedera.node.app.service.token.ReadableAccountStore; | ||
| import com.hedera.node.app.spi.fees.FeeContext; | ||
| import com.hedera.node.app.spi.fees.Fees; | ||
|
|
@@ -90,8 +92,13 @@ public void handle(@NonNull final HandleContext handleContext) { | |
| final var accountNodeRelStore = storeFactory.writableStore(WritableAccountNodeRelStore.class); | ||
| final var accountStore = storeFactory.readableStore(ReadableAccountStore.class); | ||
| final var accountId = op.accountIdOrElse(AccountID.DEFAULT); | ||
|
|
||
| validateFalse(nodeStore.sizeOfState() >= nodeConfig.maxNumber(), MAX_NODES_CREATED); | ||
| final var maybeSystemTxnDispatchEntityNum = | ||
| handleContext.dispatchMetadata().getMetadata(SYSTEM_TXN_CREATION_ENTITY_NUM, Long.class); | ||
| final var maybeNodeIsInStateForSystemTxn = | ||
| isNodeInStateForSystemTxn(handleContext.dispatchMetadata(), handleContext.nodeIdGenerator(), nodeStore); | ||
| validateTrue( | ||
| maybeNodeIsInStateForSystemTxn || (nodeStore.sizeOfState() < nodeConfig.maxNumber()), | ||
| MAX_NODES_CREATED); | ||
| addressBookValidator.validateAccount( | ||
| accountId, accountStore, accountNodeRelStore, handleContext.expiryValidator()); | ||
| addressBookValidator.validateDescription(op.description(), nodeConfig); | ||
|
|
@@ -116,12 +123,24 @@ public void handle(@NonNull final HandleContext handleContext) { | |
| nodeBuilder.grpcProxyEndpoint(op.grpcProxyEndpoint()); | ||
| } | ||
|
|
||
| // Since nodes won't be removed from state, we can set the nodeId to the next available id | ||
| // in the state based on the size of the state. | ||
| final var node = nodeBuilder.nodeId(nodeStore.sizeOfState()).build(); | ||
| long nextNodeId; | ||
| Node node; | ||
|
|
||
| // If a system-dispatched transplant transaction for nodes in override network (non-prod environments) | ||
| // attempts to create a node that already exists in the state (even if marked as deleted), | ||
| // neither the highest node ID nor the entity count should be incremented. | ||
| if (maybeNodeIsInStateForSystemTxn) { | ||
| // Assign node id using the one provided by the system dispatch metadata | ||
| nextNodeId = maybeSystemTxnDispatchEntityNum.get(); | ||
| node = nodeBuilder.nodeId(nextNodeId).build(); | ||
| nodeStore.put(node); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we know if the transplant didnt add any new nodes. (total nodes > current network) |
||
| } else { | ||
| // Assign node id using a dedicated generator to avoid reuse | ||
| nextNodeId = handleContext.nodeIdGenerator().newNodeId(); | ||
| node = nodeBuilder.nodeId(nextNodeId).build(); | ||
| nodeStore.putAndIncrementCount(node); | ||
| } | ||
|
|
||
| nodeStore.putAndIncrementCount(node); | ||
| // add account id relation | ||
| accountNodeRelStore.put(op.accountIdOrThrow(), node.nodeId()); | ||
|
|
||
| final var recordBuilder = handleContext.savepointStack().getBaseBuilder(NodeCreateStreamBuilder.class); | ||
|
|
@@ -141,4 +160,25 @@ public Fees calculateFees(@NonNull final FeeContext feeContext) { | |
| calculator.addVerificationsPerTransaction(Math.max(0, feeContext.numTxnSignatures() - 1)); | ||
| return calculator.calculate(); | ||
| } | ||
|
|
||
| /** | ||
| * Determines if a system-dispatched node creation transaction targets a node ID | ||
| * that already exists in the current state. | ||
| * | ||
| * <p>If the dispatch metadata provides a node ID (as in system transactions), this method checks | ||
| * if that node ID is already present in the node store. If not, it uses the next node ID from the generator. | ||
| * | ||
| * @param metadata the dispatch metadata containing optional system transaction node ID | ||
| * @param nodeIdGenerator the generator for new node IDs | ||
| * @param nodeStore the store containing current node state | ||
| * @return {@code true} if the node ID (from metadata or generator) already exists in the state; {@code false} otherwise | ||
| */ | ||
| private boolean isNodeInStateForSystemTxn( | ||
| final HandleContext.DispatchMetadata metadata, | ||
| final NodeIdGenerator nodeIdGenerator, | ||
| final ReadableNodeStore nodeStore) { | ||
| final var systemTxnCreationNum = metadata.getMetadataIfPresent(SYSTEM_TXN_CREATION_ENTITY_NUM, Long.class); | ||
| final var nextNodeId = systemTxnCreationNum != null ? systemTxnCreationNum : nodeIdGenerator.peekAtNewNodeId(); | ||
| return nodeStore.get(nextNodeId) != null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.