Skip to content

Commit 490d076

Browse files
committed
more cleanups + lint + rebase
1 parent 2f27bd6 commit 490d076

4 files changed

Lines changed: 29 additions & 22 deletions

File tree

glue/src/stateful/actor/core.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ mod tests {
882882
use commonware_storage::{mmr::Location, qmdb::sync::Target};
883883
use commonware_utils::{
884884
channel::{mpsc, oneshot},
885+
range::NonEmptyRange,
885886
NZUsize,
886887
};
887888
use std::{
@@ -1496,7 +1497,7 @@ mod tests {
14961497
) -> <Self::Databases as DatabaseSet<deterministic::Context>>::SyncTargets {
14971498
vec![Target {
14981499
root: block.digest(),
1499-
range: Location::new(0)..Location::new(100),
1500+
range: NonEmptyRange::new(Location::new(0)..Location::new(100)).unwrap(),
15001501
}]
15011502
}
15021503
}
@@ -1542,7 +1543,7 @@ mod tests {
15421543
assert_eq!(received.targets[0].root, block1.digest());
15431544
assert_eq!(
15441545
received.targets[0].range,
1545-
Location::new(0)..Location::new(100),
1546+
NonEmptyRange::new(Location::new(0)..Location::new(100)).unwrap(),
15461547
);
15471548
});
15481549
}

glue/src/stateful/tests/multi_db_app.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ use commonware_storage::{
5252
translator::TwoCap,
5353
};
5454
use commonware_utils::{
55+
non_empty_range,
56+
range::NonEmptyRange,
5557
sync::{AsyncRwLock, Mutex},
5658
test_rng, NZUsize, NZU64,
5759
};
5860
use rand::Rng;
59-
use std::{collections::BTreeMap, ops::Range, sync::Arc, time::Duration};
61+
use std::{collections::BTreeMap, sync::Arc, time::Duration};
6062

6163
/// The QMDB database type used by the multi-db e2e tests.
6264
type Qmdb<E> = fixed::Db<E, sha256::Digest, sha256::Digest, Sha256, TwoCap>;
@@ -76,9 +78,9 @@ pub(crate) struct Block {
7678
parent: sha256::Digest,
7779
height: Height,
7880
root_a: sha256::Digest,
79-
range_a: Range<Location>,
81+
range_a: NonEmptyRange<Location>,
8082
root_b: sha256::Digest,
81-
range_b: Range<Location>,
83+
range_b: NonEmptyRange<Location>,
8284
}
8385

