Skip to content

Commit 947f490

Browse files
committed
Merge rust-bitcoin#5016: Automated nightly rustfmt (2025-09-21)
7354fb0 2025-09-21 automated rustfmt nightly (Fmt Bot) Pull request description: Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action ACKs for top commit: apoelstra: ACK 7354fb0; successfully ran local tests Tree-SHA512: 9a5da1aa9ae3fef56722236e43f74c0eba859aee7feae3ab81443ee887f0befe13c427cfa711aa967f0181f620b81ebfab84a2236e1b248f92987c954f1763f6
2 parents 78c64a6 + 7354fb0 commit 947f490

File tree

11 files changed

+110
-52
lines changed

11 files changed

+110
-52
lines changed

fuzz/fuzz_targets/p2p/arbitrary_addrv2.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::convert::TryFrom;
22
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
3+
34
use arbitrary::{Arbitrary, Unstructured};
45
use honggfuzz::fuzz;
56
use p2p::address::AddrV2;
@@ -11,17 +12,26 @@ fn do_test(data: &[u8]) {
1112
if let Ok(addr_v2) = a {
1213
if let Ok(ip_addr) = IpAddr::try_from(addr_v2.clone()) {
1314
let round_trip: AddrV2 = AddrV2::from(ip_addr);
14-
assert_eq!(addr_v2, round_trip, "AddrV2 -> IpAddr -> AddrV2 should round-trip correctly");
15+
assert_eq!(
16+
addr_v2, round_trip,
17+
"AddrV2 -> IpAddr -> AddrV2 should round-trip correctly"
18+
);
1519
}
1620

1721
if let Ok(ip_addr) = Ipv4Addr::try_from(addr_v2.clone()) {
1822
let round_trip: AddrV2 = AddrV2::from(ip_addr);
19-
assert_eq!(addr_v2, round_trip, "AddrV2 -> Ipv4Addr -> AddrV2 should round-trip correctly");
23+
assert_eq!(
24+
addr_v2, round_trip,
25+
"AddrV2 -> Ipv4Addr -> AddrV2 should round-trip correctly"
26+
);
2027
}
2128

2229
if let Ok(ip_addr) = Ipv6Addr::try_from(addr_v2.clone()) {
2330
let round_trip: AddrV2 = AddrV2::from(ip_addr);
24-
assert_eq!(addr_v2, round_trip, "AddrV2 -> Ipv6Addr -> AddrV2 should round-trip correctly");
31+
assert_eq!(
32+
addr_v2, round_trip,
33+
"AddrV2 -> Ipv6Addr -> AddrV2 should round-trip correctly"
34+
);
2535
}
2636
}
2737
}

fuzz/fuzz_targets/p2p/deserialize_addrv2.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use honggfuzz::fuzz;
22

33
fn do_test(data: &[u8]) {
4-
let _: Result<p2p::address::AddrV2, _> =
5-
bitcoin::consensus::encode::deserialize(data);
4+
let _: Result<p2p::address::AddrV2, _> = bitcoin::consensus::encode::deserialize(data);
65
}
76

