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

Versioning of public types #1544

Closed
xgreenx opened this issue Dec 14, 2023 · 3 comments · Fixed by #1600
Closed

Versioning of public types #1544

xgreenx opened this issue Dec 14, 2023 · 3 comments · Fixed by #1600
Assignees
Labels
SDK team The issue is ready to be addressed by SDK team upgradability

Comments

@xgreenx
Copy link
Collaborator

xgreenx commented Dec 14, 2023

We need to make all public complex types like Blocks, Transactions, Inputs, Outputs, and Consensus to support versioning. It is not related to the primitive types.

Using Rust enums for versioning types in the context of blockchains
Enums can be used to version types in the context of blockchains. This is particularly useful for representing changes to the blockchain protocol over time without breaking compatibility with existing nodes.

Example:

enum ConsensusAlgorithmVersion {
  V1(ConsensusAlgorithmV1),
  V2(ConsensusAlgorithmV2),
}

struct ConsensusAlgorithmV1 {
    voting_mechanism: VotingMechanism,
}

struct ConsensusAlgorithmV2 {
    voting_mechanism: VotingMechanism,
}

impl From<ConsensusAlgorithmV1> for ConsensusAlgorithmV2 {
    fn from(algorithm: ConsensusAlgorithmV1) -> ConsensusAlgorithmV2 {
        ConsensusAlgorithmV2 {
            voting_mechanism: algorithm.voting_mechanism,
        }
    }
}

Existing code that interacts with the blockchain can use the ConsensusAlgorithmVersion enum to determine the specific version of the consensus algorithm that is used for the current block. This allows you to introduce new versions of the consensus algorithm without breaking existing code that handles consensus messages.

Benefits of using enums for versioning types

  • Flexibility: You can easily add new versions of the type without modifying existing code.
  • Backward compatibility: Existing code that handles the older version of the type will continue to work seamlessly with the new version.
  • Maintainability: It is easier to track and manage changes to the type over time.

Most of them already are enums. But some of them(like Block) - not. In the scope of this task, we need to revise all existing types and decide which ones should be enums and which should not. It may also require fuel-specs modifications.

Notes:

Add #[non_exhaustive] flag.

@xgreenx xgreenx added upgradability SDK team The issue is ready to be addressed by SDK team labels Dec 14, 2023
@Dentosal
Copy link
Member

Should we use #[non_exhaustive] for the version enum? This way users of the type must handle the cases where they're not aware of the new values yet.

@Voxelot
Copy link
Member

Voxelot commented Dec 19, 2023

This story should also include the ability to configure the block height at which these versions take effect

@MitchTurner
Copy link
Member

We need to make sure we are covering all types that get included in the DB. There are also subtypes, like BlockHeader that definitely needs to be versioned.

How can we feel confident that we have caught all relevant types?

MitchTurner added a commit that referenced this issue Jan 23, 2024
Part of: #1544

---------

Co-authored-by: Hannes Karppila <[email protected]>
MitchTurner added a commit that referenced this issue Jan 25, 2024
Dentosal added a commit that referenced this issue Jan 31, 2024
Closes #1544

Addresses breaking changes from
FuelLabs/fuel-vm#654

---------

Co-authored-by: Turner <[email protected]>
@bvrooman bvrooman mentioned this issue Mar 21, 2024
5 tasks
crypto523 added a commit to crypto523/fuel-core that referenced this issue Oct 7, 2024
crypto523 added a commit to crypto523/fuel-core that referenced this issue Oct 7, 2024
Part of: FuelLabs/fuel-core#1544

---------

Co-authored-by: Hannes Karppila <[email protected]>
crypto523 added a commit to crypto523/fuel-core that referenced this issue Oct 7, 2024
crypto523 added a commit to crypto523/fuel-core that referenced this issue Oct 7, 2024
Closes FuelLabs/fuel-core#1544

Addresses breaking changes from
FuelLabs/fuel-vm#654

---------

Co-authored-by: Turner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK team The issue is ready to be addressed by SDK team upgradability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants