Skip to content

Commit

Permalink
lang: Remove CLOSED_ACCOUNT_DISCRIMINATOR (#2726)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Dec 12, 2023
1 parent 61244a8 commit 4c0af6d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
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

1 comment on commit 4c0af6d

@vercel
Copy link

@vercel vercel bot commented on 4c0af6d Dec 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-200ms.vercel.app
anchor-lang.com
anchor-docs-git-master-200ms.vercel.app
www.anchor-lang.com

Please sign in to comment.