Skip to content

Commit 44abc53

Browse files
committed
Change all instances of Accumulator to Aggragate
1 parent 59fc618 commit 44abc53

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ See the `node/README.md` to run an initial block download using _SwiftSync_.
1010

1111
## Crates
1212

13-
- `accumulator`: A hash-based SwiftSync accumulator used to add and subtrack elements from a set.
13+
- `aggregate`: A hash-based data structure used to add and subtrack elements from a set.
1414
- `node`: Perform fast IBD using a SwiftSync hints file.

aggregate/src/lib.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sha256t_tag! {
1111
/// added and removed the equivalent amount of times, the accumulator is zero. In the context of
1212
/// bitcoin, this is used to add and remove hashes of [`OutPoint`] data.
1313
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, std::hash::Hash)]
14-
pub struct Accumulator {
14+
pub struct Aggregate {
1515
high: u128,
1616
low: u128,
1717
}
@@ -36,14 +36,14 @@ fn split_in_half(a: [u8; 32]) -> ([u8; 16], [u8; 16]) {
3636

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

44-
impl Accumulator {
44+
impl Aggregate {
4545
/// The zero accumulator
46-
pub const ZERO: Accumulator = Accumulator { high: 0, low: 0 };
46+
pub const ZERO: Aggregate = Aggregate { high: 0, low: 0 };
4747

4848
/// Build a new accumulator.
4949
pub const fn new() -> Self {
@@ -66,10 +66,10 @@ impl Accumulator {
6666
}
6767

6868
/// Update the accumulator
69-
pub fn update(&mut self, update: AccumulatorUpdate) {
69+
pub fn update(&mut self, update: AggregateUpdate) {
7070
match update {
71-
AccumulatorUpdate::Add(added) => self.add_hashed_outpoint(added),
72-
AccumulatorUpdate::Spent(spent) => self.spend_hashed_outpoint(spent),
71+
AggregateUpdate::Add(added) => self.add_hashed_outpoint(added),
72+
AggregateUpdate::Spent(spent) => self.spend_hashed_outpoint(spent),
7373
}
7474
}
7575

@@ -101,7 +101,7 @@ impl Accumulator {
101101
}
102102
}
103103

104-
impl Default for Accumulator {
104+
impl Default for Aggregate {
105105
fn default() -> Self {
106106
Self::ZERO
107107
}
@@ -218,7 +218,7 @@ mod tests {
218218

219219
#[test]
220220
fn test_accumulator_is_zero() {
221-
let mut acc = Accumulator::default();
221+
let mut acc = Aggregate::default();
222222
let [outpoint_one, outpoint_two, outpoint_three, outpoint_four, outpoint_five] =
223223
make_five_outpoint();
224224
// Add the members
@@ -241,10 +241,10 @@ mod tests {
241241
fn test_same_state() {
242242
let [outpoint_one, outpoint_two, outpoint_three, outpoint_four, outpoint_five] =
243243
make_five_outpoint();
244-
let mut acc_ref = Accumulator::default();
244+
let mut acc_ref = Aggregate::default();
245245
acc_ref.add(outpoint_two);
246246
acc_ref.add(outpoint_four);
247-
let mut acc_cmp = Accumulator::default();
247+
let mut acc_cmp = Aggregate::default();
248248
acc_cmp.add(outpoint_one);
249249
acc_cmp.add(outpoint_two);
250250
acc_cmp.add(outpoint_three);
@@ -266,7 +266,7 @@ mod tests {
266266
let hash_three = hash_outpoint(outpoint_three);
267267
let hash_four = hash_outpoint(outpoint_four);
268268
let hash_five = hash_outpoint(outpoint_five);
269-
let mut acc = Accumulator::default();
269+
let mut acc = Aggregate::default();
270270
acc.add_hashed_outpoint(hash_five);
271271
acc.add_hashed_outpoint(hash_four);
272272
acc.add_hashed_outpoint(hash_one);
@@ -288,17 +288,17 @@ mod tests {
288288
let hash_three = hash_outpoint(outpoint_three);
289289
let hash_four = hash_outpoint(outpoint_four);
290290
let hash_five = hash_outpoint(outpoint_five);
291-
let mut acc = Accumulator::default();
292-
acc.update(AccumulatorUpdate::Add(hash_one));
293-
acc.update(AccumulatorUpdate::Add(hash_two));
294-
acc.update(AccumulatorUpdate::Add(hash_three));
295-
acc.update(AccumulatorUpdate::Add(hash_four));
296-
acc.update(AccumulatorUpdate::Add(hash_five));
297-
acc.update(AccumulatorUpdate::Spent(hash_five));
298-
acc.update(AccumulatorUpdate::Spent(hash_four));
299-
acc.update(AccumulatorUpdate::Spent(hash_three));
300-
acc.update(AccumulatorUpdate::Spent(hash_two));
301-
acc.update(AccumulatorUpdate::Spent(hash_one));
291+
let mut acc = Aggregate::default();
292+
acc.update(AggregateUpdate::Add(hash_one));
293+
acc.update(AggregateUpdate::Add(hash_two));
294+
acc.update(AggregateUpdate::Add(hash_three));
295+
acc.update(AggregateUpdate::Add(hash_four));
296+
acc.update(AggregateUpdate::Add(hash_five));
297+
acc.update(AggregateUpdate::Spent(hash_five));
298+
acc.update(AggregateUpdate::Spent(hash_four));
299+
acc.update(AggregateUpdate::Spent(hash_three));
300+
acc.update(AggregateUpdate::Spent(hash_two));
301+
acc.update(AggregateUpdate::Spent(hash_one));
302302
assert!(acc.is_zero());
303303
}
304304

aggregate/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use aggregate::{Accumulator, MultAggregate};
1+
use aggregate::{Aggregate, MultAggregate};
22
use bitcoin::{OutPoint, Txid};
33
use rusqlite::Connection;
44

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

77
#[test]
88
fn test_static_utxo_set() {
9-
let mut acc = Accumulator::new();
9+
let mut acc = Aggregate::new();
1010
let conn = Connection::open("../contrib/data/signet_outpoints.sqlite").unwrap();
1111
let mut stmt = conn.prepare(SELECT_STMT).unwrap();
1212
let mut rows = stmt.query([]).unwrap();

node/src/bin/ibd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use kernel::{ChainstateManager, ChainstateManagerOptions, ContextBuilder};
1111

1212
use node::{
1313
bootstrap_dns, elapsed_time, get_blocks_for_range, hashes_from_chain, sync_block_headers,
14-
AccumulatorState, ChainExt,
14+
AggregateState, ChainExt,
1515
};
1616
use p2p::net::TimeoutParams;
1717

@@ -77,7 +77,7 @@ fn main() {
7777
tracing::info!("Assume valid height: {}", chain.best_header().height());
7878
let (tx, rx) = channel();
7979
let main_routine_time = Instant::now();
80-
let mut accumulator_state = AccumulatorState::new(rx);
80+
let mut accumulator_state = AggregateState::new(rx);
8181
let acc_task = std::thread::spawn(move || accumulator_state.verify());
8282
let peers = Arc::new(Mutex::new(peers));
8383
let mut tasks = Vec::new();

node/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
time::{Duration, Instant},
1212
};
1313

14-
use aggregate::{Accumulator, AccumulatorUpdate};
14+
use aggregate::{Aggregate, AggregateUpdate};
1515
use bitcoin::{
1616
consensus,
1717
key::rand::{seq::SliceRandom, thread_rng},
@@ -43,15 +43,15 @@ pub fn elapsed_time(then: Instant) {
4343
}
4444

4545
#[derive(Debug)]
46-
pub struct AccumulatorState {
47-
acc: Accumulator,
48-
update_rx: Receiver<AccumulatorUpdate>,
46+
pub struct AggregateState {
47+
acc: Aggregate,
48+
update_rx: Receiver<AggregateUpdate>,
4949
}
5050

51-
impl AccumulatorState {
52-
pub fn new(rx: Receiver<AccumulatorUpdate>) -> Self {
51+
impl AggregateState {
52+
pub fn new(rx: Receiver<AggregateUpdate>) -> Self {
5353
Self {
54-
acc: Accumulator::new(),
54+
acc: Aggregate::new(),
5555
update_rx: rx,
5656
}
5757
}
@@ -179,7 +179,7 @@ pub fn get_blocks_for_range(
179179
chain: Arc<ChainstateManager>,
180180
hints: Arc<Mutex<Hintsfile>>,
181181
peers: Arc<Mutex<Vec<SocketAddr>>>,
182-
updater: Sender<AccumulatorUpdate>,
182+
updater: Sender<AggregateUpdate>,
183183
hashes: Arc<Mutex<Vec<Vec<BlockHash>>>>,
184184
) {
185185
let mut batch = Vec::new();
@@ -265,7 +265,7 @@ pub fn get_blocks_for_range(
265265
if !transaction.is_coinbase() {
266266
for input in transaction.inputs {
267267
let input_hash = aggregate::hash_outpoint(input.previous_output);
268-
let update = AccumulatorUpdate::Spent(input_hash);
268+
let update = AggregateUpdate::Spent(input_hash);
269269
updater
270270
.send(update)
271271
.expect("accumulator task must not panic");
@@ -283,7 +283,7 @@ pub fn get_blocks_for_range(
283283
vout: vout as u32,
284284
};
285285
let input_hash = aggregate::hash_outpoint(outpoint);
286-
let update = AccumulatorUpdate::Add(input_hash);
286+
let update = AggregateUpdate::Add(input_hash);
287287
updater
288288
.send(update)
289289
.expect("accumulator task must not panic");

0 commit comments

Comments
 (0)