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

lang: Remove CLOSED_ACCOUNT_DISCRIMINATOR #2726

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- cli: Make `cargo build-sbf` the default build command ([#2694](https://github.com/coral-xyz/anchor/pull/2694)).
- cli: Require explicit `overflow-checks` flag ([#2716](https://github.com/coral-xyz/anchor/pull/2716)).
- ts: Remove `anchor-deprecated-state` feature ([#2717](https://github.com/coral-xyz/anchor/pull/2717)).
- lang: Remove `CLOSED_ACCOUNT_DISCRIMINATOR` ([#2726](https://github.com/coral-xyz/anchor/pull/2726)).

## [0.29.0] - 2023-10-16

Expand Down
6 changes: 4 additions & 2 deletions docs/src/pages/docs/account-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ Minimal reference examples for Anchor account [constraints](https://docs.rs/anch

- [Github](https://github.com/solana-developers/anchor-examples/tree/main/account-constraints/close)
[Solpg](https://beta.solpg.io/https://github.com/solana-developers/anchor-examples/tree/main/account-constraints/close)
- Marks the account as closed at the end of the instruction’s execution (sets its discriminator to the CLOSED_ACCOUNT_DISCRIMINATOR) and sends its lamports to the specified account.
- Closes the account by:

Setting the discriminator to a special variant makes account revival attacks (where a subsequent instruction adds the rent exemption lamports again) impossible.
- Sending the lamports to the specified account
- Assigning the owner to the System Program
- Resetting the data of the account

Requires mut to exist on the account.

Expand Down
10 changes: 4 additions & 6 deletions lang/derive/accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,10 @@ use syn::parse_macro_input;
/// <code>#[account(close = &lt;target_account&gt;)]</code>
/// </td>
/// <td>
/// Marks the account as closed at the end of the instruction’s execution
/// (sets its discriminator to the <code>CLOSED_ACCOUNT_DISCRIMINATOR</code>)
/// and sends its lamports to the specified account.<br>
/// Setting the discriminator to a special variant
/// makes account revival attacks (where a subsequent instruction
/// adds the rent exemption lamports again) impossible.<br>
/// Closes the account by:<br>
/// &nbsp;&nbsp;&nbsp;&nbsp;- Sending the lamports to the specified account<br>
/// &nbsp;&nbsp;&nbsp;&nbsp;- Assigning the owner to the System Program<br>
/// &nbsp;&nbsp;&nbsp;&nbsp;- Resetting the data of the account<br><br>
/// Requires <code>mut</code> to exist on the account.
/// <br><br>
/// Example:
Expand Down
3 changes: 0 additions & 3 deletions lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,6 @@ pub mod prelude {
/// Internal module used by macros and unstable apis.
#[doc(hidden)]
pub mod __private {
/// The discriminator anchor uses to mark an account as closed.
pub const CLOSED_ACCOUNT_DISCRIMINATOR: [u8; 8] = [255, 255, 255, 255, 255, 255, 255, 255];

pub use anchor_attribute_account::ZeroCopyAccessor;

pub use anchor_attribute_event::EventIndex;
Expand Down
Loading