87
fn main() {

p2p/src/address.rs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use alloc::vec;
99
use alloc::vec::Vec;
1010
use core::{fmt, iter};
1111
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
12+
1213
#[cfg(feature = "arbitrary")]
1314
use arbitrary::{Arbitrary, Unstructured};
14-
1515
use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
1616
use io::{BufRead, Read, Write};
1717

@@ -448,8 +448,28 @@ impl std::error::Error for AddrV2ToIpv6AddrError {}
448448
impl<'a> Arbitrary<'a> for Address {
449449
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
450450
let socket_addr = match bool::arbitrary(u)? {
451-
true => SocketAddr::new(IpAddr::V4(Ipv4Addr::new(u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?)), u.arbitrary()?),
452-
false => SocketAddr::new(IpAddr::V6(Ipv6Addr::new(u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?)), u.arbitrary()?)
451+
true => SocketAddr::new(
452+
IpAddr::V4(Ipv4Addr::new(
453+
u.arbitrary()?,
454+
u.arbitrary()?,
455+
u.arbitrary()?,
456+
u.arbitrary()?,
457+
)),
458+
u.arbitrary()?,
459+
),
460+
false => SocketAddr::new(
461+
IpAddr::V6(Ipv6Addr::new(
462+
u.arbitrary()?,
463+
u.arbitrary()?,
464+
u.arbitrary()?,
465+
u.arbitrary()?,
466+
u.arbitrary()?,
467+
u.arbitrary()?,
468+
u.arbitrary()?,
469+
u.arbitrary()?,
470+
)),
471+
u.arbitrary()?,
472+
),
453473
};
454474

455475
Ok(Address::new(&socket_addr, u.arbitrary()?))
@@ -459,24 +479,47 @@ impl<'a> Arbitrary<'a> for Address {
459479
impl<'a> Arbitrary<'a> for AddrV2 {
460480
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
461481
match u.int_in_range(0..=5)? {
462-
0 => Ok(AddrV2::Ipv4(Ipv4Addr::new(u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?))),
463-
1 => Ok(AddrV2::Ipv6(Ipv6Addr::new(u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?))),
482+
0 => Ok(AddrV2::Ipv4(Ipv4Addr::new(
483+
u.arbitrary()?,
484+
u.arbitrary()?,
485+
u.arbitrary()?,
486+
u.arbitrary()?,
487+
))),
488+
1 => Ok(AddrV2::Ipv6(Ipv6Addr::new(
489+
u.arbitrary()?,
490+
u.arbitrary()?,
491+
u.arbitrary()?,
492+
u.arbitrary()?,
493+
u.arbitrary()?,
494+
u.arbitrary()?,
495+
u.arbitrary()?,
496+
u.arbitrary()?,
497+
))),
464498
2 => Ok(AddrV2::TorV3(u.arbitrary()?)),
465499
3 => Ok(AddrV2::I2p(u.arbitrary()?)),
466-
4 => Ok(AddrV2::Cjdns(Ipv6Addr::new(u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?, u.arbitrary()?))),
467-
_ => Ok(AddrV2::Unknown(u.arbitrary()?, Vec::<u8>::arbitrary(u)?))
500+
4 => Ok(AddrV2::Cjdns(Ipv6Addr::new(
501+
u.arbitrary()?,
502+
u.arbitrary()?,
503+
u.arbitrary()?,
504+
u.arbitrary()?,
505+
u.arbitrary()?,
506+
u.arbitrary()?,
507+
u.arbitrary()?,
508+
u.arbitrary()?,
509+
))),
510+
_ => Ok(AddrV2::Unknown(u.arbitrary()?, Vec::<u8>::arbitrary(u)?)),
468511
}
469512
}
470513
}
471514

472515
#[cfg(feature = "arbitrary")]
473516
impl<'a> Arbitrary<'a> for AddrV2Message {
474517
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
475-
Ok(AddrV2Message{
518+
Ok(AddrV2Message {
476519
time: u.arbitrary()?,
477520
services: u.arbitrary()?,
478521
addr: u.arbitrary()?,
479-
port: u.arbitrary()?
522+
port: u.arbitrary()?,
480523
})
481524
}
482525
}

p2p/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ use alloc::string::String;
3939
use core::borrow::{Borrow, BorrowMut};
4040
use core::str::FromStr;
4141
use core::{fmt, ops};
42+
4243
#[cfg(feature = "arbitrary")]
4344
use arbitrary::{Arbitrary, Unstructured};
44-
4545
use bitcoin::consensus::encode::{self, Decodable, Encodable};
4646
use bitcoin::network::{Network, Params, TestnetVersion};
4747
use hex::FromHex;
@@ -481,9 +481,7 @@ impl<'a> Arbitrary<'a> for ServiceFlags {
481481

482482
#[cfg(feature = "arbitrary")]
483483
impl<'a> Arbitrary<'a> for Magic {
484-
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
485-
Ok(Magic(u.arbitrary()?))
486-
}
484+
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> { Ok(Magic(u.arbitrary()?)) }
487485
}
488486

489487
#[cfg(test)]

p2p/src/message.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use alloc::boxed::Box;
1010
use alloc::string::String;
1111
use alloc::vec;
1212
use alloc::vec::Vec;
13+
use core::{cmp, fmt};
1314

1415
#[cfg(feature = "arbitrary")]
1516
use arbitrary::{Arbitrary, Unstructured};
16-
use core::{cmp, fmt};
17-
1817
use bitcoin::block::HeaderExt;
1918
use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt};
2019
use bitcoin::merkle_tree::MerkleBlock;
@@ -817,7 +816,7 @@ impl Decodable for CheckedData {
817816
expected: expected_checksum,
818817
actual: checksum,
819818
}
820-
.into())
819+
.into())
821820
} else {
822821
Ok(CheckedData { data, checksum })
823822
}

p2p/src/message_blockdata.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//! Bitcoin data (blocks and transactions) around.
77
88
use alloc::vec::Vec;
9+
910
#[cfg(feature = "arbitrary")]
1011
use arbitrary::{Arbitrary, Unstructured};
11-
1212
use bitcoin::block::BlockHash;
1313
use bitcoin::consensus::encode::{self, Decodable, Encodable};
1414
use bitcoin::transaction::{Txid, Wtxid};
@@ -135,14 +135,22 @@ impl_consensus_encoding!(GetHeadersMessage, version, locator_hashes, stop_hash);
135135
#[cfg(feature = "arbitrary")]
136136
impl<'a> Arbitrary<'a> for GetHeadersMessage {
137137
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
138-
Ok(GetHeadersMessage{version: u.arbitrary()?, locator_hashes: Vec::<BlockHash>::arbitrary(u)?, stop_hash: u.arbitrary()?})
138+
Ok(GetHeadersMessage {
139+
version: u.arbitrary()?,
140+
locator_hashes: Vec::<BlockHash>::arbitrary(u)?,
141+
stop_hash: u.arbitrary()?,
142+
})
139143
}
140144
}
141145

142146
#[cfg(feature = "arbitrary")]
143147
impl<'a> Arbitrary<'a> for GetBlocksMessage {
144148
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
145-
Ok(GetBlocksMessage{version: u.arbitrary()?, locator_hashes: Vec::<BlockHash>::arbitrary(u)?, stop_hash: u.arbitrary()?})
149+
Ok(GetBlocksMessage {
150+
version: u.arbitrary()?,
151+
locator_hashes: Vec::<BlockHash>::arbitrary(u)?,
152+
stop_hash: u.arbitrary()?,
153+
})
146154
}
147155
}
148156

@@ -157,10 +165,7 @@ impl<'a> Arbitrary<'a> for Inventory {
157165
4 => Ok(Inventory::WTx(u.arbitrary()?)),
158166
5 => Ok(Inventory::WitnessTransaction(u.arbitrary()?)),
159167
6 => Ok(Inventory::WitnessBlock(u.arbitrary()?)),
160-
_ => Ok(Inventory::Unknown {
161-
inv_type: u.arbitrary()?,
162-
hash: u.arbitrary()?
163-
})
168+
_ => Ok(Inventory::Unknown { inv_type: u.arbitrary()?, hash: u.arbitrary()? }),
164169
}
165170
}
166171
}

p2p/src/message_bloom.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use alloc::vec::Vec;
88

99
#[cfg(feature = "arbitrary")]
1010
use arbitrary::{Arbitrary, Unstructured};
11-
1211
use bitcoin::consensus::{encode, Decodable, Encodable, ReadExt};
1312
use io::{BufRead, Write};
1413

@@ -77,22 +76,22 @@ impl<'a> Arbitrary<'a> for BloomFlags {
7776
match u.int_in_range(0..=2)? {
7877
0 => Ok(BloomFlags::None),
7978
1 => Ok(BloomFlags::All),
80-
_ => Ok(BloomFlags::PubkeyOnly)
79+
_ => Ok(BloomFlags::PubkeyOnly),
8180
}
8281
}
8382
}
8483

8584
#[cfg(feature = "arbitrary")]
8685
impl<'a> Arbitrary<'a> for FilterAdd {
8786
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
88-
Ok(FilterAdd{ data: Vec::<u8>::arbitrary(u)? })
87+
Ok(FilterAdd { data: Vec::<u8>::arbitrary(u)? })
8988
}
9089
}
9190

