update
This commit is contained in:
@@ -172,6 +172,8 @@ pub struct Snapshot {
|
||||
pub state: CommunityState,
|
||||
pub control: ControlFold,
|
||||
pub members: BTreeSet<PublicKey>,
|
||||
/// Wraps the store holds per channel that no held key can open.
|
||||
pub unreadable: BTreeMap<ChannelId, usize>,
|
||||
}
|
||||
|
||||
pub async fn create<S>(
|
||||
@@ -529,6 +531,7 @@ pub async fn fold(client: &Client, state: &CommunityState) -> Result<Option<Snap
|
||||
let mut editions = Vec::new();
|
||||
let mut observed: BTreeMap<PublicKey, u64> = BTreeMap::new();
|
||||
let mut guestbook_rumors = Vec::new();
|
||||
let mut unreadable: BTreeMap<ChannelId, usize> = BTreeMap::new();
|
||||
let mut cached: BTreeMap<ChannelId, BTreeMap<EventId, Observed>> = BTreeMap::new();
|
||||
|
||||
for plane in &planes {
|
||||
@@ -544,19 +547,23 @@ pub async fn fold(client: &Client, state: &CommunityState) -> Result<Option<Snap
|
||||
continue;
|
||||
};
|
||||
|
||||
// A retired key reads only what was sealed before its rotation published.
|
||||
if !plane.accepts(wrap) {
|
||||
continue;
|
||||
}
|
||||
|
||||
match plane.kind {
|
||||
PlaneKind::Control(_) => {
|
||||
// A retired root reads only what was sealed before its rotation.
|
||||
if !plane.accepts(wrap) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(edition) = cord02::open_edition(wrap, &plane.group, &plane.address, true)
|
||||
{
|
||||
editions.push(edition);
|
||||
}
|
||||
}
|
||||
PlaneKind::Guestbook => {
|
||||
if !plane.accepts(wrap) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok((_, rumor)) = cord02::guestbook::open(wrap, &plane.group) {
|
||||
observe(&mut observed, rumor.author, rumor.at_ms);
|
||||
guestbook_rumors.push(rumor);
|
||||
@@ -568,11 +575,18 @@ pub async fn fold(client: &Client, state: &CommunityState) -> Result<Option<Snap
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok((opened, rumor)) =
|
||||
concord::cord03::open(wrap, &plane.group, &channel, epoch)
|
||||
{
|
||||
cache::cache_rumor(client, &channel, &opened).await?;
|
||||
observe(&mut observed, rumor.author, rumor.at_ms);
|
||||
let opened = if plane.accepts(wrap) {
|
||||
concord::cord03::open(wrap, &plane.group, &channel, epoch).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
match opened {
|
||||
Some((opened, rumor)) => {
|
||||
cache::cache_rumor(client, &channel, &opened).await?;
|
||||
observe(&mut observed, rumor.author, rumor.at_ms);
|
||||
}
|
||||
None => *unreadable.entry(channel).or_default() += 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -627,6 +641,7 @@ pub async fn fold(client: &Client, state: &CommunityState) -> Result<Option<Snap
|
||||
state,
|
||||
control,
|
||||
members,
|
||||
unreadable,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1137,4 +1152,43 @@ mod tests {
|
||||
assert!(retired.accepts(&event_at(1_000_000)));
|
||||
assert!(!retired.accepts(&event_at(1_001_000)));
|
||||
}
|
||||
|
||||
/// A wrap addressed to a held channel plane that will not open is counted, so
|
||||
/// the panel can tell a quiet room from one whose history it cannot read.
|
||||
#[test]
|
||||
fn a_fold_counts_the_channel_wraps_it_cannot_open() {
|
||||
smol::block_on(async {
|
||||
let client = client();
|
||||
let keys = Keys::generate();
|
||||
let signer = UniversalSigner::new(keys.clone());
|
||||
|
||||
let created = create(&client, &signer, &metadata("coop"))
|
||||
.await
|
||||
.expect("creates");
|
||||
|
||||
let (channel, plane) = planes(&created)
|
||||
.expect("planes")
|
||||
.into_iter()
|
||||
.find_map(|plane| match plane.kind {
|
||||
PlaneKind::Channel(channel, _) => Some((channel, plane)),
|
||||
_ => None,
|
||||
})
|
||||
.expect("a channel plane");
|
||||
|
||||
// Sealed to the channel's own address, but not a seal at all, so no
|
||||
// held key opens it.
|
||||
let junk = EventBuilder::new(Kind::GiftWrap, "not a seal")
|
||||
.custom_created_at(Timestamp::from_secs(1_700_000_000))
|
||||
.finalize(plane.group.keys())
|
||||
.expect("signs");
|
||||
client.database().save_event(&junk).await.expect("saves");
|
||||
|
||||
let snapshot = fold(&client, &created)
|
||||
.await
|
||||
.expect("folds")
|
||||
.expect("a control plane");
|
||||
|
||||
assert_eq!(snapshot.unreadable.get(&channel).copied(), Some(1));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user