Skip to content

Commit

Permalink
Add epoch history support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines authored and Solana Maintainers committed May 3, 2021
1 parent 54a9535 commit 605690c
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 348 deletions.
3 changes: 1 addition & 2 deletions src/generic_stake_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct ValidatorStake {
pub identity: Pubkey,
pub vote_address: Pubkey,
pub stake_state: ValidatorStakeState,
pub memo: String,
}

pub trait GenericStakePool {
Expand All @@ -26,5 +25,5 @@ pub trait GenericStakePool {
rpc_client: &RpcClient,
dry_run: bool,
desired_validator_stake: &[ValidatorStake],
) -> Result<Vec<String>, Box<dyn error::Error>>;
) -> Result<(Vec<String>, bool), Box<dyn error::Error>>;
}
80 changes: 36 additions & 44 deletions src/legacy_stake_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl GenericStakePool for LegacyStakePool {
rpc_client: &RpcClient,
dry_run: bool,
validator_stake: &[ValidatorStake],
) -> Result<Vec<String>, Box<dyn error::Error>> {
) -> Result<(Vec<String>, bool), Box<dyn error::Error>> {
let (init_transactions, update_transactions) = self.build_transactions(
rpc_client,
self.authorized_staker.pubkey(),
Expand All @@ -53,12 +53,14 @@ impl GenericStakePool for LegacyStakePool {
dry_run,
init_transactions,
&self.authorized_staker,
&mut vec![],
)? {
)?
.failed
.is_empty()
{
return Err("Failed to initialize stake pool. Unable to continue".into());
}

let mut notifications = vec![
let notes = vec![
format!("Baseline stake amount: {}", Sol(self.baseline_stake_amount)),
format!("Bonus stake amount: {}", Sol(self.bonus_stake_amount)),
];
Expand All @@ -67,25 +69,24 @@ impl GenericStakePool for LegacyStakePool {
dry_run,
update_transactions,
&self.authorized_staker,
&mut notifications,
)?;
)?
.failed
.is_empty();

if !ok {
error!("One or more transactions failed to execute")
}
Ok(notifications)
Ok((notes, ok))
}
}

type TransactionWithMemo = (Transaction, String);

impl LegacyStakePool {
fn build_transactions(
&mut self,
rpc_client: &RpcClient,
authorized_staker: Pubkey,
validator_stake: &[ValidatorStake],
) -> Result<(Vec<TransactionWithMemo>, Vec<TransactionWithMemo>), Box<dyn error::Error>> {
) -> Result<(Vec<Transaction>, Vec<Transaction>), Box<dyn error::Error>> {
let mut init_transactions = vec![];
let mut update_transactions = vec![];
let mut source_stake_lamports_required = 0;
Expand Down Expand Up @@ -114,7 +115,6 @@ impl LegacyStakePool {
for ValidatorStake {
identity,
vote_address,
memo,
stake_state,
} in validator_stake
{
Expand Down Expand Up @@ -153,27 +153,23 @@ impl LegacyStakePool {
)
})?.state
} else {
let memo = format!(
info!(
"Creating baseline stake account for validator {} ({})",
identity, baseline_stake_address
);
debug!("Adding transaction: {}", memo);

source_stake_lamports_required += self.baseline_stake_amount;
init_transactions.push((
Transaction::new_unsigned(Message::new(
&stake_instruction::split_with_seed(
&self.source_stake_address,
&authorized_staker,
self.baseline_stake_amount,
&baseline_stake_address,
&authorized_staker,
baseline_seed,
),
Some(&authorized_staker),
)),
memo,
));
init_transactions.push(Transaction::new_unsigned(Message::new(
&stake_instruction::split_with_seed(
&self.source_stake_address,
&authorized_staker,
self.baseline_stake_amount,
&baseline_stake_address,
&authorized_staker,
baseline_seed,
),
Some(&authorized_staker),
)));
StakeActivationState::Inactive
};

Expand All @@ -192,26 +188,22 @@ impl LegacyStakePool {
})?
.state
} else {
let memo = format!(
info!(
"Creating bonus stake account for validator {} ({})",
identity, bonus_stake_address
);
debug!("Adding transaction: {}", memo);
source_stake_lamports_required += self.bonus_stake_amount;
init_transactions.push((
Transaction::new_unsigned(Message::new(
&stake_instruction::split_with_seed(
&self.source_stake_address,
&authorized_staker,
self.bonus_stake_amount,
&bonus_stake_address,
&authorized_staker,
bonus_seed,
),
Some(&authorized_staker),
)),
memo,
));
init_transactions.push(Transaction::new_unsigned(Message::new(
&stake_instruction::split_with_seed(
&self.source_stake_address,
&authorized_staker,
self.bonus_stake_amount,
&bonus_stake_address,
&authorized_staker,
bonus_seed,
),
Some(&authorized_staker),
)));
StakeActivationState::Inactive
};

Expand All @@ -224,7 +216,7 @@ impl LegacyStakePool {
bonus_stake_activation_state,
stake_state,
) {
update_transactions.push((transaction, memo.clone()))
update_transactions.push(transaction)
}
}

Expand Down
Loading

0 comments on commit 605690c

Please sign in to comment.