|
29 | 29 | //! let mut last_accepted = None; |
30 | 30 | //! let (accepted_tx, mut accepted_rx) = commonware_utils::channel::mpsc::channel(16); |
31 | 31 | //! |
| 32 | +//! // `is_forward` is application policy, usually based on consensus metadata |
| 33 | +//! // (height, round, view, certificate sequence) associated with each root. |
| 34 | +//! // Roots are hashes and do not have a natural ordering on their own. |
| 35 | +//! |
32 | 36 | //! // Consensus task: insert roots that the chain has made canonical. |
33 | 37 | //! loop { |
34 | 38 | //! let trusted_root = consensus_client.canonical_root_at_tip().await?; |
35 | 39 | //! if let Some(target) = matcher.insert_trusted_root(trusted_root) { |
| 40 | +//! // Join succeeded: this trusted root already had a resolver target cached. |
36 | 41 | //! if is_forward(&last_accepted, &target) { |
37 | 42 | //! last_accepted = Some(target.clone()); |
38 | 43 | //! accepted_tx.clone().send(target).await?; |
|
44 | 49 | //! loop { |
45 | 50 | //! let target = resolver.current_target().await?; |
46 | 51 | //! if let Some(target) = matcher.insert_candidate_target(target) { |
| 52 | +//! // Join succeeded: this target's root was already trusted by consensus. |
47 | 53 | //! if is_forward(&last_accepted, &target) { |
48 | 54 | //! last_accepted = Some(target.clone()); |
49 | 55 | //! accepted_tx.clone().send(target).await?; |
@@ -161,14 +167,10 @@ pub(crate) mod tests; |
161 | 167 | /// describe the same database state. Callers that learn trusted canonical roots from another source |
162 | 168 | /// can cache these targets and use [`TargetMatcher`] to find a target whose root has been trusted |
163 | 169 | /// before passing it to [`sync`]. |
164 | | -pub trait CurrentResolver: Send + Sync + Clone + 'static { |
165 | | - /// Merkle family used by the database. |
166 | | - type Family: Graftable; |
167 | | - /// Root digest type. |
168 | | - type Digest: Digest; |
169 | | - /// Error type returned by the resolver. |
170 | | - type Error: std::error::Error + Send + 'static; |
171 | | - |
| 170 | +pub trait CurrentResolver: qmdb_sync::Resolver |
| 171 | +where |
| 172 | + Self::Family: Graftable, |
| 173 | +{ |
172 | 174 | /// Fetch the latest full authenticated [`Target`]. |
173 | 175 | #[allow(clippy::type_complexity)] |
174 | 176 | fn current_target( |
@@ -1013,10 +1015,6 @@ macro_rules! impl_current_current_resolver { |
1013 | 1015 | S: Strategy, |
1014 | 1016 | $($($where_extra)+)? |
1015 | 1017 | { |
1016 | | - type Family = F; |
1017 | | - type Digest = H::Digest; |
1018 | | - type Error = qmdb::Error<F>; |
1019 | | - |
1020 | 1018 | async fn current_target(&self) -> Result<Target<F, H::Digest>, Self::Error> { |
1021 | 1019 | let hasher = qmdb::hasher::<H>(); |
1022 | 1020 | let witness = self.ops_root_witness(&hasher).await?; |
@@ -1048,10 +1046,6 @@ macro_rules! impl_current_current_resolver { |
1048 | 1046 | S: Strategy, |
1049 | 1047 | $($($where_extra)+)? |
1050 | 1048 | { |
1051 | | - type Family = F; |
1052 | | - type Digest = H::Digest; |
1053 | | - type Error = qmdb::Error<F>; |
1054 | | - |
1055 | 1049 | async fn current_target(&self) -> Result<Target<F, H::Digest>, Self::Error> { |
1056 | 1050 | let db = self.read().await; |
1057 | 1051 | let hasher = qmdb::hasher::<H>(); |
@@ -1084,10 +1078,6 @@ macro_rules! impl_current_current_resolver { |
1084 | 1078 | S: Strategy, |
1085 | 1079 | $($($where_extra)+)? |
1086 | 1080 | { |
1087 | | - type Family = F; |
1088 | | - type Digest = H::Digest; |
1089 | | - type Error = qmdb::Error<F>; |
1090 | | - |
1091 | 1081 | async fn current_target(&self) -> Result<Target<F, H::Digest>, Self::Error> { |
1092 | 1082 | let guard = self.read().await; |
1093 | 1083 | let db = guard.as_ref() |
|
0 commit comments