Avoid sending duplicate stake delegation transactions for the same epoch (#10158)
automerge
This commit is contained in:
parent
8da2e1b2f7
commit
429802a138
|
@ -542,6 +542,7 @@ fn process_confirmations(
|
|||
ok
|
||||
}
|
||||
|
||||
#[allow(clippy::cognitive_complexity)] // Yeah I know...
|
||||
fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
solana_logger::setup_with_default("solana=info");
|
||||
let config = get_config();
|
||||
|
@ -578,6 +579,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
let mut source_stake_lamports_required = 0;
|
||||
let mut create_stake_transactions = vec![];
|
||||
let mut delegate_stake_transactions = vec![];
|
||||
let mut stake_activated_in_current_epoch: HashSet<Pubkey> = HashSet::new();
|
||||
|
||||
for RpcVoteAccountInfo {
|
||||
vote_pubkey,
|
||||
|
@ -605,7 +607,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.unwrap();
|
||||
|
||||
// Transactions to create the baseline and bonus stake accounts
|
||||
if let Ok((balance, _)) = get_stake_account(&rpc_client, &baseline_stake_address) {
|
||||
if let Ok((balance, stake_state)) = get_stake_account(&rpc_client, &baseline_stake_address)
|
||||
{
|
||||
if balance != config.baseline_stake_amount {
|
||||
error!(
|
||||
"Unexpected balance in stake account {}: {}, expected {}",
|
||||
|
@ -613,6 +616,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
);
|
||||
process::exit(1);
|
||||
}
|
||||
if let Some(delegation) = stake_state.delegation() {
|
||||
if epoch_info.epoch == delegation.activation_epoch {
|
||||
stake_activated_in_current_epoch.insert(baseline_stake_address);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info!(
|
||||
"Need to create baseline stake account for validator {}",
|
||||
|
@ -638,7 +646,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
));
|
||||
}
|
||||
|
||||
if let Ok((balance, _)) = get_stake_account(&rpc_client, &bonus_stake_address) {
|
||||
if let Ok((balance, stake_state)) = get_stake_account(&rpc_client, &bonus_stake_address) {
|
||||
if balance != config.bonus_stake_amount {
|
||||
error!(
|
||||
"Unexpected balance in stake account {}: {}, expected {}",
|
||||
|
@ -646,6 +654,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
);
|
||||
process::exit(1);
|
||||
}
|
||||
if let Some(delegation) = stake_state.delegation() {
|
||||
if epoch_info.epoch == delegation.activation_epoch {
|
||||
stake_activated_in_current_epoch.insert(bonus_stake_address);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info!(
|
||||
"Need to create bonus stake account for validator {}",
|
||||
|
@ -683,6 +696,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
);
|
||||
|
||||
// Delegate baseline stake
|
||||
if !stake_activated_in_current_epoch.contains(&baseline_stake_address) {
|
||||
delegate_stake_transactions.push((
|
||||
Transaction::new_unsigned(Message::new_with_payer(
|
||||
&[stake_instruction::delegate_stake(
|
||||
|
@ -698,9 +712,11 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
lamports_to_sol(config.baseline_stake_amount),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
if quality_block_producers.contains(&node_pubkey) {
|
||||
// Delegate bonus stake
|
||||
if !stake_activated_in_current_epoch.contains(&bonus_stake_address) {
|
||||
delegate_stake_transactions.push((
|
||||
Transaction::new_unsigned(
|
||||
Message::new_with_payer(
|
||||
|
@ -718,6 +734,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
lamports_to_sol(config.bonus_stake_amount),
|
||||
),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// Deactivate bonus stake
|
||||
delegate_stake_transactions.push((
|
||||
|
@ -837,7 +854,14 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
&config.authorized_staker,
|
||||
)?;
|
||||
|
||||
if !process_confirmations(confirmations, Some(¬ifier)) {
|
||||
if !process_confirmations(
|
||||
confirmations,
|
||||
if config.dry_run {
|
||||
None
|
||||
} else {
|
||||
Some(¬ifier)
|
||||
},
|
||||
) {
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue