Skip to content

Commit

Permalink
fix: remove bits audit
Browse files Browse the repository at this point in the history
  • Loading branch information
rustaceanrob committed Nov 1, 2024
1 parent 4cb1728 commit 4412c7e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 3 additions & 1 deletion example/testnet4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::{net::Ipv4Addr, str::FromStr};
const NETWORK: Network = Network::Testnet4;
const RECOVERY_HEIGHT: u32 = 0;

// THE TESTNET4 DOES NOT CURRENTLY HAVE PEERS THAT SERVE COMPACT BLOCK FILTERS

#[tokio::main]
async fn main() {
// Add third-party logging
Expand All @@ -23,7 +25,7 @@ async fn main() {
let mut addresses = HashSet::new();
addresses.insert(address);
// Add preferred peers to connect to
let peer = TrustedPeer::from_ip(Ipv4Addr::new(95, 217, 73, 162));
let peer = TrustedPeer::from_ip(Ipv4Addr::new(18, 189, 156, 102));
// Create a new node builder
let builder = NodeBuilder::new(NETWORK);
// Add node preferences and build the node/client
Expand Down
3 changes: 2 additions & 1 deletion src/chain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const REORG_LOOKBACK: u32 = 7;
const MAX_HEADER_SIZE: usize = 20_000;
const FILTER_BASIC: u8 = 0x00;

#[allow(unused)]
#[derive(Debug)]
pub(crate) struct Chain<H: HeaderStore> {
header_chain: HeaderChain,
Expand Down Expand Up @@ -358,7 +359,7 @@ impl<H: HeaderStore> Chain<H> {
}

// All the headers connect with each other and is the difficulty adjustment not absurd
if !header_batch.connected_with_valid_bits(&self.params).await {
if !header_batch.connected().await {
return Err(HeaderSyncError::HeadersNotConnected);
}

Expand Down
13 changes: 3 additions & 10 deletions src/chain/header_batch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bitcoin::{block::Header, params::Params, Target};
use bitcoin::block::Header;

use crate::{
impl_sourceless_error,
Expand All @@ -20,18 +20,11 @@ impl HeadersBatch {
}

// Are they all logically connected?
pub(crate) async fn connected_with_valid_bits(&self, params: &Params) -> bool {
pub(crate) async fn connected(&self) -> bool {
self.batch
.iter()
.zip(self.batch.iter().skip(1))
.all(|(first, second)| {
let transition = Target::from_compact(first.bits).max_transition_threshold(params);
if Target::from_compact(second.bits).gt(&transition) {
println!("There is a problem");
}
first.block_hash().eq(&second.prev_blockhash)
&& Target::from_compact(second.bits).le(&transition)
})
.all(|(first, second)| first.block_hash().eq(&second.prev_blockhash))
}

// Are all the blocks of sufficient work and meet their own target?
Expand Down

0 comments on commit 4412c7e

Please sign in to comment.