Skip to content

Commit 7699bc3

Browse files
committed
chore: Apply Clippy lint manual_inspect
1 parent e9c1ab8 commit 7699bc3

File tree

26 files changed

+245
-408
lines changed

26 files changed

+245
-408
lines changed

stackslib/src/burnchains/bitcoin/address.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,8 @@ impl SegwitBitcoinAddress {
302302

303303
pub fn from_bech32(s: &str) -> Option<SegwitBitcoinAddress> {
304304
let (hrp, quintets, variant) = bech32::decode(s)
305-
.map_err(|e| {
306-
test_debug!("Failed to decode '{}': {:?}", s, &e);
307-
e
305+
.inspect_err(|_e| {
306+
test_debug!("Failed to decode '{s}': {_e:?}");
308307
})
309308
.ok()?;
310309

@@ -327,9 +326,8 @@ impl SegwitBitcoinAddress {
327326
prog.append(&mut quintets[1..].to_vec());
328327

329328
let bytes = Vec::from_base32(&prog)
330-
.map_err(|e| {
331-
test_debug!("Failed to decode quintets: {:?}", &e);
332-
e
329+
.inspect_err(|_e| {
330+
test_debug!("Failed to decode quintets: {_e:?}");
333331
})
334332
.ok()?;
335333

stackslib/src/burnchains/bitcoin/bits.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,15 @@ impl BitcoinTxInputStructured {
112112
Instruction::PushBytes(payload) => payload,
113113
_ => {
114114
// not pushbytes, so this can't be a multisig script
115-
test_debug!(
116-
"Not a multisig script: Instruction {} is not a PushBytes",
117-
i
118-
);
115+
test_debug!("Not a multisig script: Instruction {i} is not a PushBytes");
119116
return None;
120117
}
121118
};
122119

123120
let pubk = BitcoinPublicKey::from_slice(payload)
124-
.map_err(|e| {
121+
.inspect_err(|&e| {
125122
// not a public key
126-
warn!(
127-
"Not a multisig script: pushbytes {} is not a public key ({:?})",
128-
i, e
129-
);
130-
e
123+
warn!("Not a multisig script: pushbytes {i} is not a public key ({e:?})");
131124
})
132125
.ok()?;
133126

@@ -169,13 +162,9 @@ impl BitcoinTxInputStructured {
169162
for i in 0..pubkey_vecs.len() {
170163
let payload = &pubkey_vecs[i];
171164
let pubk = BitcoinPublicKey::from_slice(&payload[..])
172-
.map_err(|e| {
165+
.inspect_err(|&e| {
173166
// not a public key
174-
warn!(
175-
"Not a multisig script: item {} is not a public key ({:?})",
176-
i, e
177-
);
178-
e
167+
warn!("Not a multisig script: item {i} is not a public key ({e:?})");
179168
})
180169
.ok()?;
181170

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,8 @@ impl BitcoinIndexer {
627627
)?;
628628

629629
// what's the last header we have from the canonical history?
630-
let canonical_end_block = orig_spv_client.get_headers_height().map_err(|e| {
631-
error!(
632-
"Failed to get the last block from {}",
633-
canonical_headers_path
634-
);
635-
e
630+
let canonical_end_block = orig_spv_client.get_headers_height().inspect_err(|_e| {
631+
error!("Failed to get the last block from {canonical_headers_path}");
636632
})?;
637633

638634
// bootstrap reorg client
@@ -694,13 +690,12 @@ impl BitcoinIndexer {
694690

695691
let reorg_headers = reorg_spv_client
696692
.read_block_headers(start_block, start_block + REORG_BATCH_SIZE)
697-
.map_err(|e| {
693+
.inspect_err(|_e| {
698694
error!(
699695
"Failed to read reorg Bitcoin headers from {} to {}",
700696
start_block,
701697
start_block + REORG_BATCH_SIZE
702698
);
703-
e
704699
})?;
705700

706701
if reorg_headers.is_empty() {
@@ -724,13 +719,12 @@ impl BitcoinIndexer {
724719
// got reorg headers. Find the equivalent headers in our canonical history
725720
let canonical_headers = orig_spv_client
726721
.read_block_headers(start_block, start_block + REORG_BATCH_SIZE)
727-
.map_err(|e| {
722+
.inspect_err(|_e| {
728723
error!(
729724
"Failed to read canonical headers from {} to {}",
730725
start_block,
731726
start_block + REORG_BATCH_SIZE
732727
);
733-
e
734728
})?;
735729

736730
assert!(

stackslib/src/burnchains/bitcoin/spv.rs

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -832,33 +832,23 @@ impl SpvClient {
832832
// fetching headers in ascending order, so verify that the first item in
833833
// `block_headers` connects to a parent in the DB (if it has one)
834834
self.insert_block_headers_after(insert_height, block_headers)
835-
.map_err(|e| {
836-
error!("Failed to insert block headers: {:?}", &e);
837-
e
838-
})?;
835+
.inspect_err(|e| error!("Failed to insert block headers: {e:?}"))?;
839836

840837
// check work
841838
let chain_tip = self.get_headers_height()?;
842839
self.validate_header_work(
843840
(insert_height.saturating_sub(1)) / BLOCK_DIFFICULTY_CHUNK_SIZE,
844841
chain_tip / BLOCK_DIFFICULTY_CHUNK_SIZE + 1,
845842
)
846-
.map_err(|e| {
847-
error!(
848-
"Received headers with bad target, difficulty, or continuity: {:?}",
849-
&e
850-
);
851-
e
843+
.inspect_err(|e| {
844+
error!("Received headers with bad target, difficulty, or continuity: {e:?}")
852845
})?;
853846
} else {
854847
// fetching headers in descending order, so verify that the last item in
855848
// `block_headers` connects to a child in the DB (if it has one)
856849
let headers_len = block_headers.len() as u64;
857850
self.insert_block_headers_before(insert_height, block_headers)
858-
.map_err(|e| {
859-
error!("Failed to insert block headers: {:?}", &e);
860-
e
861-
})?;
851+
.inspect_err(|e| error!("Failed to insert block headers: {e:?}"))?;
862852

863853
// check work
864854
let interval_start = if insert_height % BLOCK_DIFFICULTY_CHUNK_SIZE == 0 {
@@ -870,29 +860,21 @@ impl SpvClient {
870860
let interval_end = (insert_height + 1 + headers_len) / BLOCK_DIFFICULTY_CHUNK_SIZE + 1;
871861

872862
self.validate_header_work(interval_start, interval_end)
873-
.map_err(|e| {
874-
error!(
875-
"Received headers with bad target, difficulty, or continuity: {:?}",
876-
&e
877-
);
878-
e
863+
.inspect_err(|e| {
864+
error!("Received headers with bad target, difficulty, or continuity: {e:?}")
879865
})?;
880866
}
881867

882868
if num_headers > 0 {
883869
let total_work_after = self.update_chain_work()?;
884870
if total_work_after < total_work_before {
885871
error!(
886-
"New headers represent less work than the old headers ({} < {})",
887-
total_work_before, total_work_after
872+
"New headers represent less work than the old headers ({total_work_before} < {total_work_after})"
888873
);
889874
return Err(btc_error::InvalidChainWork);
890875
}
891876

892-
debug!(
893-
"Handled {} Headers: {}-{}",
894-
num_headers, first_header_hash, last_header_hash
895-
);
877+
debug!("Handled {num_headers} Headers: {first_header_hash}-{last_header_hash}");
896878
} else {
897879
debug!("Handled empty header reply");
898880
}
@@ -956,22 +938,16 @@ impl SpvClient {
956938
);
957939

958940
SpvClient::validate_header_integrity(start_height, &block_headers, self.check_txcount)
959-
.map_err(|e| {
960-
error!("Received invalid headers: {:?}", &e);
961-
e
962-
})?;
963-
964-
let parent_header = match self.read_block_header(start_height)? {
965-
Some(header) => header,
966-
None => {
967-
warn!(
968-
"No header for block {} -- cannot insert {} headers into {}",
969-
start_height,
970-
block_headers.len(),
971-
self.headers_path
972-
);
973-
return Err(btc_error::NoncontiguousHeader);
974-
}
941+
.inspect_err(|e| error!("Received invalid headers: {e:?}"))?;
942+
943+
let Some(parent_header) = self.read_block_header(start_height)? else {
944+
warn!(
945+
"No header for block {} -- cannot insert {} headers into {}",
946+
start_height,
947+
block_headers.len(),
948+
self.headers_path
949+
);
950+
return Err(btc_error::NoncontiguousHeader);
975951
};
976952

977953
// contiguous?
@@ -1010,10 +986,7 @@ impl SpvClient {
1010986
);
1011987

1012988
SpvClient::validate_header_integrity(start_height, &block_headers, self.check_txcount)
1013-
.map_err(|e| {
1014-
error!("Received invalid headers: {:?}", &e);
1015-
e
1016-
})?;
989+
.inspect_err(|e| error!("Received invalid headers: {e:?}"))?;
1017990

1018991
match self.read_block_header(end_height)? {
1019992
Some(child_header) => {
@@ -1028,10 +1001,7 @@ impl SpvClient {
10281001
None => {
10291002
// if we're inserting headers in reverse order, we're not guaranteed to have the
10301003
// child.
1031-
debug!(
1032-
"No header for child block {}, so will not validate continuity",
1033-
end_height
1034-
);
1004+
debug!("No header for child block {end_height}, so will not validate continuity");
10351005
}
10361006
}
10371007

stackslib/src/burnchains/burnchain.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,12 @@ impl Burnchain {
683683

684684
if headers_height == 0 || headers_height < self.first_block_height {
685685
debug!("Fetch initial headers");
686-
indexer.sync_headers(headers_height, None).map_err(|e| {
687-
error!("Failed to sync initial headers");
688-
sleep_ms(100);
689-
e
690-
})?;
686+
indexer
687+
.sync_headers(headers_height, None)
688+
.inspect_err(|_e| {
689+
error!("Failed to sync initial headers");
690+
sleep_ms(100);
691+
})?;
691692
}
692693
Ok(())
693694
}
@@ -1137,13 +1138,9 @@ impl Burnchain {
11371138
let headers_path = indexer.get_headers_path();
11381139

11391140
// sanity check -- what is the height of our highest header
1140-
let headers_height = indexer.get_highest_header_height().map_err(|e| {
1141-
error!(
1142-
"Failed to read headers height from {}: {:?}",
1143-
headers_path, &e
1144-
);
1145-
e
1146-
})?;
1141+
let headers_height = indexer
1142+
.get_highest_header_height()
1143+
.inspect_err(|e| error!("Failed to read headers height from {headers_path}: {e:?}"))?;
11471144

11481145
if headers_height == 0 {
11491146
return Ok((0, false));
@@ -1152,16 +1149,12 @@ impl Burnchain {
11521149
// did we encounter a reorg since last sync? Find the highest common ancestor of the
11531150
// remote bitcoin peer's chain state.
11541151
// Note that this value is 0-indexed -- the smallest possible value it returns is 0.
1155-
let reorg_height = indexer.find_chain_reorg().map_err(|e| {
1156-
error!("Failed to check for reorgs from {}: {:?}", headers_path, &e);
1157-
e
1158-
})?;
1152+
let reorg_height = indexer
1153+
.find_chain_reorg()
1154+
.inspect_err(|e| error!("Failed to check for reorgs from {headers_path}: {e:?}"))?;
11591155

11601156
if reorg_height < headers_height {
1161-
warn!(
1162-
"Burnchain reorg detected: highest common ancestor at height {}",
1163-
reorg_height
1164-
);
1157+
warn!("Burnchain reorg detected: highest common ancestor at height {reorg_height}");
11651158
return Ok((reorg_height, true));
11661159
} else {
11671160
// no reorg

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4896,16 +4896,12 @@ impl SortitionDB {
48964896
let qry = "SELECT * FROM snapshots WHERE sortition_id = ?1";
48974897
let args = [&sortition_id];
48984898
query_row_panic(conn, qry, &args, || {
4899-
format!(
4900-
"FATAL: multiple block snapshots for the same block {}",
4901-
sortition_id
4902-
)
4899+
format!("FATAL: multiple block snapshots for the same block {sortition_id}")
49034900
})
4904-
.map(|x| {
4901+
.inspect(|x| {
49054902
if x.is_none() {
4906-
test_debug!("No snapshot with sortition ID {}", sortition_id);
4903+
test_debug!("No snapshot with sortition ID {sortition_id}");
49074904
}
4908-
x
49094905
})
49104906
}
49114907

stackslib/src/chainstate/burn/operations/leader_block_commit.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,19 +1131,17 @@ impl LeaderBlockCommitOp {
11311131
.is_after_pox_sunset_end(self.block_height, epoch.epoch_id)
11321132
{
11331133
// sunset has begun and we're not in epoch 2.1 or later, so apply sunset check
1134-
self.check_after_pox_sunset().map_err(|e| {
1135-
warn!("Invalid block-commit: bad PoX after sunset: {:?}", &e;
1134+
self.check_after_pox_sunset().inspect_err(|e| {
1135+
warn!("Invalid block-commit: bad PoX after sunset: {e:?}";
11361136
"apparent_sender" => %apparent_sender_repr);
1137-
e
11381137
})?;
11391138
vec![]
11401139
} else {
11411140
// either in epoch 2.1, or the PoX sunset hasn't completed yet
11421141
self.check_pox(epoch.epoch_id, burnchain, tx, reward_set_info)
1143-
.map_err(|e| {
1144-
warn!("Invalid block-commit: bad PoX: {:?}", &e;
1142+
.inspect_err(|e| {
1143+
warn!("Invalid block-commit: bad PoX: {e:?}";
11451144
"apparent_sender" => %apparent_sender_repr);
1146-
e
11471145
})?
11481146
};
11491147

0 commit comments

Comments
 (0)