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

add SetSubnetOwner to Chain interface #2031

Merged
merged 33 commits into from
Sep 28, 2023

Conversation

dhrubabasu
Copy link
Contributor

No description provided.

Base automatically changed from simplify-subnet-auth-verification to dev September 15, 2023 21:52
@dhrubabasu dhrubabasu self-assigned this Sep 18, 2023
@dhrubabasu dhrubabasu marked this pull request as draft September 18, 2023 15:10
@dhrubabasu dhrubabasu added the vm This involves virtual machines label Sep 18, 2023
@dhrubabasu dhrubabasu added this to the v1.10.11 milestone Sep 21, 2023
@dhrubabasu dhrubabasu marked this pull request as ready for review September 21, 2023 19:20
vms/platformvm/config/execution_config.go Outdated Show resolved Hide resolved
vms/platformvm/state/diff.go Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
vms/platformvm/state/state.go Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
Comment on lines 432 to 442
type wrappedFxOwner struct {
owner fx.Owner
size int
}

func wrappedFxOwnerSize(_ ids.ID, w *wrappedFxOwner) int {
if w == nil {
return ids.IDLen + constants.PointerOverhead
}
return ids.IDLen + w.size + constants.PointerOverhead
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand this wrapper is just to be able to use fx.Owner in a sizedCache without recalculating the size every time.
The wrapper feels like a band-aid to me. I'd add a size method to fx.Owner interface to let ever owner be used in a sizedCache. Also fx.Owner implementation may be able to calculate statically their serialized size, without need to actually serialize data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't think it made sense to have a Bytes() like method for fx.Owner since the normal usage is passing it into another struct. This is a special case since we're explicitly tracking the owners separately so I'd like to keep it contained here

Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a Size() method to fx.Owner, not a Bytes() one.
I don't see why this is a special case. I can imagine other clients, possibly in other VMs may be interested in caching fx.Owners. So by having Size() method defined we'd avoid them the wrapper thing.
Also I'd like to avoid the wrapper in the P-chain. state is already pretty complex, I really don't see why we should add ad-hoc machinery to handle objects serialization and caching. We should push all of those machinery to the object themselves and slim down P-chain state.

Copy link
Contributor

@joshua-kim joshua-kim Sep 28, 2023

Choose a reason for hiding this comment

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

I would prefer implementing this wrapper as it's currently done for now and if we find that we keep needing this in other places we can consider implementing it on the fx package. I like package being able to define their own abstractions and keeping the interface as minimal as possible

Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

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

I'd handle fx.Owner size calculation differently.
Moreover I believe this change would require a db migration. Will it be part of a different PR?

@dhrubabasu
Copy link
Contributor Author

Moreover I believe this change would require a db migration. Will it be part of a different PR?

This will not require a db migration, I'm lazily populating the subnetOwner db.

@StephenButtolph StephenButtolph modified the milestones: v1.10.11, v1.10.12 Sep 22, 2023
Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

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

I'd introduce Size() method for fx.Owner so to avoid complicating P-chain state further.

vms/platformvm/state/diff.go Show resolved Hide resolved
Comment on lines 359 to 361
// Subnet ID --> Owner of the subnet
subnetOwners map[ids.ID]fx.Owner
subnetOwnerCache cache.Cacher[ids.ID, *wrappedFxOwner] // cache of subnetID -> owner if the entry is nil, it is not in the database
Copy link
Contributor

Choose a reason for hiding this comment

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

feel free to ignore this comment: It's consistent w/ the rest of the code but I personally don't think we need comments here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, we'll keep it for now but I'll probably make a follow-up cleaning up the comments

vms/platformvm/state/state.go Outdated Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
Comment on lines 432 to 442
type wrappedFxOwner struct {
owner fx.Owner
size int
}

func wrappedFxOwnerSize(_ ids.ID, w *wrappedFxOwner) int {
if w == nil {
return ids.IDLen + constants.PointerOverhead
}
return ids.IDLen + w.size + constants.PointerOverhead
}
Copy link
Contributor

@joshua-kim joshua-kim Sep 28, 2023

Choose a reason for hiding this comment

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

I would prefer implementing this wrapper as it's currently done for now and if we find that we keep needing this in other places we can consider implementing it on the fx package. I like package being able to define their own abstractions and keeping the interface as minimal as possible

vms/platformvm/state/state.go Outdated Show resolved Hide resolved
Comment on lines +2347 to +2348
subnetID := subnetID
owner := owner
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought loop variables in go were created once and the value was updated with each iteration, so I thought we wouldn't need these copies here. I think it's safe to remove these lines but i could be wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct, it is safe to remove but I'd like to keep them since it's easier to understand that this is correct

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the linter is going to yell at us because we are passing references to these values into functions. While it is true that those functions don't hold a reference to them... it feels like this is more clearly correct (until go 1.22)

vms/platformvm/state/state.go Outdated Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
vms/platformvm/state/state.go Outdated Show resolved Hide resolved
@@ -834,9 +893,14 @@ func (s *state) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) {
return nil, fmt.Errorf("%q %w", subnetID, errIsNotSubnet)
}

s.SetSubnetOwner(subnetID, subnet.Owner)
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels a bit weird (to be performing a write on the read)... But I think it's ok

Comment on lines +2347 to +2348
subnetID := subnetID
owner := owner
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the linter is going to yell at us because we are passing references to these values into functions. While it is true that those functions don't hold a reference to them... it feels like this is more clearly correct (until go 1.22)

vms/platformvm/state/state.go Outdated Show resolved Hide resolved
@StephenButtolph
Copy link
Contributor

I'd introduce Size() method for fx.Owner so to avoid complicating P-chain state further.

Generally, the fx doesn't know how it is serialized. So it isn't clear to me how we could actually do this

@StephenButtolph StephenButtolph merged commit e4b7e82 into dev Sep 28, 2023
14 of 15 checks passed
@StephenButtolph StephenButtolph deleted the add-support-for-setting-subnet-owner branch September 28, 2023 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm This involves virtual machines
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants