From 4c0af6dc5394c714a70296eae686b261f520f206 Mon Sep 17 00:00:00 2001
From: acheron <98934430+acheroncrypto@users.noreply.github.com>
Date: Tue, 12 Dec 2023 20:55:21 +0100
Subject: [PATCH] lang: Remove `CLOSED_ACCOUNT_DISCRIMINATOR` (#2726)
---
CHANGELOG.md | 1 +
docs/src/pages/docs/account-constraints.md | 6 ++++--
lang/derive/accounts/src/lib.rs | 10 ++++------
lang/src/lib.rs | 3 ---
4 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0fe4a071c6..468c113987 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/docs/src/pages/docs/account-constraints.md b/docs/src/pages/docs/account-constraints.md
index cc90ee2123..9f5f618553 100644
--- a/docs/src/pages/docs/account-constraints.md
+++ b/docs/src/pages/docs/account-constraints.md
@@ -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.
diff --git a/lang/derive/accounts/src/lib.rs b/lang/derive/accounts/src/lib.rs
index 4f9348ed58..cb47c0ee40 100644
--- a/lang/derive/accounts/src/lib.rs
+++ b/lang/derive/accounts/src/lib.rs
@@ -386,12 +386,10 @@ use syn::parse_macro_input;
/// #[account(close = <target_account>)]
///
///
CLOSED_ACCOUNT_DISCRIMINATOR
)
-/// and sends its lamports to the specified account.mut
to exist on the account.
///