Prevent rent-paying account creation (backport #22292) (#22428)

* 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

(cherry picked from commit 637e366b18)

# Conflicts:
#	runtime/src/bank.rs
#	runtime/src/lib.rs

* Fix conflicts and rework for TransactionRefCells

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
mergify[bot]
2022-01-11 23:17:03 +00:00
committed by GitHub
parent f0695ef6d9
commit 58dcc451a9
24 changed files with 821 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