sui_rpc/light_client/events/config.rs
1use std::time::Duration;
2
3use sui_sdk_types::Address;
4
5/// Configuration for [`super::AuthenticatedEventsClient`].
6///
7/// All fields are public so callers can construct one inline. The
8/// defaults match the upstream reference client's choices unless noted
9/// otherwise.
10#[derive(Clone, Debug)]
11pub struct AuthenticatedEventsConfig {
12 /// The stream id (a Sui address, typically the publishing package's
13 /// id) to subscribe to.
14 pub stream_id: Address,
15
16 /// First checkpoint to read from. `None` means "start from the
17 /// network's current tip at construction time".
18 pub start_checkpoint: Option<u64>,
19
20 /// Maximum number of events to request per `ListEvents` page. The
21 /// server clamps to 1000 per the v2alpha contract.
22 pub page_size: u32,
23
24 /// Buffer capacity of the mpsc channel between the streaming task
25 /// and the consumer. Larger values smooth over bursts; smaller
26 /// values apply more backpressure to the producer.
27 pub channel_capacity: usize,
28
29 /// Maximum number of consecutive RPC errors to tolerate before the
30 /// streaming task gives up and aborts the stream with the last
31 /// error.
32 pub max_connect_retries: u32,
33
34 /// Base backoff between RPC retry attempts. Each subsequent attempt
35 /// waits an additional `retry_backoff`.
36 pub retry_backoff: Duration,
37
38 /// Upper bound on random jitter added to each retry sleep, to avoid
39 /// thundering-herd reconnects when multiple consumers see the same
40 /// failure mode.
41 pub retry_jitter: Duration,
42
43 /// Cadence at which the streaming task fetches the on-chain
44 /// [`EventStreamHead`] and reconciles it against the locally
45 /// replayed MMR. Smaller values release events to the consumer
46 /// faster at the cost of more OCS inclusion-proof round trips.
47 ///
48 /// [`EventStreamHead`]: sui_sdk_types::framework::EventStreamHead
49 pub head_check_interval: Duration,
50}
51
52impl AuthenticatedEventsConfig {
53 /// Construct a config with the [`Default`] field values, scoped to
54 /// the given stream.
55 pub fn new(stream_id: Address) -> Self {
56 Self {
57 stream_id,
58 ..Self::default_for_dummy_stream()
59 }
60 }
61
62 /// Default field values for every field except `stream_id`, which
63 /// has no sensible default. Used by [`Self::new`] and the inline
64 /// builder pattern below.
65 fn default_for_dummy_stream() -> Self {
66 Self {
67 stream_id: Address::ZERO,
68 start_checkpoint: None,
69 page_size: 1000,
70 channel_capacity: 256,
71 max_connect_retries: 5,
72 retry_backoff: Duration::from_millis(500),
73 retry_jitter: Duration::from_millis(250),
74 head_check_interval: Duration::from_secs(30),
75 }
76 }
77}