Skip to content

Commit e8e3dfb

Browse files
authored
Merge pull request #278 from input-output-hk/sg/clippy-untouched-modules
Use clippy in relatively-untouched modules
2 parents c9dc38f + 033eb84 commit e8e3dfb

File tree

12 files changed

+98
-95
lines changed

12 files changed

+98
-95
lines changed

.github/workflows/run-tests-on-push-to-main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ jobs:
2727
run: |
2828
cargo clippy \
2929
--package acropolis_common \
30-
--package acropolis_codec
30+
--package acropolis_codec \
31+
--package acropolis_module_assets_state \
32+
--package acropolis_module_block_unpacker \
33+
--package acropolis_module_consensus \
34+
--package acropolis_module_drdd_state \
35+
--package acropolis_module_snapshot_bootstrapper \
36+
--package acropolis_module_spdd_state \
37+
--package acropolis_module_utxo_state
3138
3239
- name: Run Build
3340
run: cargo build --verbose

modules/assets_state/src/asset_registry.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ pub struct AssetRegistry {
2626
id_to_key: Vec<AssetKey>,
2727
}
2828

29+
impl Default for AssetRegistry {
30+
fn default() -> Self {
31+
Self::new()
32+
}
33+
}
34+
2935
impl AssetRegistry {
3036
pub fn new() -> Self {
3137
Self {
@@ -52,8 +58,8 @@ impl AssetRegistry {
5258

5359
pub fn lookup_id(&self, policy: &PolicyId, name: &AssetName) -> Option<AssetId> {
5460
let key = AssetKey {
55-
policy: Arc::new(policy.clone()),
56-
name: Arc::new(name.clone()),
61+
policy: Arc::new(*policy),
62+
name: Arc::new(*name),
5763
};
5864
self.key_to_id.get(&key).copied()
5965
}

modules/assets_state/src/assets_state.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl AssetsState {
8484
// Always handle the mint deltas (This is how assets get initialized)
8585
{
8686
let mut reg = registry.lock().await;
87-
state = match state.handle_mint_deltas(&deltas_msg.deltas, &mut *reg) {
87+
state = match state.handle_mint_deltas(&deltas_msg.deltas, &mut reg) {
8888
Ok(new_state) => new_state,
8989
Err(e) => {
9090
error!("Asset deltas handling error: {e:#}");
@@ -97,7 +97,7 @@ impl AssetsState {
9797
if storage_config.store_info {
9898
let mut reg = registry.lock().await;
9999
state = match state
100-
.handle_cip25_metadata(&mut *reg, &deltas_msg.cip25_metadata_updates)
100+
.handle_cip25_metadata(&mut reg, &deltas_msg.cip25_metadata_updates)
101101
{
102102
Ok(new_state) => new_state,
103103
Err(e) => {
@@ -125,20 +125,19 @@ impl AssetsState {
125125

126126
if storage_config.store_info {
127127
let reg = registry.lock().await;
128-
state =
129-
match state.handle_cip68_metadata(&utxo_deltas_msg.deltas, &*reg) {
130-
Ok(new_state) => new_state,
131-
Err(e) => {
132-
error!("CIP-68 metadata handling error: {e:#}");
133-
state
134-
}
135-
};
128+
state = match state.handle_cip68_metadata(&utxo_deltas_msg.deltas, &reg)
129+
{
130+
Ok(new_state) => new_state,
131+
Err(e) => {
132+
error!("CIP-68 metadata handling error: {e:#}");
133+
state
134+
}
135+
};
136136
}
137137

138138
if storage_config.store_transactions.is_enabled() {
139139
let reg = registry.lock().await;
140-
state = match state.handle_transactions(&utxo_deltas_msg.deltas, &*reg)
141-
{
140+
state = match state.handle_transactions(&utxo_deltas_msg.deltas, &reg) {
142141
Ok(new_state) => new_state,
143142
Err(e) => {
144143
error!("Transactions handling error: {e:#}");
@@ -161,7 +160,7 @@ impl AssetsState {
161160
Self::check_sync(&current_block, block_info, "address");
162161

163162
let reg = registry.lock().await;
164-
state = match state.handle_address_deltas(&address_deltas_msg.deltas, &*reg)
163+
state = match state.handle_address_deltas(&address_deltas_msg.deltas, &reg)
165164
{
166165
Ok(new_state) => new_state,
167166
Err(e) => {
@@ -299,7 +298,7 @@ impl AssetsState {
299298
}
300299
AssetsStateQuery::GetAssetInfo { policy, name } => {
301300
let reg = registry.lock().await;
302-
match reg.lookup_id(&policy, &name) {
301+
match reg.lookup_id(policy, name) {
303302
Some(asset_id) => match state.get_asset_info(&asset_id, &reg) {
304303
Ok(Some(info)) => AssetsStateQueryResponse::AssetInfo(info),
305304
Ok(None) => AssetsStateQueryResponse::NotFound,
@@ -318,7 +317,7 @@ impl AssetsState {
318317
}
319318
AssetsStateQuery::GetAssetHistory { policy, name } => {
320319
let reg = registry.lock().await;
321-
match reg.lookup_id(&policy, &name) {
320+
match reg.lookup_id(policy, name) {
322321
Some(asset_id) => match state.get_asset_history(&asset_id) {
323322
Ok(Some(history)) => {
324323
AssetsStateQueryResponse::AssetHistory(history)
@@ -339,7 +338,7 @@ impl AssetsState {
339338
}
340339
AssetsStateQuery::GetAssetAddresses { policy, name } => {
341340
let reg = registry.lock().await;
342-
match reg.lookup_id(&policy, &name) {
341+
match reg.lookup_id(policy, name) {
343342
Some(asset_id) => match state.get_asset_addresses(&asset_id) {
344343
Ok(Some(addresses)) => {
345344
AssetsStateQueryResponse::AssetAddresses(addresses)
@@ -360,7 +359,7 @@ impl AssetsState {
360359
}
361360
AssetsStateQuery::GetAssetTransactions { policy, name } => {
362361
let reg = registry.lock().await;
363-
match reg.lookup_id(&policy, &name) {
362+
match reg.lookup_id(policy, name) {
364363
Some(asset_id) => match state.get_asset_transactions(&asset_id) {
365364
Ok(Some(txs)) => AssetsStateQueryResponse::AssetTransactions(txs),
366365
Ok(None) => AssetsStateQueryResponse::NotFound,
@@ -379,7 +378,7 @@ impl AssetsState {
379378
}
380379
AssetsStateQuery::GetPolicyIdAssets { policy } => {
381380
let reg = registry.lock().await;
382-
match state.get_policy_assets(&policy, &reg) {
381+
match state.get_policy_assets(policy, &reg) {
383382
Ok(Some(assets)) => AssetsStateQueryResponse::PolicyIdAssets(assets),
384383
Ok(None) => AssetsStateQueryResponse::NotFound,
385384
Err(e) => AssetsStateQueryResponse::Error(e.to_string()),

modules/assets_state/src/state.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use acropolis_common::{
55
math::update_value_with_delta,
66
queries::assets::{AssetHistory, PolicyAssets},
77
Address, AddressDelta, AssetAddressEntry, AssetInfoRecord, AssetMetadataStandard,
8-
AssetMintRecord, AssetName, Datum, Lovelace, NativeAssetDelta, PolicyAsset, PolicyId,
8+
AssetMintRecord, AssetName, Datum, Lovelace, NativeAssetsDelta, PolicyAsset, PolicyId,
99
ShelleyAddress, TxIdentifier, UTXODelta,
1010
};
1111
use anyhow::Result;
@@ -27,19 +27,14 @@ pub struct AssetsStorageConfig {
2727
pub index_by_policy: bool,
2828
}
2929

30-
#[derive(Debug, Clone, Copy)]
30+
#[derive(Debug, Default, Clone, Copy)]
3131
pub enum StoreTransactions {
32+
#[default]
3233
None,
3334
All,
3435
Last(u64),
3536
}
3637

37-
impl Default for StoreTransactions {
38-
fn default() -> Self {
39-
StoreTransactions::None
40-
}
41-
}
42-
4338
impl StoreTransactions {
4439
pub fn is_enabled(&self) -> bool {
4540
!matches!(self, StoreTransactions::None)
@@ -123,7 +118,7 @@ impl State {
123118
if let Some(key) = registry.lookup(*id) {
124119
out.push(PolicyAsset {
125120
policy: *key.policy,
126-
name: key.name.as_ref().clone(),
121+
name: *key.name.as_ref(),
127122
quantity: *amount,
128123
});
129124
}
@@ -235,7 +230,7 @@ impl State {
235230
let key = registry.lookup(*asset_id)?;
236231
Some(PolicyAsset {
237232
policy: *policy_id,
238-
name: (*key.name).clone(),
233+
name: *key.name,
239234
quantity: *supply,
240235
})
241236
})
@@ -273,7 +268,7 @@ impl State {
273268

274269
pub fn handle_mint_deltas(
275270
&self,
276-
deltas: &[(TxIdentifier, Vec<(PolicyId, Vec<NativeAssetDelta>)>)],
271+
deltas: &[(TxIdentifier, NativeAssetsDelta)],
277272
registry: &mut AssetRegistry,
278273
) -> Result<Self> {
279274
let mut new_supply = self.supply.clone();
@@ -286,7 +281,7 @@ impl State {
286281
for (tx_identifier, tx_deltas) in deltas {
287282
for (policy_id, asset_deltas) in tx_deltas {
288283
for delta in asset_deltas {
289-
let asset_id = registry.get_or_insert(*policy_id, delta.name.clone());
284+
let asset_id = registry.get_or_insert(*policy_id, delta.name);
290285

291286
if let Some(supply) = new_supply.as_mut() {
292287
let delta_amount = delta.amount;
@@ -314,7 +309,7 @@ impl State {
314309
.entry(asset_id)
315310
.and_modify(|rec| rec.mint_or_burn_count += 1)
316311
.or_insert(AssetInfoRecord {
317-
initial_mint_tx: tx_identifier.clone(),
312+
initial_mint_tx: *tx_identifier,
318313
mint_or_burn_count: 1,
319314
onchain_metadata: None,
320315
metadata_standard: None,
@@ -385,7 +380,7 @@ impl State {
385380
if let Some(asset_id) = registry.lookup_id(policy_id, &asset.name) {
386381
let entry = txs_map.entry(asset_id).or_default();
387382

388-
let should_push = entry.back().map_or(true, |last| last != &tx_identifier);
383+
let should_push = entry.back() != Some(&tx_identifier);
389384

390385
if should_push {
391386
entry.push_back(tx_identifier);

modules/consensus/src/consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Consensus {
9595
block_info,
9696
CardanoMessage::BlockValidation(status),
9797
)) => match status {
98-
ValidationStatus::Go => all_ok && true,
98+
ValidationStatus::Go => all_ok,
9999
ValidationStatus::NoGo(err) => {
100100
error!(
101101
block = block_info.number,

modules/spdd_state/src/spdd_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ impl SPDDState {
142142
}
143143
};
144144

145-
return Arc::new(Message::StateQueryResponse(StateQueryResponse::SPDD(
145+
Arc::new(Message::StateQueryResponse(StateQueryResponse::SPDD(
146146
response,
147-
)));
147+
)))
148148
}
149149
});
150150

modules/spdd_state/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl State {
5757
// we plus 2 to epoch number
5858
pub fn get_epoch_total_active_stakes(&self, epoch: u64) -> Option<u64> {
5959
if epoch <= 2 {
60-
return None;
60+
None
6161
} else {
6262
self.spdd_history
6363
.get_by_index(epoch - 2)

modules/utxo_state/src/address_delta_publisher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl AddressDeltaObserver for AddressDeltaPublisher {
6161
Message::Cardano((block.clone(), CardanoMessage::AddressDeltas(message)));
6262
self.context
6363
.message_bus
64-
.publish(&topic, Arc::new(message_enum))
64+
.publish(topic, Arc::new(message_enum))
6565
.await
6666
.unwrap_or_else(|e| error!("Failed to publish: {e}"));
6767
}

modules/utxo_state/src/fjall_async_immutable_utxo_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl FjallAsyncImmutableUTXOStore {
5959
fn should_flush(&self) -> bool {
6060
let count = self.write_counter.fetch_add(1, Ordering::Relaxed) + 1;
6161
let threshold = self.flush_every.load(Ordering::Relaxed);
62-
threshold != 0 && count % threshold == 0
62+
threshold != 0 && count.is_multiple_of(threshold)
6363
}
6464
}
6565

modules/utxo_state/src/fjall_immutable_utxo_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl FjallImmutableUTXOStore {
5757
fn should_flush(&self) -> bool {
5858
let count = self.write_counter.fetch_add(1, Ordering::Relaxed) + 1;
5959
let threshold = self.flush_every.load(Ordering::Relaxed);
60-
threshold != 0 && count % threshold == 0
60+
threshold != 0 && count.is_multiple_of(threshold)
6161
}
6262
}
6363

0 commit comments

Comments
 (0)