Clippy
This commit is contained in:
@@ -19,7 +19,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
assert_eq!(z, 340_282_366_920_938_463_463_374_607_431_768_211_454);
|
||||
|
||||
assert_eq!(u128::from(1u32.to_le()), 1);
|
||||
assert_eq!(u128::from(1u32.to_be()), 0x1_000_000);
|
||||
assert_eq!(u128::from(1u32.to_be()), 0x0100_0000);
|
||||
|
||||
assert_eq!(solana_bpf_rust_128bit_dep::uadd(10, 20), 30u128);
|
||||
assert_eq!(solana_bpf_rust_128bit_dep::usubtract(30, 20), 10u128);
|
||||
|
@@ -53,7 +53,8 @@ unsafe impl std::alloc::GlobalAlloc for BumpAllocator {
|
||||
static A: BumpAllocator = BumpAllocator;
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
pub fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_accounts: &[AccountInfo],
|
||||
_instruction_data: &[u8],
|
||||
|
@@ -27,6 +27,7 @@ fn custom_panic(info: &core::panic::PanicInfo<'_>) {
|
||||
}
|
||||
|
||||
entrypoint_deprecated!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
|
@@ -6,6 +6,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
|
@@ -7,6 +7,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
|
@@ -6,6 +6,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_accounts: &[AccountInfo],
|
||||
|
@@ -14,6 +14,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_accounts: &[AccountInfo],
|
||||
|
@@ -8,6 +8,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_accounts: &[AccountInfo],
|
||||
|
@@ -21,6 +21,7 @@ fn return_sstruct() -> SStruct {
|
||||
}
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
|
@@ -3,6 +3,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
|
@@ -16,6 +16,7 @@ use solana_program::{
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
|
@@ -141,9 +141,10 @@ pub fn process_instruction(
|
||||
trace!("contract already exists");
|
||||
return Err(InstructionError::AccountAlreadyInitialized);
|
||||
}
|
||||
let mut budget_state = BudgetState::default();
|
||||
budget_state.pending_budget = Some(*expr);
|
||||
budget_state.initialized = true;
|
||||
let budget_state = BudgetState {
|
||||
pending_budget: Some(*expr),
|
||||
initialized: true,
|
||||
};
|
||||
budget_state.serialize(&mut contract_keyed_account.try_account_ref_mut()?.data)
|
||||
}
|
||||
BudgetInstruction::ApplyTimestamp(dt) => {
|
||||
|
@@ -10,7 +10,7 @@ solana_sdk::declare_program!(
|
||||
process_instruction
|
||||
);
|
||||
|
||||
fn process_instruction(
|
||||
pub fn process_instruction(
|
||||
program_id: &Pubkey,
|
||||
keyed_accounts: &[KeyedAccount],
|
||||
data: &[u8],
|
||||
|
@@ -562,13 +562,15 @@ mod tests {
|
||||
} else if sysvar::rent::check_id(&meta.pubkey) {
|
||||
account::create_account(&Rent::default(), 1)
|
||||
} else if meta.pubkey == invalid_stake_state_pubkey() {
|
||||
let mut account = Account::default();
|
||||
account.owner = id();
|
||||
account
|
||||
Account {
|
||||
owner: id(),
|
||||
..Account::default()
|
||||
}
|
||||
} else if meta.pubkey == invalid_vote_state_pubkey() {
|
||||
let mut account = Account::default();
|
||||
account.owner = solana_vote_program::id();
|
||||
account
|
||||
Account {
|
||||
owner: solana_vote_program::id(),
|
||||
..Account::default()
|
||||
}
|
||||
} else {
|
||||
Account::default()
|
||||
})
|
||||
|
@@ -272,16 +272,18 @@ impl VoteState {
|
||||
}
|
||||
|
||||
fn get_max_sized_vote_state() -> VoteState {
|
||||
let mut vote_state = Self::default();
|
||||
vote_state.votes = VecDeque::from(vec![Lockout::default(); MAX_LOCKOUT_HISTORY]);
|
||||
vote_state.root_slot = Some(std::u64::MAX);
|
||||
vote_state.epoch_credits = vec![(0, 0, 0); MAX_EPOCH_CREDITS_HISTORY];
|
||||
let mut authorized_voters = AuthorizedVoters::default();
|
||||
for i in 0..=MAX_LEADER_SCHEDULE_EPOCH_OFFSET {
|
||||
authorized_voters.insert(i, solana_sdk::pubkey::new_rand());
|
||||
}
|
||||
vote_state.authorized_voters = authorized_voters;
|
||||
vote_state
|
||||
|
||||
VoteState {
|
||||
votes: VecDeque::from(vec![Lockout::default(); MAX_LOCKOUT_HISTORY]),
|
||||
root_slot: Some(std::u64::MAX),
|
||||
epoch_credits: vec![(0, 0, 0); MAX_EPOCH_CREDITS_HISTORY],
|
||||
authorized_voters,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn check_slots_are_valid(
|
||||
@@ -463,10 +465,7 @@ impl VoteState {
|
||||
where
|
||||
F: Fn(Pubkey) -> Result<(), InstructionError>,
|
||||
{
|
||||
let epoch_authorized_voter = self.get_and_update_authorized_voter(current_epoch).expect(
|
||||
"the clock epoch is monotonically increasing, so authorized voter must be known",
|
||||
);
|
||||
|
||||
let epoch_authorized_voter = self.get_and_update_authorized_voter(current_epoch);
|
||||
verify(epoch_authorized_voter)?;
|
||||
|
||||
// The offset in slots `n` on which the target_epoch
|
||||
@@ -514,17 +513,16 @@ impl VoteState {
|
||||
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) -> Pubkey {
|
||||
let pubkey = self
|
||||
.authorized_voters
|
||||
.get_and_cache_authorized_voter_for_epoch(current_epoch)
|
||||
.expect(
|
||||
"Internal functions should
|
||||
only call this will monotonically increasing current_epoch",
|
||||
"Internal functions should only call this will monotonically increasing current_epoch",
|
||||
);
|
||||
self.authorized_voters
|
||||
.purge_authorized_voters(current_epoch);
|
||||
Some(pubkey)
|
||||
pubkey
|
||||
}
|
||||
|
||||
fn pop_expired_votes(&mut self, slot: Slot) {
|
||||
@@ -702,9 +700,7 @@ pub fn process_vote<S: std::hash::BuildHasher>(
|
||||
}
|
||||
|
||||
let mut vote_state = versioned.convert_to_current();
|
||||
let authorized_voter = vote_state
|
||||
.get_and_update_authorized_voter(clock.epoch)
|
||||
.expect("the clock epoch is monotonically increasing, so authorized voter must be known");
|
||||
let authorized_voter = vote_state.get_and_update_authorized_voter(clock.epoch);
|
||||
verify_authorized_signer(&authorized_voter, signers)?;
|
||||
|
||||
vote_state.process_vote(vote, slot_hashes, clock.epoch)?;
|
||||
@@ -712,7 +708,7 @@ pub fn process_vote<S: std::hash::BuildHasher>(
|
||||
vote.slots
|
||||
.iter()
|
||||
.max()
|
||||
.ok_or_else(|| VoteError::EmptySlots)
|
||||
.ok_or(VoteError::EmptySlots)
|
||||
.and_then(|slot| vote_state.process_timestamp(*slot, timestamp))?;
|
||||
}
|
||||
vote_account.set_state(&VoteStateVersions::Current(Box::new(vote_state)))
|
||||
@@ -1571,8 +1567,10 @@ mod tests {
|
||||
|
||||
assert_eq!(vote_state.commission_split(1), (0, 1, false));
|
||||
|
||||
let mut vote_state = VoteState::default();
|
||||
vote_state.commission = std::u8::MAX;
|
||||
let mut vote_state = VoteState {
|
||||
commission: std::u8::MAX,
|
||||
..VoteState::default()
|
||||
};
|
||||
assert_eq!(vote_state.commission_split(1), (1, 0, false));
|
||||
|
||||
vote_state.commission = 99;
|
||||
@@ -1726,8 +1724,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vote_process_timestamp() {
|
||||
let (slot, timestamp) = (15, 1_575_412_285);
|
||||
let mut vote_state = VoteState::default();
|
||||
vote_state.last_timestamp = BlockTimestamp { slot, timestamp };
|
||||
let mut vote_state = VoteState {
|
||||
last_timestamp: BlockTimestamp { slot, timestamp },
|
||||
..VoteState::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
vote_state.process_timestamp(slot - 1, timestamp + 1),
|
||||
@@ -1791,14 +1791,14 @@ mod tests {
|
||||
// If no new authorized voter was set, the same authorized voter
|
||||
// is locked into the next epoch
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(1).unwrap(),
|
||||
vote_state.get_and_update_authorized_voter(1),
|
||||
original_voter
|
||||
);
|
||||
|
||||
// Try to get the authorized voter for epoch 5, implies
|
||||
// the authorized voter for epochs 1-4 were unchanged
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(5).unwrap(),
|
||||
vote_state.get_and_update_authorized_voter(5),
|
||||
original_voter
|
||||
);
|
||||
|
||||
@@ -1820,7 +1820,7 @@ mod tests {
|
||||
|
||||
// Try to get the authorized voter for epoch 6, unchanged
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(6).unwrap(),
|
||||
vote_state.get_and_update_authorized_voter(6),
|
||||
original_voter
|
||||
);
|
||||
|
||||
@@ -1828,7 +1828,7 @@ mod tests {
|
||||
// be the new authorized voter
|
||||
for i in 7..10 {
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(i).unwrap(),
|
||||
vote_state.get_and_update_authorized_voter(i),
|
||||
new_authorized_voter
|
||||
);
|
||||
}
|
||||
@@ -1904,31 +1904,22 @@ mod tests {
|
||||
// voters is correct
|
||||
for i in 9..epoch_offset {
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(i).unwrap(),
|
||||
vote_state.get_and_update_authorized_voter(i),
|
||||
original_voter
|
||||
);
|
||||
}
|
||||
for i in epoch_offset..3 + epoch_offset {
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(i).unwrap(),
|
||||
new_voter
|
||||
);
|
||||
assert_eq!(vote_state.get_and_update_authorized_voter(i), new_voter);
|
||||
}
|
||||
for i in 3 + epoch_offset..6 + epoch_offset {
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(i).unwrap(),
|
||||
new_voter2
|
||||
);
|
||||
assert_eq!(vote_state.get_and_update_authorized_voter(i), new_voter2);
|
||||
}
|
||||
for i in 6 + epoch_offset..9 + epoch_offset {
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(i).unwrap(),
|
||||
new_voter3
|
||||
);
|
||||
assert_eq!(vote_state.get_and_update_authorized_voter(i), new_voter3);
|
||||
}
|
||||
for i in 9 + epoch_offset..=10 + epoch_offset {
|
||||
assert_eq!(
|
||||
vote_state.get_and_update_authorized_voter(i).unwrap(),
|
||||
vote_state.get_and_update_authorized_voter(i),
|
||||
original_voter
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user