Skip to content

Commit fdac6b1

Browse files
committed
chore: use clippy in chain_store
1 parent e8e3dfb commit fdac6b1

File tree

3 files changed

+42
-51
lines changed

3 files changed

+42
-51
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
--package acropolis_codec \
3131
--package acropolis_module_assets_state \
3232
--package acropolis_module_block_unpacker \
33+
--package acropolis_module_chain_store \
3334
--package acropolis_module_consensus \
3435
--package acropolis_module_drdd_state \
3536
--package acropolis_module_snapshot_bootstrapper \

modules/chain_store/src/chain_store.rs

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ impl ChainStore {
6969
BlocksStateQueryResponse::Error("Invalid message for blocks-state".into()),
7070
)));
7171
};
72-
let Some(state) = query_history.lock().await.current().map(|s| s.clone()) else {
72+
let Some(state) = query_history.lock().await.current().cloned() else {
7373
return Arc::new(Message::StateQueryResponse(StateQueryResponse::Blocks(
7474
BlocksStateQueryResponse::Error("unitialised state".to_string()),
7575
)));
7676
};
77-
let res = Self::handle_blocks_query(&query_store, &state, &query)
77+
let res = Self::handle_blocks_query(&query_store, &state, query)
7878
.unwrap_or_else(|err| BlocksStateQueryResponse::Error(err.to_string()));
7979
Arc::new(Message::StateQueryResponse(StateQueryResponse::Blocks(res)))
8080
}
@@ -95,23 +95,20 @@ impl ChainStore {
9595
error!("Could not insert block: {err}");
9696
}
9797

