Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Governance: Update addin accounts discriminators to Anchor compatible #3026

Merged
merged 1 commit into from
Mar 24, 2022

Conversation

SebastianBor
Copy link
Contributor

@SebastianBor SebastianBor commented Mar 23, 2022

Summary

MaxVoterWeightRecord and VoterWeightRecord are defined in spl-governance-addin-api but they are owned by the addin programs. In order to make them easier to use in Anchor based programs their discriminators were updated to match the ones automatically generated by Anchor.

For backward compatibility with existing addins the legacy discriminator are also considered as valid ones.

@SebastianBor SebastianBor marked this pull request as ready for review March 23, 2022 22:14
@ckamm
Copy link
Contributor

ckamm commented Mar 23, 2022

When I looked at this last time, the attempt to be compatible with Anchor didn't work because the discriminator field was part of the struct itself in spl-gov, while it's implicit for Anchor accounts structs. That was the reason the struct still needed to be wrapped (and we never ended up testing the account discriminator value). Wrapping code: https://github.com/blockworks-foundation/voter-stake-registry/blob/master/programs/voter-stake-registry/src/governance.rs

How do you use the struct with anchor without wrapping it?

@SebastianBor
Copy link
Contributor Author

SebastianBor commented Mar 23, 2022

How do you use the struct with anchor without wrapping it?

I redefine the structs in Anchor program without the discriminator.
This way they are also automatically exported to the IDL without any workarounds

@SebastianBor SebastianBor merged commit 762c584 into master Mar 24, 2022
@SebastianBor SebastianBor deleted the governance-anchor-compatible-discriminators branch March 24, 2022 18:28
@SebastianBor SebastianBor restored the governance-anchor-compatible-discriminators branch March 24, 2022 18:30
@joncinque joncinque deleted the governance-anchor-compatible-discriminators branch December 3, 2023 14:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants