Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/network/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}

pub(in crate::network) fn block(&mut self, hash: BlockHash) -> Vec<u8> {
let inv = Inventory::Block(hash);
let inv = Inventory::WitnessBlock(hash);
let msg = NetworkMessage::GetData(vec![inv]);
self.serialize(msg)
}
Expand Down Expand Up @@ -79,6 +79,35 @@
.expect("encryption to in memory buffer cannot fail.")
}

#[cfg(test)]
mod tests {

Check failure on line 83 in src/network/outbound.rs

View workflow job for this annotation

GitHub Actions / check (stable)

items after a test module

Check failure on line 83 in src/network/outbound.rs

View workflow job for this annotation

GitHub Actions / check (nightly)

items after a test module

Check failure on line 83 in src/network/outbound.rs

View workflow job for this annotation

GitHub Actions / check (beta)

items after a test module
use bitcoin::{hashes::Hash, BlockHash, Network};

use super::{MessageGenerator, Transport};

#[test]
fn block_request_uses_witness_inventory() {
let mut gen = MessageGenerator {
network: Network::Bitcoin,
transport: Transport::V1,
};
let bytes = gen.block(BlockHash::all_zeros());
let raw: bitcoin::p2p::message::RawNetworkMessage =
bitcoin::consensus::deserialize(&bytes).unwrap();
if let bitcoin::p2p::message::NetworkMessage::GetData(inv) = raw.payload() {
assert!(
matches!(
inv[0],
bitcoin::p2p::message_blockdata::Inventory::WitnessBlock(_)
),
"block request must use WitnessBlock to preserve segwit witness data"
);
} else {
panic!("expected GetData message");
}
}
}

pub(in crate::network) fn make_version(port: Option<u16>, network: &Network) -> VersionMessage {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand Down
Loading