1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4use tycho_types::cell::HashBytes;
5#[cfg(feature = "server")]
6use {anyhow::Result, bytes::Bytes, futures_util::future::BoxFuture, std::ops::Range};
7
8#[cfg(feature = "server")]
9pub trait MempoolService: Send + Sync + 'static {
10 fn dump_bans(&self) -> Result<Vec<DumpBansItem>>;
12
13 fn dump_events(&self, req: DumpEventsRequest) -> Result<String>;
15
16 fn manual_ban(&self, req: BanRequest) -> BoxFuture<'static, Result<String>>;
19
20 fn manual_unban(&self, peer_id: HashBytes) -> BoxFuture<'static, Result<()>>;
24
25 fn list_events(
31 &self,
32 req: ListEventsRequest,
33 ) -> BoxFuture<'static, Result<Vec<MempoolEventDisplay>>>;
34
35 fn delete_events(&self, millis: Range<u64>) -> BoxFuture<'static, Result<()>>;
40
41 fn get_event_point(&self, point_key: PointKey) -> BoxFuture<'static, Result<Bytes>>;
43}
44
45#[derive(Debug, Serialize, Deserialize)]
46pub struct DumpBansItem {
47 pub peer_id: HashBytes,
48 pub until_millis: u64,
49 pub created_millis: u64,
50 pub record_seq_no: u32,
51}
52
53#[derive(Debug, Serialize, Deserialize)]
54pub struct DumpEventsRequest {
55 pub peer_id: Option<HashBytes>,
56 pub pretty: bool,
57}
58
59#[derive(Debug, Serialize, Deserialize)]
60pub struct BanRequest {
61 pub peer_id: HashBytes,
62 pub duration: Duration,
63 pub pretty: bool,
64}
65
66#[derive(Debug, Serialize, Deserialize)]
67pub struct ListEventsRequest {
68 pub count: u16,
69 pub page: u32,
70 pub asc: bool,
71 pub with_ids: bool,
72}
73
74#[derive(Debug, Serialize, Deserialize)]
75pub struct MempoolEventDisplay {
76 pub created: u64,
77 pub seq_no: u32,
78 pub peer_id: HashBytes,
79 pub points: usize,
80 pub kind: String,
81 pub message: String,
82 pub point_refs: Option<Vec<StoredPointKeyRef>>,
83}
84
85#[derive(Debug, Serialize, Deserialize)]
86pub struct StoredPointKeyRef {
87 pub stored: bool,
88 pub key: PointKey,
89}
90
91#[derive(Debug, Serialize, Deserialize)]
92pub struct PointKey(pub u32, pub HashBytes);