Use Slot and Epoch type aliases instead of raw u64 (#6693)

automerge
This commit is contained in:
Michael Vines
2019-11-02 00:38:30 -07:00
committed by Grimes
parent f9a9b7f610
commit 50a17fc00b
41 changed files with 583 additions and 473 deletions

View File

@ -424,7 +424,7 @@ impl Stake {
}
}
fn deactivate(&mut self, epoch: u64) -> Result<(), StakeError> {
fn deactivate(&mut self, epoch: Epoch) -> Result<(), StakeError> {
if self.deactivation_epoch != std::u64::MAX {
Err(StakeError::AlreadyDeactivated)
} else {

View File

@ -2,14 +2,16 @@ use crate::storage_instruction::StorageAccountType;
use log::*;
use num_derive::FromPrimitive;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::account::Account;
use solana_sdk::account::KeyedAccount;
use solana_sdk::account_utils::State;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::sysvar;
use solana_sdk::{
account::{Account, KeyedAccount},
account_utils::State,
clock::Epoch,
hash::Hash,
instruction::InstructionError,
pubkey::Pubkey,
signature::Signature,
sysvar,
};
use std::collections::BTreeMap;
// Todo Tune this for actual use cases when PoRep is feature complete
@ -19,15 +21,15 @@ pub const MAX_PROOFS_PER_SEGMENT: usize = 80;
#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Credits {
// current epoch
epoch: u64,
epoch: Epoch,
// currently pending credits
pub current_epoch: u64,
pub current_epoch: Epoch,
// credits ready to be claimed
pub redeemable: u64,
}
impl Credits {
pub fn update_epoch(&mut self, current_epoch: u64) {
pub fn update_epoch(&mut self, current_epoch: Epoch) {
if self.epoch != current_epoch {
self.epoch = current_epoch;
self.redeemable += self.current_epoch;

View File

@ -313,7 +313,7 @@ impl VoteState {
self.epoch_credits.iter()
}
fn pop_expired_votes(&mut self, slot: u64) {
fn pop_expired_votes(&mut self, slot: Slot) {
loop {
if self.votes.back().map_or(false, |v| v.is_expired(slot)) {
self.votes.pop_back();
@ -465,9 +465,7 @@ pub fn create_account(
mod tests {
use super::*;
use crate::vote_state;
use solana_sdk::account::Account;
use solana_sdk::account_utils::State;
use solana_sdk::hash::hash;
use solana_sdk::{account::Account, account_utils::State, hash::hash};
const MAX_RECENT_VOTES: usize = 16;
@ -528,7 +526,7 @@ mod tests {
vote_account: &mut Account,
vote: &Vote,
slot_hashes: &[SlotHash],
epoch: u64,
epoch: Epoch,
) -> Result<VoteState, InstructionError> {
process_vote(
&mut KeyedAccount::new(vote_pubkey, true, vote_account),