Skip to content

Commit 788776e

Browse files
committed
Merge remote-tracking branch 'origin/main' into danlaine/keyless-inactivity-floor
2 parents 667153b + 72b8724 commit 788776e

73 files changed

Lines changed: 6089 additions & 3157 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/sync/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ curl http://localhost:9090/metrics
117117
4. **Sync Iteration Loop**: For each sync iteration:
118118
- **Database Initialization**: Client opens a new database (or reopens existing one)
119119
- **Connection**: Client establishes connection to server
120-
- **Initial Sync Target**: Client requests server metadata to determine sync target (inactivity floor, size, and root digest)
120+
- **Initial Sync Target**: Client requests server metadata to determine sync target (sync boundary, size, and root digest)
121121
- **Dynamic Target Updates**: Client periodically requests target updates during sync to handle new operations added by the server
122122
- **Sync Completion**: Client continues until all operations are applied and state matches server's target
123123
- **Database Closure**: Client closes the database to prepare for next iteration

examples/sync/src/bin/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use commonware_codec::{EncodeShared, Read};
88
use commonware_runtime::{
99
tokio as tokio_runtime, BufferPooler, Clock, Metrics, Network, Runner, Spawner, Storage,
1010
};
11-
use commonware_storage::qmdb::sync;
11+
use commonware_storage::{mmr, qmdb::sync};
1212
use commonware_sync::{
1313
any, crate_version, current, databases::DatabaseType, immutable, keyless, net::Resolver,
1414
Digest, Error, Key,
@@ -60,9 +60,9 @@ struct Config {
6060
async fn target_update_task<E, Op, D>(
6161
context: E,
6262
resolver: Resolver<Op, D>,
63-
update_tx: mpsc::Sender<sync::Target<D>>,
63+
update_tx: mpsc::Sender<sync::Target<mmr::Family, D>>,
6464
interval_duration: Duration,
65-
initial_target: sync::Target<D>,
65+
initial_target: sync::Target<mmr::Family, D>,
6666
) -> Result<(), Error>
6767
where
6868
E: Clock,

examples/sync/src/bin/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,19 @@ where
160160
state.request_counter.inc();
161161

162162
// Get the current database state
163-
let (root, inactivity_floor, size) = {
163+
let (root, sync_boundary, size) = {
164164
let database = state.database.read().await;
165165
(
166166
database.root(),
167-
database.inactivity_floor().await,
167+
database.sync_boundary().await,
168168
database.size().await,
169169
)
170170
};
171171
let response = wire::GetSyncTargetResponse::<Key> {
172172
request_id: request.request_id,
173173
target: Target {
174174
root,
175-
range: non_empty_range!(inactivity_floor, size),
175+
range: non_empty_range!(sync_boundary, size),
176176
},
177177
};
178178

@@ -430,7 +430,7 @@ where
430430
.collect::<String>();
431431
info!(
432432
size = ?database.size().await,
433-
inactivity_floor = ?database.inactivity_floor().await,
433+
sync_boundary = ?database.sync_boundary().await,
434434
root = %root_hex,
435435
"{} database ready",
436436
DB::name()

examples/sync/src/databases/any.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ where
123123
self.bounds().await.end
124124
}
125125

126-
async fn inactivity_floor(&self) -> Location {
127-
self.inactivity_floor_loc()
126+
async fn sync_boundary(&self) -> Location {
127+
self.sync_boundary()
128128
}
129129

130130
fn historical_proof(

examples/sync/src/databases/current.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ where
139139
self.bounds().await.end
140140
}
141141

142-
async fn inactivity_floor(&self) -> Location {
143-
self.inactivity_floor_loc()
142+
async fn sync_boundary(&self) -> Location {
143+
self.sync_boundary()
144144
}
145145

146146
fn historical_proof(

examples/sync/src/databases/immutable.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ where
129129
self.bounds().await.end
130130
}
131131

132-
async fn inactivity_floor(&self) -> Location {
133-
// For Immutable databases, all retained operations are active,
134-
// so the inactivity floor equals the pruning boundary.
135-
self.bounds().await.start
132+
async fn sync_boundary(&self) -> Location {
133+
self.sync_boundary().await
136134
}
137135

138136
fn historical_proof(

examples/sync/src/databases/keyless.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ where
144144
self.bounds().await.end
145145
}
146146

147-
async fn inactivity_floor(&self) -> Location {
148-
self.inactivity_floor_loc()
147+
async fn sync_boundary(&self) -> Location {
148+
self.sync_boundary()
149149
}
150150

151151
async fn historical_proof(

examples/sync/src/databases/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ pub trait Syncable: Sized {
7575
/// Get the total number of operations in the database (including pruned operations).
7676
fn size(&self) -> impl Future<Output = Location<Self::Family>> + Send;
7777

78-
/// Get the inactivity floor, the location below which all operations are inactive.
79-
fn inactivity_floor(&self) -> impl Future<Output = Location<Self::Family>> + Send;
78+
/// Get the most recent location from which this database can safely be synced.
79+
///
80+
/// Callers constructing a sync target should use this value (or any earlier retained
81+
/// location) as the `range.start`.
82+
fn sync_boundary(&self) -> impl Future<Output = Location<Self::Family>> + Send;
8083

8184
/// Get historical proof and operations.
8285
fn historical_proof(

examples/sync/src/net/resolver.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use crate::net::request_id;
33
use commonware_codec::{EncodeShared, IsUnit, Read};
44
use commonware_cryptography::Digest;
55
use commonware_runtime::{Network, Spawner};
6-
use commonware_storage::{mmr::Location, qmdb::sync};
6+
use commonware_storage::{
7+
mmr::{self, Location},
8+
qmdb::sync,
9+
};
710
use commonware_utils::channel::{mpsc, oneshot};
811
use std::num::NonZeroU64;
912

@@ -42,7 +45,7 @@ where
4245
}
4346

4447
/// Returns the current sync target from the server.
45-
pub async fn get_sync_target(&self) -> Result<sync::Target<D>, crate::Error> {
48+
pub async fn get_sync_target(&self) -> Result<sync::Target<mmr::Family, D>, crate::Error> {
4649
let request_id = self.request_id_generator.next();
4750
let request =
4851
wire::Message::GetSyncTargetRequest(wire::GetSyncTargetRequest { request_id });
@@ -75,6 +78,7 @@ where
7578
Op::Cfg: IsUnit,
7679
D: Digest,
7780
{
81+
type Family = mmr::Family;
7882
type Digest = D;
7983
type Op = Op;
8084
type Error = crate::Error;
@@ -86,7 +90,8 @@ where
8690
max_ops: NonZeroU64,
8791
include_pinned_nodes: bool,
8892
_cancel_rx: oneshot::Receiver<()>,
89-
) -> Result<sync::resolver::FetchResult<Self::Op, Self::Digest>, Self::Error> {
93+
) -> Result<sync::resolver::FetchResult<Self::Family, Self::Op, Self::Digest>, Self::Error>
94+
{
9095
let request_id = self.request_id_generator.next();
9196
let request = wire::Message::GetOperationsRequest(wire::GetOperationsRequest {
9297
request_id,

0 commit comments

Comments
 (0)