Matías Barrios (matias.barrios@kudelskisecurity.com)
We discussed with some teammates about the account closing process. In theory, if the account lamports
field is 0 or smaller than the rent value for an epoch, then the System Program should delete the account in the next epoch.
Theoretically, this is the only requirement to close an account. Rez Khan mentioned that might be necessary to zero out the data
field. This Poc is intended to verify what is the minimum requirements to close an account.
- Create an account with some
lamports
balance, and a non-zerodata
field. - Check the account state.
- Withdraw the lamports balance from the account, without modifying the
data
field. - Check that account is closed.
You can run the test with cargo test:
cargo test
To check the println!
macros of the test, run the test showing the outputs:
cargo test -- --show-output
- We demonstrated that when
lamports=0
the account is deleted by the system program, even when the data is not 0. - We still have to test the case when
lamports
is slightly smaller than the rent. In theory, it should be deleted too. - Is not necessary to trigger an instruction to transfer the lamports balance. In the context of the instruction, the balance of the accounts can be modified inline if the accounts owners are flagged as
signer
. - In the instruction context, the system program monitors that the changes in the lamports balances of the total of the accounts equals to 0.
- The transaction cost is equal to the amount of required signatures * 5000 lamports.
- in ocassions,
solana_program_test
takes too long to complete transaction, even having a successful outcome at the end of the transaction (according to log).