Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions changelog.d/clock-step2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Changed

- **net: PeerHub uses NodeClock, drop second mock battery (Step 2).** PeerHub no longer has its own mock clock; it holds NodeClock. `set_mock` sets the clock and calls `on_clock_jump()` which requests tx INVs, runs heartbeat, then queues self-announce on live peers. TxRelay still has its own mock clock; setmocktime still notifies it. That is Step 3.
4 changes: 3 additions & 1 deletion crates/rbitcoin-net/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::error::NetError;
use bitcoin::block::Header;
use bitcoin::hashes::Hash;
use bitcoin::{Block, BlockHash, CompactTarget, ScriptBuf, Target, Transaction, Txid, Work};
#[allow(unused_imports)]
use rbitcoin_consensus::NodeClock;
use rbitcoin_consensus::{
accept_and_connect_block_preverified, confirm_wire_load_from_plan as consensus_load_from_plan,
confirm_wire_load_phase_pipelined, confirm_write_phase, genesis_block, header_to_record,
Expand Down Expand Up @@ -360,7 +362,7 @@ impl ChainHub {
generate_lock: std::sync::Mutex::new(()),
mempool: std::sync::OnceLock::new(),
self_weak: std::sync::OnceLock::new(),
clock: rbitcoin_consensus::NodeClock::new(),
clock: NodeClock::new(),
invalidated: Invalidated::new(),
held_bodies: RwLock::new(HeldBodies::new()),
precious: RwLock::new(None),
Expand Down
2 changes: 1 addition & 1 deletion crates/rbitcoin-net/src/ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ mod tests {
relay: true,
};
let (tx, mut rx) = mpsc::unbounded_channel();
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let sess = peers.register(
addr,
addr,
Expand Down
2 changes: 1 addition & 1 deletion crates/rbitcoin-net/src/overlay_addrman_journey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn only_net_dials_and_peers_file(am: &Mutex<crate::seeds::AddrMan>, overlays: [c
#[test]
fn overlay_config() {
dial_targets_roundtrip();
let hub = PeerHub::new();
let hub = PeerHub::new(rbitcoin_consensus::NodeClock::new());
let am = Arc::new(Mutex::new(crate::seeds::AddrMan::new()));
hub.set_addrman(am.clone());
let pk = [
Expand Down
4 changes: 2 additions & 2 deletions crates/rbitcoin-net/src/peer_blocksonly_journey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn getdata_txs(rx: &mut mpsc::UnboundedReceiver<PeerOut>) -> Vec<Inventory> {
}

fn set_relay_clock(hub: &crate::chain::ChainHub, peers: &crate::peers::PeerHub, now: u64) {
peers.set_mock_now(now);
peers.set_mock(now);
hub.mempool().unwrap().note_mock_now(now);
}

Expand Down Expand Up @@ -609,7 +609,7 @@ fn peer_blocksonly_and_orphan_tx() {
assert!(!hub.in_ibd(), "blocksonly is not IBD");
let mp = crate::tx_relay::MempoolHub::open(dir.join("mp"), Arc::clone(&hub.query)).unwrap();
mp.set_relay_enabled(false);
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
peers.attach_mempool(&mp);
assert!(hub.attach_mempool(mp).is_ok());
let t0 = 1_700_000_000u64;
Expand Down
2 changes: 1 addition & 1 deletion crates/rbitcoin-net/src/peer_catchup_journey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn peer_catchup_compact_reorg() {
mp.set_relay_enabled(true);
assert!(hub.attach_mempool(mp).is_ok());

let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 18444);
let ver = bitcoin::p2p::message_network::VersionMessage {
version: 70016,
Expand Down
2 changes: 1 addition & 1 deletion crates/rbitcoin-net/src/peer_header_dos_journey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ async fn peer_header_dos_and_self_announce() {
params.apply_test_activation_height("cltv", 111).unwrap();
let hub = ChainHub::new(q, params, Milestone::NONE);
hub.ensure_genesis().unwrap();
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());

handshake_verack_and_addrv2(&hub, &peers).await;
unknown_parent_bodies(&hub, &peers).await;
Expand Down
2 changes: 1 addition & 1 deletion crates/rbitcoin-net/src/peer_hostile_journey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn hostile_peer_session() {
.unwrap()
.block_hash();

let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let bind = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 18444);
let ver = hostile_ver(bind);
let peer = peers.register(
Expand Down
14 changes: 8 additions & 6 deletions crates/rbitcoin-net/src/peer_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::*;
use crate::peers::{CappedSet, PeerOut};
use bitcoin::BlockHash;
#[allow(unused_imports)]
use rbitcoin_consensus::NodeClock;
use rbitcoin_consensus::{ChainParams, Milestone};
use rbitcoin_query::Query;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -426,7 +428,7 @@ async fn partial_for_a_block_connected_elsewhere_frees_the_slot() {
vec![spend(1)],
);

let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(NodeClock::new());
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 18447);
let ver = VersionMessage {
version: 70016,
Expand Down Expand Up @@ -585,7 +587,7 @@ fn same_peer_pending_cmpct_does_not_getblocktxn_again() {
block.header.merkle_root = block.compute_merkle_root().unwrap();
let hsi = HeaderAndShortIds::from_block(&block, 0xbeef, 2, &[]).unwrap();
let hash = block.block_hash();
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(NodeClock::new());
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 18446);
let ver = VersionMessage {
version: 70016,
Expand Down Expand Up @@ -1337,7 +1339,7 @@ fn recent_reject_skips_atmp_on_second_send(via_cidr: bool) {
mp.set_relay_enabled(true);
assert!(hub.attach_mempool(mp).is_ok());

let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(NodeClock::new());
if via_cidr {
let mut table = crate::net_permissions::NetPermTable::default();
table
Expand Down Expand Up @@ -2181,7 +2183,7 @@ fn getdata_skips_reconstruct_when_serve_inflight_at_cap() {
.unwrap();
assert!(hashes.len() >= 20);

let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(NodeClock::new());
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 18444);
let ver = bitcoin::p2p::message_network::VersionMessage {
version: 70016,
Expand Down Expand Up @@ -2388,7 +2390,7 @@ fn snapshot_omits_peer_after_tcp_fin() {
use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpListener, TcpStream};
use std::time::Duration;

let hub = PeerHub::new();
let hub = PeerHub::new(NodeClock::new());
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 18444);
let ver = VersionMessage {
version: 70016,
Expand Down Expand Up @@ -2860,7 +2862,7 @@ async fn inv_and_getdata_at_cap_stay_one_past_disconnects() {
}
#[tokio::test]
async fn over_budget_reader_waits_until_one_byte_is_written() {
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(NodeClock::new());
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 1));
let ver = bitcoin::p2p::message_network::VersionMessage {
version: 70016,
Expand Down
10 changes: 5 additions & 5 deletions crates/rbitcoin-net/src/peer_tip_announce_journey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ async fn tip_announce_compact_requires_parent(hub: &crate::chain::ChainHub) {
.block_hash();
let parent = hub.tip_header().unwrap().prev_blockhash;
let ev = tip_event(hub, 0);
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let sess_behind = live_peer(&peers, 18444, 1, false);
sess_behind.note_best_known(behind);
let (out_tx, mut out_rx) = mpsc::unbounded_channel();
Expand Down Expand Up @@ -389,7 +389,7 @@ async fn tip_announce_depth_and_fill_slot(hub: &crate::chain::ChainHub) {
.query
.reconstruct_block_at_height(Height(tip_h))
.unwrap();
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let session = live_peer(&peers, 18446, 3, true);
assert!(session.try_cmpct_fill(hash));
let mut follow = PeerFollowState::new();
Expand All @@ -415,7 +415,7 @@ async fn tip_announce_depth_and_fill_slot(hub: &crate::chain::ChainHub) {
async fn tip_announce_serve_inflight_untouched(hub: &crate::chain::ChainHub) {
use std::sync::atomic::Ordering;
let hash = hub.tip_hash().unwrap();
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let (out_tx, mut out_rx) = mpsc::unbounded_channel();

let wrap = live_peer(&peers, 18447, 4, false);
Expand Down Expand Up @@ -600,7 +600,7 @@ async fn tip_announce_hb_relays_before_connect(hub: &crate::chain::ChainHub) {
let pref: Vec<usize> = (0..block.txdata.len()).collect();
let hsi = HeaderAndShortIds::from_block(&block, 1, 2, &pref).expect("hsi");

let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let a = live_peer(&peers, 18449, 6, false);
let b = live_peer(&peers, 18450, 7, false);
b.set_hb_to(true);
Expand Down Expand Up @@ -970,7 +970,7 @@ async fn tip_announce_merkle_second_cmpct_disconnects(hub: &crate::chain::ChainH
};
let hash = hsi.header.block_hash();
assert!(!hub.has_block(&hash));
let peers = crate::peers::PeerHub::new();
let peers = crate::peers::PeerHub::new(rbitcoin_consensus::NodeClock::new());
let session = live_peer(&peers, 18451, 8, true);
let (out_tx, _out_rx) = mpsc::unbounded_channel();
let mut follow = PeerFollowState::new();
Expand Down
Loading
Loading