Skip to content

Commit

Permalink
feat(rent-reclamation): add ConfigAction::SetRentCollector and implem…
Browse files Browse the repository at this point in the history
…ent its handling
  • Loading branch information
vovacodes committed Nov 24, 2023
1 parent ac150d5 commit e81feb6
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,32 @@ impl<'info> ConfigTransactionExecute<'info> {
let rent = Rent::get()?;

// Check applying the config actions will require reallocation of space for the multisig account.

// Handle growing members vector.
let new_members_length =
members_length_after_actions(multisig.members.len(), &transaction.actions);
if new_members_length > multisig.members.len() {
let needs_members_allocation = new_members_length > multisig.members.len();

// Handle growing rent_collector changing from None -> Some(Pubkey).
// The `rent_collector` field after applying the actions will be:
// - the `new_rent_collector` of the last `SetRentCollector` action, if any present among the actions.
// - the current `rent_collector` if no `SetRentCollector` action is present among the actions.
let new_rent_collector = transaction
.actions
.iter()
.rev()
.find_map(|action| {
if let ConfigAction::SetRentCollector { new_rent_collector } = action {
Some(*new_rent_collector)
} else {
None
}
})
.unwrap_or(multisig.rent_collector);
let needs_rent_collector_allocation =
multisig.rent_collector.is_none() && new_rent_collector.is_some();

if needs_members_allocation || needs_rent_collector_allocation {
let rent_payer = &ctx
.accounts
.rent_payer
Expand All @@ -126,7 +149,7 @@ impl<'info> ConfigTransactionExecute<'info> {
let reallocated = Multisig::realloc_if_needed(
multisig.to_account_info(),
new_members_length,
multisig.rent_collector.is_some(),
new_rent_collector.is_some(),
rent_payer.to_account_info(),
system_program.to_account_info(),
)?;
Expand Down Expand Up @@ -281,6 +304,13 @@ impl<'info> ConfigTransactionExecute<'info> {
// We don't need to invalidate prior transactions here because adding
// a spending limit doesn't affect the consensus parameters of the multisig.
}

ConfigAction::SetRentCollector { new_rent_collector } => {
multisig.rent_collector = *new_rent_collector;

// We don't need to invalidate prior transactions here because changing
// `rent_collector` doesn't affect the consensus parameters of the multisig.
}
}
}

Expand Down Expand Up @@ -313,6 +343,7 @@ fn members_length_after_actions(members_length: usize, actions: &[ConfigAction])
ConfigAction::SetTimeLock { .. } => acc,
ConfigAction::AddSpendingLimit { .. } => acc,
ConfigAction::RemoveSpendingLimit { .. } => acc,
ConfigAction::SetRentCollector { .. } => acc,
});

let abs_members_delta =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ pub enum ConfigAction {
},
/// Remove a spending limit from the multisig.
RemoveSpendingLimit { spending_limit: Pubkey },
/// Set the `rent_collector` config parameter of the multisig.
SetRentCollector { new_rent_collector: Option<Pubkey> },
}
11 changes: 11 additions & 0 deletions sdk/multisig/idl/squads_multisig_program.json
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,17 @@
"type": "publicKey"
}
]
},
{
"name": "SetRentCollector",
"fields": [
{
"name": "newRentCollector",
"type": {
"option": "publicKey"
}
}
]
}
]
}
Expand Down
13 changes: 13 additions & 0 deletions sdk/multisig/src/generated/types/ConfigAction.ts

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

2 changes: 1 addition & 1 deletion tests/suites/instructions/batchAccountsClose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TestMembers,
} from "../../utils";

const { Multisig, Proposal } = multisig.accounts;
const { Multisig } = multisig.accounts;

const programId = getTestProgramId();
const connection = createLocalhostConnection();
Expand Down
Loading

0 comments on commit e81feb6

Please sign in to comment.