reth_network/transactions/
policy.rs1use crate::transactions::config::{AnnouncementFilteringPolicy, TransactionPropagationPolicy};
2use std::fmt::Debug;
3
4pub trait TransactionPolicies: Send + Sync + Debug + 'static {
9 type Propagation: TransactionPropagationPolicy;
11 type Announcement: AnnouncementFilteringPolicy;
13
14 fn propagation_policy(&self) -> &Self::Propagation;
16
17 fn propagation_policy_mut(&mut self) -> &mut Self::Propagation;
19
20 fn announcement_filter(&self) -> &Self::Announcement;
22}
23
24#[derive(Debug, Clone, Default)]
31pub struct NetworkPolicies<P, A> {
32 propagation: P,
33 announcement: A,
34}
35
36impl<P, A> NetworkPolicies<P, A> {
37 pub const fn new(propagation: P, announcement: A) -> Self {
39 Self { propagation, announcement }
40 }
41
42 pub fn with_propagation<NewP>(self, new_propagation: NewP) -> NetworkPolicies<NewP, A>
44 where
45 NewP: TransactionPropagationPolicy,
46 {
47 NetworkPolicies::new(new_propagation, self.announcement)
48 }
49
50 pub fn with_announcement<NewA>(self, new_announcement: NewA) -> NetworkPolicies<P, NewA>
52 where
53 NewA: AnnouncementFilteringPolicy,
54 {
55 NetworkPolicies::new(self.propagation, new_announcement)
56 }
57}
58
59impl<P, A> TransactionPolicies for NetworkPolicies<P, A>
60where
61 P: TransactionPropagationPolicy + Debug,
62 A: AnnouncementFilteringPolicy + Debug,
63{
64 type Propagation = P;
65 type Announcement = A;
66
67 fn propagation_policy(&self) -> &Self::Propagation {
68 &self.propagation
69 }
70
71 fn propagation_policy_mut(&mut self) -> &mut Self::Propagation {
72 &mut self.propagation
73 }
74
75 fn announcement_filter(&self) -> &Self::Announcement {
76 &self.announcement
77 }
78}