98-
match message.as_ref() {
99-
Message::Cardano((block_info, _)) => {
100-
if block_info.new_epoch {
101-
let Ok((_, message)) = params_message.await else {
102-
return;
103-
};
104-
let mut history = history.lock().await;
105-
let mut state = history.get_current_state();
106-
if !Self::handle_new_params(&mut state, message).is_ok() {
107-
return;
108-
};
109-
history.commit(block_info.number, state);
110-
// Have the next params message ready for the next epoch
111-
params_message = params_subscription.read();
112-
}
98+
if let Message::Cardano((block_info, _)) = message.as_ref() {
99+
if block_info.new_epoch {
100+
let Ok((_, message)) = params_message.await else {
101+
return;
102+
};
103+
let mut history = history.lock().await;
104+
let mut state = history.get_current_state();
105+
if Self::handle_new_params(&mut state, message).is_err() {
106+
return;
107+
};
108+
history.commit(block_info.number, state);
109+
// Have the next params message ready for the next epoch
110+
params_message = params_subscription.read();
113111
}
114-
_ => (),
115112
}
116113
}
117114
});
@@ -137,7 +134,7 @@ impl ChainStore {
137134
let Some(block) = store.get_latest_block()? else {
138135
return Ok(BlocksStateQueryResponse::NotFound);
139136
};
140-
let info = Self::to_block_info(block, store, &state, true)?;
137+
let info = Self::to_block_info(block, store, state, true)?;
141138
Ok(BlocksStateQueryResponse::LatestBlock(info))
142139
}
143140
BlocksStateQuery::GetLatestBlockTransactions { limit, skip, order } => {
@@ -158,21 +155,21 @@ impl ChainStore {
158155
let Some(block) = Self::get_block_by_key(store, block_key)? else {
159156
return Ok(BlocksStateQueryResponse::NotFound);
160157
};
161-
let info = Self::to_block_info(block, store, &state, false)?;
158+
let info = Self::to_block_info(block, store, state, false)?;
162159
Ok(BlocksStateQueryResponse::BlockInfo(info))
163160
}
164161
BlocksStateQuery::GetBlockBySlot { slot } => {
165162
let Some(block) = store.get_block_by_slot(*slot)? else {
166163
return Ok(BlocksStateQueryResponse::NotFound);
167164
};
168-
let info = Self::to_block_info(block, store, &state, false)?;
165+
let info = Self::to_block_info(block, store, state, false)?;
169166
Ok(BlocksStateQueryResponse::BlockBySlot(info))
170167
}
171168
BlocksStateQuery::GetBlockByEpochSlot { epoch, slot } => {
172169
let Some(block) = store.get_block_by_epoch_slot(*epoch, *slot)? else {
173170
return Ok(BlocksStateQueryResponse::NotFound);
174171
};
175-
let info = Self::to_block_info(block, store, &state, false)?;
172+
let info = Self::to_block_info(block, store, state, false)?;
176173
Ok(BlocksStateQueryResponse::BlockByEpochSlot(info))
177174
}
178175
BlocksStateQuery::GetNextBlocks {
@@ -185,7 +182,7 @@ impl ChainStore {
185182
blocks: vec![],
186183
}));
187184
}
188-
let Some(block) = Self::get_block_by_key(store, &block_key)? else {
185+
let Some(block) = Self::get_block_by_key(store, block_key)? else {
189186
return Ok(BlocksStateQueryResponse::NotFound);
190187
};
191188
let number = match block_key {
@@ -195,7 +192,7 @@ impl ChainStore {
195192
let min_number = number + 1 + skip;
196193
let max_number = min_number + limit - 1;
197194
let blocks = store.get_blocks_by_number_range(min_number, max_number)?;
198-
let info = Self::to_block_info_bulk(blocks, store, &state, false)?;
195+
let info = Self::to_block_info_bulk(blocks, store, state, false)?;
199196
Ok(BlocksStateQueryResponse::NextBlocks(NextBlocks {
200197
blocks: info,
201198
}))
@@ -210,7 +207,7 @@ impl ChainStore {
210207
blocks: vec![],
211208
}));
212209
}
213-
let Some(block) = Self::get_block_by_key(store, &block_key)? else {
210+
let Some(block) = Self::get_block_by_key(store, block_key)? else {
214211
return Ok(BlocksStateQueryResponse::NotFound);
215212
};
216213
let number = match block_key {
@@ -224,7 +221,7 @@ impl ChainStore {
224221
};
225222
let min_number = max_number.saturating_sub(limit - 1);
226223
let blocks = store.get_blocks_by_number_range(min_number, max_number)?;
227-
let info = Self::to_block_info_bulk(blocks, store, &state, false)?;
224+
let info = Self::to_block_info_bulk(blocks, store, state, false)?;
228225
Ok(BlocksStateQueryResponse::PreviousBlocks(PreviousBlocks {
229226
blocks: info,
230227
}))
@@ -325,7 +322,7 @@ impl ChainStore {
325322
is_latest: bool,
326323
) -> Result<BlockInfo> {
327324
let blocks = vec![block];
328-
let mut info = Self::to_block_info_bulk(blocks, store, &state, is_latest)?;
325+
let mut info = Self::to_block_info_bulk(blocks, store, state, is_latest)?;
329326
Ok(info.remove(0))
330327
}
331328

@@ -491,17 +488,13 @@ impl ChainStore {
491488
for tx in decoded.txs() {
492489
let hash = TxHash(*tx.hash());
493490
for output in tx.outputs() {
494-
match output.address() {
495-
Ok(pallas_address) => match map_parameters::map_address(&pallas_address) {
496-
Ok(address) => {
497-
addresses
498-
.entry(BechOrdAddress(address))
499-
.or_insert_with(Vec::new)
500-
.push(hash.clone());
501-
}
502-
_ => (),
503-
},
504-
_ => (),
491+
if let Ok(pallas_address) = output.address() {
492+
if let Ok(address) = map_parameters::map_address(&pallas_address) {
493+
addresses
494+
.entry(BechOrdAddress(address))
495+
.or_insert_with(Vec::new)
496+
.push(hash);
497+
}
505498
}
506499
}
507500
}
@@ -518,16 +511,13 @@ impl ChainStore {
518511
}
519512

520513
fn handle_new_params(state: &mut State, message: Arc<Message>) -> Result<()> {
521-
match message.as_ref() {
522-
Message::Cardano((_, CardanoMessage::ProtocolParams(params))) => {
523-
if let Some(byron) = &params.params.byron {
524-
state.byron_heavy_delegates = byron.heavy_delegation.clone();
525-
}
526-
if let Some(shelley) = &params.params.shelley {
527-
state.shelley_genesis_delegates = shelley.gen_delegs.clone();
528-
}
514+
if let Message::Cardano((_, CardanoMessage::ProtocolParams(params))) = message.as_ref() {
515+
if let Some(byron) = &params.params.byron {
516+
state.byron_heavy_delegates = byron.heavy_delegation.clone();
517+
}
518+
if let Some(shelley) = &params.params.shelley {
519+
state.shelley_genesis_delegates = shelley.gen_delegs.clone();
529520
}
530-
_ => (),
531521
}
532522
Ok(())
533523
}

modules/chain_store/src/stores/fjall.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,21 @@ impl FjallBlockStore {
131131
minicbor::encode(raw, &mut bytes).expect("infallible");
132132
bytes
133133
};
134-
batch.insert(&self.blocks, &*info.hash, encoded);
134+
batch.insert(&self.blocks, *info.hash, encoded);
135135
batch.insert(
136136
&self.block_hashes_by_slot,
137137
info.slot.to_be_bytes(),
138-
&*info.hash,
138+
*info.hash,
139139
);
140140
batch.insert(
141141
&self.block_hashes_by_number,
142142
info.number.to_be_bytes(),
143-
&*info.hash,
143+
*info.hash,
144144
);
145145
batch.insert(
146146
&self.block_hashes_by_epoch_slot,
147147
epoch_slot_key(info.epoch, info.epoch_slot),
148-
&*info.hash,
148+
*info.hash,
149149
);
150150
}
151151

0 commit comments

Comments
 (0)