Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Refactor stake program into solana_program #17906

Merged
merged 15 commits into from
Jun 15, 2021

Conversation

joncinque
Copy link
Contributor

Problem

The solana_stake_program crate is not available on-chain, causing programs to copy all of its code where needed. This was flagged by the stake pool audit at solana-labs/solana-program-library#1865

Summary of Changes

Move the essential instruction and state types into solana_program. In order to move as little as possible, new types were introduced (renamed from the stake program core types) in solana_stake_program which require sdk-level types. There's a few little goofy parts, mainly having the StakeConfig struct implement ConfigState in the config program directly, and a few functions in the StakeConverter type which should really belong directly on the Stake type in solana_program, but that will require the vote program to be moved over as well.

Note that no logic was changed, this is entirely a refactor. CI will probably catch any lingering issues, so I'll fix them all as they're flagged up.

Fixes #

@joncinque joncinque requested a review from t-nelson June 14, 2021 13:04
@codecov
Copy link

codecov bot commented Jun 14, 2021

Codecov Report

Merging #17906 (a55ae3a) into master (1f38bf2) will increase coverage by 0.0%.
The diff coverage is 90.5%.

@@           Coverage Diff           @@
##           master   #17906   +/-   ##
=======================================
  Coverage    82.6%    82.6%           
=======================================
  Files         431      435    +4     
  Lines      121614   121584   -30     
=======================================
+ Hits       100460   100497   +37     
+ Misses      21154    21087   -67     

Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Wdyt about calling the new module sdk/program/src/stake_program/..? I know that's a change from how we're handling things in the programs directory, but I find all the stake::id() declarations pretty terse, esp in contrast with system_program::id()

@t-nelson
Copy link
Contributor

Wdyt about calling the new module sdk/program/src/stake_program/..?

An alternative could be to wrap the declare_id!() in pub mod program { }

@CriesofCarrots
Copy link
Contributor

An alternative could be to wrap the declare_id!() in pub mod program { }

Oh totally, something like this could be better than renaming the directory.

Copy link
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

I'm wondering if we should maintain pub use of the public API features from the solana-stake-program crate to avoid breaking any external consumers? stake-o-matic comes to mind. They can probably be marked with the deprecated attribute.

@joncinque
Copy link
Contributor Author

Wdyt about calling the new module sdk/program/src/stake_program/..?

I hesitated a lot with the name of stake over stake_program -- either works for me! Calling it stake_program when the actual processor code is elsewhere seemed weird to me, but the system_program example seems to set the standard for keeping the _program suffix. On the other hand, I do like the stake::program::id(). If I get both of your 👍 on that, I'll do it!

@joncinque
Copy link
Contributor Author

I'm wondering if we should maintain pub use of the public API features from the solana-stake-program crate to avoid breaking any external consumers? stake-o-matic comes to mind. They can probably be marked with the deprecated attribute.

Good idea, I'll do that

@joncinque
Copy link
Contributor Author

maintain pub use of the public API features from the solana-stake-program crate to avoid breaking any external consumers

@t-nelson done in 4631664

@joncinque
Copy link
Contributor Author

This is ready for another review on my side

CriesofCarrots
CriesofCarrots previously approved these changes Jun 14, 2021
Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

lgtm! Couple nits

@joncinque joncinque added the v1.7 label Jun 14, 2021
@mergify mergify bot dismissed CriesofCarrots’s stale review June 14, 2021 22:54

Pull request has been modified.

@joncinque joncinque merged commit 1b1d34d into solana-labs:master Jun 15, 2021
joncinque added a commit to joncinque/solana that referenced this pull request Jun 15, 2021
* Move stake state / instructions into solana_program

* Update account-decoder

* Update cli and runtime

* Update all other parts

* Commit Cargo.lock changes in programs/bpf

* Update cli stake instruction import

* Allow integer arithmetic

* Update ABI digest

* Bump rust mem instruction count

* Remove useless structs

* Move stake::id() -> stake::program::id()

* Re-export from solana_sdk and mark deprecated

* Address feedback

* Run cargo fmt
joncinque added a commit that referenced this pull request Jun 15, 2021
* Refactor stake program into solana_program (#17906)

* Move stake state / instructions into solana_program

* Update account-decoder

* Update cli and runtime

* Update all other parts

* Commit Cargo.lock changes in programs/bpf

* Update cli stake instruction import

* Allow integer arithmetic

* Update ABI digest

* Bump rust mem instruction count

* Remove useless structs

* Move stake::id() -> stake::program::id()

* Re-export from solana_sdk and mark deprecated

* Address feedback

* Run cargo fmt

* Run cargo fmt post cherry-pick
@joncinque joncinque deleted the stake-refactor branch June 16, 2021 11:22
@brooksprumo brooksprumo mentioned this pull request Aug 23, 2021
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.

3 participants