Vote program updates
This commit is contained in:
@ -464,9 +464,7 @@ impl VoteState {
|
|||||||
where
|
where
|
||||||
F: Fn(Pubkey) -> Result<(), InstructionError>,
|
F: Fn(Pubkey) -> Result<(), InstructionError>,
|
||||||
{
|
{
|
||||||
let epoch_authorized_voter = self.get_and_update_authorized_voter(current_epoch).expect(
|
let epoch_authorized_voter = self.get_and_update_authorized_voter(current_epoch)?;
|
||||||
"the clock epoch is monotonically increasing, so authorized voter must be known",
|
|
||||||
);
|
|
||||||
|
|
||||||
verify(epoch_authorized_voter)?;
|
verify(epoch_authorized_voter)?;
|
||||||
|
|
||||||
@ -480,10 +478,10 @@ impl VoteState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the latest authorized_voter
|
// Get the latest authorized_voter
|
||||||
let (latest_epoch, latest_authorized_pubkey) = self.authorized_voters.last().expect(
|
let (latest_epoch, latest_authorized_pubkey) = self
|
||||||
"Earlier call to `get_and_update_authorized_voter()` guarantees
|
.authorized_voters
|
||||||
at least the voter for `epoch` exists in the map",
|
.last()
|
||||||
);
|
.ok_or(InstructionError::InvalidAccountData)?;
|
||||||
|
|
||||||
// If we're not setting the same pubkey as authorized pubkey again,
|
// If we're not setting the same pubkey as authorized pubkey again,
|
||||||
// then update the list of prior voters to mark the expiration
|
// then update the list of prior voters to mark the expiration
|
||||||
@ -515,17 +513,17 @@ impl VoteState {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_and_update_authorized_voter(&mut self, current_epoch: Epoch) -> Option<Pubkey> {
|
fn get_and_update_authorized_voter(
|
||||||
|
&mut self,
|
||||||
|
current_epoch: Epoch,
|
||||||
|
) -> Result<Pubkey, InstructionError> {
|
||||||
let pubkey = self
|
let pubkey = self
|
||||||
.authorized_voters
|
.authorized_voters
|
||||||
.get_and_cache_authorized_voter_for_epoch(current_epoch)
|
.get_and_cache_authorized_voter_for_epoch(current_epoch)
|
||||||
.expect(
|
.ok_or(InstructionError::InvalidAccountData)?;
|
||||||
"Internal functions should
|
|
||||||
only call this will monotonically increasing current_epoch",
|
|
||||||
);
|
|
||||||
self.authorized_voters
|
self.authorized_voters
|
||||||
.purge_authorized_voters(current_epoch);
|
.purge_authorized_voters(current_epoch);
|
||||||
Some(pubkey)
|
Ok(pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop_expired_votes(&mut self, slot: Slot) {
|
fn pop_expired_votes(&mut self, slot: Slot) {
|
||||||
@ -708,9 +706,7 @@ pub fn process_vote<S: std::hash::BuildHasher>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut vote_state = versioned.convert_to_current();
|
let mut vote_state = versioned.convert_to_current();
|
||||||
let authorized_voter = vote_state
|
let authorized_voter = vote_state.get_and_update_authorized_voter(clock.epoch)?;
|
||||||
.get_and_update_authorized_voter(clock.epoch)
|
|
||||||
.expect("the clock epoch is monotonically increasing, so authorized voter must be known");
|
|
||||||
verify_authorized_signer(&authorized_voter, signers)?;
|
verify_authorized_signer(&authorized_voter, signers)?;
|
||||||
|
|
||||||
vote_state.process_vote(vote, slot_hashes, clock.epoch)?;
|
vote_state.process_vote(vote, slot_hashes, clock.epoch)?;
|
||||||
|
Reference in New Issue
Block a user