Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["accumulator", "node"]
default-members = ["accumulator"]
members = ["aggregate", "node"]
default-members = ["aggregate"]
resolver = "2"

[workspace.dependencies]
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# SwiftSync

:warning::construction: This project is still under construction and expected to change significantly. Use at your own risk :construction::warning:
:construction: This is a research project not intended for real use. :construction:

This repository is a collection of crates related to a SwiftSync node implementation. Some crates will be SwiftSync-specific, while others may have broader use cases.
This repository is a collection of crates related to a _SwiftSync_ node implementation. _SwiftSync_ is a protocol that allows nearly-stateless, parallelizable Bitcoin initial block download without adding additional cryptographic assumptions. You may read the [initial writeup here](https://gist.github.com/RubenSomsen/a61a37d14182ccd78760e477c78133cd).

- `accumulator`: A hash-based SwiftSync accumulator used to add and subtrack elements from a set.
## Executables

See the `node/README.md` to run an initial block download using _SwiftSync_.

## Crates

- `aggregate`: A hash-based data structure used to add and subtrack elements from a set.
- `node`: Perform fast IBD using a SwiftSync hints file.
2 changes: 1 addition & 1 deletion accumulator/Cargo.toml → aggregate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "accumulator"
name = "aggregate"
version = "0.1.0"
edition = "2021"

Expand Down
File renamed without changes.
46 changes: 23 additions & 23 deletions accumulator/src/lib.rs → aggregate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sha256t_tag! {
/// added and removed the equivalent amount of times, the accumulator is zero. In the context of
/// bitcoin, this is used to add and remove hashes of [`OutPoint`] data.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, std::hash::Hash)]
pub struct Accumulator {
pub struct Aggregate {
high: u128,
low: u128,
}
Expand All @@ -36,14 +36,14 @@ fn split_in_half(a: [u8; 32]) -> ([u8; 16], [u8; 16]) {

/// Update an accumulator by adding or spending a pre-hashed outpoint
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccumulatorUpdate {
pub enum AggregateUpdate {
Add([u8; 32]),
Spent([u8; 32]),
}

impl Accumulator {
impl Aggregate {
/// The zero accumulator
pub const ZERO: Accumulator = Accumulator { high: 0, low: 0 };
pub const ZERO: Aggregate = Aggregate { high: 0, low: 0 };

/// Build a new accumulator.
pub const fn new() -> Self {
Expand All @@ -66,10 +66,10 @@ impl Accumulator {
}

/// Update the accumulator
pub fn update(&mut self, update: AccumulatorUpdate) {
pub fn update(&mut self, update: AggregateUpdate) {
match update {
AccumulatorUpdate::Add(added) => self.add_hashed_outpoint(added),
AccumulatorUpdate::Spent(spent) => self.spend_hashed_outpoint(spent),
AggregateUpdate::Add(added) => self.add_hashed_outpoint(added),
AggregateUpdate::Spent(spent) => self.spend_hashed_outpoint(spent),
}
}

Expand Down Expand Up @@ -101,7 +101,7 @@ impl Accumulator {
}
}

impl Default for Accumulator {
impl Default for Aggregate {
fn default() -> Self {
Self::ZERO
}
Expand Down Expand Up @@ -218,7 +218,7 @@ mod tests {

#[test]
fn test_accumulator_is_zero() {
let mut acc = Accumulator::default();
let mut acc = Aggregate::default();
let [outpoint_one, outpoint_two, outpoint_three, outpoint_four, outpoint_five] =
make_five_outpoint();
// Add the members
Expand All @@ -241,10 +241,10 @@ mod tests {
fn test_same_state() {
let [outpoint_one, outpoint_two, outpoint_three, outpoint_four, outpoint_five] =
make_five_outpoint();
let mut acc_ref = Accumulator::default();
let mut acc_ref = Aggregate::default();
acc_ref.add(outpoint_two);
acc_ref.add(outpoint_four);
let mut acc_cmp = Accumulator::default();
let mut acc_cmp = Aggregate::default();
acc_cmp.add(outpoint_one);
acc_cmp.add(outpoint_two);
acc_cmp.add(outpoint_three);
Expand All @@ -266,7 +266,7 @@ mod tests {
let hash_three = hash_outpoint(outpoint_three);
let hash_four = hash_outpoint(outpoint_four);
let hash_five = hash_outpoint(outpoint_five);
let mut acc = Accumulator::default();
let mut acc = Aggregate::default();
acc.add_hashed_outpoint(hash_five);
acc.add_hashed_outpoint(hash_four);
acc.add_hashed_outpoint(hash_one);
Expand All @@ -288,17 +288,17 @@ mod tests {
let hash_three = hash_outpoint(outpoint_three);
let hash_four = hash_outpoint(outpoint_four);
let hash_five = hash_outpoint(outpoint_five);
let mut acc = Accumulator::default();
acc.update(AccumulatorUpdate::Add(hash_one));
acc.update(AccumulatorUpdate::Add(hash_two));
acc.update(AccumulatorUpdate::Add(hash_three));
acc.update(AccumulatorUpdate::Add(hash_four));
acc.update(AccumulatorUpdate::Add(hash_five));
acc.update(AccumulatorUpdate::Spent(hash_five));
acc.update(AccumulatorUpdate::Spent(hash_four));
acc.update(AccumulatorUpdate::Spent(hash_three));
acc.update(AccumulatorUpdate::Spent(hash_two));
acc.update(AccumulatorUpdate::Spent(hash_one));
let mut acc = Aggregate::default();
acc.update(AggregateUpdate::Add(hash_one));
acc.update(AggregateUpdate::Add(hash_two));
acc.update(AggregateUpdate::Add(hash_three));
acc.update(AggregateUpdate::Add(hash_four));
acc.update(AggregateUpdate::Add(hash_five));
acc.update(AggregateUpdate::Spent(hash_five));
acc.update(AggregateUpdate::Spent(hash_four));
acc.update(AggregateUpdate::Spent(hash_three));
acc.update(AggregateUpdate::Spent(hash_two));
acc.update(AggregateUpdate::Spent(hash_one));
assert!(acc.is_zero());
}

Expand Down
4 changes: 2 additions & 2 deletions accumulator/tests/test.rs → aggregate/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use accumulator::{Accumulator, MultAggregate};
use aggregate::{Aggregate, MultAggregate};
use bitcoin::{OutPoint, Txid};
use rusqlite::Connection;

const SELECT_STMT: &str = "SELECT txid, vout FROM utxos";

#[test]
fn test_static_utxo_set() {
let mut acc = Accumulator::new();
let mut acc = Aggregate::new();
let conn = Connection::open("../contrib/data/signet_outpoints.sqlite").unwrap();
let mut stmt = conn.prepare(SELECT_STMT).unwrap();
let mut rows = stmt.query([]).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
build = "build.rs"

[dependencies]
accumulator = { path = "../accumulator/" }
aggregate = { path = "../aggregate/" }
bitcoin = { workspace = true }
kernel = { workspace = true }
hintsfile = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions node/src/bin/ibd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use kernel::{ChainstateManager, ChainstateManagerOptions, ContextBuilder};

use node::{
bootstrap_dns, elapsed_time, get_blocks_for_range, hashes_from_chain, sync_block_headers,
AccumulatorState, ChainExt,
AggregateState, ChainExt,
};
use p2p::net::TimeoutParams;

Expand Down Expand Up @@ -77,7 +77,7 @@ fn main() {
tracing::info!("Assume valid height: {}", chain.best_header().height());
let (tx, rx) = channel();
let main_routine_time = Instant::now();
let mut accumulator_state = AccumulatorState::new(rx);
let mut accumulator_state = AggregateState::new(rx);
let acc_task = std::thread::spawn(move || accumulator_state.verify());
let peers = Arc::new(Mutex::new(peers));
let mut tasks = Vec::new();
Expand Down
24 changes: 12 additions & 12 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
time::{Duration, Instant},
};

use accumulator::{Accumulator, AccumulatorUpdate};
use aggregate::{Aggregate, AggregateUpdate};
use bitcoin::{
consensus,
key::rand::{seq::SliceRandom, thread_rng},
Expand Down Expand Up @@ -43,15 +43,15 @@ pub fn elapsed_time(then: Instant) {
}

#[derive(Debug)]
pub struct AccumulatorState {
acc: Accumulator,
update_rx: Receiver<AccumulatorUpdate>,
pub struct AggregateState {
acc: Aggregate,
update_rx: Receiver<AggregateUpdate>,
}

impl AccumulatorState {
pub fn new(rx: Receiver<AccumulatorUpdate>) -> Self {
impl AggregateState {
pub fn new(rx: Receiver<AggregateUpdate>) -> Self {
Self {
acc: Accumulator::new(),
acc: Aggregate::new(),
update_rx: rx,
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ pub fn get_blocks_for_range(
chain: Arc<ChainstateManager>,
hints: Arc<Mutex<Hintsfile>>,
peers: Arc<Mutex<Vec<SocketAddr>>>,
updater: Sender<AccumulatorUpdate>,
updater: Sender<AggregateUpdate>,
hashes: Arc<Mutex<Vec<Vec<BlockHash>>>>,
) {
let mut batch = Vec::new();
Expand Down Expand Up @@ -264,8 +264,8 @@ pub fn get_blocks_for_range(
let tx_hash = transaction.compute_txid();
if !transaction.is_coinbase() {
for input in transaction.inputs {
let input_hash = accumulator::hash_outpoint(input.previous_output);
let update = AccumulatorUpdate::Spent(input_hash);
let input_hash = aggregate::hash_outpoint(input.previous_output);
let update = AggregateUpdate::Spent(input_hash);
updater
.send(update)
.expect("accumulator task must not panic");
Expand All @@ -282,8 +282,8 @@ pub fn get_blocks_for_range(
txid: tx_hash,
vout: vout as u32,
};
let input_hash = accumulator::hash_outpoint(outpoint);
let update = AccumulatorUpdate::Add(input_hash);
let input_hash = aggregate::hash_outpoint(outpoint);
let update = AggregateUpdate::Add(input_hash);
updater
.send(update)
.expect("accumulator task must not panic");
Expand Down