9291
#[cfg(feature = "arbitrary")]
9392
impl<'a> Arbitrary<'a> for FilterLoad {
9493
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
95-
Ok(FilterLoad{
94+
Ok(FilterLoad {
9695
filter: Vec::<u8>::arbitrary(u)?,
9796
hash_funcs: u.arbitrary()?,
9897
tweak: u.arbitrary()?,

p2p/src/message_compact_blocks.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
#[cfg(feature = "arbitrary")]
77
use arbitrary::{Arbitrary, Unstructured};
8-
98
use bitcoin::bip152;
109

1110
use crate::consensus::impl_consensus_encoding;
@@ -52,27 +51,27 @@ impl_consensus_encoding!(BlockTxn, transactions);
5251
#[cfg(feature = "arbitrary")]
5352
impl<'a> Arbitrary<'a> for SendCmpct {
5453
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
55-
Ok(SendCmpct{ send_compact: u.arbitrary()?, version: u.arbitrary()? })
54+
Ok(SendCmpct { send_compact: u.arbitrary()?, version: u.arbitrary()? })
5655
}
5756
}
5857

5958
#[cfg(feature = "arbitrary")]
6059
impl<'a> Arbitrary<'a> for CmpctBlock {
6160
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
62-
Ok(CmpctBlock{ compact_block: u.arbitrary()? })
61+
Ok(CmpctBlock { compact_block: u.arbitrary()? })
6362
}
6463
}
6564

6665
#[cfg(feature = "arbitrary")]
6766
impl<'a> Arbitrary<'a> for GetBlockTxn {
6867
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
69-
Ok(GetBlockTxn{ txs_request: u.arbitrary()? })
68+
Ok(GetBlockTxn { txs_request: u.arbitrary()? })
7069
}
7170
}
7271

7372
#[cfg(feature = "arbitrary")]
7473
impl<'a> Arbitrary<'a> for BlockTxn {
7574
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
76-
Ok(BlockTxn{ transactions: u.arbitrary()? })
75+
Ok(BlockTxn { transactions: u.arbitrary()? })
7776
}
7877
}

p2p/src/message_filter.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use alloc::vec::Vec;
88

99
#[cfg(feature = "arbitrary")]
1010
use arbitrary::{Arbitrary, Unstructured};
11-
1211
use bitcoin::bip158::{FilterHash, FilterHeader};
1312
use bitcoin::block::BlockHash;
1413
use units::BlockHeight;
@@ -90,7 +89,7 @@ impl_consensus_encoding!(CFCheckpt, filter_type, stop_hash, filter_headers);
9089
#[cfg(feature = "arbitrary")]
9190
impl<'a> Arbitrary<'a> for GetCFilters {
9291
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
93-
Ok(GetCFilters{
92+
Ok(GetCFilters {
9493
filter_type: u.arbitrary()?,
9594
start_height: u.arbitrary()?,
9695
stop_hash: u.arbitrary()?,
@@ -101,7 +100,7 @@ impl<'a> Arbitrary<'a> for GetCFilters {
101100
#[cfg(feature = "arbitrary")]
102101
impl<'a> Arbitrary<'a> for CFilter {
103102
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
104-
Ok(CFilter{
103+
Ok(CFilter {
105104
filter_type: u.arbitrary()?,
106105
block_hash: u.arbitrary()?,
107106
filter: Vec::<u8>::arbitrary(u)?,
@@ -112,7 +111,7 @@ impl<'a> Arbitrary<'a> for CFilter {
112111
#[cfg(feature = "arbitrary")]
113112
impl<'a> Arbitrary<'a> for GetCFHeaders {
114113
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
115-
Ok(GetCFHeaders{
114+
Ok(GetCFHeaders {
116115
filter_type: u.arbitrary()?,
117116
start_height: u.arbitrary()?,
118117
stop_hash: u.arbitrary()?,
@@ -123,7 +122,7 @@ impl<'a> Arbitrary<'a> for GetCFHeaders {
123122
#[cfg(feature = "arbitrary")]
124123
impl<'a> Arbitrary<'a> for CFHeaders {
125124
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
126-
Ok(CFHeaders{
125+
Ok(CFHeaders {
127126
filter_type: u.arbitrary()?,
128127
stop_hash: u.arbitrary()?,
129128
previous_filter_header: u.arbitrary()?,
@@ -135,18 +134,17 @@ impl<'a> Arbitrary<'a> for CFHeaders {
135134
#[cfg(feature = "arbitrary")]
136135
impl<'a> Arbitrary<'a> for GetCFCheckpt {
137136
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
138-
Ok(GetCFCheckpt{ filter_type: u.arbitrary()?, stop_hash: u.arbitrary()? })
137+
Ok(GetCFCheckpt { filter_type: u.arbitrary()?, stop_hash: u.arbitrary()? })
139138
}
140139
}
141140

142141
#[cfg(feature = "arbitrary")]
143142
impl<'a> Arbitrary<'a> for CFCheckpt {
144143
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
145-
Ok(CFCheckpt{
144+
Ok(CFCheckpt {
146145
filter_type: u.arbitrary()?,
147146
stop_hash: u.arbitrary()?,
148147
filter_headers: Vec::<FilterHeader>::arbitrary(u)?,
149148
})
150149
}
151150
}
152-

0 commit comments

Comments
 (0)