diff --git a/programs/native/vote/src/lib.rs b/programs/native/vote/src/lib.rs index 2af852b56..78c3d0e55 100644 --- a/programs/native/vote/src/lib.rs +++ b/programs/native/vote/src/lib.rs @@ -9,13 +9,24 @@ use solana_sdk::pubkey::Pubkey; use solana_sdk::solana_entrypoint; use solana_sdk::vote_program::{self, Vote, VoteInstruction, VoteState}; +// TODO: Deprecate the RegisterAccount instruction and its awkward delegation +// semantics. fn register(keyed_accounts: &mut [KeyedAccount]) -> Result<(), ProgramError> { if !vote_program::check_id(&keyed_accounts[1].account.owner) { error!("account[1] is not assigned to the VOTE_PROGRAM"); Err(ProgramError::InvalidArgument)?; } - let vote_state = VoteState::new(*keyed_accounts[0].signer_key().unwrap()); + // TODO: This assumes keyed_accounts[0] is the SystemInstruction::CreateAccount + // that created keyed_accounts[1]. Putting any other signed instruction in + // keyed_accounts[0] would allow the owner to highjack the vote account and + // insert itself into the leader rotation. + let from_id = keyed_accounts[0].signer_key().unwrap(); + + // Awkwardly configure the voting account to claim that the account that + // initially funded it is both the identity of the staker and the fullnode + // that should sign blocks on behalf of the staker. + let vote_state = VoteState::new(*from_id, *from_id); vote_state.serialize(&mut keyed_accounts[1].account.userdata)?; Ok(()) diff --git a/sdk/src/vote_program.rs b/sdk/src/vote_program.rs index ef644f856..2c2793cc9 100644 --- a/sdk/src/vote_program.rs +++ b/sdk/src/vote_program.rs @@ -50,6 +50,7 @@ pub enum VoteInstruction { pub struct VoteState { pub votes: VecDeque, pub node_id: Pubkey, + pub staker_id: Pubkey, } pub fn get_max_size() -> usize { @@ -61,9 +62,13 @@ pub fn get_max_size() -> usize { } impl VoteState { - pub fn new(node_id: Pubkey) -> Self { + pub fn new(node_id: Pubkey, staker_id: Pubkey) -> Self { let votes = VecDeque::new(); - Self { votes, node_id } + Self { + votes, + node_id, + staker_id, + } } pub fn deserialize(input: &[u8]) -> Result { diff --git a/src/leader_scheduler.rs b/src/leader_scheduler.rs index e5cb9ed3c..1ea132137 100644 --- a/src/leader_scheduler.rs +++ b/src/leader_scheduler.rs @@ -343,7 +343,7 @@ impl LeaderScheduler { vote.tick_height > lower_bound && vote.tick_height <= upper_bound }) - .map(|_| vote_state.node_id); + .map(|_| vote_state.staker_id); } }