8486
impl Write for Block {
@@ -114,9 +116,9 @@ impl Read for Block {
114116
parent: sha256::Digest::read(buf)?,
115117
height: Height::read(buf)?,
116118
root_a: sha256::Digest::read(buf)?,
117-
range_a: Range::read(buf)?,
119+
range_a: NonEmptyRange::read(buf)?,
118120
root_b: sha256::Digest::read(buf)?,
119-
range_b: Range::read(buf)?,
121+
range_b: NonEmptyRange::read(buf)?,
120122
})
121123
}
122124
}
@@ -160,9 +162,9 @@ impl Block {
160162
parent: sha256::Digest::EMPTY,
161163
height: Height::zero(),
162164
root_a: sha256::Digest::EMPTY,
163-
range_a: Location::new(0)..Location::new(1),
165+
range_a: non_empty_range!(Location::new(0), Location::new(1)),
164166
root_b: sha256::Digest::EMPTY,
165-
range_b: Location::new(0)..Location::new(1),
167+
range_b: non_empty_range!(Location::new(0), Location::new(1)),
166168
}
167169
}
168170
}
@@ -243,9 +245,9 @@ impl<E: Rng + Spawner + Metrics + Clock + Storage> Application<E> for App {
243245
parent: parent.digest(),
244246
height,
245247
root_a: merkleized_a.root(),
246-
range_a: merkleized_a.inactivity_floor()..merkleized_a.size(),
248+
range_a: non_empty_range!(merkleized_a.inactivity_floor(), merkleized_a.size()),
247249
root_b: merkleized_b.root(),
248-
range_b: merkleized_b.inactivity_floor()..merkleized_b.size(),
250+
range_b: non_empty_range!(merkleized_b.inactivity_floor(), merkleized_b.size()),
249251
};
250252
Some(Proposed {
251253
block,
@@ -262,9 +264,11 @@ impl<E: Rng + Spawner + Metrics + Clock + Storage> Application<E> for App {
262264
let tip = ancestry.peek()?;
263265
let (merkleized_a, merkleized_b) = Self::execute(tip.height(), batches).await;
264266
let matches_a = merkleized_a.root() == tip.root_a
265-
&& (merkleized_a.inactivity_floor()..merkleized_a.size()) == tip.range_a;
267+
&& non_empty_range!(merkleized_a.inactivity_floor(), merkleized_a.size())
268+
== tip.range_a;
266269
let matches_b = merkleized_b.root() == tip.root_b
267-
&& (merkleized_b.inactivity_floor()..merkleized_b.size()) == tip.range_b;
270+
&& non_empty_range!(merkleized_b.inactivity_floor(), merkleized_b.size())
271+
== tip.range_b;
268272
if !matches_a || !matches_b {
269273
return None;
270274
}

glue/src/stateful/tests/single_db_app.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ use commonware_storage::{
5151
translator::TwoCap,
5252
};
5353
use commonware_utils::{
54+
non_empty_range,
55+
range::NonEmptyRange,
5456
sync::{AsyncRwLock, Mutex},
5557
test_rng, NZUsize, NZU64,
5658
};
5759
use rand::Rng;
58-
use std::{collections::BTreeMap, ops::Range, sync::Arc, time::Duration};
60+
use std::{collections::BTreeMap, sync::Arc, time::Duration};
5961

6062
/// The QMDB database type used by the single-db e2e tests.
6163
type Qmdb<E> = fixed::Db<E, sha256::Digest, sha256::Digest, Sha256, TwoCap>;
@@ -70,7 +72,7 @@ pub(crate) struct Block {
7072
parent: sha256::Digest,
7173
height: Height,
7274
state_root: sha256::Digest,
73-
range: Range<Location>,
75+
range: NonEmptyRange<Location>,
7476
}
7577

7678
impl Write for Block {
@@ -102,7 +104,7 @@ impl Read for Block {
102104
parent: sha256::Digest::read(buf)?,
103105
height: Height::read(buf)?,
104106
state_root: sha256::Digest::read(buf)?,
105-
range: Range::read(buf)?,
107+
range: NonEmptyRange::read(buf)?,
106108
})
107109
}
108110
}
@@ -146,7 +148,7 @@ impl Block {
146148
parent: sha256::Digest::EMPTY,
147149
height: Height::zero(),
148150
state_root: sha256::Digest::EMPTY,
149-
range: Location::new(0)..Location::new(1),
151+
range: non_empty_range!(Location::new(0), Location::new(1)),
150152
}
151153
}
152154
}
@@ -210,7 +212,7 @@ impl<E: Rng + Spawner + Metrics + Clock + Storage> Application<E> for App {
210212
parent: parent.digest(),
211213
height,
212214
state_root: merkleized.root(),
213-
range: merkleized.inactivity_floor()..merkleized.size(),
215+
range: non_empty_range!(merkleized.inactivity_floor(), merkleized.size()),
214216
};
215217
Some(Proposed { block, merkleized })
216218
}
@@ -224,7 +226,7 @@ impl<E: Rng + Spawner + Metrics + Clock + Storage> Application<E> for App {
224226
let tip = ancestry.peek()?;
225227
let merkleized = Self::execute(tip.height(), batches).await;
226228
if merkleized.root() != tip.state_root
227-
|| (merkleized.inactivity_floor()..merkleized.size()) != tip.range
229+
|| non_empty_range!(merkleized.inactivity_floor(), merkleized.size()) != tip.range
228230
{
229231
return None;
230232
}

storage/src/qmdb/sync/engine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ mod tests {
622622
use super::*;
623623
use crate::mmr::Proof;
624624
use commonware_cryptography::sha256;
625-
use commonware_utils::channel::oneshot;
625+
use commonware_utils::{channel::oneshot, non_empty_range};
626626

627627
#[test]
628628
fn test_outstanding_requests() {
@@ -657,11 +657,11 @@ mod tests {
657657
fn duplicate_target_updates_are_ignored() {
658658
let target = Target {
659659
root: sha256::Digest::from([7; 32]),
660-
range: Location::new(10)..Location::new(20),
660+
range: non_empty_range!(Location::new(10), Location::new(20)),
661661
};
662662
let distinct = Target {
663663
root: sha256::Digest::from([8; 32]),
664-
range: Location::new(10)..Location::new(20),
664+
range: non_empty_range!(Location::new(10), Location::new(20)),
665665
};
666666

667667
assert!(is_duplicate_target_update(&target, &target));

0 commit comments

Comments
 (0)