Skip to content

Commit

Permalink
sdk: evict rent_collector
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 5, 2024
1 parent b44f12d commit f82438c
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 22 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ members = [
"sdk/pubkey",
"sdk/quic-definitions",
"sdk/rent",
"sdk/rent-collector",
"sdk/rent-debits",
"sdk/reserved-account-keys",
"sdk/reward-info",
Expand Down Expand Up @@ -534,6 +535,7 @@ solana-quic-definitions = { path = "sdk/quic-definitions", version = "=2.2.0" }
solana-rayon-threadlimit = { path = "rayon-threadlimit", version = "=2.2.0" }
solana-remote-wallet = { path = "remote-wallet", version = "=2.2.0", default-features = false }
solana-rent = { path = "sdk/rent", version = "=2.2.0", default-features = false }
solana-rent-collector = { path = "sdk/rent-collector", version = "=2.2.0" }
solana-rent-debits = { path = "sdk/rent-debits", version = "=2.2.0" }
solana-reserved-account-keys = { path = "sdk/reserved-account-keys", version = "=2.2.0", default-features = false }
solana-reward-info = { path = "sdk/reward-info", version = "=2.2.0" }
Expand Down
16 changes: 16 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ full = [
"solana-genesis-config",
"solana-hard-forks",
"solana-poh-config",
"solana-rent-collector",
"solana-shred-version",
"solana-signature",
"solana-transaction-context/debug-signature",
Expand Down Expand Up @@ -78,6 +79,7 @@ frozen-abi = [
"solana-genesis-config/frozen-abi",
"solana-inflation/frozen-abi",
"solana-poh-config/frozen-abi",
"solana-rent-collector/frozen-abi",
"solana-program/frozen-abi",
"solana-reward-info/frozen-abi",
"solana-short-vec/frozen-abi",
Expand Down Expand Up @@ -167,6 +169,9 @@ solana-pubkey = { workspace = true, default-features = false, features = [
"std",
] }
solana-quic-definitions = { workspace = true, optional = true }
solana-rent-collector = { workspace = true, features = [
"serde",
], optional = true }
solana-rent-debits = { workspace = true }
solana-reserved-account-keys = { workspace = true }
solana-reward-info = { workspace = true, features = ["serde"] }
Expand Down
37 changes: 37 additions & 0 deletions sdk/rent-collector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "solana-rent-collector"
description = "Calculate and collect rent from accounts."
documentation = "https://docs.rs/solana-rent-collector"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-account = { workspace = true }
solana-clock = { workspace = true }
solana-epoch-schedule = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-genesis-config = { workspace = true }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
solana-sdk-ids = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
solana-logger = { workspace = true }

[features]
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"]
serde = ["dep:serde", "dep:serde_derive"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[lints]
workspace = true
39 changes: 22 additions & 17 deletions sdk/src/rent_collector.rs → sdk/rent-collector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#![cfg(feature = "full")]
//! Calculate and collect rent from accounts.
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]

//! calculate and collect rent from Accounts
use {
solana_account::{AccountSharedData, ReadableAccount, WritableAccount},
solana_sdk::{
clock::Epoch,
epoch_schedule::EpochSchedule,
genesis_config::GenesisConfig,
incinerator,
pubkey::Pubkey,
rent::{Rent, RentDue},
},
solana_clock::Epoch,
solana_epoch_schedule::EpochSchedule,
solana_genesis_config::GenesisConfig,
solana_pubkey::Pubkey,
solana_rent::{Rent, RentDue},
solana_sdk_ids::incinerator,
};

#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
#[derive(Clone, Debug, PartialEq)]
pub struct RentCollector {
pub epoch: Epoch,
pub epoch_schedule: EpochSchedule,
Expand Down Expand Up @@ -215,7 +218,9 @@ impl std::ops::AddAssign for CollectedInfo {

#[cfg(test)]
mod tests {
use {super::*, assert_matches::assert_matches, solana_account::Account, solana_sdk::sysvar};
use {
super::*, assert_matches::assert_matches, solana_account::Account, solana_sdk_ids::sysvar,
};

fn default_rent_collector_clone_with_epoch(epoch: Epoch) -> RentCollector {
RentCollector::default().clone_with_epoch(epoch)
Expand Down Expand Up @@ -374,7 +379,7 @@ mod tests {

// collect rent on a newly-created account
let collected = rent_collector
.collect_from_created_account(&solana_sdk::pubkey::new_rand(), &mut created_account);
.collect_from_created_account(&solana_pubkey::new_rand(), &mut created_account);
assert!(created_account.lamports() < old_lamports);
assert_eq!(
created_account.lamports() + collected.rent_amount,
Expand All @@ -385,7 +390,7 @@ mod tests {

// collect rent on a already-existing account
let collected = rent_collector
.collect_from_existing_account(&solana_sdk::pubkey::new_rand(), &mut existing_account);
.collect_from_existing_account(&solana_pubkey::new_rand(), &mut existing_account);
assert!(existing_account.lamports() < old_lamports);
assert_eq!(
existing_account.lamports() + collected.rent_amount,
Expand All @@ -406,7 +411,7 @@ mod tests {
let epoch = 3;
let huge_lamports = 123_456_789_012;
let tiny_lamports = 789_012;
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();

assert_eq!(account.rent_epoch(), 0);

Expand Down Expand Up @@ -441,7 +446,7 @@ mod tests {
account.set_owner(sysvar::id());
account.set_lamports(tiny_lamports);

let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();

assert_eq!(account.rent_epoch(), 0);

Expand Down
7 changes: 3 additions & 4 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ pub use solana_poh_config as poh_config;
pub mod precompiles;
pub mod program_utils;
pub mod pubkey;
pub mod rent_collector;
#[deprecated(since = "2.2.0", note = "Use `solana_rent_collector` crate instead")]
pub use solana_rent_collector as rent_collector;
#[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")]
pub mod reward_info {
pub use solana_reward_info::RewardInfo;
Expand Down Expand Up @@ -228,12 +229,10 @@ macro_rules! saturating_add_assign {
}};
}

#[macro_use]
extern crate serde_derive;
pub extern crate bs58;
extern crate log as logger;
extern crate serde_derive;

#[cfg_attr(feature = "frozen-abi", macro_use)]
#[cfg(feature = "frozen-abi")]
extern crate solana_frozen_abi_macro;

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/program_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod tests {

#[test]
fn test_limited_deserialize() {
#[derive(Deserialize, Serialize)]
#[derive(serde_derive::Deserialize, serde_derive::Serialize)]
enum Foo {
Bar(Vec<u8>),
}
Expand Down
16 changes: 16 additions & 0 deletions svm/examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f82438c

Please sign in to comment.