Skip to content

Commit

Permalink
set rent epoch to max on new account creation (solana-labs#29528)
Browse files Browse the repository at this point in the history
* set rent epoch to max on new account creation

* add comment
  • Loading branch information
jeffwashington authored and gnapoli23 committed Jan 10, 2023
1 parent 46b67fa commit 6df7638
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
2 changes: 1 addition & 1 deletion client-test/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fn test_account_subscription() {
"lamports": 100,
"data": "",
"executable": false,
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": 0,
},
});
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5841,7 +5841,7 @@ pub mod tests {
"executable": false,
"owner": "11111111111111111111111111111111",
"lamports": rent_exempt_amount,
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": 0,
}
],
Expand Down
6 changes: 3 additions & 3 deletions rpc/src/rpc_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ mod tests {
"lamports": balance,
"data": [base64::encode(expected_data), encoding],
"executable": false,
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": expected_data.len(),
},
},
Expand Down Expand Up @@ -1059,7 +1059,7 @@ mod tests {
"lamports": 100,
"data": expected_data,
"executable": false,
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": account.data().len(),
},
},
Expand Down Expand Up @@ -1239,7 +1239,7 @@ mod tests {
"lamports": 100,
"data": "",
"executable": false,
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": 0,
},
},
Expand Down
58 changes: 35 additions & 23 deletions rpc/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,10 @@ pub(crate) mod tests {
space: usize,
}

fn make_account_result(account_result: AccountResult) -> serde_json::Value {
fn make_account_result(
non_default_account: bool,
account_result: AccountResult,
) -> serde_json::Value {
json!({
"jsonrpc": "2.0",
"method": "accountNotification",
Expand All @@ -1284,7 +1287,7 @@ pub(crate) mod tests {
"executable": false,
"lamports": account_result.lamports,
"owner": "11111111111111111111111111111111",
"rentEpoch": 0,
"rentEpoch": if non_default_account {u64::MAX} else {0},
"space": account_result.space,
},
},
Expand Down Expand Up @@ -1329,25 +1332,31 @@ pub(crate) mod tests {
0,
&system_program::id(),
);
let expected0 = make_account_result(AccountResult {
lamports: 1,
subscription: 0,
space: 0,
data: "",
});
let expected0 = make_account_result(
true,
AccountResult {
lamports: 1,
subscription: 0,
space: 0,
data: "",
},
);

let tx1 = {
let instruction =
system_instruction::transfer(&alice.pubkey(), &mint_keypair.pubkey(), 1);
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
Transaction::new(&[&alice, &mint_keypair], message, blockhash)
};
let expected1 = make_account_result(AccountResult {
lamports: 0,
subscription: 1,
space: 0,
data: "",
});
let expected1 = make_account_result(
false,
AccountResult {
lamports: 0,
subscription: 1,
space: 0,
data: "",
},
);

let tx2 = system_transaction::create_account(
&mint_keypair,
Expand All @@ -1357,12 +1366,15 @@ pub(crate) mod tests {
1024,
&system_program::id(),
);
let expected2 = make_account_result(AccountResult {
lamports: 1,
subscription: 2,
space: 1024,
data: "error: data too large for bs58 encoding",
});
let expected2 = make_account_result(
true,
AccountResult {
lamports: 1,
subscription: 2,
space: 1024,
data: "error: data too large for bs58 encoding",
},
);

let subscribe_cases = vec![
(alice.pubkey(), tx0, expected0),
Expand Down Expand Up @@ -1860,7 +1872,7 @@ pub(crate) mod tests {
"executable": false,
"lamports": 1,
"owner": "Stake11111111111111111111111111111111111111",
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": 16,
},
"pubkey": alice.pubkey().to_string(),
Expand Down Expand Up @@ -2027,7 +2039,7 @@ pub(crate) mod tests {
"executable": false,
"lamports": lamports,
"owner": "Stake11111111111111111111111111111111111111",
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": 16,
},
"pubkey": pubkey,
Expand Down Expand Up @@ -2308,7 +2320,7 @@ pub(crate) mod tests {
"executable": false,
"lamports": lamports,
"owner": "Stake11111111111111111111111111111111111111",
"rentEpoch": 0,
"rentEpoch": u64::MAX,
"space": 16,
},
"pubkey": pubkey,
Expand Down
11 changes: 10 additions & 1 deletion runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,16 @@ impl Accounts {
(account, 0)
}
})
.unwrap_or_default()
.unwrap_or_else(|| {
let mut default_account = AccountSharedData::default();
if set_exempt_rent_epoch_max {
// All new accounts must be rent-exempt (enforced in Bank::execute_loaded_transaction).
// Currently, rent collection sets rent_epoch to u64::MAX, but initializing the account
// with this field already set would allow us to skip rent collection for these accounts.
default_account.set_rent_epoch(u64::MAX);
}
(default_account, 0)
})
};

if !validated_fee_payer {
Expand Down

0 comments on commit 6df7638

Please sign in to comment.