updat
This commit is contained in:
@@ -17,7 +17,7 @@ use nostr_sdk::prelude::*;
|
||||
use state::UniversalSigner;
|
||||
|
||||
use crate::cache::{self, Observed};
|
||||
use crate::history::{CURSOR_OVERLAP_MS, Window};
|
||||
use crate::history::{CURSOR_OVERLAP, Window};
|
||||
|
||||
/// How much of what a relay stores a cold subscription replays per relay.
|
||||
const LIVE_REPLAY: usize = 500;
|
||||
@@ -35,15 +35,15 @@ pub struct Plane {
|
||||
/// The wrap's author: the control signer for Control, the group's own key otherwise.
|
||||
pub address: PublicKey,
|
||||
pub group: GroupKey,
|
||||
/// Epoch seconds the key behind this plane was retired.
|
||||
pub retired_at: Option<u64>,
|
||||
/// When the rotation that retired this plane's key published.
|
||||
pub retired_at: Option<Timestamp>,
|
||||
}
|
||||
|
||||
impl Plane {
|
||||
/// Whether a wrap sealed under this plane is still inside its key's life.
|
||||
pub fn accepts(&self, wrap: &Event) -> bool {
|
||||
self.retired_at
|
||||
.is_none_or(|retired| wrap.created_at.as_secs() <= retired)
|
||||
.is_none_or(|retired| wrap.created_at <= retired)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ pub fn planes(state: &CommunityState) -> Result<Vec<Plane>> {
|
||||
control_pk: None,
|
||||
retired_at: None,
|
||||
});
|
||||
|
||||
let group = control_group_key(&root.key, &state.id, epoch)?;
|
||||
planes.push(Plane {
|
||||
kind: PlaneKind::Control(epoch),
|
||||
@@ -124,12 +125,12 @@ pub fn plane_filter(planes: &[Plane]) -> Filter {
|
||||
pub fn live_filter(planes: &[Plane], window: Window) -> Filter {
|
||||
let mut filter = plane_filter(planes);
|
||||
|
||||
if let Some(until_ms) = window.until_ms {
|
||||
filter = filter.until(Timestamp::from_secs(until_ms / 1000));
|
||||
if let Some(until) = window.until {
|
||||
filter = filter.until(until);
|
||||
}
|
||||
|
||||
if let Some(since_ms) = window.since_ms {
|
||||
filter = filter.since(Timestamp::from_secs(since_ms / 1000));
|
||||
if let Some(since) = window.since {
|
||||
filter = filter.since(since);
|
||||
}
|
||||
|
||||
filter.limit(LIVE_REPLAY)
|
||||
@@ -140,13 +141,13 @@ pub fn live_window(state: &CommunityState) -> Window {
|
||||
let floor = state
|
||||
.channels
|
||||
.iter()
|
||||
.filter_map(|channel| state.cursors.get(&channel.id)?.newest_ms)
|
||||
.filter_map(|channel| state.cursors.get(&channel.id)?.newest)
|
||||
.min();
|
||||
|
||||
match floor {
|
||||
Some(floor) => Window {
|
||||
since_ms: Some(floor.saturating_sub(CURSOR_OVERLAP_MS)),
|
||||
until_ms: None,
|
||||
since: Some(floor - CURSOR_OVERLAP),
|
||||
until: None,
|
||||
},
|
||||
None => Window::default(),
|
||||
}
|
||||
@@ -213,7 +214,7 @@ where
|
||||
}
|
||||
|
||||
/// Best-effort publication of the genesis wraps to the community's relays.
|
||||
async fn publish_wraps(client: &Client, wraps: &[Event], relays: &[RelayUrl]) {
|
||||
pub(crate) async fn publish_wraps(client: &Client, wraps: &[Event], relays: &[RelayUrl]) {
|
||||
connect_relays(client, relays).await;
|
||||
|
||||
for wrap in wraps {
|
||||
@@ -428,7 +429,7 @@ fn refresh(mut held: CommunityState, fresh: CommunityState) -> CommunityState {
|
||||
Some(held) => {
|
||||
held.name = channel.name;
|
||||
|
||||
if cut.is_some_and(|cut| channel.epoch.0 <= cut) {
|
||||
if cut.is_some_and(|cut| channel.epoch <= cut) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -767,16 +768,16 @@ mod tests {
|
||||
state.cursors.insert(
|
||||
channel,
|
||||
concord::state::ChannelCursor {
|
||||
newest_ms: Some(2_000_000),
|
||||
oldest_ms: Some(1_000),
|
||||
newest: Some(Timestamp::from_secs(2_000_000)),
|
||||
oldest: Some(Timestamp::from_secs(1_000)),
|
||||
exhausted: false,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
live_window(&state),
|
||||
Window {
|
||||
since_ms: Some(2_000_000 - CURSOR_OVERLAP_MS),
|
||||
until_ms: None,
|
||||
since: Some(Timestamp::from_secs(2_000_000) - CURSOR_OVERLAP),
|
||||
until: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1138,7 +1139,7 @@ mod tests {
|
||||
priors: vec![HeldKey {
|
||||
epoch: Epoch(0),
|
||||
key: [0x07; 32],
|
||||
retired_at: Some(1_000),
|
||||
retired_at: Some(Timestamp::from_secs(1_000)),
|
||||
}],
|
||||
}];
|
||||
|
||||
@@ -1148,7 +1149,7 @@ mod tests {
|
||||
.find(|plane| plane.kind == PlaneKind::Channel(channel, Epoch(0)))
|
||||
.expect("the retired epoch keeps a plane");
|
||||
|
||||
assert_eq!(retired.retired_at, Some(1_000));
|
||||
assert_eq!(retired.retired_at, Some(Timestamp::from_secs(1_000)));
|
||||
assert!(retired.accepts(&event_at(1_000_000)));
|
||||
assert!(!retired.accepts(&event_at(1_001_000)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user