Prevent rent-paying account creation (#22292)

* Fixup typo

* Add new feature

* Add new TransactionError

* Add framework for checking account state before and after transaction processing

* Fail transactions that leave new rent-paying accounts

* Only check rent-state of writable tx accounts

* Review comments: combine process_result success behavior; log and metrics before feature activation

* Fix tests that assume rent-exempt accounts are okay

* Remove test no longer relevant

* Remove native/sysvar special case

* Move metrics submission to report legacy->legacy rent paying transitions as well
This commit is contained in:
Tyera Eulberg
2022-01-11 11:32:25 -07:00
committed by GitHub
parent a49ef49f87
commit 637e366b18
24 changed files with 819 additions and 179 deletions

View File

@ -72,7 +72,7 @@ async fn setup_vote(context: &mut ProgramTestContext) -> Pubkey {
instructions.push(system_instruction::create_account(
&context.payer.pubkey(),
&validator_keypair.pubkey(),
42,
Rent::default().minimum_balance(0),
0,
&system_program::id(),
));
@ -182,57 +182,6 @@ async fn clock_sysvar_updated_from_warp() {
);
}
#[tokio::test]
async fn rent_collected_from_warp() {
let program_id = Pubkey::new_unique();
// Initialize and start the test network
let program_test = ProgramTest::default();
let mut context = program_test.start_with_context().await;
let account_size = 100;
let keypair = Keypair::new();
let account_lamports = Rent::default().minimum_balance(account_size) - 100; // not rent exempt
let instruction = system_instruction::create_account(
&context.payer.pubkey(),
&keypair.pubkey(),
account_lamports,
account_size as u64,
&program_id,
);
let transaction = Transaction::new_signed_with_payer(
&[instruction],
Some(&context.payer.pubkey()),
&[&context.payer, &keypair],
context.last_blockhash,
);
context
.banks_client
.process_transaction(transaction)
.await
.unwrap();
let account = context
.banks_client
.get_account(keypair.pubkey())
.await
.expect("account exists")
.unwrap();
assert_eq!(account.lamports, account_lamports);
// Warp forward and see that rent has been collected
// This test was a bit flaky with one warp, but two warps always works
let slots_per_epoch = context.genesis_config().epoch_schedule.slots_per_epoch;
context.warp_to_slot(slots_per_epoch).unwrap();
context.warp_to_slot(slots_per_epoch * 2).unwrap();
let account = context
.banks_client
.get_account(keypair.pubkey())
.await
.expect("account exists")
.unwrap();
assert!(account.lamports < account_lamports);
}
#[tokio::test]
async fn stake_rewards_from_warp() {
// Initialize and start the test network