use {
crate::consensus::{BlockhashStatus, Result, SwitchForkDecision, TowerError},
serde::{Deserialize, Serialize},
solana_clock::Slot,
solana_pubkey::Pubkey,
solana_signature::Signature,
solana_signer::Signer,
solana_vote_program::vote_state::{BlockTimestamp, Vote, vote_state_1_14_11::VoteState1_14_11},
};
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "FJeuD6UBJe9D8s6iWwianu6KcnJxSozHxDpPQMTrkNJK")
)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Tower1_7_14 {
pub(crate) node_pubkey: Pubkey,
pub(crate) threshold_depth: usize,
pub(crate) threshold_size: f64,
pub(crate) vote_state: VoteState1_14_11,
pub(crate) last_vote: Vote,
#[serde(skip)]
pub(crate) last_vote_tx_blockhash: BlockhashStatus,
pub(crate) last_timestamp: BlockTimestamp,
#[serde(skip)]
pub(crate) stray_restored_slot: Option<Slot>,
#[serde(skip)]
pub(crate) last_switch_threshold_check: Option<(Slot, SwitchForkDecision)>,
}
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample),
frozen_abi(digest = "82njBGFDS9sGdbSuqdeANPe8rmZW1zsrPRpdgnSmZkpY")
)]
#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct SavedTower1_7_14 {
pub(crate) signature: Signature,
pub(crate) data: Vec<u8>,
#[serde(skip)]
pub(crate) node_pubkey: Pubkey,
}
impl SavedTower1_7_14 {
pub fn new<T: Signer>(tower: &Tower1_7_14, keypair: &T) -> Result<Self> {
let node_pubkey = keypair.pubkey();
if tower.node_pubkey != node_pubkey {
return Err(TowerError::WrongTower(format!(
"node_pubkey is {:?} but found tower for {:?}",
node_pubkey, tower.node_pubkey
)));
}
let data = bincode::serialize(tower)?;
let signature = keypair.sign_message(&data);
Ok(Self {
signature,
data,
node_pubkey,
})
}
}