Skip to content
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

Introduce ShortNodeID #3313

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Introduce ShortNodeID #3313

wants to merge 29 commits into from

Conversation

tsachiherman
Copy link
Contributor

@tsachiherman tsachiherman commented Aug 20, 2024

Why this should be merged

This PR is the first step toward ACP-20.
The existing NodeID was renamed into ShortNodeID, and a new, backward compatible NodeID was added.
Given that the ACP-20 changes are expected to be massive, I'd like to merge this backward-compatible change
before moving with the rest of the changes.

How this works

For most of the places, the usages of NodeID would remain as is.
Places that need to retain the classic NodeID were modified to be using the ShortNodeID.
The change is expected to be in a single direction only. i.e. ShortNodeID can be converted into NodeID by calling it's NodeID() function. No conversion from NodeID to ShortNodeID should be needed.

How this was tested

Tested against existing unit tests.

@tsachiherman tsachiherman self-assigned this Aug 20, 2024
@tsachiherman tsachiherman changed the title [wip] Prepare for ACP-20 : Update NodeID and ShortNodeID Introduce ShortNodeID Aug 22, 2024
@tsachiherman tsachiherman marked this pull request as ready for review August 22, 2024 18:01
ids/node_id.go Show resolved Hide resolved
Copy link
Contributor

@StephenButtolph StephenButtolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think we should be removing ids.NodeIDLen entirely. Every usage of it right now seems like it will break in the future.
  • "vms/platformvm/txs".Validator#NodeID should be a ids.ShortNodeID because it is serialized.
    • "vms/platformvm/txs/fee.intrinsicValidatorBandwidth" should be using ids.ShortNodeIDLen
    • "vms/platformvm/txs/fee.IntrinsicRemoveSubnetValidatorTxComplexities" should be using ids.ShortNodeIDLen
  • "vms/platformvm/txs.RemoveSubnetValidatorTx".NodeID should be a ids.ShortNodeID because it is serialized.

@@ -100,12 +100,12 @@ var _ = e2e.DescribePChain("[Workflow]", func() {

// Use a random node ID to ensure that repeated test runs will succeed
// against a network that persists across runs.
validatorID, err := ids.ToNodeID(utils.RandomBytes(ids.NodeIDLen))
validatorID, err := ids.ToShortNodeID(utils.RandomBytes(ids.NodeIDLen))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validatorID, err := ids.ToShortNodeID(utils.RandomBytes(ids.NodeIDLen))
validatorID, err := ids.ToShortNodeID(utils.RandomBytes(ids.ShortNodeIDLen))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this file use ids.ShortNodeID rather than keeping it generic as ids.NodeID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this file use ids.ShortNodeID rather than keeping it generic as ids.NodeID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marshalDiffKey and unmarshalDiffKey seem to make the assumption that ids.NodeID has the same length as ids.ShortNodeID. This doesn't seem safe in the long term

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. let me address that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this file use ids.ShortNodeID rather than keeping it generic as ids.NodeID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR - but we should move this file out into an idstest package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created #3343 to track this.

Comment on lines 72 to 74
for _, shortNodeID := range DefaultNodeIDs {
c.NodeIDs = append(c.NodeIDs, shortNodeID.NodeID())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be transforming the types here. I think the users of this util should be specifying the NodeID type they expect to have used.

@@ -623,7 +623,7 @@ func TestGetCurrentValidators(t *testing.T) {
found := false
for i := 0; i < len(response.Validators); i++ {
gotVdr := response.Validators[i].(pchainapi.PermissionlessValidator)
if gotVdr.NodeID != nodeID {
if gotVdr.NodeID.Compare(nodeID) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change from using != to .Compare (here and below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the NodeID is now a struct, using a comparison method allow us to ensure we can retain the comparison functionality even if we were to add, let's say, a non-comparable variable to the struct ( i.e. pointer ).
I figured that since we already having a comparison method, we should use it instead of relying on a mix of comparison techniques.

func (id *NodeID) UnmarshalText(text []byte) error {
return id.UnmarshalJSON(text)
type NodeID struct {
ShortNodeID `serialize:"true"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this diff is "forwards safe" I think we should be able to add an additional field (or somehow else change the serialized format of this struct) without breaking a ton of tests.

Comment on lines 56 to 61
packer := wrappers.Packer{
Bytes: make([]byte, preimageLen),
}
packer.PackFixedBytes(ip.NodeID[:])
packer.PackFixedBytes(ip.NodeID.Bytes())
packer.PackLong(timestamp)
ip.GossipID = hashing.ComputeHash256Array(packer.Bytes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks dubious. If ip.NodeID.Bytes() started returning 32 bytes, it seems like this may behave unexpectedly.

I need to look into this a bit more carefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the context of this PR, I believe that this change is safe. The ip.NodeID is populated few lines above as NodeID: ids.ShortNodeIDFromCert(cert).NodeID(). Hence, guarantee that it's a 20 bytes slice.
Future PRs would need to update this logic, naturally.

@tsachiherman tsachiherman removed the request for review from dhrubabasu September 4, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants