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

[ACP-99] ValidatorSetManager Solidity Contract #99

Conversation

Nuttymoon
Copy link
Contributor

ACP that defines:

  1. A reference implementation for a minimal Solidity smart contract to manage a Subnet’s validator set from an Avalanche EVM chain
  2. A reference architecture to easily plug in custom “security modules” on top of this contract (e.g. to implement a PoS Subnet)

Rendered

@Nuttymoon Nuttymoon marked this pull request as draft June 5, 2024 09:43
@aaronbuchwald
Copy link
Contributor

Hmm so it looks like there are two different architectures that we could take here.

  1. ValidatorSetManager + Owner PoS/PoA (as suggested in this PR):
  • Create the ValidatorSetManager contract to be listed as the owner of a Subnet
  • Create an arbitrary owner contract that could be PoS/PoA to call the ValidatorSetManager
  1. xL1StakingLibrary + Reference PoS/PoA:
  • Create a library that provides high level functions to send and parse the required messages from the P-Chain
  • Create reference implementations using the library for PoS/PoA

I'm not sure which implementation would be cleaner or a more standard way to handle things in Solidity, curious for others thoughts on the best way to handle this as well.

I think a lot of this will depend on how much functionality is easily shared between the different reference implementations.

ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
@Nuttymoon
Copy link
Contributor Author

Nuttymoon commented Jun 6, 2024

@aaronbuchwald
Hmm so it looks like there are two different architectures that we could take here.

  1. ValidatorSetManager + Owner PoS/PoA (as suggested in this PR):

    • Create the ValidatorSetManager contract to be listed as the owner of a Subnet

    • Create an arbitrary owner contract that could be PoS/PoA to call the ValidatorSetManager

  2. xL1StakingLibrary + Reference PoS/PoA:

    • Create a library that provides high level functions to send and parse the required messages from the P-Chain
    • Create reference implementations using the library for PoS/PoA

I'm not sure which implementation would be cleaner or a more standard way to handle things in Solidity, curious for others thoughts on the best way to handle this as well.

I think a lot of this will depend on how much functionality is easily shared between the different reference implementations.

IMO going for option 1. has 2 benefits:

  • As I mentioned in the PR, this allows auditing the reference implementation contract that xL1 builders can instantly reuse securely and at no cost
  • This minimizes the number of times that the SetSubnetValidatorManagerTx has to be issued on the P-Chain

That being said, it doesn't prevent splitting up the ValidatorSetManager contract into 2 pieces, one being the library described above.

@Nuttymoon Nuttymoon force-pushed the validatorsetmanager-solidity-contract branch from 24d6f56 to 9e75d53 Compare June 11, 2024 09:33
@Nuttymoon Nuttymoon force-pushed the validatorsetmanager-solidity-contract branch from 35ef97f to 895c29e Compare August 28, 2024 13:59
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
@minghinmatthewlam
Copy link

minghinmatthewlam commented Aug 28, 2024

Thanks for this initial draft ACP @Nuttymoon , overall looks great! Here's our WIP branch for validator manager, looking forward to sync on design considerations for this ACP.

@Nuttymoon
Copy link
Contributor Author

Nuttymoon commented Aug 28, 2024

@minghinmatthewlam
Thanks for this initial draft ACP @Nuttymoon , overall looks great! Here's our WIP branch for validator manager, looking forward to sync on design considerations for this ACP.

Tbh I spotted the branch and have been stalking it for a few weeks hehe. Here is the implementation of ACP-99 I have been working on as well: ACP-99 contracts library

I will update the ACP proposal to reflect the implementation. I could only go that far without implementing anything.

@Nuttymoon Nuttymoon marked this pull request as ready for review September 12, 2024 08:13
Copy link
Contributor

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

Hey @Nuttymoon, thanks again for putting together this ACP a few months back.

The ACP-77 spec is very close to being implementable now. After these changes we hope to have a functional reference implementation ready in AvalancheGo. There are a few small tweaks there that require changes to this contract interfaces, mostly the RemainingBalanceOwner and DisableOwner being set in the RegisterSubnetValidatorMessage.

After that, and now that we've also had some time to both work through implementations of the validator manager contract, it would be great to revisit ACP-99 together in earnest. The few small tweaks I think are all that's necessary to get the PR merged, and would be great to have a community call to discuss a couple aspects of it like supporting delegation, tracking historical validations in active state, and possibly making it general enough for the manager and security module pieces to be combined via either composition (as the ACP is written currently) or inheritance (the approach we took here).

Either way looking forward to discussing it!

ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
Comment on lines 52 to 83
/**
* @notice Subnet validation
* @param status The validation status
* @param nodeID The NodeID of the validator
* @param startTime The start time of the validation
* @param endTime The end time of the validation
* @param periods The list of validation periods.
* The index is the nonce associated with the weight update.
* @param activeSeconds The time during which the validator was active during this validation
* @param uptimeSeconds The uptime of the validator for this validation
*/
struct Validation {
ValidationStatus status;
bytes32 nodeID;
uint64 startTime;
uint64 endTime;
ValidationPeriod[] periods;
uint64 activeSeconds;
uint64 uptimeSeconds;
}

/**
* @notice Subnet validation period
* @param weight The weight of the validator during the period
* @param startTime The start time of the validation period
* @param endTime The end time of the validation period (only ≠ 0 when the period is over)
*/
struct ValidationPeriod {
uint64 weight;
uint64 startTime;
uint64 endTime;
}
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 there may be a few inconsistencies here:

  • Both Validation and ValidationPeriod have startTime and endTime. As is, it seems like they likely belong only in ValidationPeriod.
  • The comment mentions the index being the nonce for the validator, but that's not included in any of the struct fields. This likely needs to be tracked per validation period.
  • uptimeSeconds seems to fit better in ValidationPeriod than Validation, since it can only be tracked for a specific period while the validator is active.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is just for discussion after this ACP is merged, but curious what your thoughts are on leaving historic validation tracking to indexers/archive nodes, and only keeping the active validator set around in state.

I think this could make sense to prevent large state growth overtime, etc.

Copy link
Contributor Author

@Nuttymoon Nuttymoon Oct 7, 2024

Choose a reason for hiding this comment

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

  • Yes, it is possible to use validation.periods[0].startTime instead of validation.startTime to avoid duplicating data. For endTime it would be a little bit trickier: validation.periods[validation.periods.length - 1].endTime (but irrelevant to store endTime anyway if we choose to remove history)
  • I thought it was enough to use the array index as the place to store the nonce since it is incremented by 1 at each weight change
  • I chose to track uptimeSeconds at the Validation level because I don't think it is useful to track it at the ValidationPeriod level and thought it might be difficult to differentiate the uptime from a specific period than from the whole validation. The latter depends on how the uptime is tracked at the VM level. Do we have more information about how this will be handled btw?

About the validation historic tracking, I agree that it is most likely not needed. Thus my open question at the end.

ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
@Nuttymoon
Copy link
Contributor Author

Hey @Nuttymoon, thanks again for putting together this ACP a few months back.

...

Thanks @michaelkaplan13 for reviewing! I'd be more than happy to discuss this ACP ofc! Maybe it would be nice to dedicate an upcoming Developer Community Call to it @meaghanfitzgerald?

I'll make sure to update the ACP when changes to ACP-77 are finalized and merged.

@Nuttymoon
Copy link
Contributor Author

Hi, I just updated the ACP to reflect the latest changed made to ACP-77

Copy link
Contributor

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

A few minor suggestions, but otherwise makes sense to me!

Noting a few questions/considerations here for the official discussion thread/community call (but these by no means need to be discussed or answered to merge the ACP)..

  • For a PoS security module to support delegation, do would the interface methods included here be internal, with other external functions added that support the additional parameters?
  • Which pieces are state are tracked by the security module vs manager contracts? They don't need to be included in the ACP since it just defines the interfaces of course, but think it would be helpful to talk through to ensure the interfaces feed the needs of feasible use cases.
  • What would it looks like for a manager to upgrade from a PoA security module to a PoS security module? One complexity we tried to work through was still allowing for the removal of existing PoA validators but allowing anyone to remove them after the conversion.

Looking forward to continue the discussion now that ACP-77 is more finalized and this PR can also be merged!

ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
ACPs/99-validatorsetmanager-contract/README.md Outdated Show resolved Hide resolved
@Nuttymoon Nuttymoon force-pushed the validatorsetmanager-solidity-contract branch from 9350c60 to 664c893 Compare November 19, 2024 16:55
@Nuttymoon
Copy link
Contributor Author

Nuttymoon commented Nov 19, 2024

I think we are ready to merge @michaelkaplan13.

The latest commit 664c893 implements your suggestion about PChainOwner, refactors the structs declaration layout and adds a function that I missed when updating the interface (updateUptime).

@avalanche-foundation-admin avalanche-foundation-admin merged commit c6f4185 into avalanche-foundation:main Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants