Skip to content

Commit

Permalink
chore(clippy): make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
drcpu-github committed Nov 2, 2024
1 parent 87fb008 commit 4924e0f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 46 deletions.
12 changes: 5 additions & 7 deletions data_structures/src/staking/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,11 @@ where
) -> StakesResult<Coins, Address, Coins, Epoch> {
let coins_after = self.coins.sub(coins);

if coins_after > Coins::zero() {
if coins_after < minimum_stakeable {
Err(StakesError::AmountIsBelowMinimum {
amount: coins_after,
minimum: minimum_stakeable,
})?;
}
if coins_after > Coins::zero() && coins_after < minimum_stakeable {
Err(StakesError::AmountIsBelowMinimum {
amount: coins_after,
minimum: minimum_stakeable,
})?;
}

self.coins = coins_after;
Expand Down
1 change: 0 additions & 1 deletion node/src/actors/chain_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ impl Handler<EpochNotification<EveryEpochPayload>> for ChainManager {
let rank_subset: Vec<_> = stakes
.rank(Capability::Mining, previous_epoch)
.take(replication_factor.into())
.map(|sk| sk)
.collect();
for (i, (stake_key, _)) in rank_subset.into_iter().enumerate() {
log::warn!(
Expand Down
45 changes: 22 additions & 23 deletions node/src/actors/chain_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,30 +1033,29 @@ impl ChainManager {
let superblock_period = chain_info.consensus_constants.superblock_period;
if get_protocol_version(Some(block_epoch)) == ProtocolVersion::V1_8
&& get_protocol_version_activation_epoch(ProtocolVersion::V2_0) == Epoch::MAX
&& block_epoch % u32::from(superblock_period) == 0
{
if block_epoch % u32::from(superblock_period) == 0 {
let min_total_stake = self
.consensus_constants_wit2
.get_wit2_minimum_total_stake_nanowits();
let activation_delay = self
.consensus_constants_wit2
.get_wit2_activation_delay_epochs();
if stakes.total_staked() >= Wit::from(min_total_stake) {
register_protocol_version(
ProtocolVersion::V2_0,
block_epoch + activation_delay,
20,
);
if let Some(epoch_constants) = &mut self.epoch_constants {
match epoch_constants
.set_values_for_wit2(20, block_epoch + activation_delay)
{
Ok(_) => (),
Err(_) => panic!("Could not set wit/2 checkpoint variables"),
};
} else {
panic!("Could not set wit/2 checkpoint variables");
}
let min_total_stake = self
.consensus_constants_wit2
.get_wit2_minimum_total_stake_nanowits();
let activation_delay = self
.consensus_constants_wit2
.get_wit2_activation_delay_epochs();
if stakes.total_staked() >= Wit::from(min_total_stake) {
register_protocol_version(
ProtocolVersion::V2_0,
block_epoch + activation_delay,
20,
);
if let Some(epoch_constants) = &mut self.epoch_constants {
match epoch_constants
.set_values_for_wit2(20, block_epoch + activation_delay)
{
Ok(_) => (),
Err(_) => panic!("Could not set wit/2 checkpoint variables"),
};
} else {
panic!("Could not set wit/2 checkpoint variables");
}
}
}
Expand Down
24 changes: 9 additions & 15 deletions validations/src/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ pub type ValidatedStakeTransaction<'a> = (
);

/// Function to validate a stake transaction.
#[allow(clippy::too_many_arguments)]
pub fn validate_stake_transaction<'a>(
st_tx: &'a StakeTransaction,
utxo_diff: &UtxoDiff<'_>,
Expand Down Expand Up @@ -1449,11 +1450,7 @@ pub fn validate_unstake_transaction<'a>(
}

// TODO: modify this to enable delegated staking with multiple withdrawer addresses on a single validator
let nonce = stake_entry
.first()
.map(|stake| stake.value.nonce)
.unwrap()
.into();
let nonce = stake_entry.first().map(|stake| stake.value.nonce).unwrap();
if ut_tx.body.nonce != nonce {
return Err(TransactionError::UnstakeInvalidNonce {
used: ut_tx.body.nonce,
Expand Down Expand Up @@ -1540,11 +1537,11 @@ pub fn validate_unstake_signature(
let signature = ut_tx.signature.signature.clone().try_into().map_err(fte)?;
let public_key = ut_tx.signature.public_key.clone().try_into().map_err(fte)?;

verify(&public_key, &message.to_vec(), &signature).map_err(|e| {
verify(&public_key, message.as_ref(), &signature).map_err(|e| {
TransactionError::VerifyTransactionSignatureFail {
hash: {
let mut sha256 = [0; 32];
sha256.copy_from_slice(&message.to_vec());
sha256.copy_from_slice(message.as_ref());
Hash::SHA256(sha256)
},
msg: e.to_string(),
Expand Down Expand Up @@ -1834,6 +1831,7 @@ pub fn update_utxo_diff<'a, IterInputs, IterOutputs>(
None
};

#[allow(clippy::cast_sign_loss)]
let output_to_insert = if get_protocol_version(Some(epoch)) >= ProtocolVersion::V2_0 {
if output.time_lock < checkpoint_zero_timestamp.try_into().unwrap() {
ValueTransferOutput {
Expand Down Expand Up @@ -1888,16 +1886,12 @@ pub fn validate_block_transactions(
let mut genesis_value_available = max_total_value_genesis;

// Check stake transactions are added in V1_8 at the earliest
if protocol_version == ProtocolVersion::V1_7 {
if block.txns.stake_txns.len() > 0 {
return Err(TransactionError::NoStakeTransactionsAllowed.into());
}
if protocol_version == ProtocolVersion::V1_7 && !block.txns.stake_txns.is_empty() {
return Err(TransactionError::NoStakeTransactionsAllowed.into());
}
// Check stake transactions are added in V2_0 at the earliest
if protocol_version <= ProtocolVersion::V1_8 {
if block.txns.unstake_txns.len() > 0 {
return Err(TransactionError::NoUnstakeTransactionsAllowed.into());
}
if protocol_version <= ProtocolVersion::V1_8 && !block.txns.unstake_txns.is_empty() {
return Err(TransactionError::NoUnstakeTransactionsAllowed.into());
}

// TODO: replace for loop with a try_fold
Expand Down

0 comments on commit 4924e0f

Please sign in to comment.