Git Product home page Git Product logo

cbf-staging's Introduction

cbf-staging

This is a work in progress staging area for a rust based BIP157 implementation, that is intended to be used as a backend for BDK based wallets.

The code is early draft.

Checkout current Issue Tracker and the Planning doc for better understanding of approach and current status.

cbf-staging's People

Contributors

rajarshimaitra avatar

Watchers

 avatar

Forkers

dhruv-1001

cbf-staging's Issues

Finalising the PeerManager

Currently we have a rough peer management setup here https://github.com/rajarshimaitra/cbf-staging/blob/main/src/peermngr.rs which can connect to multiple nodes. and send and receive data. Few tests are also included.

This task is to create a basic testable peer manager, and test is in parallel without depending on other module's ongoin work. For reference check the planning-doc

  • Remove AddressManager from PeerManager. Make it connect to two hard coded known CBF nodes out there.. Or your own regtest CBF nodes at development stage.

  • Create a basic validation engine that will follow the BIP157 Client operation section.

  • Pass network data from two peers into validation function. Validation should return the faulty peer to ban after validating.

  • Use the same strategy of Mocking as AddressManager to simulate various validation edge cases.

  • Try to fit the PeerManager into the Sync interface here

    cbf-staging/src/sync.rs

    Lines 233 to 286 in e919073

    pub fn sync_headers<F>(
    peer: Arc<Peer>,
    store: Arc<ChainStore<Full>>,
    sync_fn: F,
    ) -> Result<Option<ChainStore<Snapshot>>, CompactFiltersError>
    where
    F: Fn(usize) -> Result<(), CompactFiltersError>,
    {
    let locators = store.get_locators()?;
    let locators_vec = locators.iter().map(|(hash, _)| hash).cloned().collect();
    let locators_map: HashMap<_, _> = locators.into_iter().collect();
    peer.send(NetworkMessage::GetHeaders(GetHeadersMessage::new(
    locators_vec,
    Default::default(),
    )))?;
    let (mut snapshot, mut last_hash) = if let NetworkMessage::Headers(headers) = peer
    .recv("headers", Some(Duration::from_secs(TIMEOUT_SECS)))?
    .ok_or(CompactFiltersError::Timeout)?
    {
    if headers.is_empty() {
    return Ok(None);
    }
    match locators_map.get(&headers[0].prev_blockhash) {
    None => return Err(CompactFiltersError::InvalidHeaders),
    Some(from) => (store.start_snapshot(*from)?, headers[0].prev_blockhash),
    }
    } else {
    return Err(CompactFiltersError::InvalidResponse);
    };
    let mut sync_height = store.get_height()?;
    while sync_height < peer.get_version().start_height as usize {
    peer.send(NetworkMessage::GetHeaders(GetHeadersMessage::new(
    vec![last_hash],
    Default::default(),
    )))?;
    if let NetworkMessage::Headers(headers) = peer
    .recv("headers", Some(Duration::from_secs(TIMEOUT_SECS)))?
    .ok_or(CompactFiltersError::Timeout)?
    {
    let batch_len = headers.len();
    last_hash = snapshot.apply(sync_height, headers)?;
    sync_height += batch_len;
    sync_fn(sync_height)?;
    } else {
    return Err(CompactFiltersError::InvalidResponse);
    }
    }
    Ok(Some(snapshot))
    }
    .

Finalize AddressManager and Mocking

Currently in the new address manager module https://github.com/rajarshimaitra/cbf-staging/blob/main/src/address_manager_2.rs we are not using any Arc<> for multi threading. Instead its done via MPSC channels, and only a single thread will ever have access of the final data store..

The other version of address manager here https://github.com/rajarshimaitra/cbf-staging/blob/main/src/address_manager.rs uses various Arcs to do synchronicity.. But it often goes into certain deadlock situations..

The task is to:

  • Finalize the new address manager
  • Finalize a strategy to create MockWorkers that will read up addresses from local scope and feed them to the AddressFetcher.
  • Write test to validate basic address management functionalities with this mock worker.
  • Store addresses into persistent storage. Simple json files for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.